]> Creatis software - gdcm.git/blob - src/gdcmFile.cxx
COMP: Remove deprecated call from cascade deprecated functions...
[gdcm.git] / src / gdcmFile.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmFile.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/07/23 01:54:03 $
7   Version:   $Revision: 1.259 $
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 //
20 // --------------  Remember ! ----------------------------------
21 //
22 // Image Position Patient                              (0020,0032):
23 // If not found (ACR_NEMA) we try Image Position       (0020,0030)
24 // If not found (ACR-NEMA), we consider Slice Location (0020,1041)
25 //                                   or Location       (0020,0050) 
26 //                                   as the Z coordinate, 
27 // 0. for all the coordinates if nothing is found
28 //
29 // Image Position (Patient) (0020,0032) VM=3 What is it used for?
30 // -->
31 //  The attribute Patient Orientation (0020,0020) from the General Image Module 
32 // is of type 2C and has the condition Required if image does not require 
33 // Image Orientation (0020,0037) and Image Position (0020,0032). 
34 // However, if the image does require the attributes 
35 // - Image Orientation (Patient) (0020,0037), VM=6
36 // - Image Position Patient (0020,0032), VM=3
37 // then attribute Patient Orientation (0020,0020) should not be present
38 //  in the images.
39 //
40 // Remember also :
41 // Patient Position (0018,5100) values : HFP   = Head First-Prone
42 //                                       HFS   = Head First-Supine
43 //                                       HFDR  = Head First-Decubitus Right
44 //                                       HFDL = Head First-Decubitus Left
45 //                                       FFDR = Feet First-Decubitus Right
46 //                                       FFDL = Feet First-Decubitus Left
47 //                                       FFP  = Feet First-Prone
48 //                                       FFS  = Feet First-Supine
49 //                    can also find      SEMIERECT
50 //                                       SUPINE
51 // CS 2 Patient Orientation (0020 0020)
52 //               When the coordinates of the image 
53 //               are always present, this field is almost never used.
54 //               Better we don't tust it too much ...
55 //               Found Values are :      L\P
56 //                                       L\FP
57 //                                       P\F
58 //                                       L\F
59 //                                       P\FR
60 //                                       R\F
61 //
62 // (0020|0037) [Image Orientation (Patient)] [1\0\0\0\1\0 ]
63
64                                       
65 // ---------------------------------------------------------------
66 //
67 #include "gdcmFile.h"
68 #include "gdcmGlobal.h"
69 #include "gdcmUtil.h"
70 #include "gdcmDebug.h"
71 #include "gdcmTS.h"
72 #include "gdcmValEntry.h"
73 #include "gdcmBinEntry.h"
74 #include "gdcmSeqEntry.h"
75 #include "gdcmRLEFramesInfo.h"
76 #include "gdcmJPEGFragmentsInfo.h"
77
78 #include <vector>
79 #include <stdio.h> //sscanf
80 #include <stdlib.h> // for atoi
81 #include <math.h> // for pow
82
83 namespace gdcm 
84 {
85 //-----------------------------------------------------------------------------
86 // Constructor / Destructor
87
88 /**
89  * \brief Constructor used when we want to generate dicom files from scratch
90  */
91 File::File():
92    Document()
93 {
94    RLEInfo  = new RLEFramesInfo;
95    JPEGInfo = new JPEGFragmentsInfo;
96    GrPixel  = 0x7fe0;  // to avoid further troubles
97    NumPixel = 0x0010;
98 }
99
100
101 /**
102  * \brief   Canonical destructor.
103  */
104 File::~File ()
105 {
106    if ( RLEInfo )
107       delete RLEInfo;
108    if ( JPEGInfo )
109       delete JPEGInfo;
110 }
111
112 //-----------------------------------------------------------------------------
113 // Public
114 /**
115  * \brief   Loader  
116  * @return false if file cannot be open or no swap info was found,
117  *         or no tag was found.
118  */
119 bool File::Load( ) 
120 {
121    if ( ! this->Document::Load( ) )
122       return false;
123
124     return DoTheLoadingJob( );   
125 }
126
127 /**
128  * \brief   Does the Loading Job (internal use only)
129  * @return false if file cannot be open or no swap info was found,
130  *         or no tag was found.
131  */
132 bool File::DoTheLoadingJob( ) 
133 {
134
135    // for some ACR-NEMA images GrPixel, NumPixel is *not* 7fe0,0010
136    // We may encounter the 'RETired' (0x0028, 0x0200) tag
137    // (Image Location") . This entry contains the number of
138    // the group that contains the pixel data (hence the "Pixel Data"
139    // is found by indirection through the "Image Location").
140    // Inside the group pointed by "Image Location" the searched element
141    // is conventionally the element 0x0010 (when the norm is respected).
142    // When the "Image Location" is missing we default to group 0x7fe0.
143    // Note: this IS the right place for the code
144  
145    // Image Location
146    const std::string &imgLocation = GetEntryValue(0x0028, 0x0200);
147    if ( imgLocation == GDCM_UNFOUND )
148    {
149       // default value
150       GrPixel = 0x7fe0;
151    }
152    else
153    {
154       GrPixel = (uint16_t) atoi( imgLocation.c_str() );
155    }   
156
157    // sometimes Image Location value doesn't follow
158    // the supposed processor endianness.
159    // see gdcmData/cr172241.dcm
160    if ( GrPixel == 0xe07f )
161    {
162       GrPixel = 0x7fe0;
163    }
164
165    if ( GrPixel != 0x7fe0 )
166    {
167       // This is a kludge for old dirty Philips imager.
168       NumPixel = 0x1010;
169    }
170    else
171    {
172       NumPixel = 0x0010;
173    }
174
175    // Now, we know GrPixel and NumPixel.
176    // Let's create a VirtualDictEntry to allow a further VR modification
177    // and force VR to match with BitsAllocated.
178    DocEntry *entry = GetDocEntry(GrPixel, NumPixel); 
179    if ( entry != 0 )
180    {
181       // Compute the RLE or JPEG info
182       OpenFile();
183       const std::string &ts = GetTransferSyntax();
184       Fp->seekg( entry->GetOffset(), std::ios::beg );
185       if ( Global::GetTS()->IsRLELossless(ts) ) 
186          ComputeRLEInfo();
187       else if ( Global::GetTS()->IsJPEG(ts) )
188          ComputeJPEGFragmentInfo();
189       CloseFile();
190
191       // Create a new BinEntry to change the DictEntry
192       // The changed DictEntry will have 
193       // - a correct PixelVR OB or OW)
194       // - the name to "Pixel Data"
195       BinEntry *oldEntry = dynamic_cast<BinEntry *>(entry);
196       if (oldEntry)
197       {
198          std::string PixelVR;
199          // 8 bits allocated is a 'O Bytes' , as well as 24 (old ACR-NEMA RGB)
200          // more than 8 (i.e 12, 16) is a 'O Words'
201          if ( GetBitsAllocated() == 8 || GetBitsAllocated() == 24 ) 
202             PixelVR = "OB";
203          else
204             PixelVR = "OW";
205
206          // Change only made if usefull
207          if ( PixelVR != oldEntry->GetVR() )
208          {
209             DictEntry* newDict = NewVirtualDictEntry(GrPixel,NumPixel,
210                                                      PixelVR,"1","Pixel Data");
211
212             BinEntry *newEntry = new BinEntry(newDict);
213             newEntry->Copy(entry);
214             newEntry->SetBinArea(oldEntry->GetBinArea(),oldEntry->IsSelfArea());
215             oldEntry->SetSelfArea(false);
216
217             RemoveEntry(oldEntry);
218             AddEntry(newEntry);
219          }
220       }
221    }
222    return true;
223 }
224 /**
225  * \brief  This predicate, based on hopefully reasonable heuristics,
226  *         decides whether or not the current File was properly parsed
227  *         and contains the mandatory information for being considered as
228  *         a well formed and usable Dicom/Acr File.
229  * @return true when File is the one of a reasonable Dicom/Acr file,
230  *         false otherwise. 
231  */
232 bool File::IsReadable()
233 {
234    if ( !Document::IsReadable() )
235    {
236       return false;
237    }
238
239    const std::string &res = GetEntryValue(0x0028, 0x0005);
240    if ( res != GDCM_UNFOUND && atoi(res.c_str()) > 4 )
241    {
242       gdcmWarningMacro("Wrong Image Dimensions" << res);
243       return false; // Image Dimensions
244    }
245    bool b0028_0100 = true;
246    if ( !GetDocEntry(0x0028, 0x0100) )
247    {
248       gdcmWarningMacro("Bits Allocated (0028|0100) not found"); 
249       //return false; // "Bits Allocated"
250       b0028_0100 = false;
251    }
252    bool b0028_0101 = true;
253    if ( !GetDocEntry(0x0028, 0x0101) )
254    {
255       gdcmWarningMacro("Bits Stored (0028|0101) not found");
256       //return false; // "Bits Stored"
257       b0028_0101 = false;
258    }
259    bool b0028_0102 = true;
260    if ( !GetDocEntry(0x0028, 0x0102) )
261    {
262       gdcmWarningMacro("Hight Bit (0028|0102) not found"); 
263       //return false; // "High Bit"
264       b0028_0102 = false;
265    }
266    bool b0028_0103 = true;
267    if ( !GetDocEntry(0x0028, 0x0103) )
268    {
269       gdcmWarningMacro("Pixel Representation (0028|0103) not found");
270       //return false; // "Pixel Representation" i.e. 'Sign' ( 0 : unsigned, 1 : signed)
271       b0028_0103 = false;
272    }
273
274    if ( !b0028_0100 && !b0028_0101 && !b0028_0102 && !b0028_0103)
275    {
276       gdcmWarningMacro("Too much mandatory Tags missing !");
277       return false;
278    }
279
280    if ( !GetDocEntry(GrPixel, NumPixel) )
281    {
282       gdcmWarningMacro("Pixel Dicom Element " << std::hex <<
283                         GrPixel << "|" << NumPixel << "not found");
284       return false; // Pixel Dicom Element not found :-(
285    }
286    return true;
287 }
288
289 /**
290  * \brief gets the info from 0020,0013 : Image Number else 0.
291  * @return image number
292  */
293 int File::GetImageNumber()
294 {
295    //0020 0013 : Image Number
296    std::string strImNumber = GetEntryValue(0x0020,0x0013);
297    if ( strImNumber != GDCM_UNFOUND )
298    {
299       return atoi( strImNumber.c_str() );
300    }
301    return 0;   //Hopeless
302 }
303
304 /**
305  * \brief gets the info from 0008,0060 : Modality
306  * @return Modality Type
307  */
308 ModalityType File::GetModality()
309 {
310    // 0008 0060 : Modality
311    std::string strModality = GetEntryValue(0x0008,0x0060);
312    if ( strModality != GDCM_UNFOUND )
313    {
314            if ( strModality.find("AU")  < strModality.length()) return AU;
315       else if ( strModality.find("AS")  < strModality.length()) return AS;
316       else if ( strModality.find("BI")  < strModality.length()) return BI;
317       else if ( strModality.find("CF")  < strModality.length()) return CF;
318       else if ( strModality.find("CP")  < strModality.length()) return CP;
319       else if ( strModality.find("CR")  < strModality.length()) return CR;
320       else if ( strModality.find("CT")  < strModality.length()) return CT;
321       else if ( strModality.find("CS")  < strModality.length()) return CS;
322       else if ( strModality.find("DD")  < strModality.length()) return DD;
323       else if ( strModality.find("DF")  < strModality.length()) return DF;
324       else if ( strModality.find("DG")  < strModality.length()) return DG;
325       else if ( strModality.find("DM")  < strModality.length()) return DM;
326       else if ( strModality.find("DS")  < strModality.length()) return DS;
327       else if ( strModality.find("DX")  < strModality.length()) return DX;
328       else if ( strModality.find("ECG") < strModality.length()) return ECG;
329       else if ( strModality.find("EPS") < strModality.length()) return EPS;
330       else if ( strModality.find("FA")  < strModality.length()) return FA;
331       else if ( strModality.find("FS")  < strModality.length()) return FS;
332       else if ( strModality.find("HC")  < strModality.length()) return HC;
333       else if ( strModality.find("HD")  < strModality.length()) return HD;
334       else if ( strModality.find("LP")  < strModality.length()) return LP;
335       else if ( strModality.find("LS")  < strModality.length()) return LS;
336       else if ( strModality.find("MA")  < strModality.length()) return MA;
337       else if ( strModality.find("MR")  < strModality.length()) return MR;
338       else if ( strModality.find("NM")  < strModality.length()) return NM;
339       else if ( strModality.find("OT")  < strModality.length()) return OT;
340       else if ( strModality.find("PT")  < strModality.length()) return PT;
341       else if ( strModality.find("RF")  < strModality.length()) return RF;
342       else if ( strModality.find("RG")  < strModality.length()) return RG;
343       else if ( strModality.find("RTDOSE")   
344                                         < strModality.length()) return RTDOSE;
345       else if ( strModality.find("RTIMAGE")  
346                                         < strModality.length()) return RTIMAGE;
347       else if ( strModality.find("RTPLAN")
348                                         < strModality.length()) return RTPLAN;
349       else if ( strModality.find("RTSTRUCT") 
350                                         < strModality.length()) return RTSTRUCT;
351       else if ( strModality.find("SM")  < strModality.length()) return SM;
352       else if ( strModality.find("ST")  < strModality.length()) return ST;
353       else if ( strModality.find("TG")  < strModality.length()) return TG;
354       else if ( strModality.find("US")  < strModality.length()) return US;
355       else if ( strModality.find("VF")  < strModality.length()) return VF;
356       else if ( strModality.find("XA")  < strModality.length()) return XA;
357       else if ( strModality.find("XC")  < strModality.length()) return XC;
358
359       else
360       {
361          /// \todo throw error return value ???
362          /// specified <> unknown in our database
363          return Unknow;
364       }
365    }
366    return Unknow;
367 }
368
369 /**
370  * \brief   Retrieve the number of columns of image.
371  * @return  The encountered size when found, 0 by default.
372  *          0 means the file is NOT USABLE. The caller will have to check
373  */
374 int File::GetXSize()
375 {
376    const std::string &strSize = GetEntryValue(0x0028,0x0011);
377    if ( strSize == GDCM_UNFOUND )
378    {
379       return 0;
380    }
381    return atoi( strSize.c_str() );
382 }
383
384 /**
385  * \brief   Retrieve the number of lines of image.
386  * \warning The defaulted value is 1 as opposed to File::GetXSize()
387  * @return  The encountered size when found, 1 by default 
388  *          (The ACR-NEMA file contains a Signal, not an Image).
389  */
390 int File::GetYSize()
391 {
392    const std::string &strSize = GetEntryValue(0x0028,0x0010);
393    if ( strSize != GDCM_UNFOUND )
394    {
395       return atoi( strSize.c_str() );
396    }
397    if ( IsDicomV3() )
398    {
399       return 0;
400    }
401
402    // The Rows (0028,0010) entry was optional for ACR/NEMA.
403    // (at least some images didn't have it.)
404    // It might hence be a signal (1D image). So we default to 1:
405    return 1;
406 }
407
408 /**
409  * \brief   Retrieve the number of planes of volume or the number
410  *          of frames of a multiframe.
411  * \warning When present we consider the "Number of Frames" as the third
412  *          dimension. When missing we consider the third dimension as
413  *          being the ACR-NEMA "Planes" tag content.
414  * @return  The encountered size when found, 1 by default (single image).
415  */
416 int File::GetZSize()
417 {
418    // Both  DicomV3 and ACR/Nema consider the "Number of Frames"
419    // as the third dimension.
420    const std::string &strSize = GetEntryValue(0x0028,0x0008);
421    if ( strSize != GDCM_UNFOUND )
422    {
423       return atoi( strSize.c_str() );
424    }
425
426    // We then consider the "Planes" entry as the third dimension 
427    const std::string &strSize2 = GetEntryValue(0x0028,0x0012);
428    if ( strSize2 != GDCM_UNFOUND )
429    {
430       return atoi( strSize2.c_str() );
431    }
432    return 1;
433 }
434
435 /**
436   * \brief gets the info from 0018,1164 : ImagerPixelSpacing
437   *                      then 0028,0030 : Pixel Spacing
438   *             else 1.0
439   * @return X dimension of a pixel
440   */
441 float File::GetXSpacing()
442 {
443    float xspacing = 1.0;
444    float yspacing = 1.0;
445    int nbValues;
446
447    // To follow David Clunie's advice, we first check ImagerPixelSpacing
448
449    const std::string &strImagerPixelSpacing = GetEntryValue(0x0018,0x1164);
450    if ( strImagerPixelSpacing != GDCM_UNFOUND )
451    {
452       if ( ( nbValues = sscanf( strImagerPixelSpacing.c_str(), 
453             "%f\\%f", &yspacing, &xspacing)) != 2 )
454       {
455          // if no values, xspacing is set to 1.0
456          if ( nbValues == 0 )
457             xspacing = 1.0;
458          // if single value is found, xspacing is defaulted to yspacing
459          if ( nbValues == 1 )
460             xspacing = yspacing;
461
462          if ( xspacing == 0.0 )
463             xspacing = 1.0;
464
465          return xspacing;
466       }  
467    }
468
469    const std::string &strSpacing = GetEntryValue(0x0028,0x0030);
470
471    if ( strSpacing == GDCM_UNFOUND )
472    {
473       gdcmWarningMacro( "Unfound Pixel Spacing (0028,0030)" );
474       return 1.;
475    }
476
477    if ( ( nbValues = sscanf( strSpacing.c_str(), 
478          "%f \\%f ", &yspacing, &xspacing)) != 2 )
479    {
480       // if no values, xspacing is set to 1.0
481       if ( nbValues == 0 )
482          xspacing = 1.0;
483       // if single value is found, xspacing is defaulted to yspacing
484       if ( nbValues == 1 )
485          xspacing = yspacing;
486
487       if ( xspacing == 0.0 )
488          xspacing = 1.0;
489
490       return xspacing;
491    }
492
493    // to avoid troubles with David Clunie's-like images (at least one)
494    if ( xspacing == 0. && yspacing == 0.)
495       return 1.;
496
497    if ( xspacing == 0.)
498    {
499       gdcmWarningMacro("gdcmData/CT-MONO2-8-abdo.dcm-like problem");
500       // seems to be a bug in the header ...
501       nbValues = sscanf( strSpacing.c_str(), "%f \\0\\%f ", &yspacing, &xspacing);
502       gdcmAssertMacro( nbValues == 2 );
503    }
504
505    return xspacing;
506 }
507
508 /**
509   * \brief gets the info from 0018,1164 : ImagerPixelSpacing
510   *               then from   0028,0030 : Pixel Spacing                         
511   *             else 1.0
512   * @return Y dimension of a pixel
513   */
514 float File::GetYSpacing()
515 {
516    float yspacing = 1.;
517    int nbValues;
518    // To follow David Clunie's advice, we first check ImagerPixelSpacing
519
520    const std::string &strImagerPixelSpacing = GetEntryValue(0x0018,0x1164);
521    if ( strImagerPixelSpacing != GDCM_UNFOUND )
522    {
523       nbValues = sscanf( strImagerPixelSpacing.c_str(), "%f", &yspacing);
524    
525    // if sscanf cannot read any float value, it won't affect yspacing
526       if ( nbValues == 0 )
527             yspacing = 1.0;
528
529       if ( yspacing == 0.0 )
530             yspacing = 1.0;
531
532       return yspacing;  
533    }
534
535    std::string strSpacing = GetEntryValue(0x0028,0x0030);  
536    if ( strSpacing == GDCM_UNFOUND )
537    {
538       gdcmWarningMacro("Unfound Pixel Spacing (0028,0030)");
539       return 1.;
540     }
541
542    // if sscanf cannot read any float value, it won't affect yspacing
543    nbValues = sscanf( strSpacing.c_str(), "%f", &yspacing);
544
545    // if no values, yspacing is set to 1.0
546    if ( nbValues == 0 )
547       yspacing = 1.0;
548
549    if ( yspacing == 0.0 )
550       yspacing = 1.0;
551
552    return yspacing;
553
554
555 /**
556  * \brief gets the info from 0018,0088 : Space Between Slices
557  *                 else from 0018,0050 : Slice Thickness
558  *                 else 1.0
559  * @return Z dimension of a voxel-to be
560  */
561 float File::GetZSpacing()
562 {
563    // Spacing Between Slices : distance between the middle of 2 slices
564    // Slices may be :
565    //   jointives     (Spacing between Slices = Slice Thickness)
566    //   overlapping   (Spacing between Slices < Slice Thickness)
567    //   disjointes    (Spacing between Slices > Slice Thickness)
568    // Slice Thickness : epaisseur de tissus sur laquelle est acquis le signal
569    //   It only concerns the MRI guys, not people wanting to visualize volumes
570    //   If Spacing Between Slices is missing, 
571    //   we suppose slices joint together
572    
573    const std::string &strSpacingBSlices = GetEntryValue(0x0018,0x0088);
574
575    if ( strSpacingBSlices == GDCM_UNFOUND )
576    {
577       gdcmWarningMacro("Unfound Spacing Between Slices (0018,0088)");
578       const std::string &strSliceThickness = GetEntryValue(0x0018,0x0050);       
579       if ( strSliceThickness == GDCM_UNFOUND )
580       {
581          gdcmWarningMacro("Unfound Slice Thickness (0018,0050)");
582          return 1.;
583       }
584       else
585       {
586          // if no 'Spacing Between Slices' is found, 
587          // we assume slices join together
588          // (no overlapping, no interslice gap)
589          // if they don't, we're fucked up
590          return (float)atof( strSliceThickness.c_str() );
591       }
592    }
593    //else
594    return (float)atof( strSpacingBSlices.c_str() );
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       gdcmWarningMacro( "Unfound Image Position Patient (0020,0032)");
611       strImPos = GetEntryValue(0x0020,0x0030); // For ACR-NEMA images
612       if ( strImPos == GDCM_UNFOUND )
613       {
614          gdcmWarningMacro( "Unfound Image Position (RET) (0020,0030)");
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 File::GetYOrigin()
634 {
635    float xImPos, yImPos, zImPos;
636    std::string strImPos = GetEntryValue(0x0020,0x0032);
637
638    if ( strImPos == GDCM_UNFOUND)
639    {
640       gdcmWarningMacro( "Unfound Image Position Patient (0020,0032)");
641       strImPos = GetEntryValue(0x0020,0x0030); // For ACR-NEMA images
642       if ( strImPos == GDCM_UNFOUND )
643       {
644          gdcmWarningMacro( "Unfound Image Position (RET) (0020,0030)");
645          return 0.;
646       }  
647    }
648
649    if ( sscanf( strImPos.c_str(), "%f \\%f \\%f ", &xImPos, &yImPos, &zImPos) != 3 )
650    {
651       return 0.;
652    }
653
654    return yImPos;
655 }
656
657 /**
658  * \brief gets the info from 0020,0032 : Image Position Patient
659  *                 else from 0020,0030 : Image Position (RET)
660  *                 else from 0020,1041 : Slice Location
661  *                 else from 0020,0050 : Location
662  *                 else 0.
663  * @return up-left image corner Z position
664  */
665 float File::GetZOrigin()
666 {
667    float xImPos, yImPos, zImPos; 
668    std::string strImPos = GetEntryValue(0x0020,0x0032);
669
670    if ( strImPos != GDCM_UNFOUND )
671    {
672       if ( sscanf( strImPos.c_str(), "%f \\%f \\%f ", &xImPos, &yImPos, &zImPos) != 3)
673       {
674          gdcmWarningMacro( "Wrong Image Position Patient (0020,0032)");
675          return 0.;  // bug in the element 0x0020,0x0032
676       }
677       else
678       {
679          return zImPos;
680       }
681    }
682
683    strImPos = GetEntryValue(0x0020,0x0030); // For ACR-NEMA images
684    if ( strImPos != GDCM_UNFOUND )
685    {
686       if ( sscanf( strImPos.c_str(), 
687           "%f \\%f \\%f ", &xImPos, &yImPos, &zImPos ) != 3 )
688       {
689          gdcmWarningMacro( "Wrong Image Position (RET) (0020,0030)");
690          return 0.;  // bug in the element 0x0020,0x0032
691       }
692       else
693       {
694          return zImPos;
695       }
696    }
697
698    // for *very* old ACR-NEMA images
699    std::string strSliceLocation = GetEntryValue(0x0020,0x1041);
700    if ( strSliceLocation != GDCM_UNFOUND )
701    {
702       if ( sscanf( strSliceLocation.c_str(), "%f ", &zImPos) != 1)
703       {
704          gdcmWarningMacro( "Wrong Slice Location (0020,1041)");
705          return 0.;  // bug in the element 0x0020,0x1041
706       }
707       else
708       {
709          return zImPos;
710       }
711    }
712    gdcmWarningMacro( "Unfound Slice Location (0020,1041)");
713
714    std::string strLocation = GetEntryValue(0x0020,0x0050);
715    if ( strLocation != GDCM_UNFOUND )
716    {
717       if ( sscanf( strLocation.c_str(), "%f ", &zImPos) != 1 )
718       {
719          gdcmWarningMacro( "Wrong Location (0020,0050)");
720          return 0.;  // bug in the element 0x0020,0x0050
721       }
722       else
723       {
724          return zImPos;
725       }
726    }
727    gdcmWarningMacro( "Unfound Location (0020,0050)");  
728
729    return 0.; // Hopeless
730 }
731
732 /**
733   * \brief gets the info from 0020,0037 : Image Orientation Patient
734   * (needed to organize DICOM files based on their x,y,z position)
735   * @param iop adress of the (6)float array to receive values
736   * @return cosines of image orientation patient
737   */
738 bool File::GetImageOrientationPatient( float iop[6] )
739 {
740    std::string strImOriPat;
741    //iop is supposed to be float[6]
742    iop[0] = iop[1] = iop[2] = iop[3] = iop[4] = iop[5] = 0.;
743
744    // 0020 0037 DS REL Image Orientation (Patient)
745    if ( (strImOriPat = GetEntryValue(0x0020,0x0037)) != GDCM_UNFOUND )
746    {
747       if ( sscanf( strImOriPat.c_str(), "%f \\ %f \\%f \\%f \\%f \\%f ", 
748           &iop[0], &iop[1], &iop[2], &iop[3], &iop[4], &iop[5]) != 6 )
749       {
750          gdcmWarningMacro( "Wrong Image Orientation Patient (0020,0037). Less than 6 values were found." );
751          return false;
752       }
753    }
754    //For ACR-NEMA
755    // 0020 0035 DS REL Image Orientation (RET)
756    else if ( (strImOriPat = GetEntryValue(0x0020,0x0035)) != GDCM_UNFOUND )
757    {
758       if ( sscanf( strImOriPat.c_str(), "%f \\ %f \\%f \\%f \\%f \\%f ", 
759           &iop[0], &iop[1], &iop[2], &iop[3], &iop[4], &iop[5]) != 6 )
760       {
761          gdcmWarningMacro( "wrong Image Orientation Patient (0020,0035). Less than 6 values were found." );
762          return false;
763       }
764    }
765    return true;
766 }
767
768 /**
769  * \brief   Retrieve the number of Bits Stored (actually used)
770  *          (as opposed to number of Bits Allocated)
771  * @return  The encountered number of Bits Stored, 0 by default.
772  *          0 means the file is NOT USABLE. The caller has to check it !
773  */
774 int File::GetBitsStored()
775 {
776    std::string strSize = GetEntryValue( 0x0028, 0x0101 );
777    if ( strSize == GDCM_UNFOUND )
778    {
779       gdcmWarningMacro("(0028,0101) is supposed to be mandatory");
780       return 0;  // It's supposed to be mandatory
781                  // the caller will have to check
782    }
783    return atoi( strSize.c_str() );
784 }
785
786 /**
787  * \brief   Retrieve the number of Bits Allocated
788  *          (8, 12 -compacted ACR-NEMA files-, 16, ...)
789  * @return  The encountered number of Bits Allocated, 0 by default.
790  *          0 means the file is NOT USABLE. The caller has to check it !
791  */
792 int File::GetBitsAllocated()
793 {
794    std::string strSize = GetEntryValue(0x0028,0x0100);
795    if ( strSize == GDCM_UNFOUND  )
796    {
797       gdcmWarningMacro( "(0028,0100) is supposed to be mandatory");
798       return 0; // It's supposed to be mandatory
799                 // the caller will have to check
800    }
801    return atoi( strSize.c_str() );
802 }
803
804 /**
805  * \brief   Retrieve the high bit position.
806  * \warning The method defaults to 0 when information is missing.
807  *          The responsability of checking this value is left to the caller.
808  * @return  The high bit position when present. 0 when missing.
809  */
810 int File::GetHighBitPosition()
811 {
812    std::string strSize = GetEntryValue( 0x0028, 0x0102 );
813    if ( strSize == GDCM_UNFOUND )
814    {
815       gdcmWarningMacro( "(0028,0102) is supposed to be mandatory");
816       return 0;
817    }
818    return atoi( strSize.c_str() );
819 }
820
821 /**
822  * \brief   Retrieve the number of Samples Per Pixel
823  *          (1 : gray level, 3 : RGB/YBR -1 or 3 Planes-)
824  * @return  The encountered number of Samples Per Pixel, 1 by default.
825  *          (we assume Gray level Pixels)
826  */
827 int File::GetSamplesPerPixel()
828 {
829    const std::string &strSize = GetEntryValue(0x0028,0x0002);
830    if ( strSize == GDCM_UNFOUND )
831    {
832       gdcmWarningMacro( "(0028,0002) is supposed to be mandatory");
833       return 1; // Well, it's supposed to be mandatory ...
834                 // but sometimes it's missing : *we* assume Gray pixels
835    }
836    return atoi( strSize.c_str() );
837 }
838
839 /**
840  * \brief   Retrieve the Planar Configuration for RGB images
841  *          (0 : RGB Pixels , 1 : R Plane + G Plane + B Plane)
842  * @return  The encountered Planar Configuration, 0 by default.
843  */
844 int File::GetPlanarConfiguration()
845 {
846    std::string strSize = GetEntryValue(0x0028,0x0006);
847    if ( strSize == GDCM_UNFOUND )
848    {
849       gdcmWarningMacro( "Not found : Planar Configuration (0028,0006)");
850       return 0;
851    }
852    return atoi( strSize.c_str() );
853 }
854
855 /**
856  * \brief   Return the size (in bytes) of a single pixel of data.
857  * @return  The size in bytes of a single pixel of data; 0 by default
858  *          0 means the file is NOT USABLE; the caller will have to check
859  */
860 int File::GetPixelSize()
861 {
862    // 0028 0100 US IMG Bits Allocated
863    // (in order no to be messed up by old ACR-NEMA RGB images)
864    //   if (File::GetEntryValue(0x0028,0x0100) == "24")
865    //      return 3;
866
867    std::string pixelType = GetPixelType();
868    if ( pixelType ==  "8U" || pixelType == "8S" )
869    {
870       return 1;
871    }
872    if ( pixelType == "16U" || pixelType == "16S")
873    {
874       return 2;
875    }
876    if ( pixelType == "32U" || pixelType == "32S")
877    {
878       return 4;
879    }
880    if ( pixelType == "FD" )
881    {
882       return 8;
883    }
884    gdcmWarningMacro( "Unknown pixel type");
885    return 0;
886 }
887
888 /**
889  * \brief   Build the Pixel Type of the image.
890  *          Possible values are:
891  *          - 8U  unsigned  8 bit,
892  *          - 8S    signed  8 bit,
893  *          - 16U unsigned 16 bit,
894  *          - 16S   signed 16 bit,
895  *          - 32U unsigned 32 bit,
896  *          - 32S   signed 32 bit,
897  *          - FD floating double 64 bits (Not kosher DICOM, but so usefull!)
898  * \warning 12 bit images appear as 16 bit.
899  *          24 bit images appear as 8 bit + photochromatic interp ="RGB "
900  *                                        + Planar Configuration = 0
901  * @return  0S if nothing found. NOT USABLE file. The caller has to check
902  */
903 std::string File::GetPixelType()
904 {
905    std::string bitsAlloc = GetEntryValue(0x0028, 0x0100); // Bits Allocated
906    if ( bitsAlloc == GDCM_UNFOUND )
907    {
908       gdcmWarningMacro( "Missing  Bits Allocated (0028,0100)");
909       bitsAlloc = "16"; // default and arbitrary value, not to polute the output
910    }
911
912    if ( bitsAlloc == "64" )
913    {
914       return "FD";
915    }
916    else if ( bitsAlloc == "12" )
917    {
918       // It will be unpacked
919       bitsAlloc = "16";
920    }
921    else if ( bitsAlloc == "24" )
922    {
923       // (in order no to be messed up
924       bitsAlloc = "8";  // by old RGB images)
925    }
926
927    std::string sign = GetEntryValue(0x0028, 0x0103);//"Pixel Representation"
928
929    if (sign == GDCM_UNFOUND )
930    {
931       gdcmWarningMacro( "Missing Pixel Representation (0028,0103)");
932       sign = "U"; // default and arbitrary value, not to polute the output
933    }
934    else if ( sign == "0" )
935    {
936       sign = "U";
937    }
938    else
939    {
940       sign = "S";
941    }
942    return bitsAlloc + sign;
943 }
944
945 /**
946  * \brief   Check whether the pixels are signed (1) or UNsigned (0) data.
947  * \warning The method defaults to false (UNsigned) when tag 0028|0103
948  *          is missing.
949  *          The responsability of checking this value is left to the caller
950  *          (NO transformation is performed on the pixels to make then >0)
951  * @return  True when signed, false when UNsigned
952  */
953 bool File::IsSignedPixelData()
954 {
955    std::string strSign = GetEntryValue( 0x0028, 0x0103 );
956    if ( strSign == GDCM_UNFOUND )
957    {
958       gdcmWarningMacro( "(0028,0103) is supposed to be mandatory");
959       return false;
960    }
961    int sign = atoi( strSign.c_str() );
962    if ( sign == 0 ) 
963    {
964       return false;
965    }
966    return true;
967 }
968
969 /**
970  * \brief   Check whether this a monochrome picture (gray levels) or not,
971  *          using "Photometric Interpretation" tag (0x0028,0x0004).
972  * @return  true when "MONOCHROME1" or "MONOCHROME2". False otherwise.
973  */
974 bool File::IsMonochrome()
975 {
976    const std::string &PhotometricInterp = GetEntryValue( 0x0028, 0x0004 );
977    if (  Util::DicomStringEqual(PhotometricInterp, "MONOCHROME1")
978       || Util::DicomStringEqual(PhotometricInterp, "MONOCHROME2") )
979    {
980       return true;
981    }
982    if ( PhotometricInterp == GDCM_UNFOUND )
983    {
984       gdcmWarningMacro( "Not found : Photometric Interpretation (0028,0004)");
985    }
986    return false;
987 }
988
989 /**
990  * \brief   Check whether this a MONOCHROME1 picture (high values = dark)
991  *            or not using "Photometric Interpretation" tag (0x0028,0x0004).
992  * @return  true when "MONOCHROME1" . False otherwise.
993  */
994 bool File::IsMonochrome1()
995 {
996    const std::string &PhotometricInterp = GetEntryValue( 0x0028, 0x0004 );
997    if (  Util::DicomStringEqual(PhotometricInterp, "MONOCHROME1") )
998    {
999       return true;
1000    }
1001    if ( PhotometricInterp == GDCM_UNFOUND )
1002    {
1003       gdcmWarningMacro( "Not found : Photometric Interpretation (0028,0004)");
1004    }
1005    return false;
1006 }
1007
1008 /**
1009  * \brief   Check whether this a "PALETTE COLOR" picture or not by accessing
1010  *          the "Photometric Interpretation" tag ( 0x0028, 0x0004 ).
1011  * @return  true when "PALETTE COLOR". False otherwise.
1012  */
1013 bool File::IsPaletteColor()
1014 {
1015    std::string PhotometricInterp = GetEntryValue( 0x0028, 0x0004 );
1016    if (   PhotometricInterp == "PALETTE COLOR " )
1017    {
1018       return true;
1019    }
1020    if ( PhotometricInterp == GDCM_UNFOUND )
1021    {
1022       gdcmWarningMacro( "Not found : Palette color (0028,0004)");
1023    }
1024    return false;
1025 }
1026
1027 /**
1028  * \brief   Check whether this a "YBR_FULL" color picture or not by accessing
1029  *          the "Photometric Interpretation" tag ( 0x0028, 0x0004 ).
1030  * @return  true when "YBR_FULL". False otherwise.
1031  */
1032 bool File::IsYBRFull()
1033 {
1034    std::string PhotometricInterp = GetEntryValue( 0x0028, 0x0004 );
1035    if (   PhotometricInterp == "YBR_FULL" )
1036    {
1037       return true;
1038    }
1039    if ( PhotometricInterp == GDCM_UNFOUND )
1040    {
1041       gdcmWarningMacro( "Not found : YBR Full (0028,0004)");
1042    }
1043    return false;
1044 }
1045
1046 /**
1047   * \brief tells us if LUT are used
1048   * \warning Right now, 'Segmented xxx Palette Color Lookup Table Data'
1049   *          are NOT considered as LUT, since nobody knows
1050   *          how to deal with them
1051   *          Please warn me if you know sbdy that *does* know ... jprx
1052   * @return true if LUT Descriptors and LUT Tables were found 
1053   */
1054 bool File::HasLUT()
1055 {
1056    // Check the presence of the LUT Descriptors, and LUT Tables    
1057    // LutDescriptorRed    
1058    if ( !GetDocEntry(0x0028,0x1101) )
1059    {
1060       return false;
1061    }
1062    // LutDescriptorGreen 
1063    if ( !GetDocEntry(0x0028,0x1102) )
1064    {
1065       return false;
1066    }
1067    // LutDescriptorBlue 
1068    if ( !GetDocEntry(0x0028,0x1103) )
1069    {
1070       return false;
1071    }
1072    // Red Palette Color Lookup Table Data
1073    if ( !GetDocEntry(0x0028,0x1201) )
1074    {
1075       return false;
1076    }
1077    // Green Palette Color Lookup Table Data       
1078    if ( !GetDocEntry(0x0028,0x1202) )
1079    {
1080       return false;
1081    }
1082    // Blue Palette Color Lookup Table Data      
1083    if ( !GetDocEntry(0x0028,0x1203) )
1084    {
1085       return false;
1086    }
1087
1088    // FIXME : (0x0028,0x3006) : LUT Data (CTX dependent)
1089    //         NOT taken into account, but we don't know how to use it ...   
1090    return true;
1091 }
1092
1093 /**
1094   * \brief gets the info from 0028,1101 : Lookup Table Desc-Red
1095   *             else 0
1096   * @return Lookup Table number of Bits , 0 by default
1097   *          when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
1098   * @ return bit number of each LUT item 
1099   */
1100 int File::GetLUTNbits()
1101 {
1102    std::vector<std::string> tokens;
1103    int lutNbits;
1104
1105    //Just hope Lookup Table Desc-Red = Lookup Table Desc-Red
1106    //                                = Lookup Table Desc-Blue
1107    // Consistency already checked in GetLUTLength
1108    std::string lutDescription = GetEntryValue(0x0028,0x1101);
1109    if ( lutDescription == GDCM_UNFOUND )
1110    {
1111       return 0;
1112    }
1113
1114    tokens.clear(); // clean any previous value
1115    Util::Tokenize ( lutDescription, tokens, "\\" );
1116    //LutLength=atoi(tokens[0].c_str());
1117    //LutDepth=atoi(tokens[1].c_str());
1118
1119    lutNbits = atoi( tokens[2].c_str() );
1120    tokens.clear();
1121
1122    return lutNbits;
1123 }
1124
1125 /**
1126  *\brief gets the info from 0028,1052 : Rescale Intercept
1127  * @return Rescale Intercept
1128  */
1129 float File::GetRescaleIntercept()
1130 {
1131    float resInter = 0.;
1132    /// 0028 1052 DS IMG Rescale Intercept
1133    const std::string &strRescInter = GetEntryValue(0x0028,0x1052);
1134    if ( strRescInter != GDCM_UNFOUND )
1135    {
1136       if ( sscanf( strRescInter.c_str(), "%f ", &resInter) != 1 )
1137       {
1138          // bug in the element 0x0028,0x1052
1139          gdcmWarningMacro( "Rescale Intercept (0028,1052) is empty." );
1140       }
1141    }
1142
1143    return resInter;
1144 }
1145
1146 /**
1147  *\brief   gets the info from 0028,1053 : Rescale Slope
1148  * @return Rescale Slope
1149  */
1150 float File::GetRescaleSlope()
1151 {
1152    float resSlope = 1.;
1153    //0028 1053 DS IMG Rescale Slope
1154    std::string strRescSlope = GetEntryValue(0x0028,0x1053);
1155    if ( strRescSlope != GDCM_UNFOUND )
1156    {
1157       if ( sscanf( strRescSlope.c_str(), "%f ", &resSlope) != 1 )
1158       {
1159          // bug in the element 0x0028,0x1053
1160          gdcmWarningMacro( "Rescale Slope (0028,1053) is empty.");
1161       }
1162    }
1163
1164    return resSlope;
1165 }
1166
1167 /**
1168  * \brief This function is intended to user who doesn't want 
1169  *   to have to manage a LUT and expects to get an RBG Pixel image
1170  *   (or a monochrome one ...) 
1171  * \warning to be used with GetImagePixels()
1172  * @return 1 if Gray level, 3 if Color (RGB, YBR, *or PALETTE COLOR*)
1173  */
1174 int File::GetNumberOfScalarComponents()
1175 {
1176    if ( GetSamplesPerPixel() == 3 )
1177    {
1178       return 3;
1179    }
1180       
1181    // 0028 0100 US IMG Bits Allocated
1182    // (in order no to be messed up by old RGB images)
1183    if ( GetEntryValue(0x0028,0x0100) == "24" )
1184    {
1185       return 3;
1186    }
1187        
1188    std::string strPhotometricInterpretation = GetEntryValue(0x0028,0x0004);
1189
1190    if ( ( strPhotometricInterpretation == "PALETTE COLOR ") )
1191    {
1192       if ( HasLUT() )// PALETTE COLOR is NOT enough
1193       {
1194          return 3;
1195       }
1196       else
1197       {
1198          return 1;
1199       }
1200    }
1201
1202    // beware of trailing space at end of string      
1203    // DICOM tags are never of odd length
1204    if ( strPhotometricInterpretation == GDCM_UNFOUND   || 
1205         Util::DicomStringEqual(strPhotometricInterpretation, "MONOCHROME1") ||
1206         Util::DicomStringEqual(strPhotometricInterpretation, "MONOCHROME2") )
1207    {
1208       return 1;
1209    }
1210    else
1211    {
1212       // we assume that *all* kinds of YBR are dealt with
1213       return 3;
1214    }
1215 }
1216
1217 /**
1218  * \brief This function is intended to user that DOESN'T want 
1219  *  to get RGB pixels image when it's stored as a PALETTE COLOR image
1220  *   - the (vtk) user is supposed to know how deal with LUTs - 
1221  * \warning to be used with GetImagePixelsRaw()
1222  * @return 1 if Gray level, 3 if Color (RGB or YBR - NOT 'PALETTE COLOR' -)
1223  */
1224 int File::GetNumberOfScalarComponentsRaw()
1225 {
1226    // 0028 0100 US IMG Bits Allocated
1227    // (in order no to be messed up by old RGB images)
1228    if ( File::GetEntryValue(0x0028,0x0100) == "24" )
1229    {
1230       return 3;
1231    }
1232
1233    // we assume that *all* kinds of YBR are dealt with
1234    return GetSamplesPerPixel();
1235 }
1236
1237 /**
1238  * \brief   Recover the offset (from the beginning of the file) 
1239  *          of *image* pixels (not *icone image* pixels, if any !)
1240  * @return Pixel Offset
1241  */
1242 size_t File::GetPixelOffset()
1243 {
1244    DocEntry *pxlElement = GetDocEntry(GrPixel, NumPixel);
1245    if ( pxlElement )
1246    {
1247       return pxlElement->GetOffset();
1248    }
1249    else
1250    {
1251       gdcmDebugMacro( "Big trouble : Pixel Element ("
1252                       << std::hex << GrPixel<<","<< NumPixel<< ") NOT found" );
1253       return 0;
1254    }
1255 }
1256
1257 /**
1258  * \brief   Recover the pixel area length (in Bytes)
1259  * @return Pixel Element Length, as stored in the header
1260  *         (NOT the memory space necessary to hold the Pixels 
1261  *          -in case of embeded compressed image-)
1262  *         0 : NOT USABLE file. The caller has to check.
1263  */
1264 size_t File::GetPixelAreaLength()
1265 {
1266    DocEntry *pxlElement = GetDocEntry(GrPixel, NumPixel);
1267    if ( pxlElement )
1268    {
1269       return pxlElement->GetLength();
1270    }
1271    else
1272    {
1273       gdcmDebugMacro( "Big trouble : Pixel Element ("
1274                       << std::hex << GrPixel<<","<< NumPixel<< ") NOT found" );
1275       return 0;
1276    }
1277 }
1278
1279 /**
1280  * \brief Adds the characteristics of a new element we want to anonymize
1281  * @param   group  Group number of the target tag.
1282  * @param   elem Element number of the target tag.
1283  * @param   value new value (string) to substitute with 
1284  */
1285 void File::AddAnonymizeElement (uint16_t group, uint16_t elem, 
1286                                 std::string const &value) 
1287
1288    Element el;
1289    el.Group = group;
1290    el.Elem  = elem;
1291    el.Value = value;
1292    AnonymizeList.push_back(el); 
1293 }
1294
1295 /**
1296  * \brief Overwrites in the file the values of the DicomElements
1297  *       held in the list 
1298  */
1299 void File::AnonymizeNoLoad()
1300 {
1301    std::fstream *fp = new std::fstream(Filename.c_str(), 
1302                               std::ios::in | std::ios::out | std::ios::binary); 
1303    gdcm::DocEntry *d;
1304    uint32_t offset;
1305    uint32_t lgth;
1306    uint32_t valLgth = 0;
1307    std::string *spaces;
1308    for (ListElements::iterator it = AnonymizeList.begin();  
1309                                it != AnonymizeList.end();
1310                              ++it)
1311    { 
1312       d = GetDocEntry( (*it).Group, (*it).Elem);
1313
1314       if ( d == NULL)
1315          continue;
1316
1317          if ( dynamic_cast<SeqEntry *>(d) )
1318          {
1319             gdcmWarningMacro( "You cannot 'Anonymize a SeqEntry ");
1320             continue;
1321          }
1322
1323       offset = d->GetOffset();
1324       lgth =   d->GetLength();
1325       if (valLgth < lgth)
1326       {
1327          spaces = new std::string( lgth-valLgth, ' ');
1328          (*it).Value = (*it).Value + *spaces;
1329          delete spaces;
1330       }
1331       fp->seekp( offset, std::ios::beg );
1332       fp->write( (*it).Value.c_str(), lgth );
1333      
1334    }
1335    fp->close();
1336    delete fp;
1337 }
1338
1339 /**
1340  * \brief anonymize a File (remove Patient's personal info passed with
1341  *        AddAnonymizeElement()
1342  * \note You cannot Anonymize a BinEntry (to be fixed)
1343  */
1344 bool File::AnonymizeFile()
1345 {
1346    // If Anonymisation list is empty, let's perform some basic anonymization
1347    if ( AnonymizeList.begin() == AnonymizeList.end() )
1348    {
1349       // If exist, replace by spaces
1350       SetValEntry ("  ",0x0010, 0x2154); // Telephone   
1351       SetValEntry ("  ",0x0010, 0x1040); // Adress
1352       SetValEntry ("  ",0x0010, 0x0020); // Patient ID
1353
1354       DocEntry* patientNameHE = GetDocEntry (0x0010, 0x0010);
1355   
1356       if ( patientNameHE ) // we replace it by Study Instance UID (why not ?)
1357       {
1358          std::string studyInstanceUID =  GetEntryValue (0x0020, 0x000d);
1359          if ( studyInstanceUID != GDCM_UNFOUND )
1360          {
1361             SetValEntry(studyInstanceUID, 0x0010, 0x0010);
1362          }
1363          else
1364          {
1365             SetValEntry("anonymised", 0x0010, 0x0010);
1366          }
1367       }
1368    }
1369    else
1370    {
1371       gdcm::DocEntry *d;
1372       for (ListElements::iterator it = AnonymizeList.begin();  
1373                                   it != AnonymizeList.end();
1374                                 ++it)
1375       {  
1376          d = GetDocEntry( (*it).Group, (*it).Elem);
1377
1378          if ( d == NULL)
1379             continue;
1380
1381          if ( dynamic_cast<SeqEntry *>(d) )
1382          {
1383             gdcmWarningMacro( "You cannot 'Anonymize' a SeqEntry ");
1384             continue;
1385          }
1386
1387          if ( dynamic_cast<BinEntry *>(d) )
1388          {
1389             gdcmWarningMacro( "To 'Anonymize' a BinEntry, better use AnonymizeNoLoad (FIXME) ");
1390             continue;
1391          }
1392          else
1393             SetValEntry ((*it).Value, (*it).Group, (*it).Elem);
1394       }
1395 }
1396
1397   // In order to make definitively impossible any further identification
1398   // remove or replace all the stuff that contains a Date
1399
1400 //0008 0012 DA ID Instance Creation Date
1401 //0008 0020 DA ID Study Date
1402 //0008 0021 DA ID Series Date
1403 //0008 0022 DA ID Acquisition Date
1404 //0008 0023 DA ID Content Date
1405 //0008 0024 DA ID Overlay Date
1406 //0008 0025 DA ID Curve Date
1407 //0008 002a DT ID Acquisition Datetime
1408 //0018 9074 DT ACQ Frame Acquisition Datetime
1409 //0018 9151 DT ACQ Frame Reference Datetime
1410 //0018 a002 DT ACQ Contribution Date Time
1411 //0020 3403 SH REL Modified Image Date (RET)
1412 //0032 0032 DA SDY Study Verified Date
1413 //0032 0034 DA SDY Study Read Date
1414 //0032 1000 DA SDY Scheduled Study Start Date
1415 //0032 1010 DA SDY Scheduled Study Stop Date
1416 //0032 1040 DA SDY Study Arrival Date
1417 //0032 1050 DA SDY Study Completion Date
1418 //0038 001a DA VIS Scheduled Admission Date
1419 //0038 001c DA VIS Scheduled Discharge Date
1420 //0038 0020 DA VIS Admitting Date
1421 //0038 0030 DA VIS Discharge Date
1422 //0040 0002 DA PRC Scheduled Procedure Step Start Date
1423 //0040 0004 DA PRC Scheduled Procedure Step End Date
1424 //0040 0244 DA PRC Performed Procedure Step Start Date
1425 //0040 0250 DA PRC Performed Procedure Step End Date
1426 //0040 2004 DA PRC Issue Date of Imaging Service Request
1427 //0040 4005 DT PRC Scheduled Procedure Step Start Date and Time
1428 //0040 4011 DT PRC Expected Completion Date and Time
1429 //0040 a030 DT PRC Verification Date Time
1430 //0040 a032 DT PRC Observation Date Time
1431 //0040 a120 DT PRC DateTime
1432 //0040 a121 DA PRC Date
1433 //0040 a13a DT PRC Referenced Datetime
1434 //0070 0082 DA ??? Presentation Creation Date
1435 //0100 0420 DT ??? SOP Autorization Date and Time
1436 //0400 0105 DT ??? Digital Signature DateTime
1437 //2100 0040 DA PJ Creation Date
1438 //3006 0008 DA SSET Structure Set Date
1439 //3008 0024 DA ??? Treatment Control Point Date
1440 //3008 0054 DA ??? First Treatment Date
1441 //3008 0056 DA ??? Most Recent Treatment Date
1442 //3008 0162 DA ??? Safe Position Exit Date
1443 //3008 0166 DA ??? Safe Position Return Date
1444 //3008 0250 DA ??? Treatment Date
1445 //300a 0006 DA RT RT Plan Date
1446 //300a 022c DA RT Air Kerma Rate Reference Date
1447 //300e 0004 DA RT Review Date
1448
1449    return true;
1450 }
1451
1452 /**
1453  * \brief Performs some consistency checking on various 'File related' 
1454  *       (as opposed to 'DicomDir related') entries 
1455  *       then writes in a file all the (Dicom Elements) included the Pixels 
1456  * @param fileName file name to write to
1457  * @param writetype type of the file to be written 
1458  *          (ACR, ExplicitVR, ImplicitVR)
1459  */
1460 bool File::Write(std::string fileName, FileType writetype)
1461 {
1462    std::ofstream *fp = new std::ofstream(fileName.c_str(), 
1463                                          std::ios::out | std::ios::binary);
1464    if (*fp == NULL)
1465    {
1466       gdcmWarningMacro("Failed to open (write) File: " << fileName.c_str());
1467       return false;
1468    }
1469
1470    // Entry : 0002|0000 = group length -> recalculated
1471    ValEntry*e0000 = GetValEntry(0x0002,0x0000);
1472    if ( e0000 )
1473    {
1474       std::ostringstream sLen;
1475       sLen << ComputeGroup0002Length(writetype);
1476       e0000->SetValue(sLen.str());
1477    }
1478
1479    int i_lgPix = GetEntryLength(GrPixel, NumPixel);
1480    if (i_lgPix != -2)
1481    {
1482       // no (GrPixel, NumPixel) element
1483       std::string s_lgPix = Util::Format("%d", i_lgPix+12);
1484       s_lgPix = Util::DicomString( s_lgPix.c_str() );
1485       InsertValEntry(s_lgPix,GrPixel, 0x0000);
1486    }
1487
1488    Document::WriteContent(fp, writetype);
1489
1490    fp->close();
1491    delete fp;
1492
1493    return true;
1494 }
1495
1496 //-----------------------------------------------------------------------------
1497 // Protected
1498
1499
1500 //-----------------------------------------------------------------------------
1501 // Private
1502 /**
1503  * \brief Parse pixel data from disk of [multi-]fragment RLE encoding.
1504  *        Compute the RLE extra information and store it in \ref RLEInfo
1505  *        for later pixel retrieval usage.
1506  */
1507 void File::ComputeRLEInfo()
1508 {
1509    std::string ts = GetTransferSyntax();
1510    if ( !Global::GetTS()->IsRLELossless(ts) ) 
1511    {
1512       return;
1513    }
1514
1515    // Encoded pixel data: for the time being we are only concerned with
1516    // Jpeg or RLE Pixel data encodings.
1517    // As stated in PS 3.5-2003, section 8.2 p44:
1518    // "If sent in Encapsulated Format (i.e. other than the Native Format) the
1519    //  value representation OB is used".
1520    // Hence we expect an OB value representation. Concerning OB VR,
1521    // the section PS 3.5-2003, section A.4.c p 58-59, states:
1522    // "For the Value Representations OB and OW, the encoding shall meet the
1523    //   following specifications depending on the Data element tag:"
1524    //   [...snip...]
1525    //    - the first item in the sequence of items before the encoded pixel
1526    //      data stream shall be basic offset table item. The basic offset table
1527    //      item value, however, is not required to be present"
1528    ReadAndSkipEncapsulatedBasicOffsetTable();
1529
1530    // Encapsulated RLE Compressed Images (see PS 3.5-2003, Annex G)
1531    // Loop on the individual frame[s] and store the information
1532    // on the RLE fragments in a RLEFramesInfo.
1533    // Note: - when only a single frame is present, this is a
1534    //         classical image.
1535    //       - when more than one frame are present, then we are in 
1536    //         the case of a multi-frame image.
1537    long frameLength;
1538    while ( (frameLength = ReadTagLength(0xfffe, 0xe000)) != 0 )
1539    { 
1540       // Parse the RLE Header and store the corresponding RLE Segment
1541       // Offset Table information on fragments of this current Frame.
1542       // Note that the fragment pixels themselves are not loaded
1543       // (but just skipped).
1544       long frameOffset = Fp->tellg();
1545
1546       uint32_t nbRleSegments = ReadInt32();
1547       if ( nbRleSegments > 16 )
1548       {
1549          // There should be at most 15 segments (refer to RLEFrame class)
1550          gdcmWarningMacro( "Too many segments.");
1551       }
1552  
1553       uint32_t rleSegmentOffsetTable[16];
1554       for( int k = 1; k <= 15; k++ )
1555       {
1556          rleSegmentOffsetTable[k] = ReadInt32();
1557       }
1558
1559       // Deduce from both RLE Header and frameLength 
1560       // the fragment length, and again store this info
1561       // in a RLEFramesInfo.
1562       long rleSegmentLength[15];
1563       // skipping (not reading) RLE Segments
1564       if ( nbRleSegments > 1)
1565       {
1566          for(unsigned int k = 1; k <= nbRleSegments-1; k++)
1567          {
1568              rleSegmentLength[k] =  rleSegmentOffsetTable[k+1]
1569                                   - rleSegmentOffsetTable[k];
1570              SkipBytes(rleSegmentLength[k]);
1571           }
1572        }
1573
1574        rleSegmentLength[nbRleSegments] = frameLength 
1575                                       - rleSegmentOffsetTable[nbRleSegments];
1576        SkipBytes(rleSegmentLength[nbRleSegments]);
1577
1578        // Store the collected info
1579        RLEFrame *newFrame = new RLEFrame;
1580        newFrame->SetNumberOfFragments(nbRleSegments);
1581        for( unsigned int uk = 1; uk <= nbRleSegments; uk++ )
1582        {
1583           newFrame->SetOffset(uk,frameOffset + rleSegmentOffsetTable[uk]);
1584           newFrame->SetLength(uk,rleSegmentLength[uk]);
1585        }
1586        RLEInfo->AddFrame(newFrame);
1587    }
1588
1589    // Make sure that  we encounter a 'Sequence Delimiter Item'
1590    // at the end of the item :
1591    if ( !ReadTag(0xfffe, 0xe0dd) )
1592    {
1593       gdcmWarningMacro( "No sequence delimiter item at end of RLE item sequence");
1594    }
1595 }
1596
1597 /**
1598  * \brief Parse pixel data from disk of [multi-]fragment Jpeg encoding.
1599  *        Compute the jpeg extra information (fragment[s] offset[s] and
1600  *        length) and store it[them] in \ref JPEGInfo for later pixel
1601  *        retrieval usage.
1602  */
1603 void File::ComputeJPEGFragmentInfo()
1604 {
1605    // If you need to, look for comments of ComputeRLEInfo().
1606    std::string ts = GetTransferSyntax();
1607    if ( ! Global::GetTS()->IsJPEG(ts) )
1608    {
1609       return;
1610    }
1611
1612    ReadAndSkipEncapsulatedBasicOffsetTable();
1613
1614    // Loop on the fragments[s] and store the parsed information in a
1615    // JPEGInfo.
1616    long fragmentLength;
1617    while ( (fragmentLength = ReadTagLength(0xfffe, 0xe000)) != 0 )
1618    { 
1619       long fragmentOffset = Fp->tellg();
1620
1621        // Store the collected info
1622        JPEGFragment *newFragment = new JPEGFragment;
1623        newFragment->SetOffset(fragmentOffset);
1624        newFragment->SetLength(fragmentLength);
1625        JPEGInfo->AddFragment(newFragment);
1626
1627        SkipBytes(fragmentLength);
1628    }
1629
1630    // Make sure that  we encounter a 'Sequence Delimiter Item'
1631    // at the end of the item :
1632    if ( !ReadTag(0xfffe, 0xe0dd) )
1633    {
1634       gdcmWarningMacro( "No sequence delimiter item at end of JPEG item sequence");
1635    }
1636 }
1637
1638 /**
1639  * \brief   Assuming the internal file pointer \ref Document::Fp 
1640  *          is placed at the beginning of a tag check whether this
1641  *          tag is (TestGroup, TestElem).
1642  * \warning On success the internal file pointer \ref Document::Fp
1643  *          is modified to point after the tag.
1644  *          On failure (i.e. when the tag wasn't the expected tag
1645  *          (TestGroup, TestElem) the internal file pointer
1646  *          \ref Document::Fp is restored to it's original position.
1647  * @param   testGroup The expected group   of the tag.
1648  * @param   testElem  The expected Element of the tag.
1649  * @return  True on success, false otherwise.
1650  */
1651 bool File::ReadTag(uint16_t testGroup, uint16_t testElem)
1652 {
1653    long positionOnEntry = Fp->tellg();
1654    long currentPosition = Fp->tellg();          // On debugging purposes
1655
1656    // Read the Item Tag group and element, and make
1657    // sure they are what we expected:
1658    uint16_t itemTagGroup;
1659    uint16_t itemTagElem;
1660    try
1661    {
1662       itemTagGroup = ReadInt16();
1663       itemTagElem  = ReadInt16();
1664    }
1665    catch ( FormatError e )
1666    {
1667       //std::cerr << e << std::endl;
1668       return false;
1669    }
1670    if ( itemTagGroup != testGroup || itemTagElem != testElem )
1671    {
1672       gdcmWarningMacro( "Wrong Item Tag found:"
1673        << "   We should have found tag ("
1674        << std::hex << testGroup << "," << testElem << ")" << std::endl
1675        << "   but instead we encountered tag ("
1676        << std::hex << itemTagGroup << "," << itemTagElem << ")"
1677        << "  at address: " << "  0x(" << (unsigned int)currentPosition  << ")" 
1678        ) ;
1679       Fp->seekg(positionOnEntry, std::ios::beg);
1680
1681       return false;
1682    }
1683    return true;
1684 }
1685
1686 /**
1687  * \brief   Assuming the internal file pointer \ref Document::Fp 
1688  *          is placed at the beginning of a tag (TestGroup, TestElement),
1689  *          read the length associated to the Tag.
1690  * \warning On success the internal file pointer \ref Document::Fp
1691  *          is modified to point after the tag and it's length.
1692  *          On failure (i.e. when the tag wasn't the expected tag
1693  *          (TestGroup, TestElement) the internal file pointer
1694  *          \ref Document::Fp is restored to it's original position.
1695  * @param   testGroup The expected Group   of the tag.
1696  * @param   testElem  The expected Element of the tag.
1697  * @return  On success returns the length associated to the tag. On failure
1698  *          returns 0.
1699  */
1700 uint32_t File::ReadTagLength(uint16_t testGroup, uint16_t testElem)
1701 {
1702
1703    if ( !ReadTag(testGroup, testElem) )
1704    {
1705       return 0;
1706    }
1707                                                                                 
1708    //// Then read the associated Item Length
1709    long currentPosition = Fp->tellg();
1710    uint32_t itemLength  = ReadInt32();
1711    {
1712       gdcmWarningMacro( "Basic Item Length is: "
1713         << itemLength << std::endl
1714         << "  at address: " << std::hex << (unsigned int)currentPosition);
1715    }
1716    return itemLength;
1717 }
1718
1719 /**
1720  * \brief When parsing the Pixel Data of an encapsulated file, read
1721  *        the basic offset table (when present, and BTW dump it).
1722  */
1723 void File::ReadAndSkipEncapsulatedBasicOffsetTable()
1724 {
1725    //// Read the Basic Offset Table Item Tag length...
1726    uint32_t itemLength = ReadTagLength(0xfffe, 0xe000);
1727
1728    // When present, read the basic offset table itself.
1729    // Notes: - since the presence of this basic offset table is optional
1730    //          we can't rely on it for the implementation, and we will simply
1731    //          trash it's content (when present).
1732    //        - still, when present, we could add some further checks on the
1733    //          lengths, but we won't bother with such fuses for the time being.
1734    if ( itemLength != 0 )
1735    {
1736       char *basicOffsetTableItemValue = new char[itemLength + 1];
1737       Fp->read(basicOffsetTableItemValue, itemLength);
1738
1739 #ifdef GDCM_DEBUG
1740       for (unsigned int i=0; i < itemLength; i += 4 )
1741       {
1742          uint32_t individualLength = str2num( &basicOffsetTableItemValue[i],
1743                                               uint32_t);
1744          gdcmWarningMacro( "Read one length: " << 
1745                           std::hex << individualLength );
1746       }
1747 #endif //GDCM_DEBUG
1748
1749       delete[] basicOffsetTableItemValue;
1750    }
1751 }
1752
1753 // These are the deprecated method that one day should be removed (after the next release)
1754
1755 #ifndef GDCM_LEGACY_REMOVE
1756 /**
1757  * \brief  Constructor (DEPRECATED : temporaryly kept not to break the API)
1758  * @param  filename name of the file whose header we want to analyze
1759  * @deprecated do not use any longer
1760  */
1761 File::File( std::string const &filename )
1762      :Document( )
1763 {    
1764    RLEInfo  = new RLEFramesInfo;
1765    JPEGInfo = new JPEGFragmentsInfo;
1766
1767    SetFileName( filename );
1768    Load( ); // gdcm::Document is first Loaded, then the 'File part'
1769 }
1770
1771 /**
1772  * \brief   Loader. (DEPRECATED :  temporaryly kept not to break the API)
1773  * @param   fileName file to be open for parsing
1774  * @return false if file cannot be open or no swap info was found,
1775  *         or no tag was found.
1776  * @deprecated Use the Load() [ + SetLoadMode() ] + SetFileName() functions instead
1777  */
1778 bool File::Load( std::string const &fileName ) 
1779 {
1780    GDCM_LEGACY_REPLACED_BODY(File::Load(std::string), "1.2",
1781                              File::Load());
1782    SetFileName( fileName );
1783    if ( ! this->Document::Load( ) )
1784       return false;
1785
1786    return DoTheLoadingJob( );
1787 }
1788 #endif
1789
1790 // -----------------------------------------------------------------------------------------
1791 //             THERALYS Algorithm to determine the most similar basic orientation
1792 //
1793 //  Transliterated from original Python code.
1794 //  Kept as close as possible to the original code
1795 //  in order to speed up any further modif of Python code :-(
1796 // ------------------------------------------------------------------------------------------
1797
1798 /**
1799  * \brief  THERALYS' Algorithm to determine the most similar basic orientation
1800  *           (Axial, Coronal, Sagital) of the image
1801  * \note Should be run on the first gdcm::File of a 'coherent' Serie
1802  * @return orientation code
1803  * @return orientation code
1804  *   #   0 :   Not Applicable (neither 0020,0037 Image Orientation Patient 
1805  *   #                         nor     0020,0032Image Position     found )
1806  *   #   1 :   Axial
1807  *   #  -1 :   Axial invert
1808  *   #   2 :   Coronal
1809  *   #  -2 :   Coronal invert
1810  *   #   3 :   Sagital
1811  *   #  -3 :   Sagital invert
1812  *   #   4 :   Heart Axial
1813  *   #  -4 :   Heart Axial invert
1814  *   #   5 :   Heart Coronal
1815  *   #  -5 :   Heart Coronal invert
1816  *   #   6 :   Heart Sagital
1817  *   #  -6 :   Heart Sagital invert
1818  */
1819 float File::TypeOrientation( )
1820 {
1821    float *iop = new float[6];
1822    bool succ = GetImageOrientationPatient( iop );
1823    if ( !succ )
1824    {
1825       delete iop;
1826       return 0.;
1827    }
1828
1829    vector3D ori1;
1830    vector3D ori2;
1831
1832    ori1.x = iop[0]; ori1.y = iop[1]; ori1.z = iop[2]; 
1833    ori1.x = iop[3]; ori2.y = iop[4]; ori2.z = iop[5];
1834
1835    // two perpendicular vectors describe one plane
1836    float dicPlane[6][2][3] =
1837    { {  {1,    0,    0   },{0,       1,     0     }  },       // Axial
1838      {  {1,    0,    0   },{0,       0,    -1     }  },       // Coronal
1839      {  {0,    1,    0   },{0,       0,    -1     }  },       // Sagittal
1840      {  { 0.8, 0.5,  0.0 },{-0.1,    0.1 , -0.95  }  },       // Axial - HEART
1841      {  { 0.8, 0.5,  0.0 },{-0.6674, 0.687, 0.1794}  },       // Coronal - HEART
1842      {  {-0.1, 0.1, -0.95},{-0.6674, 0.687, 0.1794}  }        // Sagittal - HEART
1843    };
1844
1845    vector3D refA;
1846    vector3D refB;
1847    int i = 0;
1848    Res res;   // [ <result> , <memory of the last succes calcule> ]
1849    res.first = 0;
1850    res.second = 99999;
1851    for (int numDicPlane=0; numDicPlane<6; numDicPlane++)
1852    {
1853        i = i + 1;
1854        // refA=plane[0]
1855        refA.x = dicPlane[numDicPlane][0][0]; 
1856        refA.y = dicPlane[numDicPlane][0][1]; 
1857        refA.z = dicPlane[numDicPlane][0][2];
1858        // refB=plane[1]
1859        refB.x = dicPlane[numDicPlane][1][0]; 
1860        refB.y = dicPlane[numDicPlane][1][1]; 
1861        refB.z = dicPlane[numDicPlane][1][2];
1862        res=VerfCriterion(  i, CalculLikelyhood2Vec(refA,refB,ori1,ori2), res );
1863        res=VerfCriterion( -i, CalculLikelyhood2Vec(refB,refA,ori1,ori2), res );
1864    }
1865    delete iop;
1866    return res.first;
1867 /*
1868 //             i=0
1869 //             res=[0,99999]  ## [ <result> , <memory of the last succes calculus> ]
1870 //             for plane in dicPlane:
1871 //                 i=i+1
1872 //                 refA=plane[0]
1873 //                 refB=plane[1]
1874 //                 res=self.VerfCriterion(  i , self.CalculLikelyhood2Vec(refA,refB,ori1,ori2) , res )
1875 //                 res=self.VerfCriterion( -i , self.CalculLikelyhood2Vec(refB,refA,ori1,ori2) , res )
1876 //             return res[0]
1877 */
1878
1879 }
1880
1881 Res File::VerfCriterion(int typeCriterion, float criterionNew, Res res)
1882 {
1883    float type      = res.first;
1884    float criterion = res.second;
1885    if (criterionNew < criterion)
1886    {
1887       res.first  = criterionNew;
1888       res.second = typeCriterion;
1889    }
1890 /*
1891 //   type = res[0]
1892 //   criterion = res[1]
1893 // #     if criterionNew<0.1 and criterionNew<criterion:
1894 //   if criterionNew<criterion:
1895 //      criterion=criterionNew
1896 //      type=typeCriterion
1897 //   return [ type , criterion ]
1898 */
1899    return res;
1900
1901
1902 float File::CalculLikelyhood2Vec(vector3D refA, vector3D refB, 
1903                                  vector3D ori1, vector3D ori2)
1904 {
1905 //   # ------------------------- Purpose : -----------------------------------
1906 //   # - This function determines the orientation similarity of two planes.
1907 //   #   Each plane is described by two vectors.
1908 //   # ------------------------- Parameters : --------------------------------
1909 //   # - <refA>  : - type : vector 3D (float)
1910 //   # - <refB>  : - type : vector 3D (float)
1911 //   #             - Description of the first plane
1912 //   # - <ori1>  : - type : vector 3D (float)
1913 //   # - <ori2>  : - type : vector 3D (float)
1914 //   #             - Description of the second plane
1915 //   # ------------------------- Return : ------------------------------------
1916 //   #  float :   0 if the planes are perpendicular. While the difference of
1917 //   #             the orientation between the planes are big more enlarge is
1918 //   #             the criterion.
1919 //   # ------------------------- Other : -------------------------------------
1920 //   #  The calculus is based with vectors normalice
1921
1922    vector3D ori3 = ProductVectorial(ori1,ori2);
1923    vector3D refC = ProductVectorial(refA,refB);
1924    float    res  = pow(refC.x-ori3.x, 2.) + 
1925                    pow(refC.y-ori3.y, 2.) + 
1926                    pow(refC.z-ori3.z, 2.);
1927
1928 /*
1929 //   ori3=self.ProductVectorial(ori1,ori2)
1930 //   refC=self.ProductVectorial(refA,refB)
1931 //   res=math.pow(refC[0]-ori3[0],2) + math.pow(refC[1]-ori3[1],2) + math.pow(refC[2]-ori3[2],2)
1932 //   return math.sqrt(res)
1933 */
1934    return sqrt(res);
1935 }
1936
1937 vector3D File::ProductVectorial(vector3D vec1, vector3D vec2)
1938 {
1939
1940 //   # ------------------------- Purpose : -----------------------------------
1941 //   # - Calculus of the poduct vectorial between two vectors 3D
1942 //   # ------------------------- Parameters : --------------------------------
1943 //   # - <vec1>  : - type : vector 3D (float)
1944 //   # - <vec2>  : - type : vector 3D (float)
1945 //   # ------------------------- Return : ------------------------------------
1946 //   #  (vec) :    - Vector 3D
1947 //   # ------------------------- Other : -------------------------------------
1948
1949    vector3D vec3;
1950    vec3.x =    vec1.y*vec2.z - vec1.z*vec2.y;
1951    vec3.y = -( vec1.x*vec2.z - vec1.z*vec2.x);
1952    vec3.z =    vec1.x*vec2.y - vec1.y*vec2.x;
1953 /*
1954 //   vec3=[0,0,0]
1955 //   vec3[0]=vec1[1]*vec2[2]    - vec1[2]*vec2[1]
1956 //   vec3[1]=-( vec1[0]*vec2[2] - vec1[2]*vec2[0])
1957 //   vec3[2]=vec1[0]*vec2[1]    - vec1[1]*vec2[0]
1958 */
1959    return vec3;
1960 }
1961
1962 //-----------------------------------------------------------------------------
1963 // Print
1964
1965 //-----------------------------------------------------------------------------
1966 } // end namespace gdcm