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