]> Creatis software - gdcm.git/blob - Example/PrintFile.cxx
Use Argument Manager in 'utilities'
[gdcm.git] / Example / PrintFile.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: PrintFile.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/06/07 11:12:10 $
7   Version:   $Revision: 1.38 $
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 "gdcmFileHelper.h"
20 #include "gdcmDebug.h"
21
22 #include "gdcmArgMgr.h"
23
24 #include <iostream>
25
26 int main(int argc, char *argv[])
27 {
28
29    START_USAGE(usage)
30    " \n PrintFile : \n",
31    " Display the header of a ACR-NEMA/PAPYRUS/DICOM File",
32    " usage: PrintFile filein=fileName [level=n] [noshadow] [noseq] [debug] ",
33    "        level = 0,1,2 : depending on the amount of details user wants to see",
34    "        noshadow : user doesn't want to load Private groups (odd number)",
35    "        noseq    : user doesn't want to load Sequences ",
36    "        debug    : user wants to run the program in 'debug mode' ",
37    FINISH_USAGE
38
39    // Initialize Arguments Manager   
40    gdcm::ArgMgr *am= new gdcm::ArgMgr(argc, argv);
41   
42    if (argc == 1)
43    {
44       am->ArgMgrUsage(usage); // Display 'usage'
45       delete am;
46       return 0;
47    }
48
49    char *fileName = am->ArgMgrWantString("filein",usage);
50
51    int loadMode;
52    if ( am->ArgMgrDefined("noshadow") && am->ArgMgrDefined("noseq") )
53        loadMode = NO_SEQ | NO_SHADOW;  
54    else if ( am->ArgMgrDefined("noshadow") )
55       loadMode = NO_SHADOW;
56    else if ( am->ArgMgrDefined("noseq") )
57       loadMode = NO_SEQ;
58    else
59       loadMode = 0;
60
61    int level = am->ArgMgrGetInt("level", 2);
62
63    if (am->ArgMgrDefined("debug"))
64       gdcm::Debug::DebugOn();
65
66    /* if unused Param we give up */
67    if ( am->ArgMgrPrintUnusedLabels() )
68    { 
69       am->ArgMgrUsage(usage);
70       delete am;
71       return 0;
72    } 
73  
74    // gdcm::File::IsReadable() is no usable here, because we deal with
75    // any kind of gdcm-Parsable *document* 
76    // not only gdcm::File (as opposed to gdcm::DicomDir)
77
78    gdcm::File *e1 = new gdcm::File();
79    e1->SetLoadMode(loadMode);
80
81    bool res = e1->Load( fileName );
82    if ( !res )
83    {
84       delete e1;
85       delete am;
86       return 0;
87    }
88
89    gdcm::FileHelper *f1 = new gdcm::FileHelper(e1);
90    f1->SetPrintLevel( level );
91
92    f1->Print();   
93
94    std::cout << "\n\n" << std::endl; 
95
96    std::cout <<std::endl;
97    std::cout <<" dataSize    " << f1->GetImageDataSize()    << std::endl;
98    std::cout <<" dataSizeRaw " << f1->GetImageDataRawSize() << std::endl;
99
100    int nX,nY,nZ,sPP,planarConfig;
101    std::string pixelType;
102    nX=e1->GetXSize();
103    nY=e1->GetYSize();
104    nZ=e1->GetZSize();
105    std::cout << " DIMX=" << nX << " DIMY=" << nY << " DIMZ=" << nZ << std::endl;
106
107    pixelType    = e1->GetPixelType();
108    sPP          = e1->GetSamplesPerPixel();
109    planarConfig = e1->GetPlanarConfiguration();
110    
111    std::cout << " pixelType= ["            << pixelType 
112              << "] SamplesPerPixel= ["     << sPP
113              << "] PlanarConfiguration= [" << planarConfig 
114              << "] "<< std::endl 
115              << " PhotometricInterpretation= [" 
116                                 << e1->GetEntryValue(0x0028,0x0004)
117              << "] "<< std::endl;
118
119    int numberOfScalarComponents=e1->GetNumberOfScalarComponents();
120    std::cout << " NumberOfScalarComponents = " << numberOfScalarComponents <<std::endl
121              << " LUT = " << (e1->HasLUT() ? "TRUE" : "FALSE")
122              << std::endl;
123
124   
125    if ( e1->GetEntryValue(0x0002,0x0010) == gdcm::GDCM_NOTLOADED ) 
126    {
127       std::cout << "Transfer Syntax not loaded. " << std::endl
128                 << "Better you increase MAX_SIZE_LOAD_ELEMENT_VALUE"
129                 << std::endl;
130       return 0;
131    }
132   
133    std::string transferSyntaxName = e1->GetTransferSyntaxName();
134    std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl;
135    std::cout << " SwapCode= " << e1->GetSwapCode() << std::endl;
136    
137    if(e1->IsReadable())
138       std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
139    else
140       std::cout <<std::endl<<fileName<<" is NOT Readable"<<std::endl;
141    std::cout<<std::flush;
142    delete e1;
143    delete f1;
144    delete am;
145    return 0;
146    
147 }