]> Creatis software - gdcm.git/commitdiff
* src/gdcmDocEntryArchive.cxx : complete the print function, that prints
authorregrain <regrain>
Tue, 23 Nov 2004 11:14:13 +0000 (11:14 +0000)
committerregrain <regrain>
Tue, 23 Nov 2004 11:14:13 +0000 (11:14 +0000)
     all replaced DocEntry's
   * src/gdcmFile.[h|cxx] : remove all changes of the header when getting datas.
     Now, each needed DocEntry to modify is duplicated, modified and inserted
     to the header using DocEntryArchive. Thus, after save, we can restore the
     header initial state.
   -- BeNours

ChangeLog
src/gdcmDocEntryArchive.cxx
src/gdcmFile.cxx
src/gdcmFile.h

index 15d4ca7dec720833ed092082f20b2d9bcbdead0e..f4cff36dfee3c76910f2edd481f24e489787f24c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2004-11-23 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
+   * src/gdcmDocEntryArchive.cxx : complete the print function, that prints
+     all replaced DocEntry's
+   * src/gdcmFile.[h|cxx] : remove all changes of the header when getting datas.
+     Now, each needed DocEntry to modify is duplicated, modified and inserted
+     to the header using DocEntryArchive. Thus, after save, we can restore the
+     header initial state.
+
 2004-11-22 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
    * src/gdcmFile.h : fix compilation errors on zorglub linuc computer
 
index 8ee463398abba97780b6b38f22213bbc5f2e93aa..263f8a75a9994e07d15e80e3f49d8571aa2db277 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntryArchive.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/11/19 18:49:39 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2004/11/23 11:14:13 $
+  Version:   $Revision: 1.2 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -49,6 +49,14 @@ DocEntryArchive::~DocEntryArchive()
  */
 void DocEntryArchive::Print(std::ostream &os) 
 {
+   os << "Elements in archives :" << std::endl;
+   for(TagDocEntryHT::iterator it = Archive.begin();
+       it!=Archive.end();
+       ++it)
+   {
+      if(it->second)
+         it->second->Print(os);
+   }
 }
 
 //-----------------------------------------------------------------------------
index 94c6efcbdb5fec8f75ace534725f06002929ea8e..d198c1c96c7c1f19cfef5ac4d8a1493ab23f2540 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/11/19 18:49:39 $
-  Version:   $Revision: 1.158 $
+  Date:      $Date: 2004/11/23 11:14:13 $
+  Version:   $Revision: 1.159 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -75,7 +75,7 @@ File::File(std::string const & filename )
  */
 void File::Initialise()
 {
-   WriteMode = WMODE_NATIVE;
+   WriteMode = WMODE_DECOMPRESSED;
    WriteType = WTYPE_IMPL_VR;
    PixelConverter = NULL; //just in case
    Archive = NULL;
@@ -336,7 +336,7 @@ uint8_t* File::GetImageData()
       pixelData = PixelConverter->GetDecompressed();
    }
 
-// PIXELCONVERT CLEANME
+/*// PIXELCONVERT CLEANME
    // Restore the header in a disk-consistent state
    // (if user asks twice to get the pixels from disk)
    if ( PixelRead != -1 ) // File was "read" before
@@ -391,7 +391,7 @@ uint8_t* File::GetImageData()
 
    // We say the value *is* loaded.
    SetPixelData(pixelData);
-// END PIXELCONVERT CLEANME
+// END PIXELCONVERT CLEANME*/
 
    return pixelData;
 }
@@ -473,7 +473,7 @@ uint8_t* File::GetImageDataRaw ()
       return 0;
    }
 
-// PIXELCONVERT CLEANME
+/*// PIXELCONVERT CLEANME
    // Restore the header in a disk-consistent state
    // (if user asks twice to get the pixels from disk)
    if ( PixelRead != -1 ) // File was "read" before
@@ -503,7 +503,7 @@ uint8_t* File::GetImageDataRaw ()
    SetPixelData(decompressed);
  
    PixelRead = 1; // PixelRaw
-// END PIXELCONVERT CLEANME
+// END PIXELCONVERT CLEANME*/
 
    return decompressed;
 }
@@ -673,6 +673,19 @@ bool File::WriteBase (std::string const & fileName, FileType type)
       fp1->write("DICM", 4);
    }
 
+   switch(WriteMode)
+   {
+      case WMODE_NATIVE :
+         SetWriteToNative();
+         break;
+      case WMODE_DECOMPRESSED :
+         SetWriteToDecompressed();
+         break;
+      case WMODE_RGB :
+         SetWriteToRGB();
+         break;
+   }
+
    // --------------------------------------------------------------
    // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
    //
@@ -686,12 +699,7 @@ bool File::WriteBase (std::string const & fileName, FileType type)
    std::string rows, columns; 
    if ( HeaderInternal->GetFileType() == ACR_LIBIDO)
    {
-      SetToLibido();
-      //rows    = HeaderInternal->GetEntryByNumber(0x0028, 0x0010);
-      //columns = HeaderInternal->GetEntryByNumber(0x0028, 0x0011);
-
-      //HeaderInternal->SetEntryByNumber(columns,  0x0028, 0x0010);
-      //HeaderInternal->SetEntryByNumber(rows   ,  0x0028, 0x0011);
+      SetWriteToLibido();
    }
    // ----------------- End of Special Patch ----------------
       
@@ -722,11 +730,13 @@ bool File::WriteBase (std::string const & fileName, FileType type)
 
    if ( HeaderInternal->GetFileType() == ACR_LIBIDO )
    {
-      RestoreFromLibido();
-      //HeaderInternal->SetEntryByNumber(rows   , 0x0028, 0x0010);
-      //HeaderInternal->SetEntryByNumber(columns, 0x0028, 0x0011);
+      RestoreWriteFromLibido();
    }
    // ----------------- End of Special Patch ----------------
+
+   RestoreWrite();
+
+
    fp1->close ();
    delete fp1;
 
@@ -761,23 +771,82 @@ void File::SetPixelData(uint8_t* data)
    }
 }
 
-void File::SetToRAW()
+void File::SetWriteToNative()
 {
+// Nothing to do
 }
 
-void File::SetToRGB()
+void File::SetWriteToDecompressed()
 {
+//   if (( !HeaderInternal->HasLUT() ) || (!PixelConverter->BuildRGBImage()))
+   if(HeaderInternal->HasLUT() && PixelConverter->BuildRGBImage())
+   {
+      SetWriteToRGB();
+   } 
+   else
+   {
+      ValEntry* photInt = CopyValEntry(0x0028,0x0004);
+      photInt->SetValue("MONOCHROME1 ");
+      photInt->SetLength(12);
+
+      BinEntry* pixel = CopyBinEntry(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel());
+      pixel->SetValue(GDCM_BINLOADED);
+      pixel->SetBinArea(PixelConverter->GetDecompressed(),false);
+      pixel->SetLength(PixelConverter->GetDecompressedSize());
+
+      Archive->Push(photInt);
+      Archive->Push(pixel);
+   }
+/*   else 
+   {
+      SetWriteToRGB();
+   } */
+}
+
+void File::SetWriteToRGB()
+{
+   if(PixelConverter->BuildRGBImage())
+   {
+      ValEntry* spp = CopyValEntry(0x0028,0x0002);
+      spp->SetValue("3 ");
+      spp->SetLength(2);
+
+      ValEntry* photInt = CopyValEntry(0x0028,0x0004);
+      photInt->SetValue("RGB ");
+      photInt->SetLength(4);
+
+      ValEntry* planConfig = CopyValEntry(0x0028,0x0006);
+      planConfig->SetValue("0 ");
+      planConfig->SetLength(2);
+
+      BinEntry* pixel = CopyBinEntry(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel());
+      pixel->SetValue(GDCM_BINLOADED);
+      pixel->SetBinArea(PixelConverter->GetRGB(),false);
+      pixel->SetLength(PixelConverter->GetRGBSize());
+
+      Archive->Push(spp);
+      Archive->Push(photInt);
+      Archive->Push(planConfig);
+      Archive->Push(pixel);
+   }
+   else
+   {
+      SetWriteToDecompressed();
+   }
 }
 
-void File::Restore()
+void File::RestoreWrite()
 {
+   Archive->Restore(0x0028,0x0002);
+   Archive->Restore(0x0028,0x0004);
+   Archive->Restore(0x0028,0x0006);
+   Archive->Restore(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel());
 }
 
-void File::SetToLibido()
+void File::SetWriteToLibido()
 {
    ValEntry *oldRow = dynamic_cast<ValEntry *>(HeaderInternal->GetDocEntryByNumber(0x0028, 0x0010));
    ValEntry *oldCol = dynamic_cast<ValEntry *>(HeaderInternal->GetDocEntryByNumber(0x0028, 0x0011));
-
    
    if( oldRow && oldCol )
    {
@@ -797,10 +866,47 @@ void File::SetToLibido()
    }
 }
 
-void File::RestoreFromLibido()
+void File::RestoreWriteFromLibido()
+{
+   Archive->Restore(0x0028,0x0010);
+   Archive->Restore(0x0028,0x0011);
+}
+
+ValEntry* File::CopyValEntry(uint16_t group,uint16_t element)
+{
+   DocEntry* oldE = HeaderInternal->GetDocEntryByNumber(group, element);
+   ValEntry* newE;
+
+   if(oldE)
+   {
+      newE = new ValEntry(oldE->GetDictEntry());
+      newE->Copy(oldE);
+   }
+   else
+   {
+      newE = GetHeader()->NewValEntryByNumber(group,element);
+   }
+
+   return(newE);
+}
+
+BinEntry* File::CopyBinEntry(uint16_t group,uint16_t element)
 {
-   Archive->Restore(0x0028, 0x0010);
-   Archive->Restore(0x0028, 0x0011);
+   DocEntry* oldE = HeaderInternal->GetDocEntryByNumber(group, element);
+   BinEntry* newE;
+
+   if(oldE)
+   {
+      newE = new BinEntry(oldE->GetDictEntry());
+      newE->Copy(oldE);
+   }
+   else
+   {
+      newE = GetHeader()->NewBinEntryByNumber(group,element);
+   }
+
+
+   return(newE);
 }
 
 //-----------------------------------------------------------------------------
index 4a1ffa52504ecf049374f7463f75c2f06f624206..f5ba811975455ad77d2ee9ba1a97d014b2fca570 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.h,v $
   Language:  C++
-  Date:      $Date: 2004/11/23 09:13:26 $
-  Version:   $Revision: 1.72 $
+  Date:      $Date: 2004/11/23 11:14:13 $
+  Version:   $Revision: 1.73 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -108,12 +108,16 @@ public:
 protected:
    bool WriteBase(std::string const& fileName, FileType type);
 
-   void SetToRAW();
-   void SetToRGB();
-   void Restore();
+   void SetWriteToNative();
+   void SetWriteToDecompressed();
+   void SetWriteToRGB();
+   void RestoreWrite();
 
-   void SetToLibido();
-   void RestoreFromLibido();
+   void SetWriteToLibido();
+   void RestoreWriteFromLibido();
+
+   ValEntry* CopyValEntry(uint16_t group,uint16_t element);
+   BinEntry* CopyBinEntry(uint16_t group,uint16_t element);
 
 private:
    void Initialise();
@@ -139,7 +143,7 @@ private:
    
    /// Wether already parsed or not
    bool Parsed;
-      
+
    /// Utility pixel converter
    PixelConvert* PixelConverter;