]> Creatis software - gdcm.git/commitdiff
now gdcmFile::GetImageData loads pixels *and* updates 7fe0,0010 voidArea
authorjpr <jpr>
Thu, 10 Jun 2004 15:17:05 +0000 (15:17 +0000)
committerjpr <jpr>
Thu, 10 Jun 2004 15:17:05 +0000 (15:17 +0000)
(it helps !)

src/gdcmDocument.cxx
src/gdcmFile.cxx
src/gdcmValEntry.cxx

index 36f1e817376d0e5aa988fb38061a7b1cbe7b3ead..57596e4a3eee090433fb3ffafdcc9031cf84c7bc 100644 (file)
@@ -444,6 +444,8 @@ FILE *gdcmDocument::OpenFile(bool exception_on_error)
         throw gdcmFileError("gdcmDocument::gdcmDocument(const char *, bool)");
      else
      {
+        std::cout <<"gdcmDocument::OpenFile cannot open file: " 
+                  << filename.c_str() << std::endl;
         dbg.Verbose(0, "gdcmDocument::OpenFile cannot open file: ",
                     filename.c_str());
         return (NULL);
@@ -1058,20 +1060,21 @@ void gdcmDocument::WriteEntryValue(gdcmDocEntry *tag, FILE *_fp,FileType type)
                
                //--------------------------------
                //
-               // FIXME
+               // FIXME :right now, both value and voidArea belong to gdcmValue
                //
                // -------------------------------
                
-               
-/*     // to go on compiling 
-   void *voidArea;
-   voidArea = tag->GetVoidArea();  // to go on compiling
-   if (voidArea != NULL) 
-   { // there is a 'non string' LUT, overlay, etc
-      fwrite ( voidArea,(size_t)lgr ,(size_t)1 ,_fp); // Elem value
-      return;            
-   }
-*/      
+//   if (gdcmBinEntry* BinEntry = dynamic_cast< gdcmBinEntry* >(tag) ) {                       
+      void *voidArea;
+      gdcmBinEntry *BinEntry= (gdcmBinEntry *)tag;;
+      voidArea = BinEntry->GetVoidArea();      
+      if (voidArea != NULL) 
+      { // there is a 'non string' LUT, overlay, etc
+         fwrite ( voidArea,(size_t)lgr ,(size_t)1 ,_fp); // Elem value
+         return;            
+      }
+//   } 
+           
    if (vr == "US" || vr == "SS") 
    {
       // some 'Short integer' fields may be mulivaluated
@@ -1120,22 +1123,42 @@ void gdcmDocument::WriteEntryValue(gdcmDocEntry *tag, FILE *_fp,FileType type)
 
 bool gdcmDocument::WriteEntry(gdcmDocEntry *tag, FILE *_fp,FileType type)
 {
-   guint32 length = tag->GetLength();
-   gdcmValEntry * Vtag = (gdcmValEntry *) tag;
-std::cout << "gdcmDocument::WriteEntry  Vtag->GetValue() " << Vtag->GetValue() << std::endl;
+   guint32 length = tag->GetLength();  
+
+   if (gdcmValEntry* ValEntry = dynamic_cast< gdcmValEntry* >(tag) )   {
    // The value of a tag MUST (see the DICOM norm) be an odd number of
-   // bytes. When this is not the case, pad with an additional byte:
-   if(length%2==1)
-   { 
-      Vtag->SetValue(Vtag->GetValue()+"\0");
-      Vtag->SetLength(Vtag->GetReadLength()+1);
-   }
+   // bytes. When this is not the case, pad with an additional byte:   
+      if(length%2==1) { 
+         ValEntry->SetValue(ValEntry->GetValue()+"\0");
+         ValEntry->SetLength(ValEntry->GetReadLength()+1);
+      }
 
-   WriteEntryTagVRLength(Vtag, _fp, type);
+   WriteEntryTagVRLength(ValEntry, _fp, type);
        std::cout << "after WriteEntryTagVRLength " << std::endl;
-   WriteEntryValue(Vtag, _fp, type);
+   WriteEntryValue(ValEntry, _fp, type);
        std::cout << "after WriteEntryValue " << std::endl;
-   return true;
+   return true;        
+       }
+       
+   if (gdcmBinEntry* BinEntry = dynamic_cast< gdcmBinEntry* >(tag) )   {
+       //
+       // FIXME : when voidArea belong to gdcmBinEntry only, fix voidArea length
+       //
+   // The value of a tag MUST (see the DICOM norm) be an odd number of
+   // bytes. When this is not the case, pad with an additional byte:   
+       /*
+      if(length%2==1) { 
+         Vtag->SetValue(Vtag->GetValue()+"\0");
+         Vtag->SetLength(Vtag->GetReadLength()+1);
+      }
+*/
+
+   WriteEntryTagVRLength(tag, _fp, type);
+       std::cout << "after WriteEntryTagVRLength " << std::endl;
+   WriteEntryValue(tag, _fp, type);
+       std::cout << "after WriteEntryValue " << std::endl;
+   return true;        
+       }
 }
 
 /**
@@ -1175,9 +1198,7 @@ bool gdcmDocument::WriteEntries(FILE *_fp,FileType type)
             // Ignore the "shadow" groups
             continue;
          if ((*tag2).second->GetVR() == "SQ" ) // ignore Sequences
-            continue;
-         //if ((*tag2).second->GetDepthLevel() != 0) // Not only ignore the SQ element
-         //   continue;            
+            continue;    
       } 
       if (! WriteEntry((*tag2).second,_fp,type) ) {
                   std::cout << "Write Failure " << std::endl;
index bf0bd1a2d9a1e8a84a5e759afe1f912230edc02e..5b89912c1956dca32774aeffe5f00036a1db0ad0 100644 (file)
@@ -225,10 +225,14 @@ size_t gdcmFile::GetImageDataSizeRaw(void) {
  */
 void * gdcmFile::GetImageData (void) {
    PixelData = new char[lgrTotale];
-   if (PixelData)
+   if (PixelData) {
       GetImageDataIntoVector(PixelData, lgrTotale);
-      
+               GetHeader()->SetEntryVoidAreaByNumber(PixelData, 
+                      GetHeader()->GetGrPixel(),  
+                      GetHeader()->GetNumPixel()); 
+   }      
    PixelRead=0; // no PixelRaw
+       
    return(PixelData);
 }
 
@@ -322,8 +326,13 @@ void * gdcmFile::GetImageDataRaw (void) {
                /// Create a member lgrTotaleRaw ???
       lgrTotale /= 3;
    PixelData = new char[lgrTotale];
-   if (PixelData)
+       
+   if (PixelData) {
       GetImageDataIntoVectorRaw(PixelData, lgrTotale);
+               GetHeader()->SetEntryVoidAreaByNumber(PixelData, 
+                      GetHeader()->GetGrPixel(),  
+                      GetHeader()->GetNumPixel()); 
+   }                           
    PixelRead=1; // PixelRaw
    return(PixelData);
 }
index e2579ee7cbb956c63dc57ba17b7d2945c7456c21..a329b54ce035fdf711f7393eab12532b5c655aba 100644 (file)
@@ -17,7 +17,7 @@
  * @param   e Pointer to existing dictionary entry
  */
 gdcmValEntry::gdcmValEntry(gdcmDictEntry* e) : gdcmDocEntry(e) {
-   voidArea = NULL;
+   voidArea = NULL; // will be in BinEntry ?
 }
 
 /**