]> Creatis software - gdcm.git/blobdiff - src/gdcmFile.cxx
Add some comments about pixel spacing
[gdcm.git] / src / gdcmFile.cxx
index 6d45581b8e9c420d9acb1f1ec63752835e723e80..9c55ec89dbe7b06e16f140041949b297a6d1e656 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.cxx,v $
   Language:  C++
-  Date:      $Date: 2006/03/29 16:13:00 $
-  Version:   $Revision: 1.317 $
+  Date:      $Date: 2006/06/08 13:37:33 $
+  Version:   $Revision: 1.321 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -216,6 +216,11 @@ bool File::DoTheLoadingJob( )
       // The changed DictEntry will have 
       // - a correct PixelVR OB or OW)
       // - the name to "Pixel Data"
+      
+       //==>Take it easy!
+       //==> Just change the VR !
+
+/* 
       DataEntry *oldEntry = dynamic_cast<DataEntry *>(entry);
       if (oldEntry)
       {
@@ -229,21 +234,34 @@ bool File::DoTheLoadingJob( )
 
          // Change only made if usefull
          if ( PixelVR != oldEntry->GetVR() )
-         {
-            DictEntry* newDict = DictEntry::New(GrPixel,NumPixel,
-                                                PixelVR,"1","Pixel Data");
-
-            DataEntry *newEntry = DataEntry::New(newDict);
-            newDict->Delete();
-            newEntry->Copy(entry);
-            newEntry->SetBinArea(oldEntry->GetBinArea(),oldEntry->IsSelfArea());
-            oldEntry->SetSelfArea(false);
-
-            RemoveEntry(oldEntry);
-            AddEntry(newEntry);
-            newEntry->Delete();
+         {       
+            //DictEntry* newDict = DictEntry::New(GrPixel,NumPixel,
+            //                                    PixelVR,"1","Pixel Data");
+            //DataEntry *newEntry = DataEntry::New(newDict);
+            //newDict->Delete();
+            //newEntry->Copy(entry);
+            //newEntry->SetBinArea(oldEntry->GetBinArea(),oldEntry->IsSelfArea());
+            //oldEntry->SetSelfArea(false);
+
+            //RemoveEntry(oldEntry);
+            //AddEntry(newEntry);
+            //newEntry->Delete();
+  
          }
       }
+*/
+         VRKey PixelVR;
+         // 8 bits allocated is a 'OB(ytes)' , as well as 24 (old ACR-NEMA RGB)
+         // more than 8 (i.e 12, 16) is a 'OW(ords)'
+         if ( GetBitsAllocated() == 8 || GetBitsAllocated() == 24 ) 
+            PixelVR = "OB";
+         else
+            PixelVR = "OW";
+         // Change only made if usefull
+         if ( PixelVR != entry->GetVR() )
+         { 
+            entry->SetVR(PixelVR);  
+         }         
    }
    return true;
 }
@@ -490,6 +508,36 @@ float File::GetXSpacing()
 {
    float xspacing = 1.0;
    uint32_t nbValue;
+/*   
+It *SHOULD* first find the IOD and then deduce which tags to read
+Eg: Cross section this is in Pixel Spacing (0028,0030)
+CR is in Imager Pixel Spacing (0018,1164)
+US is in Pixel Ratio (0028,0034)
+RT is in :
+(3002,0011) Image Plane Pixel Spacing
+(3002,0012) RT Image Position
+and
+(3004,000c) for deducing Z spacing 
+*/
+
+
+//   std::string SOPClassUID = GetEntryString(0x0008,0x0016);
+
+   /// \todo check the various SOP Class
+   ///       to get the Pixel Spacing at the proper location
+   
+       
+   // Ultrasound Image Storage (Retired)
+/* 
+   if (Util::DicomStringEqual( SOPClassUID,"1.2.840.10008.5.1.4.1.1.6")
+   {
+       - check if  SOPClassUID contains 2 parts (e.g. "4\3")
+       - guess how to deduce the spacing (FOV ?, ??)       
+   }
+   else
+   // go on with old method ...
+*/  
 
    // To follow David Clunie's advice, we first check ImagerPixelSpacing
 
@@ -1363,6 +1411,10 @@ void File::AnonymizeNoLoad()
                                it != UserAnonymizeList.end();
                              ++it)
    { 
+   
+      //std::cout << "File::AnonymizeNoLoad -------" << std::hex <<(*it).Group <<"|"<< 
+      //         (*it).Elem 
+      //         << "[" << (*it).Value << "] "<< std::dec << std::endl; 
       d = GetDocEntry( (*it).Group, (*it).Elem);
 
       if ( d == NULL)
@@ -1373,13 +1425,20 @@ void File::AnonymizeNoLoad()
          gdcmWarningMacro( "You cannot 'Anonymize' a SeqEntry ");
          continue;
       }
+      
+      valLgth = (*it).Value.size();
+      if (valLgth == 0)
+         continue;
 
       offset = d->GetOffset();
       lgth =   d->GetLength();
+      
+      //std::cout << "lgth " << lgth << " valLgth " << valLgth << std::endl;
       if (valLgth < lgth)
       {
          spaces = new std::string( lgth-valLgth, ' ');
          (*it).Value = (*it).Value + *spaces;
+         //std::cout << "[" << (*it).Value << "] " << lgth << std::endl;
          delete spaces;
       }
       fp->seekp( offset, std::ios::beg );
@@ -1539,7 +1598,7 @@ bool File::Write(std::string fileName, FileType writetype)
          // no (GrPixel, NumPixel) element
          std::string s_lgPix = Util::Format("%d", i_lgPix+12);
          s_lgPix = Util::DicomString( s_lgPix.c_str() );
-         InsertEntryString(s_lgPix,GrPixel, 0x0000);   
+         InsertEntryString(s_lgPix,GrPixel, 0x0000, "UL");   
       }
    }
    Document::WriteContent(fp, writetype);
@@ -1866,7 +1925,7 @@ void File::ReadEncapsulatedBasicOffsetTable()
 
 // These are the deprecated method that one day should be removed (after the next release)
 
-#ifndef GDCM_LEGACY_REMOVE
+//#ifndef GDCM_LEGACY_REMOVE
 /*
  * \ brief   Loader. (DEPRECATED :  temporaryly kept not to break the API)
  * @ param   fileName file to be open for parsing
@@ -1874,6 +1933,7 @@ void File::ReadEncapsulatedBasicOffsetTable()
  *         or no tag was found.
  * @deprecated Use the Load() [ + SetLoadMode() ] + SetFileName() functions instead
  */
+ /*
 bool File::Load( std::string const &fileName ) 
 {
    GDCM_LEGACY_REPLACED_BODY(File::Load(std::string), "1.2",
@@ -1885,7 +1945,7 @@ bool File::Load( std::string const &fileName )
    return DoTheLoadingJob( );
 }
 #endif
-
+*/
 //-----------------------------------------------------------------------------
 // Print