]> Creatis software - gdcm.git/commitdiff
* vtk/vtkGdcmReader.[h|cxx] : bug fix. Plane order isn't inverted
authorregrain <regrain>
Wed, 8 Dec 2004 11:37:15 +0000 (11:37 +0000)
committerregrain <regrain>
Wed, 8 Dec 2004 11:37:15 +0000 (11:37 +0000)
   * vtk/vtkGdcmWriter.[h|cxx] : correctly write images (the Y axis is inverted)
   * Test/ShowDicomSeq.cxx : new test to verify the use of AddFileName method
   * Test/ShowDicom.cxx, TestWriteWithVTK.cxx : set the threshold of regression
     test to 0.0
   * Test/TestCopyRescaleDicom.cxx : remove unused variable
   * Test/CMakeLists.txt : add the creation of the gdcmDataSeqImages.h file
     containing found sequences
   -- BeNours

ChangeLog
Testing/CMakeLists.txt
Testing/TestCopyRescaleDicom.cxx
vtk/vtkGdcmReader.cxx
vtk/vtkGdcmWriter.cxx
vtk/vtkGdcmWriter.h

index 7e630ff678b6887258ed41ce19b99438cfadb80d..e454251ff019566a807e1857cf9be0f72e3ac9fa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2004-12-08 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
+   * vtk/vtkGdcmReader.[h|cxx] : bug fix. Plane order isn't inverted
+   * vtk/vtkGdcmWriter.[h|cxx] : correctly write images (the Y axis is inverted)
+   * Test/ShowDicomSeq.cxx : new test to verify the use of AddFileName method
+   * Test/ShowDicom.cxx, TestWriteWithVTK.cxx : set the threshold of regression
+     test to 0.0
+   * Test/TestCopyRescaleDicom.cxx : remove unused variable
+   * Test/CMakeLists.txt : add the creation of the gdcmDataSeqImages.h file
+     containing found sequences
+
 2004-12-07 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
    * Test/ShowDicom.cxx, TestWriteWithVTK.cxx : bug fix, now this test pass
      not at all time
index 268f52fe7689ff18ffdae278cc49501c53c3575a..1dedc01fccefbf1720d8bcb39969f0b86f6278c0 100644 (file)
@@ -41,6 +41,7 @@ IF (GDCM_DATA_ROOT)
       )
     SET(TEST_SOURCES ${TEST_SOURCES}
       ShowDicom.cxx
+      ShowDicomSeq.cxx
       TestWriteWithVTK.cxx
       )
   ENDIF(GDCM_VTK)
@@ -90,6 +91,12 @@ IF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)
     "${GDCM_DATA_ROOT}/*.nema"
     "${GDCM_DATA_ROOT}/*.ima"
     )
+  FILE(GLOB GDCM_DATA_SEQ_IMAGES_GLOB
+    "${GDCM_DATA_ROOT}/*FileSeq0.acr"
+    "${GDCM_DATA_ROOT}/*FileSeq0.dcm"
+    "${GDCM_DATA_ROOT}/*FileSeq0.nema"
+    "${GDCM_DATA_ROOT}/*FileSeq0.ima"
+    )
 ELSE(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)   
   # Since there is a bug in cmake 1.8.3, I'll have to do two separate globs
   FILE(GLOB GDCM_DATA_IMAGES_GLOB_ACR
@@ -107,7 +114,22 @@ ELSE(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)
   SET(GDCM_DATA_IMAGES_GLOB 
     ${GDCM_DATA_IMAGES_GLOB_DCM} ${GDCM_DATA_IMAGES_GLOB_ACR}
     ${GDCM_DATA_IMAGES_GLOB_NEMA} ${GDCM_DATA_IMAGES_GLOB_IMA})
-  #SET(GDCM_DATA_IMAGES_GLOB  ${GDCM_DATA_IMAGES_GLOB_ACR})
+
+  FILE(GLOB GDCM_DATA_SEQ_IMAGES_GLOB_ACR
+    "${GDCM_DATA_ROOT}/*FileSeq0.acr"
+    )
+  FILE(GLOB GDCM_DATA_SEQ_IMAGES_GLOB_DCM
+    "${GDCM_DATA_ROOT}/*FileSeq0.dcm"
+    )
+  FILE(GLOB GDCM_DATA_SEQ_IMAGES_GLOB_NEMA
+    "${GDCM_DATA_ROOT}/*FileSeq0.nema"
+    )
+  FILE(GLOB GDCM_DATA_SEQ_IMAGES_GLOB_IMA
+    "${GDCM_DATA_ROOT}/*FileSeq0.ima"
+    )
+  SET(GDCM_DATA_SEQ_IMAGES_GLOB 
+    ${GDCM_DATA_SEQ_IMAGES_GLOB_DCM} ${GDCM_DATA_SEQ_IMAGES_GLOB_ACR}
+    ${GDCM_DATA_SEQ_IMAGES_GLOB_NEMA} ${GDCM_DATA_SEQ_IMAGES_GLOB_IMA})
 ENDIF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)   
 
 # Black list of images known to break lots of readers (efilm, xmedcon ...):
@@ -138,7 +160,23 @@ FOREACH(filename ${GDCM_DATA_IMAGES_GLOB})
   ENDIF(NOT bad_dicom)
 ENDFOREACH(filename)
 
+SET(GDCM_DATA_SEQ_IMAGES)
+FOREACH(filename ${GDCM_DATA_SEQ_IMAGES_GLOB})
+  GET_FILENAME_COMPONENT(filename_temp ${filename} NAME)
+  STRING(REGEX MATCH ${filename_temp} bad_dicom ${BLACK_LIST})
+  IF(NOT bad_dicom)
+    STRING(REGEX REPLACE "(.*)FileSeq0(.*)" "\\1FileSeq%d\\2" filename_temp2 ${filename_temp})
+
+    SET(GDCM_DATA_SEQ_IMAGES "${GDCM_DATA_SEQ_IMAGES}\n\"${filename_temp2}\",")
+  ENDIF(NOT bad_dicom)
+ENDFOREACH(filename)
+
 # Populate GDCM_DATA_IMAGES:
 FILE(WRITE "${GDCM_BINARY_DIR}/gdcmDataImages.h"
   "const char * const gdcmDataImages[] = { ${GDCM_DATA_IMAGES}\n0 };\n" 
   )
+
+# Populate GDCM_DATA_SEQ_IMAGES:
+FILE(WRITE "${GDCM_BINARY_DIR}/gdcmDataSeqImages.h"
+  "const char * const gdcmDataSeqImages[] = { ${GDCM_DATA_SEQ_IMAGES}\n0 };\n" 
+  )
index 6a1d1521bfdf511e7353a8153db71739e61fad55..4f0eb9aa2c36a54213006aaba20bf20a0d7c338a 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestCopyRescaleDicom.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/12/07 18:16:40 $
-  Version:   $Revision: 1.2 $
+  Date:      $Date: 2004/12/08 11:37:15 $
+  Version:   $Revision: 1.3 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -91,7 +91,6 @@ int CopyRescaleDicom(std::string const & filename,
    gdcm::File *copy     = new gdcm::File( copyH );
 
    size_t dataSize = original->GetImageDataSize();
-   uint8_t* imageData = original->GetImageData();
 
    size_t rescaleSize;
    uint8_t *rescaleImage;
index 539d5fc8643b21c118d61a8183a5655fe64952a3..cd4827d4a588c779b3bf8ee665a38485c0c6de56 100644 (file)
@@ -58,7 +58,7 @@
 #include <vtkPointData.h>
 #include <vtkLookupTable.h>
 
-vtkCxxRevisionMacro(vtkGdcmReader, "$Revision: 1.62 $");
+vtkCxxRevisionMacro(vtkGdcmReader, "$Revision: 1.63 $");
 vtkStandardNewMacro(vtkGdcmReader);
 
 //-----------------------------------------------------------------------------
@@ -607,7 +607,7 @@ void vtkGdcmReader::AddInternalFileName(const char* name)
  */
 size_t vtkGdcmReader::LoadImageInMemory(
              std::string fileName, 
-             unsigned char * dest,
+             unsigned char *dest,
              const unsigned long updateProgressTarget,
              unsigned long & updateProgressCount)
 {
@@ -626,13 +626,14 @@ size_t vtkGdcmReader::LoadImageInMemory(
    int numLines   = file.GetHeader()->GetYSize();
    int numPlanes  = file.GetHeader()->GetZSize();
    int lineSize   = NumComponents * numColumns * file.GetHeader()->GetPixelSize();
+   int planeSize  = lineSize * numLines;
 
-   unsigned char * source;
+   unsigned char *src;
    
    if( file.GetHeader()->HasLUT() && AllowLookupTable )
    {
       size               = file.GetImageDataSize();
-      source             = (unsigned char*) file.GetImageDataRaw();
+      src                = (unsigned char*) file.GetImageDataRaw();
       unsigned char *lut = (unsigned char*) file.GetLutRGBA();
 
       if(!this->LookupTable)
@@ -656,20 +657,19 @@ size_t vtkGdcmReader::LoadImageInMemory(
    }
    else
    {
-      size        = file.GetImageDataSize();
-      source      = (unsigned char*)file.GetImageData();
+      size = file.GetImageDataSize();
+      src  = (unsigned char*)file.GetImageData();
    } 
-   
-   unsigned char * destination = dest + size - lineSize;
 
+   unsigned char *dst = dest + planeSize - lineSize;
    for (int plane = 0; plane < numPlanes; plane++)
    {
       for (int line = 0; line < numLines; line++)
       {
          // Copy one line at proper destination:
-         memcpy((void*)destination, (void*)source, lineSize);
-         source      += lineSize;
-         destination -= lineSize;
+         memcpy((void*)dst, (void*)src, lineSize);
+         src += lineSize;
+         dst -= lineSize;
          // Update progress related:
          if (!(updateProgressCount%updateProgressTarget))
          {
@@ -677,17 +677,9 @@ size_t vtkGdcmReader::LoadImageInMemory(
          }
          updateProgressCount++;
       }
+      dst += 2 * planeSize;
    }
    
-// DO NOT remove this commented out code .
-// Nobody knows what's expecting you ...
-// Just to 'see' what was actually read on disk :-(
-
-//   FILE * f2;
-//   f2 = fopen("SpuriousFile.RAW","wb");
-//   fwrite(Dest,size,1,f2);
-//   fclose(f2); 
-   
    return size;
 }
 
index 6640ea5b774d1a309cc711d3b3ff5d32b87e2540..a7ca870e9768dc3693d979304b8f566ece420618 100644 (file)
@@ -58,7 +58,7 @@
 #include <vtkPointData.h>
 #include <vtkLookupTable.h>
 
-vtkCxxRevisionMacro(vtkGdcmWriter, "$Revision: 1.2 $");
+vtkCxxRevisionMacro(vtkGdcmWriter, "$Revision: 1.3 $");
 vtkStandardNewMacro(vtkGdcmWriter);
 
 //-----------------------------------------------------------------------------
@@ -84,6 +84,41 @@ void vtkGdcmWriter::PrintSelf(ostream& os, vtkIndent indent)
 
 //-----------------------------------------------------------------------------
 // Protected
+/**
+ * Copy the image and reverse the Y axis
+ */
+// The output datas must be deleted by the user of the method !!!
+size_t ReverseData(vtkImageData *img,unsigned char **data)
+{
+   int *dim = img->GetDimensions();
+   size_t lineSize = dim[0] * img->GetScalarSize()
+                   * img->GetNumberOfScalarComponents();
+   size_t planeSize = dim[1] * lineSize;
+   size_t size = dim[2] * planeSize;
+
+   *data = new unsigned char[size];
+
+   unsigned char *src = (unsigned char *)img->GetScalarPointer();
+   unsigned char *dst = *data + planeSize - lineSize;
+   for (int plane = 0; plane < dim[2]; plane++)
+   {
+      for (int line = 0; line < dim[1]; line++)
+      {
+         // Copy one line at proper destination:
+         memcpy((void*)dst, (void*)src, lineSize);
+
+         src += lineSize;
+         dst -= lineSize;
+      }
+      dst += 2 * planeSize;
+   }
+
+   return size;
+}
+
+/**
+ * Set the datas informations in the file
+ */
 void SetImageInformation(gdcm::File *file,vtkImageData *image)
 {
    std::ostringstream str;
@@ -166,13 +201,16 @@ void SetImageInformation(gdcm::File *file,vtkImageData *image)
    file->ReplaceOrCreateByNumber(str.str(),0x0028,0x1050);
 
    // Pixels
-   size_t size = dim[0] * dim[1] * dim[2] 
-               * image->GetScalarSize()
-               * image->GetNumberOfScalarComponents();
-   file->SetImageData((unsigned char *)image->GetScalarPointer(),size);
+   unsigned char *data;
+   size_t size = ReverseData(image,&data);
+   file->SetImageData(data,size);
 }
 
-void vtkGdcmWriter::RecursiveWrite(int dim, vtkImageData *region, ofstream *file)
+/**
+ * Write of the files
+ * The call to this method is recursive if there is some files to write
+ */ 
+void vtkGdcmWriter::RecursiveWrite(int axis, vtkImageData *image, ofstream *file)
 {
    if(file)
    {
@@ -180,24 +218,28 @@ void vtkGdcmWriter::RecursiveWrite(int dim, vtkImageData *region, ofstream *file
       return;
    }
 
-   if( region->GetScalarType() == VTK_FLOAT 
-     || region->GetScalarType() == VTK_DOUBLE )
+   if( image->GetScalarType() == VTK_FLOAT || 
+       image->GetScalarType() == VTK_DOUBLE )
    {
       vtkErrorMacro(<< "Bad input type. Scalar type musn't be of type "
                     << "VTK_FLOAT or VTKDOUBLE (found:"
-                    << region->GetScalarTypeAsString());
+                    << image->GetScalarTypeAsString());
       return;
    }
 
+   WriteFile(this->FileName,image);
+}
+
+void vtkGdcmWriter::WriteFile(char *fileName,vtkImageData *image)
+{
+   // From here, the write of the file begins
    gdcm::File *dcmFile = new gdcm::File();
 
-   ///////////////////////////////////////////////////////////////////////////
    // Set the image informations
-   SetImageInformation(dcmFile,region);
+   SetImageInformation(dcmFile,image);
 
-   ///////////////////////////////////////////////////////////////////////////
    // Write the image
-   if(!dcmFile->Write(this->FileName))
+   if(!dcmFile->Write(FileName))
    {
       vtkErrorMacro(<< "File " << this->FileName << "couldn't be written by "
                     << " the gdcm library");
index 592daec1cef3ac359b4676bf063f30e4e24ac7f0..ff255b2b079fdfa36ff0b3004a3392f6e8b6184e 100644 (file)
@@ -26,7 +26,8 @@ protected:
    vtkGdcmWriter();
    ~vtkGdcmWriter();
 
-  virtual void RecursiveWrite(int dim, vtkImageData *region, ofstream *file);
+  virtual void RecursiveWrite(int axis, vtkImageData *image, ofstream *file);
+  void WriteFile(char *fileName,vtkImageData *image);
 
 private:
 // Variables