]> Creatis software - gdcm.git/blob - src/gdcmHeader.cxx
* DEVELOPPER spread out in Doc/Website/Developpers.html, CodingStyle.html,
[gdcm.git] / src / gdcmHeader.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmHeader.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/09/23 10:17:26 $
7   Version:   $Revision: 1.188 $
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   // TODO : correct 'Pixel group' Length if necessary
112
113    int i_lgPix = GetEntryLengthByNumber(GrPixel, NumPixel);
114    if (i_lgPix != -2)
115    {
116       // no (GrPixel, NumPixel) element
117       char* dumm = new char[20];
118       sprintf(dumm ,"%d", i_lgPix+12);
119       std::string s_lgPix = dumm;
120       delete[] dumm;
121       ReplaceOrCreateByNumber(s_lgPix,GrPixel, 0x0000);
122    }
123
124    // FIXME : should be nice if we could move it to gdcmFile
125    //         (or in future gdcmPixelData class)
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          RemoveEntryNoDestroy(e);
139       }
140       e = GetDocEntryByNumber(0x0028,0x1102);
141       if (e)
142       {
143          RemoveEntryNoDestroy(e);
144       }
145       e = GetDocEntryByNumber(0x0028,0x1103);
146       if (e)
147       {
148          RemoveEntryNoDestroy(e);
149       }
150       e = GetDocEntryByNumber(0x0028,0x01201);
151       if (e)
152       {
153          RemoveEntryNoDestroy(e);
154       }
155       e = GetDocEntryByNumber(0x0028,0x1202);
156       if (e)
157       {
158          RemoveEntryNoDestroy(e);
159       }
160       e = GetDocEntryByNumber(0x0028,0x1203);
161       if (e)
162       {
163           RemoveEntryNoDestroy(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    return atoi( strSize.c_str() );
757 }
758
759 /**
760  * \ingroup gdcmHeader
761  * \brief   Retrieve the number of Bits Allocated
762  *          (8, 12 -compacted ACR-NEMA files, 16, ...)
763  * @return  The encountered number of Bits Allocated, 0 by default.
764  *          0 means the file is NOT USABLE. The caller has to check it !
765  */
766 int gdcmHeader::GetBitsAllocated()
767 {
768    std::string strSize = GetEntryByNumber(0x0028,0x0100);
769    if ( strSize == GDCM_UNFOUND )
770    {
771       dbg.Verbose(0, "gdcmHeader::GetBitsStored: this is supposed to be mandatory");
772       return 0; // It's supposed to be mandatory
773                 // the caller will have to check
774    }
775    return atoi( strSize.c_str() );
776 }
777
778 /**
779  * \ingroup gdcmHeader
780  * \brief   Retrieve the number of Samples Per Pixel
781  *          (1 : gray level, 3 : RGB -1 or 3 Planes-)
782  * @return  The encountered number of Samples Per Pixel, 1 by default.
783  *          (Gray level Pixels)
784  */
785 int gdcmHeader::GetSamplesPerPixel()
786 {
787    std::string strSize = GetEntryByNumber(0x0028,0x0002);
788    if ( strSize == GDCM_UNFOUND )
789    {
790       dbg.Verbose(0, "gdcmHeader::GetBitsStored: this is supposed to be mandatory");
791       return 1; // Well, it's supposed to be mandatory ...
792                 // but sometimes it's missing : *we* assume Gray pixels
793    }
794    return atoi( strSize.c_str() );
795 }
796
797 /**
798  * \ingroup gdcmHeader
799  * \brief   Retrieve the Planar Configuration for RGB images
800  *          (0 : RGB Pixels , 1 : R Plane + G Plane + B Plane)
801  * @return  The encountered Planar Configuration, 0 by default.
802  */
803 int gdcmHeader::GetPlanarConfiguration()
804 {
805    std::string strSize = GetEntryByNumber(0x0028,0x0006);
806    if ( strSize == GDCM_UNFOUND )
807    {
808       return 0;
809    }
810    return atoi( strSize.c_str() );
811 }
812
813 /**
814  * \ingroup gdcmHeader
815  * \brief   Return the size (in bytes) of a single pixel of data.
816  * @return  The size in bytes of a single pixel of data; 0 by default
817  *          0 means the file is NOT USABLE; the caller will have to check        
818  */
819 int gdcmHeader::GetPixelSize()
820 {
821    // 0028 0100 US IMG Bits Allocated
822    // (in order no to be messed up by old RGB images)
823    //   if (gdcmHeader::GetEntryByNumber(0x0028,0x0100) == "24")
824    //      return 3;
825
826    std::string pixelType = GetPixelType();
827    if ( pixelType ==  "8U" || pixelType == "8S" )
828    {
829       return 1;
830    }
831    if ( pixelType == "16U" || pixelType == "16S")
832    {
833       return 2;
834    }
835    if ( pixelType == "32U" || pixelType == "32S")
836    {
837       return 4;
838    }
839    if ( pixelType == "FD" )
840    {
841       return 8;
842    }
843    dbg.Verbose(0, "gdcmHeader::GetPixelSize: Unknown pixel type");
844    return 0;
845 }
846
847 /**
848  * \ingroup gdcmHeader
849  * \brief   Build the Pixel Type of the image.
850  *          Possible values are:
851  *          - 8U  unsigned  8 bit,
852  *          - 8S    signed  8 bit,
853  *          - 16U unsigned 16 bit,
854  *          - 16S   signed 16 bit,
855  *          - 32U unsigned 32 bit,
856  *          - 32S   signed 32 bit,
857  *          - FD floating double 64 bits (Not kosher DICOM, but so usefull!)
858  * \warning 12 bit images appear as 16 bit.
859  *          24 bit images appear as 8 bit
860  * @return  0S if nothing found. NOT USABLE file. The caller has to check
861  */
862 std::string gdcmHeader::GetPixelType()
863 {
864    std::string bitsAlloc = GetEntryByNumber(0x0028, 0x0100); // Bits Allocated
865    if ( bitsAlloc == GDCM_UNFOUND )
866    {
867       dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Bits Allocated");
868       bitsAlloc = "16";
869    }
870
871    if ( bitsAlloc == "64" )
872    {
873       return "FD";
874    }
875    if ( bitsAlloc == "12" )
876    {
877       // It will be unpacked
878       bitsAlloc = "16";
879    }
880    else if ( bitsAlloc == "24" )
881    {
882       // (in order no to be messed up
883       bitsAlloc = "8";  // by old RGB images)
884    }
885
886    std::string sign = GetEntryByNumber(0x0028, 0x0103); // "Pixel Representation"
887
888    if (sign == GDCM_UNFOUND )
889    {
890       dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Pixel Representation");
891       bitsAlloc = "0";
892    }
893    if ( sign == "0" )
894    {
895       sign = "U";
896    }
897    else
898    {
899       sign = "S";
900    }
901    return bitsAlloc + sign;
902 }
903
904
905 /**
906  * \ingroup gdcmHeader
907  * \brief   Recover the offset (from the beginning of the file) 
908  *          of *image* pixels (not *icone image* pixels, if any !)
909  * @return Pixel Offset
910  */
911 size_t gdcmHeader::GetPixelOffset()
912 {
913    gdcmDocEntry* pxlElement = GetDocEntryByNumber(GrPixel,NumPixel);
914    if ( pxlElement )
915    {
916       return pxlElement->GetOffset();
917    }
918    else
919    {
920 #ifdef GDCM_DEBUG
921       std::cout << "Big trouble : Pixel Element ("
922                 << std::hex << GrPixel<<","<< NumPixel<< ") NOT found"
923                 << std::endl;  
924 #endif //GDCM_DEBUG
925       return 0;
926    }
927 }
928
929 // TODO : unify those two (previous one and next one)
930 /**
931  * \ingroup gdcmHeader
932  * \brief   Recover the pixel area length (in Bytes)
933  * @return Pixel Element Length, as stored in the header
934  *         (NOT the memory space necessary to hold the Pixels 
935  *          -in case of embeded compressed image-)
936  *         0 : NOT USABLE file. The caller has to check.
937  */
938 size_t gdcmHeader::GetPixelAreaLength()
939 {
940    gdcmDocEntry* pxlElement = GetDocEntryByNumber(GrPixel,NumPixel);
941    if ( pxlElement )
942    {
943       return pxlElement->GetLength();
944    }
945    else
946    {
947 #ifdef GDCM_DEBUG
948       std::cout << "Big trouble : Pixel Element ("
949                 << std::hex << GrPixel<<","<< NumPixel<< ") NOT found"
950                 << std::endl;
951 #endif //GDCM_DEBUG
952       return 0;
953    }
954 }
955
956 /**
957   * \ingroup gdcmHeader
958   * \brief tells us if LUT are used
959   * \warning Right now, 'Segmented xxx Palette Color Lookup Table Data'
960   *          are NOT considered as LUT, since nobody knows
961   *          how to deal with them
962   *          Please warn me if you know sbdy that *does* know ... jprx
963   * @return true if LUT Descriptors and LUT Tables were found 
964   */
965 bool gdcmHeader::HasLUT()
966 {
967    // Check the presence of the LUT Descriptors, and LUT Tables    
968    // LutDescriptorRed    
969    if ( !GetDocEntryByNumber(0x0028,0x1101) )
970    {
971       return false;
972    }
973    // LutDescriptorGreen 
974    if ( !GetDocEntryByNumber(0x0028,0x1102) )
975    {
976       return false;
977    }
978    // LutDescriptorBlue 
979    if ( !GetDocEntryByNumber(0x0028,0x1103) )
980    {
981       return false;
982    }
983    // Red Palette Color Lookup Table Data
984    if ( !GetDocEntryByNumber(0x0028,0x1201) )
985    {
986       return false;
987    }
988    // Green Palette Color Lookup Table Data       
989    if ( !GetDocEntryByNumber(0x0028,0x1202) )
990    {
991       return false;
992    }
993    // Blue Palette Color Lookup Table Data      
994    if ( !GetDocEntryByNumber(0x0028,0x1203) )
995    {
996       return false;
997    }
998
999    // FIXME : (0x0028,0x3006) : LUT Data (CTX dependent)
1000    //         NOT taken into account, but we don't know how to use it ...   
1001    return true;
1002 }
1003
1004 /**
1005   * \ingroup gdcmHeader
1006   * \brief gets the info from 0028,1101 : Lookup Table Desc-Red
1007   *             else 0
1008   * @return Lookup Table number of Bits , 0 by default
1009   *          when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
1010   * @ return bit number of each LUT item 
1011   */
1012 int gdcmHeader::GetLUTNbits()
1013 {
1014    std::vector<std::string> tokens;
1015    int lutNbits;
1016
1017    //Just hope Lookup Table Desc-Red = Lookup Table Desc-Red = Lookup Table Desc-Blue
1018    // Consistency already checked in GetLUTLength
1019    std::string lutDescription = GetEntryByNumber(0x0028,0x1101);
1020    if ( lutDescription == GDCM_UNFOUND )
1021    {
1022       return 0;
1023    }
1024
1025    tokens.clear(); // clean any previous value
1026    Tokenize ( lutDescription, tokens, "\\" );
1027    //LutLength=atoi(tokens[0].c_str());
1028    //LutDepth=atoi(tokens[1].c_str());
1029
1030    lutNbits = atoi( tokens[2].c_str() );
1031    tokens.clear();
1032
1033    return lutNbits;
1034 }
1035
1036 /**
1037   * \ingroup gdcmHeader
1038   * \brief builts Red/Green/Blue/Alpha LUT from Header
1039   *         when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
1040   *          and (0028,1101),(0028,1102),(0028,1102)  
1041   *            - xxx Palette Color Lookup Table Descriptor - are found
1042   *          and (0028,1201),(0028,1202),(0028,1202) 
1043   *            - xxx Palette Color Lookup Table Data - are found 
1044   * \warning does NOT deal with :
1045   *   0028 1100 Gray Lookup Table Descriptor (Retired)
1046   *   0028 1221 Segmented Red Palette Color Lookup Table Data
1047   *   0028 1222 Segmented Green Palette Color Lookup Table Data
1048   *   0028 1223 Segmented Blue Palette Color Lookup Table Data 
1049   *   no known Dicom reader deals with them :-(
1050   * @return a RGBA Lookup Table 
1051   */ 
1052 uint8_t* gdcmHeader::GetLUTRGBA()
1053 {
1054    // Not so easy : see 
1055    // http://www.barre.nom.fr/medical/dicom2/limitations.html#Color%20Lookup%20Tables
1056
1057 //  if Photometric Interpretation # PALETTE COLOR, no LUT to be done
1058    if ( GetEntryByNumber(0x0028,0x0004) != "PALETTE COLOR " )
1059    {
1060       return NULL;
1061    }
1062
1063    int lengthR, debR, nbitsR;
1064    int lengthG, debG, nbitsG;
1065    int lengthB, debB, nbitsB;
1066    
1067    // Get info from Lut Descriptors
1068    // (the 3 LUT descriptors may be different)    
1069    std::string lutDescriptionR = GetEntryByNumber(0x0028,0x1101);
1070    if ( lutDescriptionR == GDCM_UNFOUND )
1071    {
1072       return NULL;
1073    }
1074
1075    std::string lutDescriptionG = GetEntryByNumber(0x0028,0x1102);
1076    if ( lutDescriptionG == GDCM_UNFOUND )
1077    {
1078       return NULL;
1079    }
1080
1081    std::string lutDescriptionB = GetEntryByNumber(0x0028,0x1103);
1082    if ( lutDescriptionB == GDCM_UNFOUND )
1083    {
1084       return NULL;
1085    }
1086
1087    // lengthR: Red LUT length in Bytes
1088    // debR:    subscript of the first Lut Value
1089    // nbitsR:  Lut item size (in Bits)
1090    int nbRead = sscanf( lutDescriptionR.c_str(), "%d\\%d\\%d", 
1091                         &lengthR, &debR, &nbitsR );
1092    if( nbRead != 3 )
1093    {
1094       dbg.Verbose(0, "gdcmHeader::GetLUTRGBA: trouble reading red LUT");
1095    }
1096    
1097    // lengthG: Green LUT length in Bytes
1098    // debG:    subscript of the first Lut Value
1099    // nbitsG:  Lut item size (in Bits)
1100    nbRead = sscanf( lutDescriptionG.c_str(), "%d\\%d\\%d", 
1101                     &lengthG, &debG, &nbitsG );
1102    if( nbRead != 3 )
1103    {
1104       dbg.Verbose(0, "gdcmHeader::GetLUTRGBA: trouble reading green LUT");
1105    }
1106
1107    // lengthB: Blue LUT length in Bytes
1108    // debB:    subscript of the first Lut Value
1109    // nbitsB:  Lut item size (in Bits)
1110    nbRead = sscanf( lutDescriptionB.c_str(), "%d\\%d\\%d", 
1111                     &lengthB, &debB, &nbitsB );
1112    if( nbRead != 3 )
1113    {
1114       dbg.Verbose(0, "gdcmHeader::GetLUTRGBA: trouble reading blue LUT");
1115    }
1116  
1117    // Load LUTs into memory, (as they were stored on disk)
1118    uint8_t* lutR = (uint8_t*) GetEntryBinAreaByNumber(0x0028,0x1201);
1119    uint8_t* lutG = (uint8_t*) GetEntryBinAreaByNumber(0x0028,0x1202);
1120    uint8_t* lutB = (uint8_t*) GetEntryBinAreaByNumber(0x0028,0x1203); 
1121
1122    if ( !lutR || !lutG || !lutB )
1123    {
1124       dbg.Verbose(0, "gdcmHeader::GetLUTRGBA: trouble with one of the LUT");
1125       return NULL;
1126    } 
1127    // forge the 4 * 8 Bits Red/Green/Blue/Alpha LUT 
1128
1129    uint8_t* LUTRGBA = new uint8_t[1024]; // 256 * 4 (R, G, B, Alpha) 
1130    if ( !LUTRGBA )
1131    {
1132       return NULL;
1133    }
1134    memset(LUTRGBA, 0, 1024);
1135
1136    // Bits Allocated
1137    int nb;
1138    std::string str_nb = GetEntryByNumber(0x0028,0x0100);
1139    if ( str_nb == GDCM_UNFOUND )
1140    {
1141       nb = 16;
1142    }
1143    else
1144    {
1145       nb = atoi( str_nb.c_str() );
1146    }
1147    int mult;
1148
1149    if ( nbitsR == 16 && nb == 8)
1150    {
1151       // when LUT item size is different than pixel size
1152       mult = 2; // high byte must be = low byte 
1153    }
1154    else
1155    {
1156       // See PS 3.3-2003 C.11.1.1.2 p 619
1157       mult = 1;
1158    }
1159
1160    // if we get a black image, let's just remove the '+1'
1161    // from 'i*mult+1' and check again 
1162    // if it works, we shall have to check the 3 Palettes
1163    // to see which byte is ==0 (first one, or second one)
1164    // and fix the code
1165    // We give up the checking to avoid some (useless ?)overhead 
1166    // (optimistic asumption)
1167    uint8_t* a;      
1168    int i;
1169
1170    a = LUTRGBA + 0;
1171    for( i=0; i < lengthR; ++i)
1172    {
1173       *a = lutR[i*mult+1];
1174       a += 4;
1175    }        
1176
1177    a = LUTRGBA + 1;
1178    for( i=0; i < lengthG; ++i)
1179    {
1180       *a = lutG[i*mult+1];
1181       a += 4;
1182    }  
1183
1184    a = LUTRGBA + 2;
1185    for(i=0; i < lengthB; ++i)
1186    {
1187       *a = lutB[i*mult+1];
1188       a += 4;
1189    }
1190
1191    a = LUTRGBA + 3;
1192    for(i=0; i < 256; ++i)
1193    {
1194       *a = 1; // Alpha component
1195       a += 4;
1196    }
1197    return LUTRGBA;
1198
1199
1200 /**
1201  * \brief Accesses the info from 0002,0010 : Transfert Syntax and gdcmTS
1202  *        else 1.
1203  * @return The full Transfert Syntax Name (as opposed to Transfert Syntax UID)
1204  */
1205 std::string gdcmHeader::GetTransfertSyntaxName()
1206 {
1207    // use the gdcmTS (TS : Transfert Syntax)
1208    std::string transfertSyntax = GetEntryByNumber(0x0002,0x0010);
1209
1210    if ( transfertSyntax == GDCM_NOTLOADED ) { // fusible
1211       std::cout << "Transfert Syntax not loaded. " << std::endl
1212                << "Better you increase MAX_SIZE_LOAD_ELEMENT_VALUE"
1213                << std::endl;
1214       return "Uncompressed ACR-NEMA";
1215    }
1216    if ( transfertSyntax == GDCM_UNFOUND )
1217    {
1218       dbg.Verbose(0, "gdcmHeader::GetTransfertSyntaxName:"
1219                      " unfound Transfert Syntax (0002,0010)");
1220       return "Uncompressed ACR-NEMA";
1221    }
1222
1223    while ( ! isdigit(transfertSyntax[transfertSyntax.length()-1]) )
1224    {
1225       transfertSyntax.erase(transfertSyntax.length()-1, 1);
1226    }
1227    // we do it only when we need it
1228    gdcmTS* ts         = gdcmGlobal::GetTS();
1229    std::string tsName = ts->GetValue( transfertSyntax );
1230
1231    //delete ts; /// \todo Seg Fault when deleted ?!
1232    return tsName;
1233 }
1234
1235 /**
1236  * \brief Sets the Pixel Area size in the Header
1237  *        --> not-for-rats function
1238  * @param ImageDataSize new Pixel Area Size
1239  *        warning : nothing else is checked
1240  */
1241 void gdcmHeader::SetImageDataSize(size_t ImageDataSize)
1242 {
1243    char car[20];
1244    sprintf(car,"%d",ImageDataSize);
1245  
1246    gdcmDocEntry *a = GetDocEntryByNumber(GrPixel, NumPixel);
1247    a->SetLength(ImageDataSize);
1248
1249    ImageDataSize += 8;
1250    sprintf(car,"%d",ImageDataSize);
1251
1252    const std::string content1 = car;
1253    SetEntryByNumber(content1, GrPixel, NumPixel);
1254 }
1255
1256 //-----------------------------------------------------------------------------
1257 // Protected
1258
1259 /**
1260  * \brief anonymize a Header (removes Patient's personal info)
1261  *        (read the code to see which ones ...)
1262  */
1263 bool gdcmHeader::AnonymizeHeader()
1264 {
1265    // If exist, replace by spaces
1266    SetEntryByNumber ("  ",0x0010, 0x2154); // Telephone   
1267    SetEntryByNumber ("  ",0x0010, 0x1040); // Adress
1268    SetEntryByNumber ("  ",0x0010, 0x0020); // Patient ID
1269
1270    gdcmDocEntry* patientNameHE = GetDocEntryByNumber (0x0010, 0x0010);
1271   
1272    if ( patientNameHE ) // we replace it by Study Instance UID (why not)
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 //-----------------------------------------------------------------------------