]> Creatis software - gdcm.git/blob - Testing/TestPrintAllDocument.cxx
1b19d7949119d86f5ad1f0449dc826fa048bca12
[gdcm.git] / Testing / TestPrintAllDocument.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestPrintAllDocument.cxx,v $
5   Language:  C++
6   Date:      $Date: 2006/04/07 10:58:51 $
7   Version:   $Revision: 1.13 $
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
19 // TODO : check what's *actually* usefull
20
21 #include "gdcmDictEntry.h"
22 #include "gdcmDict.h"
23 #include "gdcmDictSet.h"
24 #include "gdcmFile.h"
25 #include "gdcmUtil.h"
26 #include "gdcmCommon.h"
27 #include "gdcmDocEntry.h" 
28 #include "gdcmDocEntrySet.h"           
29 #include "gdcmDocument.h"          
30 #include "gdcmElementSet.h"        
31 #include "gdcmSeqEntry.h" 
32 #include "gdcmSQItem.h" 
33 #include "gdcmOrientation.h"
34 #include <fstream>
35 #include <iostream>
36 #include <iomanip> // for std::ios::left, ...
37
38 //Generated file:
39 #include "gdcmDataImages.h"
40
41 int TestPrintAllDocument(int argc, char *argv[])
42 {
43    //std::ostringstream s;
44    int i = 0;
45    int swapC;
46    unsigned int j;
47    std::string pixelType, photomInterp;
48    int l;
49    l = strlen("PALETTE COLOR ");
50    
51    //gdcm::Debug::DebugOn();
52    
53    while( gdcmDataImages[i] != 0 )
54    {
55       std::string filename;      
56       if (argc ==2)
57       {
58          filename = argv[1];
59       }
60       else
61       {
62          filename = GDCM_DATA_ROOT;
63          filename += "/";  //doh!      
64          filename += gdcmDataImages[i];
65       }
66       
67       std::cout << " ----------------------------------------------"
68                 << "Begin with " << filename << std::endl;
69
70       gdcm::File *f= gdcm::File::New( );
71       f->SetFileName( filename );
72       f->Load();
73
74       f->SetPrintLevel(2);
75       f->Print();
76       
77       //s.setf(std::ios::left);
78       //s << std::setw(60-filename.length()) << " ";
79       //std::cout << s.str() << gdcmDataImages[i];
80
81       std::cout << gdcmDataImages[i];
82
83       unsigned int nbSpaces;
84       if (strlen(gdcmDataImages[i]) <= 60)
85          nbSpaces = 60-strlen(gdcmDataImages[i]);
86       else
87          nbSpaces = 0;
88       for (j=0; j<nbSpaces; j++)
89          std::cout << " ";    
90
91       pixelType = f->GetPixelType();
92       std::cout << " pixelType="            << pixelType;
93       if ( pixelType == "8U" || pixelType == "8S" )
94          std::cout << " ";
95       std::cout << " Smpl.P.Pix.="          << f->GetSamplesPerPixel()
96                 << " Plan.Config.="         << f->GetPlanarConfiguration();
97  
98       photomInterp =  f->GetEntryString(0x0028,0x0004);               
99       std::cout << " Photom.Interp.="       << photomInterp;
100       for (j=0; j<l-photomInterp.length(); j++)
101          std::cout << " ";
102  
103       std::cout << " TransferSyntaxName= [" << f->GetTransferSyntaxName() << "]" ;
104
105       swapC = f->GetSwapCode();
106       if ( swapC != 1234 )
107           std::cout << " SwapCode = "       << f->GetSwapCode(); 
108       if ( f->CheckIfEntryExist(0x0088,0x0200) )
109           std::cout << " Icon Image Sequence";
110
111       std::cout << std::endl;
112
113       std::string strImageOrientationPatient = 
114                                           f->GetEntryString(0x0020,0x0037);
115       if ( strImageOrientationPatient != gdcm::GDCM_UNFOUND )
116       {
117          gdcm::Orientation *o = gdcm::Orientation::New();
118  
119          gdcm::OrientationType orient = o->GetOrientationType( f );
120          std::cout << " ---------------------- Orientation " << orient
121                    << std::endl;
122          o->Delete(); 
123       }
124
125       if( f->IsReadable() )
126       {
127          std::cout <<filename << " is Readable" 
128                    << std::endl << std::endl;
129       }
130       else
131       {
132          std::cout << filename << " is NOT Readable" 
133                    << std::endl << std::endl;
134          f->Delete();
135          return 1;
136       }
137       f->Delete();
138       
139       if (argc ==2)
140          break; // user asked to check a single file.      
141       
142       i++;
143    }
144    return 0;
145 }