]> Creatis software - gdcm.git/blob - Example/PrintFile.cxx
Now user can ask for making a DICOMDIR after anonymization.
[gdcm.git] / Example / PrintFile.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: PrintFile.cxx,v $
5   Language:  C++
6   Date:      $Date: 2007/11/08 18:14:55 $
7   Version:   $Revision: 1.88 $
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 "gdcmDocument.h"
20 #include "gdcmSeqEntry.h"
21 #include "gdcmSQItem.h"
22 #include "gdcmDataEntry.h"
23
24 #include "gdcmFileHelper.h"
25 #include "gdcmDebug.h"
26 #include "gdcmDirList.h"
27 #include "gdcmGlobal.h"
28 #include "gdcmDictSet.h"
29 #include "gdcmArgMgr.h"
30 #include "gdcmOrientation.h"
31 #include <iostream>
32
33 /// \todo : code factorization, for 'single file' an 'whole directory' processing
34
35 void ShowLutData(GDCM_NAME_SPACE::File *f);
36
37      // Nothing is written yet to get LUT Data user friendly
38      // The following is to be moved into a PixelReadConvert method
39      // Let here, waiting for a clever idea on the way to do it.
40
41 void ShowLutData(GDCM_NAME_SPACE::File *f)
42 {  
43    GDCM_NAME_SPACE::SeqEntry *modLutSeq = f->GetSeqEntry(0x0028,0x3000);
44    if ( modLutSeq !=0 )
45    {
46       GDCM_NAME_SPACE::SQItem *sqi= modLutSeq->GetFirstSQItem();
47       if ( sqi != 0 )
48       {
49          std::string lutDescriptor = sqi->GetEntryString(0x0028,0x3002);
50          if (   /*lutDescriptor   == GDCM_UNFOUND*/ 0 )
51          {
52             std::cout << "LUT Descriptor is missing" << std::endl;
53             return;
54          }
55          int length;   // LUT length in Bytes
56          int deb;      // Subscript of the first Lut Value
57          int nbits;    // Lut item size (in Bits)
58
59          int nbRead;    // nb of items in LUT descriptor (must be = 3)
60
61          nbRead = sscanf( lutDescriptor.c_str(),
62                            "%d\\%d\\%d",
63                               &length, &deb, &nbits );
64          std::cout << "length " << length 
65                   << " deb " << deb 
66                   << " nbits " << nbits
67                   << std::endl;
68          if ( nbRead != 3 )
69          {
70             std::cout << "Wrong LUT descriptor" << std::endl;
71          }
72          //LUT Data (CTX dependent)    
73          GDCM_NAME_SPACE::DataEntry *b = sqi->GetDataEntry(0x0028,0x3006); 
74          if ( b != 0 )
75          { 
76             int BitsAllocated = f->GetBitsAllocated();
77             if ( BitsAllocated <= 8 )
78             { 
79                int mult;
80                if ( ( nbits == 16 ) && ( BitsAllocated == 8 ) )
81                {
82                // when LUT item size is different than pixel size
83                   mult = 2; // high byte must be = low byte
84                }
85                else
86                {
87                // See PS 3.3-2003 C.11.1.1.2 p 619
88                   mult = 1;
89                }
90                uint8_t *lut = b->GetBinArea();
91                for( int i=0; i < length; ++i )
92                {
93                   std::cout << i+deb << " : \t"
94                               << (int) (lut[i*mult + 1]) << std::endl;
95                }
96             }
97             else
98             {
99                uint16_t *lut = (uint16_t *)(b->GetBinArea());  
100                for( int i=0; i < length; ++i )
101                {
102                   std::cout << i+deb << " : \t"
103                               << (int) (((uint16_t *)lut)[i])
104                               << std::endl;
105                }             
106             }
107          }  
108          else
109             std::cout << "No LUT Data DataEntry (0x0028,0x3006) found?!? " 
110                         << std::endl;
111       }
112       else
113          std::cout << "No First SQ Item within (0x0028,0x3000) ?!? " 
114                      << std::endl;      
115    }
116    else
117       std::cout << "No LUT Data SeqEntry (0x0028,0x3000) found " 
118                   << std::endl;
119 }
120
121 int main(int argc, char *argv[])
122 {
123
124    START_USAGE(usage)
125    " \n PrintFile : \n                                                        ",
126    " Display the header of a ACR-NEMA/PAPYRUS/DICOM File                      ",
127    " usage: PrintFile {filein=inputFileName|dirin=inputDirectoryName}[level=n]",
128    "                       [forceload=listOfElementsToForceLoad] [rec] [noex] ",
129    "                       [4DLoc= ][dict= privateDirectory]                  ",
130    "                       [ { [noshadowseq] | [noshadow][noseq] } ]          ",
131    "                       [debug] [warning]                                  ",
132    "      level = 0,1,2 : depending on the amount of details user wants to see",
133    "      rec : user wants to parse recursively the directory                 ",
134    "      noex : user doen't want extra 'user friendly' info                  ",   
135    "      4DLoc: group-elem(in hexa, no space) of the DataEntry holdind 4thDim",
136    "      listOfElementsToForceLoad : group-elem,g2-e2,... (in hexa, no space)",
137    "                                of Elements to load whatever their length ",
138    "      privateDirectory : source file full path name of Shadow Group elems ",
139    "      noshadowseq: user doesn't want to load Private Sequences            ",
140    "      noshadow   : user doesn't want to load Private groups (odd number)  ",
141    "      noseq      : user doesn't want to load Sequences                    ",
142    "      debug      : user wants to run the program in 'debug mode'          ",
143    "      warning    : user wants to be warned about any oddity in the File   ",
144    "      showlut :user wants to display the Palette Color (as an int array)  ",
145    FINISH_USAGE
146
147    // Initialize Arguments Manager   
148    GDCM_NAME_SPACE::ArgMgr *am= new GDCM_NAME_SPACE::ArgMgr(argc, argv);
149   
150    if (argc == 1 || am->ArgMgrDefined("usage") )
151    {
152       am->ArgMgrUsage(usage); // Display 'usage'
153       delete am;
154       return 1;
155    }
156
157    const char *fileName = am->ArgMgrGetString("filein");
158    const char *dirName  = am->ArgMgrGetString("dirin");
159
160    if ( (fileName == 0 && dirName == 0) ||
161         (fileName != 0 && dirName != 0) )
162    {
163       std::cerr << std::endl
164         << "Either 'filein=' or 'dirin=' must be present;" 
165         << std::endl << "Not both" << std::endl;
166       am->ArgMgrUsage(usage); // Display 'usage'  
167       delete am;
168       return 1;
169    }   
170       
171    bool noex = ( 0 != am->ArgMgrDefined("noex") );
172    bool rec  = ( 0 != am->ArgMgrDefined("rec") );   
173         
174    if (am->ArgMgrDefined("debug"))
175       GDCM_NAME_SPACE::Debug::DebugOn();
176
177    if (am->ArgMgrDefined("warning"))
178       GDCM_NAME_SPACE::Debug::WarningOn();
179        
180    int loadMode = GDCM_NAME_SPACE::LD_ALL;
181    if ( am->ArgMgrDefined("noshadowseq") )
182       loadMode |= GDCM_NAME_SPACE::LD_NOSHADOWSEQ;
183    else 
184    {
185       if ( am->ArgMgrDefined("noshadow") )
186          loadMode |= GDCM_NAME_SPACE::LD_NOSHADOW;
187       if ( am->ArgMgrDefined("noseq") )
188          loadMode |= GDCM_NAME_SPACE::LD_NOSEQ;
189    }
190
191    int level = am->ArgMgrGetInt("level", 1);
192
193    int forceLoadNb;
194    uint16_t *elemsToForceLoad 
195                            = am->ArgMgrGetXInt16Enum("forceload", &forceLoadNb);
196
197    int nbP =0;
198    uint16_t *FourthDimLoc;
199    if ( am->ArgMgrDefined("4DLoc") )
200    {
201       FourthDimLoc = am->ArgMgrGetXInt16Enum("4DLoc", &nbP);
202    
203       if (nbP != 1) 
204       {   
205          std::cout << "4DLoc must have 2 and only 2 components!" << std::endl;
206          delete am;
207          return 1;      
208       }
209    }
210
211    bool showlut = ( 0 != am->ArgMgrDefined("SHOWLUT") );
212
213    bool ddict = am->ArgMgrDefined("dict") ? true : false;
214    const char *dict = 0;
215
216    if (ddict)
217    {
218      dict = am->ArgMgrGetString("dict",0);
219    }
220
221    /* if unused Param we give up */
222    if ( am->ArgMgrPrintUnusedLabels() )
223    {
224       am->ArgMgrUsage(usage);
225       delete am;
226       return 1;
227    } 
228
229    delete am;  // we don't need Argument Manager any longer
230
231    // ----------- End Arguments Manager ---------
232
233
234    if (ddict)
235    {
236       GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->AddDict(dict);
237    }
238
239    if ( fileName != 0 ) // ====== Deal with a single file ======
240    {
241       GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
242       f->SetLoadMode(loadMode);
243       f->SetFileName( fileName );
244    f->SetMaxSizeLoadEntry(0xffff);
245
246       for (int ri=0; ri<forceLoadNb; ri++)
247       {
248          f->AddForceLoadElement((uint32_t)elemsToForceLoad[2*ri], 
249                                 (uint32_t)elemsToForceLoad[2*ri+1] );
250       }
251 // TODO : find why such a polution
252 // To avoid polluting the output with messages
253 // 'Last system error was : No such file or directory'
254
255 errno = 0; 
256
257
258       bool res = false;
259       try
260         {
261         f->Load();
262         }
263       catch(std::exception &ex)
264         {
265         std::cerr << "sorry an exception was thrown: " << ex.what() << std::endl;
266         }
267       // GDCM_NAME_SPACE::File::IsReadable() is no usable here, because we deal with
268       // any kind of gdcm-Parsable *document*
269       // not only GDCM_NAME_SPACE::File (as opposed to GDCM_NAME_SPACE::DicomDir)
270       if ( !res )
271       {
272          std::cout << "Cannot process file [" << fileName << "]" << std::endl;
273          std::cout << "Either it doesn't exist, or it's read protected "
274                    << std::endl;
275          std::cout << "or it's not a Dicom File, or its 'header' is bugged"
276                    << std::endl;
277          std::cout << "use 'PrintFile filein=... debug' to try to guess the pb"
278                    << std::endl;
279          f->Delete();
280          return 0;
281       }
282
283       if (nbP == 1)
284          f->SetFourthDimensionLocation(FourthDimLoc[0],FourthDimLoc[1]);
285
286
287       GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f);
288       fh->SetPrintLevel( level );
289
290       fh->Print();
291
292       std::cout << "\n\n" << std::endl;
293
294       std::cout <<std::endl;
295       std::cout <<" dataSize    " << fh->GetImageDataSize()    << std::endl;
296       std::cout <<" dataSizeRaw " << fh->GetImageDataRawSize() << std::endl;
297 if (!noex)
298 {
299       int nX,nY,nZ,nT,sPP,planarConfig;
300       std::string pixelType;
301       nX=f->GetXSize();
302       nY=f->GetYSize();
303       nZ=f->GetZSize();
304       nT=f->GetTSize();
305       std::cout << " DIMX=" << nX << " DIMY=" << nY 
306                 << " DIMZ=" << nZ << " DIMT=" << nT
307                 << std::endl;
308
309       pixelType    = f->GetPixelType();
310       sPP          = f->GetSamplesPerPixel();
311       std::cout << " pixelType= ["            << pixelType 
312                 << "] SamplesPerPixel= ["     << sPP
313                 << "] ";
314
315       if (sPP == 3)
316       {
317          planarConfig = f->GetPlanarConfiguration();
318          std::cout << " PlanarConfiguration= [" << planarConfig 
319                 << "] "<< std::endl;
320       } 
321       std::cout << " PhotometricInterpretation= [" 
322                 << f->GetEntryString(0x0028,0x0004)
323                 << "] "<< std::endl;
324
325       int numberOfScalarComponents=f->GetNumberOfScalarComponents();
326       std::cout << " NumberOfScalarComponents = " << numberOfScalarComponents 
327                 <<std::endl
328                 << " LUT = " << (f->HasLUT() ? "TRUE" : "FALSE")
329                 << std::endl;
330
331       if ( f->GetDataEntry(0x0002,0x0010) )
332          if ( f->GetDataEntry(0x0002,0x0010)->IsNotLoaded() ) 
333          {
334             std::cout << "Transfer Syntax not loaded. " << std::endl
335                      << "Better you increase MAX_SIZE_LOAD_ELEMENT_VALUE"
336                   << std::endl;
337             f->Delete();
338             return 0;
339          }
340   
341       std::string transferSyntaxName = f->GetTransferSyntaxName();
342       std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" 
343                 << std::endl;
344       std::cout << " SwapCode= " << f->GetSwapCode() << std::endl;
345       std::cout << " ------" << std::endl;
346
347       std::cout << "\n\n" << std::endl; 
348       std::cout << "X spacing " << f->GetXSpacing() << std::endl;
349       std::cout << "Y spacing " << f->GetYSpacing() << std::endl;
350       std::cout << "Z spacing " << f->GetZSpacing() << std::endl;
351     
352 //------------------------------
353
354       // Let's get and print some usefull fields about 'Orientation'
355       // ------------------------------------------------------------
356
357       std::string strPatientPosition = 
358                                       f->GetEntryString(0x0018,0x5100);
359       if ( strPatientPosition != GDCM_NAME_SPACE::GDCM_UNFOUND 
360         && strPatientPosition != "" )  
361             std::cout << "PatientPosition (0x0010,0x5100)= [" 
362                       << strPatientPosition << "]" << std::endl;
363  
364       std::string strViewPosition = 
365                                       f->GetEntryString(0x0018,0x5101);
366       if ( strViewPosition != GDCM_NAME_SPACE::GDCM_UNFOUND 
367         && strViewPosition != "" )  
368             std::cout << "View Position (0x0018,0x5101)= [" 
369                       << strViewPosition << "]" << std::endl;
370       
371      std::string strPatientOrientation = 
372                                       f->GetEntryString(0x0020,0x0020);
373       if ( strPatientOrientation != GDCM_NAME_SPACE::GDCM_UNFOUND
374         && strPatientOrientation != "")  
375          std::cout << "PatientOrientation (0x0020,0x0020)= [" 
376                    << strPatientOrientation << "]" << std::endl;
377
378       std::string strImageOrientationPatient = 
379                                       f->GetEntryString(0x0020,0x0037);  
380       if ( strImageOrientationPatient != GDCM_NAME_SPACE::GDCM_UNFOUND
381         && strImageOrientationPatient != "" )  
382          std::cout << "ImageOrientationPatient (0x0020,0x0037)= [" 
383                    << strImageOrientationPatient << "]" << std::endl;
384
385       std::string strImageOrientationRET = 
386                                       f->GetEntryString(0x0020,0x0035);
387       if ( strImageOrientationRET != GDCM_NAME_SPACE::GDCM_UNFOUND
388         && strImageOrientationRET != "" )  
389          std::cout << "ImageOrientationRET (0x0020,0x0035)= [" 
390                    << strImageOrientationRET << "]" << std::endl;
391
392       std::string strImagePositionPatient = 
393                                       f->GetEntryString(0x0020,0x0032);  
394       if ( strImagePositionPatient != GDCM_NAME_SPACE::GDCM_UNFOUND
395         && strImagePositionPatient != "" )  
396          std::cout << "ImagePositionPatient (0x0020,0x0032)= [" 
397                    << strImagePositionPatient << "]" << std::endl;
398
399       std::string strImagePositionPatientRET = 
400                                       f->GetEntryString(0x0020,0x0030);
401       if ( strImagePositionPatientRET != GDCM_NAME_SPACE::GDCM_UNFOUND
402         && strImagePositionPatientRET != "" )  
403          std::cout << "ImagePositionPatientRET (0x0020,0x0030)= [" 
404                    << strImagePositionPatientRET << "]" << std::endl;
405   
406      float iop[6];
407      /*bool riop = */f->GetImageOrientationPatient(iop);  
408      float ipp[3];
409      /*bool ripp = */f->GetImagePositionPatient(ipp);
410
411      std::cout << "Image Position (0x0020,0x0032|0x0030) : "
412                << ipp[0] << " , " << ipp[1] << " , "<< ipp[2]
413                << std::endl;
414      std::cout << "Image Orientation (0x0020,0x0037|0x0035) : "
415                << iop[0] << " , " << iop[1] << " , "<< iop[2] << " , "
416                << iop[3] << " , " << iop[4] << " , "<< iop[5]
417                << std::endl; 
418
419
420       // Let's compute 'user friendly' results about 'Orientation'
421       // ---------------------------------------------------------
422  
423       GDCM_NAME_SPACE::Orientation *o = GDCM_NAME_SPACE::Orientation::New();
424
425       if ( strImageOrientationPatient != GDCM_NAME_SPACE::GDCM_UNFOUND ||
426            strImageOrientationRET     != GDCM_NAME_SPACE::GDCM_UNFOUND )
427       {
428   
429          GDCM_NAME_SPACE::OrientationType orient = o->GetOrientationType( f );
430  
431          std::cout << "TypeOrientation = " << orient << " (-> " 
432                    << o->GetOrientationTypeString(orient) << " )" << std::endl;
433       }
434
435       std::string ori = o->GetOrientation ( f );
436       if (ori != "\\" )
437          std::cout << "Orientation [" << ori << "]" << std::endl;
438       o->Delete();
439 }  
440 //------------------------------
441
442
443       // Display the LUT as an int array (for debugging purpose)
444       if ( f->HasLUT() && showlut )
445       {
446          uint8_t* lutrgba = fh->GetLutRGBA();
447          if ( lutrgba == 0 )
448          {
449             std::cout << "Lut RGBA (Palette Color) not built " << std::endl;
450  
451            // Nothing is written yet to get LUT Data user friendly
452            // The following is to be moved into a PixelRedaConvert method
453   
454             GDCM_NAME_SPACE::SeqEntry *modLutSeq = f->GetSeqEntry(0x0028,0x3000);
455             if ( modLutSeq !=0 )
456             {
457                GDCM_NAME_SPACE::SQItem *sqi= modLutSeq->GetFirstSQItem();
458                if ( !sqi )
459                {
460                   std::string lutDescriptor = sqi->GetEntryString(0x0028,0x3002);
461                   int length;   // LUT length in Bytes
462                   int deb;      // Subscript of the first Lut Value
463                   int nbits;    // Lut item size (in Bits)
464                   int nbRead;   // nb of items in LUT descriptor (must be = 3)
465
466                   nbRead = sscanf( lutDescriptor.c_str(),
467                                     "%d\\%d\\%d",
468                                      &length, &deb, &nbits );
469                   if ( nbRead != 3 )
470                   {
471                       std::cout << "Wrong LUT descriptor" << std::endl;
472                   }                                                  
473                   GDCM_NAME_SPACE::DataEntry *b = sqi->GetDataEntry(0x0028,0x3006);
474                   if ( b != 0 )
475                   {
476                      if ( b->GetLength() != 0 )
477                      {
478                         std::cout << "---------------------------------------"
479                                << " We should never reach this point      "
480                                << std::endl;
481                         //LoadEntryBinArea(b);    //LUT Data (CTX dependent)
482                      }   
483                  }
484               }      
485             }
486             else
487                std::cout << "No LUT Data (0x0028,0x3000) found " << std::endl;
488         }
489          else
490          {
491             if ( fh->GetLutItemSize() == 8 )
492             {
493                for (int i=0;i<fh->GetLutItemNumber();i++)
494                   std::cout << i << " : \t"
495                          << (int)(lutrgba[i*4])   << " "
496                          << (int)(lutrgba[i*4+1]) << " "
497                          << (int)(lutrgba[i*4+2]) << std::endl;
498             }
499             else // LutItemSize assumed to be = 16
500             {
501                uint16_t* lutrgba16 = (uint16_t*)lutrgba;
502                for (int i=0;i<fh->GetLutItemNumber();i++)
503                   std::cout << i << " : \t"
504                          << (int)(lutrgba16[i*4])   << " "
505                          << (int)(lutrgba16[i*4+1]) << " "
506                          << (int)(lutrgba16[i*4+2]) << std::endl;
507             }
508          }
509       }
510       else if (showlut)
511       {
512          std::cout << "Try LUT Data "<< std::endl;
513          ShowLutData(f);
514       }
515
516       // Parsability of the GDCM_NAME_SPACE::Document already checked, after Load() !
517       
518       if ( f->IsReadable() )
519       {
520          std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
521       }
522       else if ( f->GetSeqEntry(0x0041,0x1010) )
523       {
524          std::cout <<std::endl<<fileName<<" looks like a 'PAPYRUS image' file"
525                    <<std::endl;
526       }
527       else if ( f->GetSeqEntry(0x0004,0x1220) )
528       {
529          std::cout <<std::endl<<fileName<<" looks like a 'DICOMDIR file'"
530                    <<std::endl;
531       }
532       else 
533       {
534          std::cout <<std::endl<<fileName<<" doesn't look like an image file "
535              <<std::endl; 
536       }
537  
538       std::cout<<std::flush;
539       f->Delete();
540       fh->Delete();
541    }
542          // ===========================================================================
543    else  // =============================== Deal with a Directory =====================
544    {     // ===========================================================================
545       std::cout << "dirName [" << dirName << "]" << std::endl;
546       
547       GDCM_NAME_SPACE::DirList dirList(dirName,rec); // gets recursively (or not) the file list
548       GDCM_NAME_SPACE::DirListType fileList = dirList.GetFilenames();
549       GDCM_NAME_SPACE::File *f;
550       bool res;
551
552       if (fileList.size() == 0)
553       {
554          std::cout << "No file found in : [" << dirName << "]" << std::endl;
555       }
556       
557       for( GDCM_NAME_SPACE::DirListType::iterator it  = fileList.begin();
558                                  it != fileList.end();
559                                  ++it )
560       {
561          std::cout << std::endl<<" Start processing :[" << it->c_str() << "]"
562                    << std::endl;
563          f = GDCM_NAME_SPACE::File::New();
564          f->SetLoadMode(loadMode);
565          f->SetFileName( it->c_str() );
566
567          for (int ri=0; ri<forceLoadNb; ri++)
568          {
569             printf("%04x,%04x\n",elemsToForceLoad[2*ri], 
570                                  elemsToForceLoad[2*ri+1]);
571             f->AddForceLoadElement((uint32_t)elemsToForceLoad[2*ri], 
572                                    (uint32_t)elemsToForceLoad[2*ri+1]); 
573          }
574          res = f->Load();
575
576          if ( !res )
577          {
578             std::cout << "Cannot process file [" << it->c_str() << "]" 
579                       << std::endl;
580             std::cout << "Either it doesn't exist, or it's read protected " 
581                       << std::endl;
582             std::cout << "or it's not a Dicom File, or its 'header' is bugged" 
583                       << std::endl;
584             std::cout << "use 'PrintFile filein=... debug' "
585                       << "to try to guess the pb"
586                       << std::endl;
587             f->Delete();
588             continue;
589          }
590
591          GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f);
592          fh->SetPrintLevel( level );
593          fh->Print();
594
595 //------------------------------
596 if (!noex)
597 {
598          // Lets's get and print some usefull fields about 'Orientation'
599          // ------------------------------------------------------------
600
601          std::string strPatientPosition = 
602                                        f->GetEntryString(0x0018,0x5100);
603          if ( strPatientPosition != GDCM_NAME_SPACE::GDCM_UNFOUND 
604          && strPatientPosition != "" )  
605                std::cout << "PatientPosition (0x0010,0x5100)= [" 
606                         << strPatientPosition << "]" << std::endl;
607     
608          std::string strViewPosition = 
609                                        f->GetEntryString(0x0018,0x5101);
610          if ( strViewPosition != GDCM_NAME_SPACE::GDCM_UNFOUND 
611          && strViewPosition != "" )  
612                std::cout << "strViewPosition (0x0010,0x5101)= [" 
613                         << strViewPosition << "]" << std::endl;
614          
615          std::string strPatientOrientation = 
616                                        f->GetEntryString(0x0020,0x0020);
617          if ( strPatientOrientation != GDCM_NAME_SPACE::GDCM_UNFOUND
618          && strPatientOrientation != "")  
619             std::cout << "PatientOrientation (0x0020,0x0020)= [" 
620                       << strPatientOrientation << "]" << std::endl;
621
622          std::string strImageOrientationPatient = 
623                                        f->GetEntryString(0x0020,0x0037);  
624          if ( strImageOrientationPatient != GDCM_NAME_SPACE::GDCM_UNFOUND
625          && strImageOrientationPatient != "" )  
626             std::cout << "ImageOrientationPatient (0x0020,0x0037)= [" 
627                      << strImageOrientationPatient << "]" << std::endl;
628
629          std::string strImageOrientationRET = 
630                                        f->GetEntryString(0x0020,0x0035);
631          if ( strImageOrientationRET != GDCM_NAME_SPACE::GDCM_UNFOUND
632          && strImageOrientationRET != "" )
633          {
634             std::cout << "ImageOrientationRET (0x0020,0x0035)= [" 
635                      << strImageOrientationRET << "]" << std::endl;
636          }
637
638          // Let's compute 'user friendly' results about 'Orientation'
639          // ---------------------------------------------------------
640     
641          GDCM_NAME_SPACE::Orientation *o = GDCM_NAME_SPACE::Orientation::New(); 
642
643
644          if ( strImageOrientationPatient != GDCM_NAME_SPACE::GDCM_UNFOUND ||
645             strImageOrientationRET     != GDCM_NAME_SPACE::GDCM_UNFOUND )
646          {
647      
648             GDCM_NAME_SPACE::OrientationType orient = o->GetOrientationType( f );
649     
650             std::cout << "TypeOrientation = " << orient << " (-> " 
651                      << o->GetOrientationTypeString(orient) << " )" << std::endl;
652          }
653
654          std::string ori = o->GetOrientation ( f );
655          if (ori != "\\" )
656             std::cout << "Orientation [" << ori << "]" << std::endl;
657          o->Delete(); 
658 }
659 //------------------------------- 
660         
661          if (f->IsReadable())
662             std::cout <<std::endl<<it->c_str()<<" is Readable"<<std::endl;
663          else
664             std::cout <<std::endl<<it->c_str()<<" is NOT Readable"<<std::endl;
665          std::cout << "\n\n" << std::endl;
666          f->Delete();
667          fh->Delete();
668       }
669       std::cout<<std::flush;
670    }
671    return 0;
672 }