From: regrain Date: Wed, 8 Dec 2004 11:37:15 +0000 (+0000) Subject: * vtk/vtkGdcmReader.[h|cxx] : bug fix. Plane order isn't inverted X-Git-Tag: Version1.0.bp~520 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=51e53b78f995e2dde4f75570a8bf3b0dac5209c2;p=gdcm.git * 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 -- BeNours --- diff --git a/ChangeLog b/ChangeLog index 7e630ff6..e454251f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2004-12-08 Benoit Regrain + * 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 * Test/ShowDicom.cxx, TestWriteWithVTK.cxx : bug fix, now this test pass not at all time diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt index 268f52fe..1dedc01f 100644 --- a/Testing/CMakeLists.txt +++ b/Testing/CMakeLists.txt @@ -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" + ) diff --git a/Testing/TestCopyRescaleDicom.cxx b/Testing/TestCopyRescaleDicom.cxx index 6a1d1521..4f0eb9aa 100644 --- a/Testing/TestCopyRescaleDicom.cxx +++ b/Testing/TestCopyRescaleDicom.cxx @@ -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; diff --git a/vtk/vtkGdcmReader.cxx b/vtk/vtkGdcmReader.cxx index 539d5fc8..cd4827d4 100644 --- a/vtk/vtkGdcmReader.cxx +++ b/vtk/vtkGdcmReader.cxx @@ -58,7 +58,7 @@ #include #include -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; } diff --git a/vtk/vtkGdcmWriter.cxx b/vtk/vtkGdcmWriter.cxx index 6640ea5b..a7ca870e 100644 --- a/vtk/vtkGdcmWriter.cxx +++ b/vtk/vtkGdcmWriter.cxx @@ -58,7 +58,7 @@ #include #include -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"); diff --git a/vtk/vtkGdcmWriter.h b/vtk/vtkGdcmWriter.h index 592daec1..ff255b2b 100644 --- a/vtk/vtkGdcmWriter.h +++ b/vtk/vtkGdcmWriter.h @@ -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