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