]> Creatis software - gdcm.git/blob - Example/PrintFile.cxx
gdcm::File::IsReadable() is no usable here, because we deal with
[gdcm.git] / Example / PrintFile.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: PrintFile.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/05/03 10:57:27 $
7   Version:   $Revision: 1.35 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18 #include "gdcmFile.h"
19 #include "gdcmDebug.h"
20 #include "gdcmFileHelper.h"
21
22 #include <iostream>
23
24 int main(int argc, char *argv[])
25 {
26    gdcm::File *e1;
27    gdcm::FileHelper   *f1;
28    std::string fileName;
29   
30    if (argc == 1) 
31    {
32       std::cout << " usage : PrintFile fileName printLevel debug "
33           << "short (=NOSEQ + NOSHADOW)" 
34                 << std::endl;
35     return 0;
36    }
37
38    e1 = new gdcm::File();
39
40    if (argc > 1) 
41    {
42       fileName=argv[1];
43    } 
44
45    if (argc > 3)
46       gdcm::Debug::DebugOn();
47  
48    bool res; 
49    if (argc > 4)
50       e1->SetLoadMode(NO_SEQ | NO_SHADOW); 
51
52    // gdcm::File::IsReadable() is no usable here, because we deal with
53    // any kind of gdcm::Readable *document* 
54    // not only gdcm::File (as opposed to gdcm::DicomDir)
55    res = e1->Load( fileName.c_str() );
56    if ( res )
57    {
58       delete e1;
59       return 0;
60    }
61
62    f1 = new gdcm::FileHelper(e1);
63
64    if (argc > 2)  // keep it here (f1 needs to be constructed !)
65    {
66       int level = atoi(argv[2]);   
67       f1->SetPrintLevel(level);
68    }
69
70    f1->Print();   
71
72    std::cout << "\n\n" << std::endl; 
73
74    std::cout <<std::endl;
75    std::cout <<" dataSize " << f1->GetImageDataSize() << std::endl;
76    std::cout <<" dataSizeRaw " << f1->GetImageDataRawSize() << std::endl;
77
78    int nX,nY,nZ,sPP,planarConfig;
79    std::string pixelType;
80    nX=e1->GetXSize();
81    nY=e1->GetYSize();
82    nZ=e1->GetZSize();
83    std::cout << " DIMX=" << nX << " DIMY=" << nY << " DIMZ=" << nZ << std::endl;
84
85    pixelType    = e1->GetPixelType();
86    sPP          = e1->GetSamplesPerPixel();
87    planarConfig = e1->GetPlanarConfiguration();
88    
89    std::cout << " pixelType= ["           << pixelType 
90              << "] SamplesPerPixel= ["     << sPP
91              << "] PlanarConfiguration= [" << planarConfig 
92              << "] "<< std::endl 
93              << " PhotometricInterpretation= [" 
94                                 << e1->GetEntryValue(0x0028,0x0004)
95              << "] "<< std::endl;
96
97    int numberOfScalarComponents=e1->GetNumberOfScalarComponents();
98    std::cout << " NumberOfScalarComponents = " << numberOfScalarComponents <<std::endl
99              << " LUT = " << (e1->HasLUT() ? "TRUE" : "FALSE")
100              << std::endl;
101
102   
103    if ( e1->GetEntryValue(0x0002,0x0010) == gdcm::GDCM_NOTLOADED ) 
104    {
105       std::cout << "Transfer Syntax not loaded. " << std::endl
106                 << "Better you increase MAX_SIZE_LOAD_ELEMENT_VALUE"
107                 << std::endl;
108       return 0;
109    }
110   
111    std::string transferSyntaxName = e1->GetTransferSyntaxName();
112    std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl;
113    std::cout << " SwapCode= " << e1->GetSwapCode() << std::endl;
114    
115    if(e1->IsReadable())
116       std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
117    else
118       std::cout <<std::endl<<fileName<<" is NOT Readable"<<std::endl;
119    std::cout<<std::flush;
120    delete e1;
121    delete f1;
122
123    return 0;
124    
125 }