]> Creatis software - gdcm.git/blobdiff - src/gdcmFileHelper.cxx
Replace stupid name 'PhilipsToBrucker2' by 'ToInTag'
[gdcm.git] / src / gdcmFileHelper.cxx
index 175afc0280baa7a39120c6543ad4fd7147bab925..62c0374010cd07b5e0f043fa57d3fac6ba34b8e8 100644 (file)
@@ -4,8 +4,8 @@
   Module:    $RCSfile: gdcmFileHelper.cxx,v $
   Language:  C++
 
-  Date:      $Date: 2006/04/12 13:57:32 $
-  Version:   $Revision: 1.100 $
+  Date:      $Date: 2006/05/30 08:14:50 $
+  Version:   $Revision: 1.104 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -269,9 +269,10 @@ bool FileHelper::SetEntryBinArea(uint8_t *content, int lgth,
  *          failed).
  */ 
 DataEntry *FileHelper::InsertEntryString(std::string const &content,
-                                                uint16_t group, uint16_t elem)
+                                         uint16_t group, uint16_t elem,
+                                         VRKey const &vr )
 {
-   return FileInternal->InsertEntryString(content, group, elem);
+   return FileInternal->InsertEntryString(content, group, elem, vr);
 }
 
 /**
@@ -286,9 +287,10 @@ DataEntry *FileHelper::InsertEntryString(std::string const &content,
  *          failed).
  */
 DataEntry *FileHelper::InsertEntryBinArea(uint8_t *binArea, int lgth,
-                                          uint16_t group, uint16_t elem)
+                                          uint16_t group, uint16_t elem,
+                                          VRKey const &vr )
 {
-   return FileInternal->InsertEntryBinArea(binArea, lgth, group, elem);
+   return FileInternal->InsertEntryBinArea(binArea, lgth, group, elem, vr);
 }
 
 /**
@@ -389,7 +391,7 @@ uint8_t *FileHelper::GetImageDataRaw ()
    return GetRaw();
 }
 
-#ifndef GDCM_LEGACY_REMOVE
+//#ifndef GDCM_LEGACY_REMOVE
 /*
  * \brief   Useless function, since PixelReadConverter forces us 
  *          copy the Pixels anyway.  
@@ -416,6 +418,7 @@ uint8_t *FileHelper::GetImageDataRaw ()
  * @return  On success, the number of bytes actually copied. Zero on
  *          failure e.g. MaxSize is lower than necessary.
  */
+ /*
 size_t FileHelper::GetImageDataIntoVector (void *destination, size_t maxSize)
 {
    if ( ! GetRaw() )
@@ -448,7 +451,8 @@ size_t FileHelper::GetImageDataIntoVector (void *destination, size_t maxSize)
            PixelReadConverter->GetRawSize() );
    return PixelReadConverter->GetRawSize();
 }
-#endif
+*/
+//#endif
 
 /**
  * \brief   Points the internal pointer to the callers inData
@@ -703,7 +707,7 @@ bool FileHelper::Write(std::string const &fileName)
          }
          break;
 
-  SetWriteFileTypeToExplicitVR(); // to see JPRx
+         SetWriteFileTypeToExplicitVR(); // to see JPRx
   break;
       case ACR:
       case ACR_LIBIDO:
@@ -1237,11 +1241,12 @@ We have to deal with 4 *very* different cases :
     USER_OWN_IMAGE
 -2) user modified the pixels of an existing image.
    FILTERED_IMAGE
--3) user created a new image, using existing images (eg MIP, MPR, cartography image)
+-3) user created a new image, using a set of existing images (eg MIP, MPR, cartography image)
    CREATED_IMAGE
 -4) user modified/added some tags *without processing* the pixels (anonymization..
    UNMODIFIED_PIXELS_IMAGE
-   
+-Probabely some more to be added  
 gdcm::FileHelper::CheckMandatoryElements() deals automatically with these cases.
 
 1)2)3)4)
@@ -1485,13 +1490,26 @@ void FileHelper::CheckMandatoryElements()
    // It's *not* an image comming straight from a source. We force
    // 'Media Storage SOP Class UID'  --> [Secondary Capture Image Storage]
          CopyMandatoryEntry(0x0008,0x0016,"1.2.840.10008.5.1.4.1.1.7", "UI");      
-   }   
-
+   }
+     
+   Archive->Push(0x0028,0x005); // [Image Dimensions (RET)
    // Push out 'LibIDO-special' entries, if any
    Archive->Push(0x0028,0x0015);
    Archive->Push(0x0028,0x0016);
    Archive->Push(0x0028,0x0017);
-   Archive->Push(0x0028,0x00199);
+   Archive->Push(0x0028,0x0198);  // very old versions
+   Archive->Push(0x0028,0x0199);
+   // Replace deprecated 0028 0012 US Planes   
+   // by new             0028 0008 IS Number of Frames
+   
+  ///\todo : find if there is a rule!
+   DataEntry *e_0028_0012 = FileInternal->GetDataEntry(0x0028, 0x0012);
+   if ( e_0028_0012 )
+   {
+      CopyMandatoryEntry(0x0028, 0x0008,e_0028_0012->GetString(),"IS");
+      Archive->Push(0x0028,0x0012);      
+   }
 
    // Deal with the pb of (Bits Stored = 12)
    // - we're gonna write the image as Bits Stored = 16
@@ -1552,7 +1570,56 @@ void FileHelper::CheckMandatoryElements()
    //  we write it only when we are *sure* the image comes from
    //         an imager (see also 0008,0x0064)          
       CheckMandatoryEntry(0x0018,0x1164,pixelSpacing,"DS");
+
+
+
+/*
+///Exact meaning of RETired fields
+
+// See page 73 of ACR-NEMA_300-1988.pdf !
+
+// 0020,0020 : Patient Orientation : 
+Patient direction of the first row and
+column of the images. The first entry id the direction of the raws, given by the
+direction of the last pixel in the first row from the first pixel in tha row.
+the second entry is the direction of the columns, given by the direction of the
+last pixel in the first column from the first pixel in that column.
+L : Left, F : Feet, A : Anterior, P : Posterior.
+Up to 3 letters can be used in combination to indicate oblique planes.
+
+//0020,0030 Image Position (RET)
+x,y,z coordinates im mm of the first pixel in the image
+
+// 0020,0035 Image Orientation (RET)
+Direction cosines of the R axis of the image system with respect to the
+equipment coordinate axes x,y,z, followed by direction cosines of the C axis of
+the image system with respect to the same axes
+
+//0020,0050 Location
+An image location reference, standard for the modality (such as CT bed
+position), used to indicate position. Calculation of position for other purposes
+is only from (0020,0030) and (0020,0035)
+*/
+/*
+// if imagePositionPatient    not found, default it with imagePositionRet,    if any
+// if imageOrientationPatient not found, default it with imageOrientationRet, if any
+
+   std::string imagePositionRet        = FileInternal->GetEntryString(0x0020,0x0030);
+   std::string imageOrientationRet     = FileInternal->GetEntryString(0x0020,0x0035);
+   std::string imagePositionPatient    = FileInternal->GetEntryString(0x0020,0x0032);
+   std::string imageOrientationPatient = FileInternal->GetEntryString(0x0020,0x0037);
    
+   if(  imagePositionPatient == GDCM_UNFOUND && imageOrientationPatient == GDCM_UNFOUND
+     && imagePositionRet     != GDCM_UNFOUND && imageOrientationRet     != GDCM_UNFOUND)
+   {
+      CopyMandatoryEntry(0x0020, 0x0032,imagePositionRet,"DS");
+      Archive->Push(0x0020,0x0030); 
+      CopyMandatoryEntry(0x0020, 0x0037,imageOrientationRet,"DS");
+      Archive->Push(0x0020,0x0035);        
+   }        
+*/
+    
    // Samples Per Pixel (type 1) : default to grayscale 
    CheckMandatoryEntry(0x0028,0x0002,"1","US");