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