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