* 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
+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
)
SET(TEST_SOURCES ${TEST_SOURCES}
ShowDicom.cxx
+ ShowDicomSeq.cxx
TestWriteWithVTK.cxx
)
ENDIF(GDCM_VTK)
"${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
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 ...):
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"
+ )
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
gdcm::File *copy = new gdcm::File( copyH );
size_t dataSize = original->GetImageDataSize();
- uint8_t* imageData = original->GetImageData();
size_t rescaleSize;
uint8_t *rescaleImage;
#include <vtkPointData.h>
#include <vtkLookupTable.h>
-vtkCxxRevisionMacro(vtkGdcmReader, "$Revision: 1.62 $");
+vtkCxxRevisionMacro(vtkGdcmReader, "$Revision: 1.63 $");
vtkStandardNewMacro(vtkGdcmReader);
//-----------------------------------------------------------------------------
*/
size_t vtkGdcmReader::LoadImageInMemory(
std::string fileName,
- unsigned char * dest,
+ unsigned char *dest,
const unsigned long updateProgressTarget,
unsigned long & updateProgressCount)
{
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)
}
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))
{
}
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;
}
#include <vtkPointData.h>
#include <vtkLookupTable.h>
-vtkCxxRevisionMacro(vtkGdcmWriter, "$Revision: 1.2 $");
+vtkCxxRevisionMacro(vtkGdcmWriter, "$Revision: 1.3 $");
vtkStandardNewMacro(vtkGdcmWriter);
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// 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;
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)
{
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");
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