]> Creatis software - gdcm.git/blob - src/gdcmHeader.cxx
* src/gdcmDocument.[h|cxx], gdcmFile.[h|cxx], gdcmHeader.[h|cxx]:
[gdcm.git] / src / gdcmHeader.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmHeader.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/07/30 16:09:27 $
7   Version:   $Revision: 1.180 $
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.htm 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 #include "gdcmHeader.h"
20 #include "gdcmGlobal.h"
21 #include "gdcmUtil.h"
22 #include "gdcmDebug.h"
23 #include "gdcmTS.h"
24 #include "gdcmValEntry.h"
25
26 #include <vector>
27
28 //-----------------------------------------------------------------------------
29 // Constructor / Destructor
30 /**
31  * \brief  Constructor 
32  * @param  filename name of the file whose header we want to analyze
33  * @param  exception_on_error whether we want to throw an exception or not
34  */
35 gdcmHeader::gdcmHeader( std::string const & filename, 
36                         bool exception_on_error ):
37             gdcmDocument( filename,
38                           exception_on_error )
39 {    
40    // for some ACR-NEMA images GrPixel, NumPixel is *not* 7fe0,0010
41    // We may encounter the 'RETired' (0x0028, 0x0200) tag
42    // (Image Location") . This Element contains the number of
43    // the group that contains the pixel data (hence the "Pixel Data"
44    // is found by indirection through the "Image Location").
45    // Inside the group pointed by "Image Location" the searched element
46    // is conventionally the element 0x0010 (when the norm is respected).
47    // When the "Image Location" is absent we default to group 0x7fe0.
48    // Note: this IS the right place for the code
49  
50    // Image Location
51    std::string imgLocation = GetEntryByNumber(0x0028, 0x0200);
52    if ( imgLocation == GDCM_UNFOUND )
53    {
54       // default value
55       GrPixel = 0x7fe0;
56    }
57    else
58    {
59       GrPixel = (uint16_t) atoi( imgLocation.c_str() );
60    }   
61
62    // sometimes Image Location value doesn't follow 
63    // the supposed processor endianity. 
64    // see gdcmData/cr172241.dcm      
65    if ( GrPixel == 0xe07f )
66    {
67       GrPixel = 0x7fe0;
68    }
69
70    if ( GrPixel != 0x7fe0 )
71    {
72       // This is a kludge for old dirty Philips imager.
73       NumPixel = 0x1010;
74    }
75    else
76    {
77       NumPixel = 0x0010;
78    }
79 }
80
81 /**
82  * \brief Constructor  
83  * @param exception_on_error whether we want to throw an exception or not
84  */
85 gdcmHeader::gdcmHeader(bool exception_on_error) :
86             gdcmDocument( exception_on_error )
87 {
88 }
89
90 /**
91  * \ingroup gdcmHeader
92  * \brief   Canonical destructor.
93  */
94 gdcmHeader::~gdcmHeader ()
95 {
96 }
97
98
99 /**
100  * \brief Performs some consistency checking on various 'File related' 
101  *       (as opposed to 'DicomDir related') entries 
102  *       then writes in a file all the (Dicom Elements) included the Pixels 
103  * @param fp file pointer on an already open file
104  * @param filetype Type of the File to be written 
105  *          (ACR-NEMA, ExplicitVR, ImplicitVR)
106  */
107 void gdcmHeader::Write(FILE* fp,FileType filetype) {
108    
109    // Bits Allocated
110    if ( GetEntryByNumber(0x0028,0x0100) ==  "12") {
111       SetEntryByNumber("16", 0x0028,0x0100);
112    }
113
114   // correct Pixel group Length if necessary
115
116    // TODO : create a gdcmHeader::Write method and move this part.
117    //        (only gdcmHeader knows GrPixel, NumPixel)
118
119    int i_lgPix = GetEntryLengthByNumber(GrPixel, NumPixel);
120    if (i_lgPix != -2) { // no (GrPixel, NumPixel) element
121       char * dumm = new char[20];
122       sprintf(dumm ,"%d", i_lgPix+12);
123       std::string s_lgPix = dumm;
124       delete dumm;
125       ReplaceOrCreateByNumber(s_lgPix,GrPixel, 0x0000);
126    }
127   
128    // Drop Palette Color, if necessary
129    
130    if ( GetEntryByNumber(0x0028,0x0002).c_str()[0] == '3' ) {
131     // if SamplesPerPixel = 3, sure we don't need any LUT !   
132     // Drop 0028|1101, 0028|1102, 0028|1103
133     // Drop 0028|1201, 0028|1202, 0028|1203
134
135      gdcmDocEntry *e;
136      e=GetDocEntryByNumber(0x0028,0x01101);
137      if (e) 
138         RemoveEntry(e);
139      e=GetDocEntryByNumber(0x0028,0x1102);
140      if (e) 
141         RemoveEntry(e);
142      e=GetDocEntryByNumber(0x0028,0x1103);
143
144      if (e) 
145         RemoveEntry(e);
146      e=GetDocEntryByNumber(0x0028,0x01201);
147      if (e) 
148         RemoveEntry(e);
149      e=GetDocEntryByNumber(0x0028,0x1202);
150      if (e) 
151         RemoveEntry(e);
152      e=GetDocEntryByNumber(0x0028,0x1203);
153      if (e) 
154        RemoveEntry(e);
155    }
156
157    gdcmDocument::Write(fp,filetype);
158 }
159
160 //-----------------------------------------------------------------------------
161 // Print
162
163
164 //-----------------------------------------------------------------------------
165 // Public
166
167 /**
168  * \brief  This predicate, based on hopefully reasonable heuristics,
169  *         decides whether or not the current gdcmHeader was properly parsed
170  *         and contains the mandatory information for being considered as
171  *         a well formed and usable Dicom/Acr File.
172  * @return true when gdcmHeader is the one of a reasonable Dicom/Acr file,
173  *         false otherwise. 
174  */
175 bool gdcmHeader::IsReadable()
176 {
177    if( !gdcmDocument::IsReadable() )
178    {
179       return false;
180    }
181
182    std::string res = GetEntryByNumber(0x0028, 0x0005);
183    if ( res != GDCM_UNFOUND && atoi(res.c_str()) > 4 )
184    {
185       return false; // Image Dimensions
186    }
187    if ( !GetDocEntryByNumber(0x0028, 0x0100) )
188    {
189       return false; // "Bits Allocated"
190    }
191    if ( !GetDocEntryByNumber(0x0028, 0x0101) )
192    {
193       return false; // "Bits Stored"
194    }
195    if ( !GetDocEntryByNumber(0x0028, 0x0102) )
196    {
197       return false; // "High Bit"
198    }
199    if ( !GetDocEntryByNumber(0x0028, 0x0103) )
200    {
201       return false; // "Pixel Representation" i.e. 'Sign'
202    }
203
204    return true;
205 }
206
207 /**
208  * \brief   Retrieve the number of columns of image.
209  * @return  The encountered size when found, 0 by default.
210  *          0 means the file is NOT USABLE. The caller will have to check
211  */
212 int gdcmHeader::GetXSize()
213 {
214    std::string strSize;
215    strSize = GetEntryByNumber(0x0028,0x0011);
216    if ( strSize == GDCM_UNFOUND )
217    {
218       return 0;
219    }
220
221    return atoi( strSize.c_str() );
222 }
223
224 /**
225  * \ingroup gdcmHeader
226  * \brief   Retrieve the number of lines of image.
227  * \warning The defaulted value is 1 as opposed to gdcmHeader::GetXSize()
228  * @return  The encountered size when found, 1 by default 
229  *          (The ACR-NEMA file contains a Signal, not an Image).
230  */
231 int gdcmHeader::GetYSize()
232 {
233    std::string strSize = GetEntryByNumber(0x0028,0x0010);
234    if ( strSize != GDCM_UNFOUND )
235    {
236       return atoi( strSize.c_str() );
237    }
238    if ( IsDicomV3() )
239    {
240       return 0;
241    }
242
243    // The Rows (0028,0010) entry was optional for ACR/NEMA. It might
244    // hence be a signal (1d image). So we default to 1:
245    return 1;
246 }
247
248 /**
249  * \ingroup gdcmHeader
250  * \brief   Retrieve the number of planes of volume or the number
251  *          of frames of a multiframe.
252  * \warning When present we consider the "Number of Frames" as the third
253  *          dimension. When absent we consider the third dimension as
254  *          being the ACR-NEMA "Planes" tag content.
255  * @return  The encountered size when found, 1 by default (single image).
256  */
257 int gdcmHeader::GetZSize()
258 {
259    // Both  DicomV3 and ACR/Nema consider the "Number of Frames"
260    // as the third dimension.
261    std::string strSize = GetEntryByNumber(0x0028,0x0008);
262    if ( strSize != GDCM_UNFOUND )
263    {
264       return atoi( strSize.c_str() );
265    }
266
267    // We then consider the "Planes" entry as the third dimension 
268    strSize = GetEntryByNumber(0x0028,0x0012);
269    if ( strSize != GDCM_UNFOUND )
270    {
271       return atoi( strSize.c_str() );
272    }
273
274    return 1;
275 }
276
277 /**
278   * \ingroup gdcmHeader
279   * \brief gets the info from 0028,0030 : Pixel Spacing
280   *             else 1.0
281   * @return X dimension of a pixel
282   */
283 float gdcmHeader::GetXSpacing()
284 {
285    float xspacing, yspacing;
286    std::string strSpacing = GetEntryByNumber(0x0028,0x0030);
287
288    if ( strSpacing == GDCM_UNFOUND )
289    {
290       dbg.Verbose(0, "gdcmHeader::GetXSpacing: unfound Pixel Spacing (0028,0030)");
291       return 1.;
292    }
293
294    int nbValues;
295    if( ( nbValues = sscanf( strSpacing.c_str(), 
296          "%f\\%f", &yspacing, &xspacing)) != 2 )
297    {
298       // if single value is found, xspacing is defaulted to yspacing
299       if ( nbValues == 1 )
300       {
301          return yspacing;
302       }
303    }
304    if ( xspacing == 0.)
305    {
306       dbg.Verbose(0, "gdcmHeader::GetYSpacing: gdcmData/CT-MONO2-8-abdo.dcm problem");
307       // seems to be a bug in the header ...
308       sscanf( strSpacing.c_str(), "%f\\0\\%f", &yspacing, &xspacing);
309    }
310
311    return xspacing;
312 }
313
314 /**
315   * \ingroup gdcmHeader
316   * \brief gets the info from 0028,0030 : Pixel Spacing
317   *             else 1.0
318   * @return Y dimension of a pixel
319   */
320 float gdcmHeader::GetYSpacing()
321 {
322    float yspacing = 0;
323    std::string strSpacing = GetEntryByNumber(0x0028,0x0030);
324   
325    if ( strSpacing == GDCM_UNFOUND )
326    {
327       dbg.Verbose(0, "gdcmHeader::GetYSpacing: unfound Pixel Spacing (0028,0030)");
328       return 1.;
329     }
330
331    // if sscanf cannot read any float value, it won't affect yspacing
332    sscanf( strSpacing.c_str(), "%f", &yspacing);
333
334    return yspacing;
335
336
337 /**
338   *\ingroup gdcmHeader
339   *\brief gets the info from 0018,0088 : Space Between Slices
340   *                else from 0018,0050 : Slice Thickness
341    *                else 1.0
342   * @return Z dimension of a voxel-to be
343   */
344 float gdcmHeader::GetZSpacing()
345 {
346    // Spacing Between Slices : distance entre le milieu de chaque coupe
347    // Les coupes peuvent etre :
348    //   jointives     (Spacing between Slices = Slice Thickness)
349    //   chevauchantes (Spacing between Slices < Slice Thickness)
350    //   disjointes    (Spacing between Slices > Slice Thickness)
351    // Slice Thickness : epaisseur de tissus sur laquelle est acquis le signal
352    //   ca interesse le physicien de l'IRM, pas le visualisateur de volumes ...
353    //   Si le Spacing Between Slices est absent, 
354    //   on suppose que les coupes sont jointives
355    
356    std::string strSpacingBSlices = GetEntryByNumber(0x0018,0x0088);
357
358    if ( strSpacingBSlices == GDCM_UNFOUND )
359    {
360       dbg.Verbose(0, "gdcmHeader::GetZSpacing: unfound StrSpacingBSlices");
361       std::string strSliceThickness = GetEntryByNumber(0x0018,0x0050);       
362       if ( strSliceThickness == GDCM_UNFOUND )
363       {
364          return 1.;
365       }
366       else
367       {
368          // if no 'Spacing Between Slices' is found, 
369          // we assume slices join together
370          // (no overlapping, no interslice gap)
371          // if they don't, we're fucked up
372          return atof( strSliceThickness.c_str() );
373       }
374    }
375    else
376    {
377       return atof( strSpacingBSlices.c_str() );
378    }
379 }
380
381 /**
382   *\ingroup gdcmHeader
383   *\brief gets the info from 0028,1052 : Rescale Intercept
384   * @return Rescale Intercept
385  */
386 float gdcmHeader::GetRescaleIntercept()
387 {
388    float resInter = 0.;
389    std::string strRescInter = GetEntryByNumber(0x0028,0x1052); //0028 1052 DS IMG Rescale Intercept
390    if ( strRescInter != GDCM_UNFOUND )
391    {
392       if( sscanf( strRescInter.c_str(), "%f", &resInter) != 1 )
393       {
394          // bug in the element 0x0028,0x1052
395          dbg.Verbose(0, "gdcmHeader::GetRescaleIntercept: Rescale Slope is empty");
396       }
397    }
398
399   return resInter;
400 }
401
402 /**
403   *\ingroup gdcmHeader
404   *\brief gets the info from 0028,1053 : Rescale Slope
405   * @return Rescale Slope
406  */
407 float gdcmHeader::GetRescaleSlope()
408 {
409    float resSlope = 1.;
410    std::string strRescSlope = GetEntryByNumber(0x0028,0x1053); //0028 1053 DS IMG Rescale Slope
411    if ( strRescSlope != GDCM_UNFOUND )
412    {
413       if( sscanf( strRescSlope.c_str(), "%f", &resSlope) != 1)
414       {
415          // bug in the element 0x0028,0x1053
416          dbg.Verbose(0, "gdcmHeader::GetRescaleSlope: Rescale Slope is empty");
417       }
418    }
419
420    return resSlope;
421 }
422
423 /**
424   * \ingroup gdcmHeader
425   * \brief This function is intended to user who doesn't want 
426   *   to have to manage a LUT and expects to get an RBG Pixel image
427   *   (or a monochrome one ...) 
428   * \warning to be used with GetImagePixels()
429   * @return 1 if Gray level, 3 if Color (RGB, YBR or PALETTE COLOR)
430   */
431 int gdcmHeader::GetNumberOfScalarComponents()
432 {
433    if ( GetSamplesPerPixel() == 3 )
434    {
435       return 3;
436    }
437       
438    // 0028 0100 US IMG Bits Allocated
439    // (in order no to be messed up by old RGB images)
440    if ( GetEntryByNumber(0x0028,0x0100) == "24" )
441    {
442       return 3;
443    }
444        
445    std::string strPhotometricInterpretation = GetEntryByNumber(0x0028,0x0004);
446
447    if ( ( strPhotometricInterpretation == "PALETTE COLOR ") )
448    {
449       if ( HasLUT() )// PALETTE COLOR is NOT enough
450       {
451          return 3;
452       }
453       else
454       {
455          return 1;
456       }
457    }
458
459    // beware of trailing space at end of string      
460    // DICOM tags are never of odd length
461    if ( strPhotometricInterpretation == GDCM_UNFOUND   || 
462         strPhotometricInterpretation == "MONOCHROME1 " || 
463         strPhotometricInterpretation == "MONOCHROME2 " )
464    {
465       return 1;
466    }
467    else
468    {
469       // we assume that *all* kinds of YBR are dealt with
470       return 3;
471    }
472 }
473
474 /**
475   * \ingroup gdcmHeader
476   * \brief This function is intended to user that DOESN'T want 
477   *  to get RGB pixels image when it's stored as a PALETTE COLOR image
478   *   - the (vtk) user is supposed to know how deal with LUTs - 
479   * \warning to be used with GetImagePixelsRaw()
480   * @return 1 if Gray level, 3 if Color (RGB or YBR - NOT 'PALETTE COLOR' -)
481   */
482 int gdcmHeader::GetNumberOfScalarComponentsRaw()
483 {
484    // 0028 0100 US IMG Bits Allocated
485    // (in order no to be messed up by old RGB images)
486    if ( gdcmHeader::GetEntryByNumber(0x0028,0x0100) == "24" )
487    {
488       return 3;
489    }
490
491    // we assume that *all* kinds of YBR are dealt with
492    return GetSamplesPerPixel();
493 }
494
495 //
496 // --------------  Remember ! ----------------------------------
497 //
498 // Image Position Patient                              (0020,0032):
499 // If not found (ACR_NEMA) we try Image Position       (0020,0030)
500 // If not found (ACR-NEMA), we consider Slice Location (0020,1041)
501 //                                   or Location       (0020,0050) 
502 // as the Z coordinate, 
503 // 0. for all the coordinates if nothing is found
504
505 // \todo find a way to inform the caller nothing was found
506 // \todo How to tell the caller a wrong number of values was found?
507 //
508 // ---------------------------------------------------------------
509 //
510
511 /**
512   * \brief gets the info from 0020,0032 : Image Position Patient
513   *                 else from 0020,0030 : Image Position (RET)
514   *                 else 0.
515   * @return up-left image corner X position
516   */
517     
518 float gdcmHeader::GetXOrigin()
519 {
520    float xImPos, yImPos, zImPos;  
521    std::string strImPos = GetEntryByNumber(0x0020,0x0032);
522
523    if ( strImPos == GDCM_UNFOUND )
524    {
525       dbg.Verbose(0, "gdcmHeader::GetXImagePosition: unfound Image Position Patient (0020,0032)");
526       strImPos = GetEntryByNumber(0x0020,0x0030); // For ACR-NEMA images
527       if ( strImPos == GDCM_UNFOUND )
528       {
529          dbg.Verbose(0, "gdcmHeader::GetXImagePosition: unfound Image Position (RET) (0020,0030)");
530          /// \todo How to tell the caller nothing was found ?
531          return 0.;
532       }
533    }
534
535    if( sscanf( strImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3 )
536    {
537      return 0.;
538    }
539
540    return xImPos;
541 }
542
543 /**
544   * \brief gets the info from 0020,0032 : Image Position Patient
545   *                 else from 0020,0030 : Image Position (RET)
546   *                 else 0.
547   * @return up-left image corner Y position
548   */
549 float gdcmHeader::GetYOrigin()
550 {
551    float xImPos, yImPos, zImPos;
552    std::string strImPos = GetEntryByNumber(0x0020,0x0032);
553
554    if ( strImPos == GDCM_UNFOUND)
555    {
556       dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Image Position Patient (0020,0032)");
557       strImPos = GetEntryByNumber(0x0020,0x0030); // For ACR-NEMA images
558       if ( strImPos == GDCM_UNFOUND )
559       {
560          dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Image Position (RET) (0020,0030)");
561          /// \todo How to tell the caller nothing was found ?
562          return 0.;
563       }  
564    }
565
566    if( sscanf( strImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3 )
567    {
568       return 0.;
569    }
570
571    return yImPos;
572 }
573
574 /**
575   * \brief gets the info from 0020,0032 : Image Position Patient
576   * \               else from 0020,0030 : Image Position (RET)
577   * \               else from 0020,1041 : Slice Location
578   * \               else from 0020,0050 : Location
579   * \               else 0.
580   * @return up-left image corner Z position
581   */
582 float gdcmHeader::GetZOrigin()
583 {
584    float xImPos, yImPos, zImPos; 
585    std::string strImPos = GetEntryByNumber(0x0020,0x0032);
586
587    if ( strImPos != GDCM_UNFOUND )
588    {
589       if( sscanf( strImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3)
590       {
591          dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Image Position Patient (0020,0032)");
592          return 0.;  // bug in the element 0x0020,0x0032
593       }
594       else
595       {
596          return zImPos;
597       }
598    }
599
600    strImPos = GetEntryByNumber(0x0020,0x0030); // For ACR-NEMA images
601    if ( strImPos != GDCM_UNFOUND )
602    {
603       if( sscanf( strImPos.c_str(), 
604           "%f\\%f\\%f", &xImPos, &yImPos, &zImPos ) != 3 )
605       {
606          dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Image Position (RET) (0020,0030)");
607          return 0.;  // bug in the element 0x0020,0x0032
608       }
609       else
610       {
611          return zImPos;
612       }
613    }
614
615    std::string strSliceLocation = GetEntryByNumber(0x0020,0x1041); // for *very* old ACR-NEMA images
616    if ( strSliceLocation != GDCM_UNFOUND )
617    {
618       if( sscanf( strSliceLocation.c_str(), "%f", &zImPos) != 1)
619       {
620          dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Slice Location (0020,1041)");
621          return 0.;  // bug in the element 0x0020,0x1041
622       }
623       else
624       {
625          return zImPos;
626       }
627    }
628    dbg.Verbose(0, "gdcmHeader::GetZImagePosition: unfound Slice Location (0020,1041)");
629
630    std::string strLocation = GetEntryByNumber(0x0020,0x0050);
631    if ( strLocation != GDCM_UNFOUND )
632    {
633       if( sscanf( strLocation.c_str(), "%f", &zImPos) != 1)
634       {
635          dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Location (0020,0050)");
636          return 0.;  // bug in the element 0x0020,0x0050
637       }
638       else
639       {
640          return zImPos;
641       }
642    }
643    dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Location (0020,0050)");  
644
645    return 0.; // Hopeless
646 }
647
648 /**
649   * \brief gets the info from 0020,0013 : Image Number
650   * \               else 0.
651   * @return image number
652   */
653 int gdcmHeader::GetImageNumber()
654 {
655    // The function i atoi() takes the address of an area of memory as
656    // parameter and converts the string stored at that location to an integer
657    // using the external decimal to internal binary conversion rules. This may
658    // be preferable to sscanf() since atoi() is a much smaller, simpler and
659    // faster function. sscanf() can do all possible conversions whereas
660    // atoi() can only do single decimal integer conversions.
661    std::string strImNumber = GetEntryByNumber(0x0020,0x0013); //0020 0013 IS REL Image Number
662    if ( strImNumber != GDCM_UNFOUND )
663    {
664       return atoi( strImNumber.c_str() );
665    }
666    return 0;   //Hopeless
667 }
668
669 /**
670   * \brief gets the info from 0008,0060 : Modality
671   * @return Modality Type
672   */
673 ModalityType gdcmHeader::GetModality()
674 {
675    // 0008 0060 CS ID Modality
676    std::string strModality = GetEntryByNumber(0x0008,0x0060);
677    if ( strModality != GDCM_UNFOUND )
678    {
679            if ( strModality.find("AU") < strModality.length()) return AU;
680       else if ( strModality.find("AS") < strModality.length()) return AS;
681       else if ( strModality.find("BI") < strModality.length()) return BI;
682       else if ( strModality.find("CF") < strModality.length()) return CF;
683       else if ( strModality.find("CP") < strModality.length()) return CP;
684       else if ( strModality.find("CR") < strModality.length()) return CR;
685       else if ( strModality.find("CT") < strModality.length()) return CT;
686       else if ( strModality.find("CS") < strModality.length()) return CS;
687       else if ( strModality.find("DD") < strModality.length()) return DD;
688       else if ( strModality.find("DF") < strModality.length()) return DF;
689       else if ( strModality.find("DG") < strModality.length()) return DG;
690       else if ( strModality.find("DM") < strModality.length()) return DM;
691       else if ( strModality.find("DS") < strModality.length()) return DS;
692       else if ( strModality.find("DX") < strModality.length()) return DX;
693       else if ( strModality.find("ECG") < strModality.length()) return ECG;
694       else if ( strModality.find("EPS") < strModality.length()) return EPS;
695       else if ( strModality.find("FA") < strModality.length()) return FA;
696       else if ( strModality.find("FS") < strModality.length()) return FS;
697       else if ( strModality.find("HC") < strModality.length()) return HC;
698       else if ( strModality.find("HD") < strModality.length()) return HD;
699       else if ( strModality.find("LP") < strModality.length()) return LP;
700       else if ( strModality.find("LS") < strModality.length()) return LS;
701       else if ( strModality.find("MA") < strModality.length()) return MA;
702       else if ( strModality.find("MR") < strModality.length()) return MR;
703       else if ( strModality.find("NM") < strModality.length()) return NM;
704       else if ( strModality.find("OT") < strModality.length()) return OT;
705       else if ( strModality.find("PT") < strModality.length()) return PT;
706       else if ( strModality.find("RF") < strModality.length()) return RF;
707       else if ( strModality.find("RG") < strModality.length()) return RG;
708       else if ( strModality.find("RTDOSE")   < strModality.length()) return RTDOSE;
709       else if ( strModality.find("RTIMAGE")  < strModality.length()) return RTIMAGE;
710       else if ( strModality.find("RTPLAN")   < strModality.length()) return RTPLAN;
711       else if ( strModality.find("RTSTRUCT") < strModality.length()) return RTSTRUCT;
712       else if ( strModality.find("SM") < strModality.length()) return SM;
713       else if ( strModality.find("ST") < strModality.length()) return ST;
714       else if ( strModality.find("TG") < strModality.length()) return TG;
715       else if ( strModality.find("US") < strModality.length()) return US;
716       else if ( strModality.find("VF") < strModality.length()) return VF;
717       else if ( strModality.find("XA") < strModality.length()) return XA;
718       else if ( strModality.find("XC") < strModality.length()) return XC;
719
720       else
721       {
722          /// \todo throw error return value ???
723          /// specified <> unknow in our database
724          return Unknow;
725       }
726    }
727
728    return Unknow;
729 }
730
731 /**
732  * \ingroup gdcmHeader
733  * \brief   Retrieve the number of Bits Stored (actually used)
734  *          (as opposite to number of Bits Allocated)
735  * @return  The encountered number of Bits Stored, 0 by default.
736  *          0 means the file is NOT USABLE. The caller has to check it !
737  */
738 int gdcmHeader::GetBitsStored()
739 {
740    std::string strSize = GetEntryByNumber(0x0028,0x0101);
741    if ( strSize == GDCM_UNFOUND )
742    {
743       dbg.Verbose(0, "gdcmHeader::GetBitsStored: this is supposed to be mandatory");
744       return 0;  // It's supposed to be mandatory
745                  // the caller will have to check
746    }
747
748    return atoi( strSize.c_str() );
749 }
750
751 /**
752  * \ingroup gdcmHeader
753  * \brief   Retrieve the number of Bits Allocated
754  *          (8, 12 -compacted ACR-NEMA files, 16, ...)
755  * @return  The encountered number of Bits Allocated, 0 by default.
756  *          0 means the file is NOT USABLE. The caller has to check it !
757  */
758 int gdcmHeader::GetBitsAllocated()
759 {
760    std::string strSize = GetEntryByNumber(0x0028,0x0100);
761    if ( strSize == GDCM_UNFOUND )
762    {
763       dbg.Verbose(0, "gdcmHeader::GetBitsStored: this is supposed to be mandatory");
764       return 0; // It's supposed to be mandatory
765                 // the caller will have to check
766    }
767
768    return atoi( strSize.c_str() );
769 }
770
771 /**
772  * \ingroup gdcmHeader
773  * \brief   Retrieve the number of Samples Per Pixel
774  *          (1 : gray level, 3 : RGB -1 or 3 Planes-)
775  * @return  The encountered number of Samples Per Pixel, 1 by default.
776  *          (Gray level Pixels)
777  */
778 int gdcmHeader::GetSamplesPerPixel()
779 {
780    std::string strSize = GetEntryByNumber(0x0028,0x0002);
781    if ( strSize == GDCM_UNFOUND )
782    {
783       dbg.Verbose(0, "gdcmHeader::GetBitsStored: this is supposed to be mandatory");
784       return 1; // Well, it's supposed to be mandatory ...
785                 // but sometimes it's missing : *we* assume Gray pixels
786    }
787
788    return atoi( strSize.c_str() );
789 }
790
791 /**
792  * \ingroup gdcmHeader
793  * \brief   Retrieve the Planar Configuration for RGB images
794  *          (0 : RGB Pixels , 1 : R Plane + G Plane + B Plane)
795  * @return  The encountered Planar Configuration, 0 by default.
796  */
797 int gdcmHeader::GetPlanarConfiguration()
798 {
799    std::string strSize = GetEntryByNumber(0x0028,0x0006);
800    if ( strSize == GDCM_UNFOUND )
801    {
802       return 0;
803    }
804
805    return atoi( strSize.c_str() );
806 }
807
808 /**
809  * \ingroup gdcmHeader
810  * \brief   Return the size (in bytes) of a single pixel of data.
811  * @return  The size in bytes of a single pixel of data; 0 by default
812  *          0 means the file is NOT USABLE; the caller will have to check        
813  */
814 int gdcmHeader::GetPixelSize()
815 {
816    // 0028 0100 US IMG Bits Allocated
817    // (in order no to be messed up by old RGB images)
818    //   if (gdcmHeader::GetEntryByNumber(0x0028,0x0100) == "24")
819    //      return 3;
820
821    std::string pixelType = GetPixelType();
822    if ( pixelType ==  "8U" || pixelType == "8S" )
823    {
824       return 1;
825    }
826    if ( pixelType == "16U" || pixelType == "16S")
827    {
828       return 2;
829    }
830    if ( pixelType == "32U" || pixelType == "32S")
831    {
832       return 4;
833    }
834    if ( pixelType == "FD" )
835    {
836       return 8;
837    }
838
839    dbg.Verbose(0, "gdcmHeader::GetPixelSize: Unknown pixel type");
840    return 0;
841 }
842
843 /**
844  * \ingroup gdcmHeader
845  * \brief   Build the Pixel Type of the image.
846  *          Possible values are:
847  *          - 8U  unsigned  8 bit,
848  *          - 8S    signed  8 bit,
849  *          - 16U unsigned 16 bit,
850  *          - 16S   signed 16 bit,
851  *          - 32U unsigned 32 bit,
852  *          - 32S   signed 32 bit,
853  *          - FD floating double 64 bits (Not kosher DICOM, but so usefull!)
854  * \warning 12 bit images appear as 16 bit.
855  *          24 bit images appear as 8 bit
856  * @return  0S if nothing found. NOT USABLE file. The caller has to check
857  */
858 std::string gdcmHeader::GetPixelType()
859 {
860    std::string bitsAlloc = GetEntryByNumber(0x0028, 0x0100); // Bits Allocated
861    if ( bitsAlloc == GDCM_UNFOUND )
862    {
863       dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Bits Allocated");
864       bitsAlloc = "16";
865    }
866
867    if ( bitsAlloc == "64" )
868    {
869       return "FD";
870    }
871    if ( bitsAlloc == "12" )
872    {
873       // It will be unpacked
874       bitsAlloc = "16";
875    }
876    else if ( bitsAlloc == "24" )
877    {
878       // (in order no to be messed up
879       bitsAlloc = "8";  // by old RGB images)
880    }
881
882    std::string sign = GetEntryByNumber(0x0028, 0x0103); // "Pixel Representation"
883
884    if (sign == GDCM_UNFOUND )
885    {
886       dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Pixel Representation");
887       bitsAlloc = "0";
888    }
889    if ( sign == "0" )
890    {
891       sign = "U";
892    }
893    else
894    {
895       sign = "S";
896    }
897
898    return bitsAlloc + sign;
899 }
900
901
902 /**
903  * \ingroup gdcmHeader
904  * \brief   Recover the offset (from the beginning of the file) 
905  *          of *image* pixels (not *icone image* pixels, if any !)
906  * @return Pixel Offset
907  */
908 size_t gdcmHeader::GetPixelOffset()
909 {
910    gdcmDocEntry* pxlElement = GetDocEntryByNumber(GrPixel,NumPixel);
911    if ( pxlElement )
912    {
913       return pxlElement->GetOffset();
914    }
915    else
916    {
917 #ifdef GDCM_DEBUG
918       std::cout << "Big trouble : Pixel Element ("
919                 << std::hex << GrPixel<<","<< NumPixel<< ") NOT found"
920                 << std::endl;  
921 #endif //GDCM_DEBUG
922       return 0;
923    }
924 }
925
926 // TODO : unify those two (previous one and next one)
927 /**
928  * \ingroup gdcmHeader
929  * \brief   Recover the pixel area length (in Bytes)
930  * @return Pixel Element Length, as stored in the header
931  *         (NOT the memory space necessary to hold the Pixels 
932  *          -in case of embeded compressed image-)
933  *         0 : NOT USABLE file. The caller has to check.
934  */
935 size_t gdcmHeader::GetPixelAreaLength()
936 {
937    gdcmDocEntry* pxlElement = GetDocEntryByNumber(GrPixel,NumPixel);
938    if ( pxlElement )
939    {
940       return pxlElement->GetLength();
941    }
942    else
943    {
944 #ifdef GDCM_DEBUG
945       std::cout << "Big trouble : Pixel Element ("
946                 << std::hex << GrPixel<<","<< NumPixel<< ") NOT found"
947                 << std::endl;
948 #endif //GDCM_DEBUG
949       return 0;
950    }
951 }
952
953 /**
954   * \ingroup gdcmHeader
955   * \brief tells us if LUT are used
956   * \warning Right now, 'Segmented xxx Palette Color Lookup Table Data'
957   *          are NOT considered as LUT, since nobody knows
958   *          how to deal with them
959   *          Please warn me if you know sbdy that *does* know ... jprx
960   * @return true if LUT Descriptors and LUT Tables were found 
961   */
962 bool gdcmHeader::HasLUT()
963 {
964    // Check the presence of the LUT Descriptors, and LUT Tables    
965    // LutDescriptorRed    
966    if ( !GetDocEntryByNumber(0x0028,0x1101) )
967    {
968       return false;
969    }
970    // LutDescriptorGreen 
971    if ( !GetDocEntryByNumber(0x0028,0x1102) )
972    {
973       return false;
974    }
975    // LutDescriptorBlue 
976    if ( !GetDocEntryByNumber(0x0028,0x1103) )
977    {
978       return false;
979    }
980    // Red Palette Color Lookup Table Data
981    if ( !GetDocEntryByNumber(0x0028,0x1201) )
982    {
983       return false;
984    }
985    // Green Palette Color Lookup Table Data       
986    if ( !GetDocEntryByNumber(0x0028,0x1202) )
987    {
988       return false;
989    }
990    // Blue Palette Color Lookup Table Data      
991    if ( !GetDocEntryByNumber(0x0028,0x1203) )
992    {
993       return false;
994    }
995
996    // FIXME : (0x0028,0x3006) : LUT Data (CTX dependent)
997    //         NOT taken into account, but we don't know how to use it ...   
998    return true;
999 }
1000
1001 /**
1002   * \ingroup gdcmHeader
1003   * \brief gets the info from 0028,1101 : Lookup Table Desc-Red
1004   *             else 0
1005   * @return Lookup Table number of Bits , 0 by default
1006   *          when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
1007   * @ return bit number of each LUT item 
1008   */
1009 int gdcmHeader::GetLUTNbits()
1010 {
1011    std::vector<std::string> tokens;
1012    int lutNbits;
1013
1014    //Just hope Lookup Table Desc-Red = Lookup Table Desc-Red = Lookup Table Desc-Blue
1015    // Consistency already checked in GetLUTLength
1016    std::string lutDescription = GetEntryByNumber(0x0028,0x1101);
1017    if ( lutDescription == GDCM_UNFOUND )
1018    {
1019       return 0;
1020    }
1021
1022    tokens.clear(); // clean any previous value
1023    Tokenize ( lutDescription, tokens, "\\" );
1024    //LutLength=atoi(tokens[0].c_str());
1025    //LutDepth=atoi(tokens[1].c_str());
1026
1027    lutNbits = atoi( tokens[2].c_str() );
1028    tokens.clear();
1029
1030    return lutNbits;
1031 }
1032
1033 /**
1034   * \ingroup gdcmHeader
1035   * \brief builts Red/Green/Blue/Alpha LUT from Header
1036   *         when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
1037   *          and (0028,1101),(0028,1102),(0028,1102)  
1038   *            - xxx Palette Color Lookup Table Descriptor - are found
1039   *          and (0028,1201),(0028,1202),(0028,1202) 
1040   *            - xxx Palette Color Lookup Table Data - are found 
1041   * \warning does NOT deal with :
1042   *   0028 1100 Gray Lookup Table Descriptor (Retired)
1043   *   0028 1221 Segmented Red Palette Color Lookup Table Data
1044   *   0028 1222 Segmented Green Palette Color Lookup Table Data
1045   *   0028 1223 Segmented Blue Palette Color Lookup Table Data 
1046   *   no known Dicom reader deals with them :-(
1047   * @return a RGBA Lookup Table 
1048   */ 
1049 uint8_t* gdcmHeader::GetLUTRGBA()
1050 {
1051    // Not so easy : see 
1052    // http://www.barre.nom.fr/medical/dicom2/limitations.html#Color%20Lookup%20Tables
1053
1054 //  if Photometric Interpretation # PALETTE COLOR, no LUT to be done
1055    if ( GetEntryByNumber(0x0028,0x0004) != "PALETTE COLOR " )
1056    {
1057       return NULL;
1058    }
1059
1060    int lengthR, debR, nbitsR;
1061    int lengthG, debG, nbitsG;
1062    int lengthB, debB, nbitsB;
1063    
1064    // Get info from Lut Descriptors
1065    // (the 3 LUT descriptors may be different)    
1066    std::string lutDescriptionR = GetEntryByNumber(0x0028,0x1101);
1067    if ( lutDescriptionR == GDCM_UNFOUND )
1068    {
1069       return NULL;
1070    }
1071
1072    std::string lutDescriptionG = GetEntryByNumber(0x0028,0x1102);
1073    if ( lutDescriptionG == GDCM_UNFOUND )
1074    {
1075       return NULL;
1076    }
1077
1078    std::string lutDescriptionB = GetEntryByNumber(0x0028,0x1103);
1079    if ( lutDescriptionB == GDCM_UNFOUND )
1080    {
1081       return NULL;
1082    }
1083
1084    // lengthR: Red LUT length in Bytes
1085    // debR:    subscript of the first Lut Value
1086    // nbitsR:  Lut item size (in Bits)
1087    int nbRead = sscanf( lutDescriptionR.c_str(), "%d\\%d\\%d", 
1088                         &lengthR, &debR, &nbitsR );
1089    if( nbRead != 3 )
1090    {
1091       dbg.Verbose(0, "gdcmHeader::GetLUTRGBA: trouble reading red LUT");
1092    }
1093    
1094    // lengthG: Green LUT length in Bytes
1095    // debG:    subscript of the first Lut Value
1096    // nbitsG:  Lut item size (in Bits)
1097    nbRead = sscanf( lutDescriptionG.c_str(), "%d\\%d\\%d", 
1098                     &lengthG, &debG, &nbitsG );
1099    if( nbRead != 3 )
1100    {
1101       dbg.Verbose(0, "gdcmHeader::GetLUTRGBA: trouble reading green LUT");
1102    }
1103
1104    // lengthB: Blue LUT length in Bytes
1105    // debB:    subscript of the first Lut Value
1106    // nbitsB:  Lut item size (in Bits)
1107    nbRead = sscanf( lutDescriptionB.c_str(), "%d\\%d\\%d", 
1108                     &lengthB, &debB, &nbitsB );
1109    if( nbRead != 3 )
1110    {
1111       dbg.Verbose(0, "gdcmHeader::GetLUTRGBA: trouble reading blue LUT");
1112    }
1113  
1114    // Load LUTs into memory, (as they were stored on disk)
1115    uint8_t* lutR = (uint8_t*) GetEntryVoidAreaByNumber(0x0028,0x1201);
1116    uint8_t* lutG = (uint8_t*) GetEntryVoidAreaByNumber(0x0028,0x1202);
1117    uint8_t* lutB = (uint8_t*) GetEntryVoidAreaByNumber(0x0028,0x1203); 
1118
1119    if ( !lutR || !lutG || !lutB )
1120    {
1121       dbg.Verbose(0, "gdcmHeader::GetLUTRGBA: trouble with one of the LUT");
1122       return NULL;
1123    } 
1124    // forge the 4 * 8 Bits Red/Green/Blue/Alpha LUT 
1125
1126    uint8_t* LUTRGBA = new uint8_t[1024]; // 256 * 4 (R, G, B, Alpha) 
1127    if ( !LUTRGBA )
1128    {
1129       return NULL;
1130    }
1131    memset(LUTRGBA, 0, 1024);
1132
1133    // Bits Allocated
1134    int nb;
1135    std::string str_nb = GetEntryByNumber(0x0028,0x0100);
1136    if ( str_nb == GDCM_UNFOUND )
1137    {
1138       nb = 16;
1139    }
1140    else
1141    {
1142       nb = atoi( str_nb.c_str() );
1143    }
1144    int mult;
1145
1146    if ( nbitsR == 16 && nb == 8)
1147    {
1148       // when LUT item size is different than pixel size
1149       mult = 2; // high byte must be = low byte 
1150    }
1151    else
1152    {
1153       // See PS 3.3-2003 C.11.1.1.2 p 619
1154       mult = 1;
1155    }
1156
1157    // if we get a black image, let's just remove the '+1'
1158    // from 'i*mult+1' and check again 
1159    // if it works, we shall have to check the 3 Palettes
1160    // to see which byte is ==0 (first one, or second one)
1161    // and fix the code
1162    // We give up the checking to avoid some (useless ?)overhead 
1163    // (optimistic asumption)
1164    uint8_t* a;      
1165    int i;
1166
1167    a = LUTRGBA + 0;
1168    for( i=0; i < lengthR; ++i)
1169    {
1170       *a = lutR[i*mult+1];
1171       a += 4;
1172    }        
1173
1174    a = LUTRGBA + 1;
1175    for( i=0; i < lengthG; ++i)
1176    {
1177       *a = lutG[i*mult+1];
1178       a += 4;
1179    }  
1180
1181    a = LUTRGBA + 2;
1182    for(i=0; i < lengthB; ++i)
1183    {
1184       *a = lutB[i*mult+1];
1185       a += 4;
1186    }
1187
1188    a = LUTRGBA + 3;
1189    for(i=0; i < 256; ++i)
1190    {
1191       *a = 1; // Alpha component
1192       a += 4;
1193    }
1194
1195    return LUTRGBA;
1196
1197
1198 /**
1199  * \brief Accesses the info from 0002,0010 : Transfert Syntax and gdcmTS
1200  *        else 1.
1201  * @return The full Transfert Syntax Name (as opposed to Transfert Syntax UID)
1202  */
1203 std::string gdcmHeader::GetTransfertSyntaxName()
1204 {
1205    // use the gdcmTS (TS : Transfert Syntax)
1206    std::string transfertSyntax = GetEntryByNumber(0x0002,0x0010);
1207
1208    if ( transfertSyntax == GDCM_UNFOUND )
1209    {
1210       dbg.Verbose(0, "gdcmHeader::GetTransfertSyntaxName:"
1211                      " unfound Transfert Syntax (0002,0010)");
1212       return "Uncompressed ACR-NEMA";
1213    }
1214
1215    while ( ! isdigit(transfertSyntax[transfertSyntax.length()-1]) )
1216    {
1217       transfertSyntax.erase(transfertSyntax.length()-1, 1);
1218    }
1219    // we do it only when we need it
1220    gdcmTS* ts         = gdcmGlobal::GetTS();
1221    std::string tsName = ts->GetValue( transfertSyntax );
1222
1223    //delete ts; /// \todo Seg Fault when deleted ?!
1224    return tsName;
1225 }
1226
1227 /**
1228  * \brief Sets the Pixel Area size in the Header
1229  *        --> not-for-rats function
1230  * @param ImageDataSize new Pixel Area Size
1231  *        warning : nothing else is checked
1232  */
1233 void gdcmHeader::SetImageDataSize(size_t ImageDataSize)
1234 {
1235    std::string content1;
1236    char car[20];
1237
1238    sprintf(car,"%d",ImageDataSize);
1239  
1240    gdcmDocEntry *a = GetDocEntryByNumber(GrPixel, NumPixel);
1241    a->SetLength(ImageDataSize);
1242
1243    ImageDataSize+=8;
1244    sprintf(car,"%d",ImageDataSize);
1245    content1=car;
1246    SetEntryByNumber(content1, GrPixel, NumPixel);
1247 }
1248
1249 //-----------------------------------------------------------------------------
1250 // Protected
1251
1252 /**
1253  * \brief anonymize a Header (removes Patient's personal info)
1254  *        (read the code to see which ones ...)
1255  */
1256 bool gdcmHeader::AnonymizeHeader()
1257 {
1258    gdcmDocEntry* patientNameHE = GetDocEntryByNumber (0x0010, 0x0010);
1259
1260    ReplaceIfExistByNumber ("  ",0x0010, 0x2154); // Telephone   
1261    ReplaceIfExistByNumber ("  ",0x0010, 0x1040); // Adress
1262    ReplaceIfExistByNumber ("  ",0x0010, 0x0020); // Patient ID
1263   
1264    if ( patientNameHE )
1265    {
1266       std::string studyInstanceUID =  GetEntryByNumber (0x0020, 0x000d);
1267       if ( studyInstanceUID != GDCM_UNFOUND )
1268       {
1269          ReplaceOrCreateByNumber(studyInstanceUID, 0x0010, 0x0010);
1270       }
1271       else
1272       {
1273          ReplaceOrCreateByNumber(std::string("anonymised"), 0x0010, 0x0010);
1274       }
1275    }
1276
1277   // Just for fun :-(
1278   // (if any) remove or replace all the stuff that contains a Date
1279
1280 //0008 0012 DA ID Instance Creation Date
1281 //0008 0020 DA ID Study Date
1282 //0008 0021 DA ID Series Date
1283 //0008 0022 DA ID Acquisition Date
1284 //0008 0023 DA ID Content Date
1285 //0008 0024 DA ID Overlay Date
1286 //0008 0025 DA ID Curve Date
1287 //0008 002a DT ID Acquisition Datetime
1288 //0018 9074 DT ACQ Frame Acquisition Datetime
1289 //0018 9151 DT ACQ Frame Reference Datetime
1290 //0018 a002 DT ACQ Contribution Date Time
1291 //0020 3403 SH REL Modified Image Date (RET)
1292 //0032 0032 DA SDY Study Verified Date
1293 //0032 0034 DA SDY Study Read Date
1294 //0032 1000 DA SDY Scheduled Study Start Date
1295 //0032 1010 DA SDY Scheduled Study Stop Date
1296 //0032 1040 DA SDY Study Arrival Date
1297 //0032 1050 DA SDY Study Completion Date
1298 //0038 001a DA VIS Scheduled Admission Date
1299 //0038 001c DA VIS Scheduled Discharge Date
1300 //0038 0020 DA VIS Admitting Date
1301 //0038 0030 DA VIS Discharge Date
1302 //0040 0002 DA PRC Scheduled Procedure Step Start Date
1303 //0040 0004 DA PRC Scheduled Procedure Step End Date
1304 //0040 0244 DA PRC Performed Procedure Step Start Date
1305 //0040 0250 DA PRC Performed Procedure Step End Date
1306 //0040 2004 DA PRC Issue Date of Imaging Service Request
1307 //0040 4005 DT PRC Scheduled Procedure Step Start Date and Time
1308 //0040 4011 DT PRC Expected Completion Date and Time
1309 //0040 a030 DT PRC Verification Date Time
1310 //0040 a032 DT PRC Observation Date Time
1311 //0040 a120 DT PRC DateTime
1312 //0040 a121 DA PRC Date
1313 //0040 a13a DT PRC Referenced Datetime
1314 //0070 0082 DA ??? Presentation Creation Date
1315 //0100 0420 DT ??? SOP Autorization Date and Time
1316 //0400 0105 DT ??? Digital Signature DateTime
1317 //2100 0040 DA PJ Creation Date
1318 //3006 0008 DA SSET Structure Set Date
1319 //3008 0024 DA ??? Treatment Control Point Date
1320 //3008 0054 DA ??? First Treatment Date
1321 //3008 0056 DA ??? Most Recent Treatment Date
1322 //3008 0162 DA ??? Safe Position Exit Date
1323 //3008 0166 DA ??? Safe Position Return Date
1324 //3008 0250 DA ??? Treatment Date
1325 //300a 0006 DA RT RT Plan Date
1326 //300a 022c DA RT Air Kerma Rate Reference Date
1327 //300e 0004 DA RT Review Date
1328
1329    return true;
1330 }
1331
1332 /**
1333   * \brief gets the info from 0020,0037 : Image Orientation Patient
1334   * @param iop adress of the (6)float aray to receive values
1335   * @return cosines of image orientation patient
1336   */
1337 void gdcmHeader::GetImageOrientationPatient( float* iop )
1338 {
1339    //iop is supposed to be float[6]
1340    iop[0] = iop[1] = iop[2] = iop[3] = iop[4] = iop[5] = 0;
1341
1342    // 0020 0037 DS REL Image Orientation (Patient)
1343    std::string strImOriPat = GetEntryByNumber(0x0020,0x0037);
1344    if ( strImOriPat != GDCM_UNFOUND )
1345    {
1346       if( sscanf( strImOriPat.c_str(), "%f\\%f\\%f\\%f\\%f\\%f", 
1347           &iop[0], &iop[1], &iop[2], &iop[3], &iop[4], &iop[5]) != 6 )
1348       {
1349          dbg.Verbose(0, "gdcmHeader::GetImageOrientationPatient: wrong Image Orientation Patient (0020,0037)");
1350          return ;  // bug in the element 0x0020,0x0037
1351       }
1352       else
1353       {
1354          return ;
1355       }
1356    }
1357
1358    //For ACR-NEMA
1359    // 0020 0035 DS REL Image Orientation (RET)
1360    strImOriPat = GetEntryByNumber(0x0020,0x0035);
1361    if ( strImOriPat != GDCM_UNFOUND )
1362    {
1363       if( sscanf( strImOriPat.c_str(), "%f\\%f\\%f\\%f\\%f\\%f", 
1364           &iop[0], &iop[1], &iop[2], &iop[3], &iop[4], &iop[5]) != 6 )
1365       {
1366          dbg.Verbose(0, "gdcmHeader::GetImageOrientationPatient: wrong Image Orientation Patient (0020,0035)");
1367          return ;  // bug in the element 0x0020,0x0035
1368       }
1369    }
1370    else
1371    {
1372       return;
1373    }
1374 }
1375
1376 //-----------------------------------------------------------------------------
1377 // Private
1378
1379 //-----------------------------------------------------------------------------