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