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