]> Creatis software - gdcm.git/blob - Example/PrintFile.cxx
User may now choose whether he wants to load Shadow Groups and Sequences or not
[gdcm.git] / Example / PrintFile.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: PrintFile.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/04/05 10:28:59 $
7   Version:   $Revision: 1.31 $
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    if (argc > 4)
49       e1->SetLoadMode(NO_SEQ | NO_SHADOW);
50    
51    e1->Load( fileName.c_str() );
52
53    f1 = new gdcm::FileHelper(e1);
54
55    if (argc > 2)  // keep it here (f1 needs to be constructed !)
56    {
57       int level = atoi(argv[2]);   
58       f1->SetPrintLevel(level);
59    }
60
61    f1->Print();   
62
63    std::cout << "\n\n" << std::endl; 
64
65    std::cout <<std::endl;
66    std::cout <<" dataSize " << f1->GetImageDataSize() << std::endl;
67    std::cout <<" dataSizeRaw " << f1->GetImageDataRawSize() << std::endl;
68
69    int nX,nY,nZ,sPP,planarConfig;
70    std::string pixelType;
71    nX=e1->GetXSize();
72    nY=e1->GetYSize();
73    nZ=e1->GetZSize();
74    std::cout << " DIMX=" << nX << " DIMY=" << nY << " DIMZ=" << nZ << std::endl;
75
76    pixelType    = e1->GetPixelType();
77    sPP          = e1->GetSamplesPerPixel();
78    planarConfig = e1->GetPlanarConfiguration();
79    
80    std::cout << " pixelType= ["           << pixelType 
81              << "] SamplesPerPixel= ["     << sPP
82              << "] PlanarConfiguration= [" << planarConfig 
83              << "] "<< std::endl 
84              << " PhotometricInterpretation= [" 
85                                 << e1->GetEntryValue(0x0028,0x0004)
86              << "] "<< std::endl;
87
88    int numberOfScalarComponents=e1->GetNumberOfScalarComponents();
89    std::cout << " NumberOfScalarComponents = " << numberOfScalarComponents <<std::endl
90              << " LUT = " << (e1->HasLUT() ? "TRUE" : "FALSE")
91              << std::endl;
92
93   
94    if ( e1->GetEntryValue(0x0002,0x0010) == gdcm::GDCM_NOTLOADED ) 
95    {
96       std::cout << "Transfer Syntax not loaded. " << std::endl
97                 << "Better you increase MAX_SIZE_LOAD_ELEMENT_VALUE"
98                 << std::endl;
99       return 0;
100    }
101   
102    std::string transferSyntaxName = e1->GetTransferSyntaxName();
103    std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl;
104    std::cout << " SwapCode= " << e1->GetSwapCode() << std::endl;
105    
106    if(e1->IsReadable())
107       std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
108    else
109       std::cout <<std::endl<<fileName<<" is NOT Readable"<<std::endl;
110    std::cout<<std::flush;
111    delete e1;
112    delete f1;
113
114    return 0;
115    
116 }