]> Creatis software - gdcm.git/commitdiff
* src/gdcmDocument.[h|cxx] : set the Transfert Syntax values to the header
authorregrain <regrain>
Thu, 25 Nov 2004 13:12:02 +0000 (13:12 +0000)
committerregrain <regrain>
Thu, 25 Nov 2004 13:12:02 +0000 (13:12 +0000)
     file, to be accessed by other files (like gdcmFile). Remove commented
     code. Move the change of the header to the gdcmFile, using the
     DocEntryArchive
   * src/gdcmHeader.[h|cxx] : the write is completely made in the Header.
     To be sure of that (and simplify calls), the Write of the header now
     gets a file name and not a file pointer (std::ifstream).
   * src/gdcmFile.[h|cxx] : apply the write file type to the header, using the
     DocEntryArchive. Remove all open of the written file
   -- BeNours

ChangeLog
src/gdcmDocument.cxx
src/gdcmDocument.h
src/gdcmFile.cxx
src/gdcmFile.h
src/gdcmHeader.cxx
src/gdcmHeader.h

index f582ac92377ef91cbf0592b38894286b385a3e9c..2a5ed92ab46f9f25dacf97ee46aa931d64511e1d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2004-11-25 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
+   * src/gdcmDocument.[h|cxx] : set the Transfert Syntax values to the header
+     file, to be accessed by other files (like gdcmFile). Remove commented
+     code. Move the change of the header to the gdcmFile, using the 
+     DocEntryArchive
+   * src/gdcmHeader.[h|cxx] : the write is completely made in the Header.
+     To be sure of that (and simplify calls), the Write of the header now
+     gets a file name and not a file pointer (std::ifstream).
+   * src/gdcmFile.[h|cxx] : apply the write file type to the header, using the
+     DocEntryArchive. Remove all open of the written file
+
 2004-11-25 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
    * vtk/vtkGdcmReader.cxx : compilation bug fix for the vtk part
 
index 73c7ecf74cd10d2e3c127b600eb3b826b9f09c68..48a0a32deb01f685b41c8a09efb30eed5aa0e06b 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/11/25 10:24:34 $
-  Version:   $Revision: 1.138 $
+  Date:      $Date: 2004/11/25 13:12:02 $
+  Version:   $Revision: 1.139 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 
 namespace gdcm 
 {
-static const char *TransferSyntaxStrings[] =  {
-  // Implicit VR Little Endian
-  "1.2.840.10008.1.2",
-  // Implicit VR Little Endian DLX G.E?
-  "1.2.840.113619.5.2",
-  // Explicit VR Little Endian
-  "1.2.840.10008.1.2.1",
-  // Deflated Explicit VR Little Endian
-  "1.2.840.10008.1.2.1.99",
-  // Explicit VR Big Endian
-  "1.2.840.10008.1.2.2",
-  // JPEG Baseline (Process 1)
-  "1.2.840.10008.1.2.4.50",
-  // JPEG Extended (Process 2 & 4)
-  "1.2.840.10008.1.2.4.51",
-  // JPEG Extended (Process 3 & 5)
-  "1.2.840.10008.1.2.4.52",
-  // JPEG Spectral Selection, Non-Hierarchical (Process 6 & 8)
-  "1.2.840.10008.1.2.4.53",
-  // JPEG Full Progression, Non-Hierarchical (Process 10 & 12)
-  "1.2.840.10008.1.2.4.55",
-  // JPEG Lossless, Non-Hierarchical (Process 14)
-  "1.2.840.10008.1.2.4.57",
-  // JPEG Lossless, Hierarchical, First-Order Prediction (Process 14, [Selection Value 1])
-  "1.2.840.10008.1.2.4.70",
-  // JPEG 2000 Lossless
-  "1.2.840.10008.1.2.4.90",
-  // JPEG 2000
-  "1.2.840.10008.1.2.4.91",
-  // RLE Lossless
-  "1.2.840.10008.1.2.5",
-  // Unknown
-  "Unknown Transfer Syntax"
-};
-
 //-----------------------------------------------------------------------------
 // Refer to Document::CheckSwap()
 const unsigned int Document::HEADER_LENGTH_TO_READ = 256;
@@ -497,34 +462,6 @@ void Document::Write(std::ofstream* fp, FileType filetype)
       fp->write("DICM", 4);
    }
 
-   if (filetype == ImplicitVR) 
-   {
-      std::string ts = 
-         Util::DicomString( TransferSyntaxStrings[ImplicitVRLittleEndian] );
-      ReplaceOrCreateByNumber(ts, 0x0002, 0x0010);
-      
-      /// \todo Refer to standards on page 21, chapter 6.2
-      ///       "Value representation": values with a VR of UI shall be
-      ///       padded with a single trailing null
-      ///       in the following case we have to padd manually with a 0
-      
-      SetEntryLengthByNumber(18, 0x0002, 0x0010);
-   } 
-
-   if (filetype == ExplicitVR)
-   {
-      std::string ts = 
-         Util::DicomString( TransferSyntaxStrings[ExplicitVRLittleEndian] );
-      ReplaceOrCreateByNumber(ts, 0x0002, 0x0010); //LEAK
-      
-      /// \todo Refer to standards on page 21, chapter 6.2
-      ///       "Value representation": values with a VR of UI shall be
-      ///       padded with a single trailing null
-      ///       Dans le cas suivant on doit pader manuellement avec un 0
-      
-      SetEntryLengthByNumber(20, 0x0002, 0x0010);
-   }
-  
 /**
  * \todo rewrite later, if really usefull
  *       - 'Group Length' element is optional in DICOM
@@ -538,7 +475,6 @@ void Document::Write(std::ofstream* fp, FileType filetype)
  */
  
    ElementSet::Write(fp, filetype); // This one is recursive
-
 }
 
 /**
@@ -1437,9 +1373,6 @@ void Document::ParseDES(DocEntrySet *set, long offset,
             }
 
          //////////////////// BinEntry or UNKOWN VR:
-/*            BinEntry* newBinEntry =
-               new BinEntry( newDocEntry->GetDictEntry() );  //LEAK
-            newBinEntry->Copy( newDocEntry );*/
             BinEntry* newBinEntry = new BinEntry( newDocEntry );  //LEAK
 
             // When "this" is a Document the Key is simply of the
@@ -2569,7 +2502,7 @@ bool Document::CheckSwap()
    // representation of a 32 bits integer. Hence the following dirty
    // trick :
    s32 = *((uint32_t *)(entCur));
-      
+
    switch( s32 )
    {
       case 0x00040000 :
index c36efc15712b7cbf330489e3f5d82afc9f801e8f..411d7d31859a98e519ef93d55976b38b035a40b5 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.h,v $
   Language:  C++
-  Date:      $Date: 2004/11/24 11:17:47 $
-  Version:   $Revision: 1.62 $
+  Date:      $Date: 2004/11/25 13:12:02 $
+  Version:   $Revision: 1.63 $
  
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -60,6 +60,41 @@ enum TransferSyntaxType {
   UnknownTS
 };
 
+static const char *TransferSyntaxStrings[] =  {
+  // Implicit VR Little Endian
+  "1.2.840.10008.1.2",
+  // Implicit VR Little Endian DLX G.E?
+  "1.2.840.113619.5.2",
+  // Explicit VR Little Endian
+  "1.2.840.10008.1.2.1",
+  // Deflated Explicit VR Little Endian
+  "1.2.840.10008.1.2.1.99",
+  // Explicit VR Big Endian
+  "1.2.840.10008.1.2.2",
+  // JPEG Baseline (Process 1)
+  "1.2.840.10008.1.2.4.50",
+  // JPEG Extended (Process 2 & 4)
+  "1.2.840.10008.1.2.4.51",
+  // JPEG Extended (Process 3 & 5)
+  "1.2.840.10008.1.2.4.52",
+  // JPEG Spectral Selection, Non-Hierarchical (Process 6 & 8)
+  "1.2.840.10008.1.2.4.53",
+  // JPEG Full Progression, Non-Hierarchical (Process 10 & 12)
+  "1.2.840.10008.1.2.4.55",
+  // JPEG Lossless, Non-Hierarchical (Process 14)
+  "1.2.840.10008.1.2.4.57",
+  // JPEG Lossless, Hierarchical, First-Order Prediction (Process 14, [Selection Value 1])
+  "1.2.840.10008.1.2.4.70",
+  // JPEG 2000 Lossless
+  "1.2.840.10008.1.2.4.90",
+  // JPEG 2000
+  "1.2.840.10008.1.2.4.91",
+  // RLE Lossless
+  "1.2.840.10008.1.2.5",
+  // Unknown
+  "Unknown Transfer Syntax"
+};
+
 //-----------------------------------------------------------------------------
 /**
  * \brief Derived by both Header and DicomDir
index 60c86429471f044929d325fd96a35d72c336410d..4921affdf3820fe2858911157c0295bcd9f98eaa 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/11/25 10:24:34 $
-  Version:   $Revision: 1.163 $
+  Date:      $Date: 2004/11/25 13:12:02 $
+  Version:   $Revision: 1.164 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -17,6 +17,7 @@
 =========================================================================*/
 
 #include "gdcmFile.h"
+#include "gdcmDocument.h"
 #include "gdcmDebug.h"
 #include "gdcmUtil.h"
 #include "gdcmBinEntry.h"
@@ -396,14 +397,22 @@ uint8_t* File::GetLutRGBA()
  */
 bool File::WriteBase (std::string const & fileName, FileType type)
 {
-   std::ofstream* fp1 = new std::ofstream(fileName.c_str(), 
-                              std::ios::out | std::ios::binary);
-   if (fp1 == NULL)
+   switch(type)
    {
-      dbg.Verbose(2, "Failed to open (write) File: " , fileName.c_str());
-      return false;
+      case ImplicitVR:
+         SetWriteFileTypeToImplicitVR();
+         break;
+      case ExplicitVR:
+         SetWriteFileTypeToExplicitVR();
+         break;
+      case ACR:
+         SetWriteFileTypeToACR();
+         break;
+      case ACR_LIBIDO:
+         SetWriteFileTypeToACRLibido();
+         break;
    }
-
+  
    switch(WriteMode)
    {
       case WMODE_NATIVE :
@@ -431,10 +440,10 @@ bool File::WriteBase (std::string const & fileName, FileType type)
    }*/
    // ----------------- End of Special Patch ----------------
 
-   bool check=CheckWriteIntegrity();
+   bool check = CheckWriteIntegrity();
    if(check)
    {
-      HeaderInternal->Write(fp1,type);
+      check = HeaderInternal->Write(fileName,type);
    }
 
    // --------------------------------------------------------------
@@ -449,9 +458,7 @@ bool File::WriteBase (std::string const & fileName, FileType type)
    // ----------------- End of Special Patch ----------------
 
    RestoreWrite();
-
-   fp1->close();
-   delete fp1;
+   RestoreWriteFileType();
 
    return check;
 }
@@ -468,21 +475,38 @@ bool File::CheckWriteIntegrity()
 {
    if(Pixel_Data)
    {
+      int numberBitsAllocated = HeaderInternal->GetBitsAllocated();
+      if ( numberBitsAllocated == 0 || numberBitsAllocated == 12 )
+      {
+         numberBitsAllocated = 16;
+      }
+
+      int decSize = HeaderInternal->GetXSize()
+                    * HeaderInternal->GetYSize() 
+                    * HeaderInternal->GetZSize()
+                    * ( numberBitsAllocated / 8 )
+                    * HeaderInternal->GetSamplesPerPixel();
+      int rgbSize = decSize;
+      if( HeaderInternal->HasLUT() )
+         rgbSize = decSize * 3;
+
       switch(WriteMode)
       {
          case WMODE_NATIVE :
             break;
          case WMODE_DECOMPRESSED :
-            if(GetImageDataRawSize()!=ImageDataSize)
+            if( decSize!=ImageDataSize )
             {
-               std::cerr<<"RAW : "<<GetImageDataRawSize()<<" / "<<ImageDataSize<<std::endl;
+               dbg.Verbose(0, "File::CheckWriteIntegrity: Data size is incorrect");
+               //std::cerr<<"Dec : "<<decSize<<" | "<<ImageDataSize<<std::endl;
                return false;
             }
             break;
          case WMODE_RGB :
-            if(GetImageDataSize()!=ImageDataSize)
+            if( rgbSize!=ImageDataSize )
             {
-               std::cerr<<"RGB : "<<GetImageDataSize()<<" / "<<ImageDataSize<<std::endl;
+               dbg.Verbose(0, "File::CheckWriteIntegrity: Data size is incorrect");
+               //std::cerr<<"RGB : "<<decSize<<" | "<<ImageDataSize<<std::endl;
                return false;
             }
             break;
@@ -641,6 +665,43 @@ void File::RestoreWrite()
    Archive->Restore(0x0028,0x1203);
 }
 
+void File::SetWriteFileTypeToACR()
+{
+   Archive->Push(0x0002,0x0010);
+}
+
+void File::SetWriteFileTypeToACRLibido()
+{
+   SetWriteFileTypeToACR();
+}
+
+void File::SetWriteFileTypeToExplicitVR()
+{
+   std::string ts = 
+      Util::DicomString( TransferSyntaxStrings[ExplicitVRLittleEndian] );
+
+   ValEntry* tss = CopyValEntry(0x0002,0x0010);
+   tss->SetValue(ts);
+   tss->SetLength(ts.length());
+
+   Archive->Push(tss);
+}
+
+void File::SetWriteFileTypeToImplicitVR()
+{
+   std::string ts = 
+      Util::DicomString( TransferSyntaxStrings[ImplicitVRLittleEndian] );
+
+   ValEntry* tss = CopyValEntry(0x0002,0x0010);
+   tss->SetValue(ts);
+   tss->SetLength(ts.length());
+}
+
+void File::RestoreWriteFileType()
+{
+   Archive->Restore(0x0002,0x0010);
+}
+
 void File::SetWriteToLibido()
 {
    ValEntry *oldRow = dynamic_cast<ValEntry *>(HeaderInternal->GetDocEntryByNumber(0x0028, 0x0010));
index cf48b6d1294a20c89fc8c648336247b5ab210e95..02eaae758134333b59e2504e727b01e36c82647f 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.h,v $
   Language:  C++
-  Date:      $Date: 2004/11/25 10:24:34 $
-  Version:   $Revision: 1.76 $
+  Date:      $Date: 2004/11/25 13:12:02 $
+  Version:   $Revision: 1.77 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -111,6 +111,12 @@ protected:
    void SetWriteToRGB();
    void RestoreWrite();
 
+   void SetWriteFileTypeToACR();
+   void SetWriteFileTypeToACRLibido();
+   void SetWriteFileTypeToExplicitVR();
+   void SetWriteFileTypeToImplicitVR();
+   void RestoreWriteFileType();
+
    void SetWriteToLibido();
    void RestoreWriteFromLibido();
 
@@ -126,7 +132,6 @@ private:
    void SetPixelData(uint8_t* data);
 
 private:
-
 // members variables:
 
    /// Header to use to load the file
index 84aea4d314918aebaf370a2fe606bf8298b94302..8371f3ce4a612286fe0f98b9564d146f33e9e5b7 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmHeader.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/11/23 17:12:25 $
-  Version:   $Revision: 1.205 $
+  Date:      $Date: 2004/11/25 13:12:02 $
+  Version:   $Revision: 1.206 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -102,8 +102,16 @@ Header::~Header ()
  * @param filetype Type of the File to be written 
  *          (ACR-NEMA, ExplicitVR, ImplicitVR)
  */
-void Header::Write(std::ofstream* fp,FileType filetype)
+bool Header::Write(std::string fileName,FileType filetype)
 {
+   std::ofstream* fp = new std::ofstream(fileName.c_str(), 
+                                         std::ios::out | std::ios::binary);
+   if (fp == NULL)
+   {
+      dbg.Verbose(2, "Failed to open (write) File: " , fileName.c_str());
+      return false;
+   }
+
    // Bits Allocated
    if ( GetEntryByNumber(0x0028,0x0100) ==  "12")
    {
@@ -164,6 +172,11 @@ void Header::Write(std::ofstream* fp,FileType filetype)
       }
    }
    Document::Write(fp,filetype);
+
+   fp->close();
+   delete fp;
+
+   return true;
 }
 
 //-----------------------------------------------------------------------------
index d7d7d87065aa364aa0ff40e74ab9a78c8cd84425..cbd36527205e66477f2cdeb1823967515084d3f8 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmHeader.h,v $
   Language:  C++
-  Date:      $Date: 2004/11/16 05:03:35 $
-  Version:   $Revision: 1.93 $
+  Date:      $Date: 2004/11/25 13:12:02 $
+  Version:   $Revision: 1.94 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -172,7 +172,7 @@ public:
    /// Read (used in File)
    void SetImageDataSize(size_t expectedSize);
 
-   void Write(std::ofstream* fp, FileType filetype);
+   bool Write(std::string fileName, FileType filetype);
 
    /// Initialize DICOM header when none
    void InitializeDefaultHeader();