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