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