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