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