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