]> Creatis software - gdcm.git/blob - Example/PrintFile.cxx
Sometimes a Warning is an error !
[gdcm.git] / Example / PrintFile.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: PrintFile.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/06/17 14:36:19 $
7   Version:   $Revision: 1.40 $
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    "        showlut  : user wants to display the Palette Color (as an int array)",
38    FINISH_USAGE
39
40    // Initialize Arguments Manager   
41    gdcm::ArgMgr *am= new gdcm::ArgMgr(argc, argv);
42   
43    if (argc == 1)
44    {
45       am->ArgMgrUsage(usage); // Display 'usage'
46       delete am;
47       return 0;
48    }
49
50    char *fileName = am->ArgMgrWantString("filein",usage);
51
52    int loadMode;
53    if ( am->ArgMgrDefined("noshadow") && am->ArgMgrDefined("noseq") )
54        loadMode = NO_SEQ | NO_SHADOW;  
55    else if ( am->ArgMgrDefined("noshadow") )
56       loadMode = NO_SHADOW;
57    else if ( am->ArgMgrDefined("noseq") )
58       loadMode = NO_SEQ;
59    else
60       loadMode = 0;
61
62    int level = am->ArgMgrGetInt("level", 2);
63
64    if (am->ArgMgrDefined("debug"))
65       gdcm::Debug::DebugOn();
66
67    bool showlut = ( 0 != am->ArgMgrDefined("SHOWLUT") );
68  
69    /* if unused Param we give up */
70    if ( am->ArgMgrPrintUnusedLabels() )
71    { 
72       am->ArgMgrUsage(usage);
73       delete am;
74       return 0;
75    } 
76
77    delete am;  // we don't need Argument Manager any longer
78
79    // ----------- End Arguments Manager ---------
80  
81    // gdcm::File::IsReadable() is no usable here, because we deal with
82    // any kind of gdcm-Parsable *document* 
83    // not only gdcm::File (as opposed to gdcm::DicomDir)
84
85    gdcm::File *e1 = new gdcm::File();
86    e1->SetLoadMode(loadMode);
87
88    bool res = e1->Load( fileName );
89    if ( !res )
90    {
91       delete e1;
92       return 0;
93    }
94
95    gdcm::FileHelper *f1 = new gdcm::FileHelper(e1);
96    f1->SetPrintLevel( level );
97
98    f1->Print();   
99
100    std::cout << "\n\n" << std::endl; 
101
102    std::cout <<std::endl;
103    std::cout <<" dataSize    " << f1->GetImageDataSize()    << std::endl;
104    std::cout <<" dataSizeRaw " << f1->GetImageDataRawSize() << std::endl;
105
106    int nX,nY,nZ,sPP,planarConfig;
107    std::string pixelType;
108    nX=e1->GetXSize();
109    nY=e1->GetYSize();
110    nZ=e1->GetZSize();
111    std::cout << " DIMX=" << nX << " DIMY=" << nY << " DIMZ=" << nZ << std::endl;
112
113    pixelType    = e1->GetPixelType();
114    sPP          = e1->GetSamplesPerPixel();
115    planarConfig = e1->GetPlanarConfiguration();
116    
117    std::cout << " pixelType= ["            << pixelType 
118              << "] SamplesPerPixel= ["     << sPP
119              << "] PlanarConfiguration= [" << planarConfig 
120              << "] "<< std::endl 
121              << " PhotometricInterpretation= [" 
122                                 << e1->GetEntryValue(0x0028,0x0004)
123              << "] "<< std::endl;
124
125    int numberOfScalarComponents=e1->GetNumberOfScalarComponents();
126    std::cout << " NumberOfScalarComponents = " << numberOfScalarComponents 
127              <<std::endl
128              << " LUT = " << (e1->HasLUT() ? "TRUE" : "FALSE")
129              << std::endl;
130
131    if ( e1->GetEntryValue(0x0002,0x0010) == gdcm::GDCM_NOTLOADED ) 
132    {
133       std::cout << "Transfer Syntax not loaded. " << std::endl
134                 << "Better you increase MAX_SIZE_LOAD_ELEMENT_VALUE"
135                 << std::endl;
136       return 0;
137    }
138   
139    std::string transferSyntaxName = e1->GetTransferSyntaxName();
140    std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" 
141              << std::endl;
142    std::cout << " SwapCode= " << e1->GetSwapCode() << std::endl;
143  
144    // Display the LUT as an int array (for degugging purpose)
145    if ( e1->HasLUT() && showlut )
146    {
147       uint8_t* lutrgba = f1->GetLutRGBA();
148       if ( lutrgba == 0 )
149       {
150          std::cout << "Lut RGBA not built ?!?" << std::endl;
151       }
152       else
153       {
154          if ( f1->GetLutItemSize() == 8 )
155          {
156             for (int i=0;i<f1->GetLutItemNumber();i++)
157                std::cout << (int)(lutrgba[i*4])   << " "
158                          << (int)(lutrgba[i*4+1]) << " "
159                          << (int)(lutrgba[i*4+2]) << std::endl;
160          }
161          else // LutItemSize assumed to be = 16
162          {
163             uint16_t* lutrgba16 = (uint16_t*)lutrgba;
164             for (int i=0;i<f1->GetLutItemNumber();i++)
165                std::cout << lutrgba16[i*4]   << " "
166                          << lutrgba16[i*4+1] << " "
167                          << lutrgba16[i*4+2] << std::endl;
168          }
169       }
170    }
171      
172    if(e1->IsReadable())
173       std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
174    else
175       std::cout <<std::endl<<fileName<<" is NOT Readable"<<std::endl;
176    std::cout<<std::flush;
177    delete e1;
178    delete f1;
179    return 0;   
180 }