X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=vtk%2FvtkGdcmReader.cxx;h=b8464b40b1d1271f6ea84da2622e7ef03dfdb732;hb=19e58adb834f41014689f3673e98f3b26c15c118;hp=8497a5f7c84be3ea25ebf2d16ef6ddde3eeefc95;hpb=5740f3482ac603ba6234e79a45701c2e864ee242;p=gdcm.git diff --git a/vtk/vtkGdcmReader.cxx b/vtk/vtkGdcmReader.cxx index 8497a5f7..b8464b40 100644 --- a/vtk/vtkGdcmReader.cxx +++ b/vtk/vtkGdcmReader.cxx @@ -1,4 +1,4 @@ -// $Header: /cvs/public/gdcm/vtk/vtkGdcmReader.cxx,v 1.18 2003/08/29 09:47:13 malaterre Exp $ +// $Header: /cvs/public/gdcm/vtk/vtkGdcmReader.cxx,v 1.21 2003/10/24 15:38:56 malaterre Exp $ // ////////////////////////////////////////////////////////////// // WARNING TODO CLENAME // Actual limitations of this code: @@ -48,6 +48,7 @@ #include #include "vtkGdcmReader.h" #include "gdcm.h" +#include "gdcmHeaderHelper.h" vtkGdcmReader::vtkGdcmReader() { @@ -140,12 +141,23 @@ void vtkGdcmReader::BuildFileListFromPattern() } this->RemoveAllInternalFileName(); - for (int idx = this->DataExtent[4]; idx <= this->DataExtent[5]; ++idx) + if( this->FileNameList.empty() ) { - this->ComputeInternalFileName(idx); + //Multiframe case: + this->ComputeInternalFileName(this->DataExtent[4]); vtkDebugMacro("Adding file " << this->InternalFileName); this->AddInternalFileName(this->InternalFileName); } + else + { + //stack of 2D dicom case: + for (int idx = this->DataExtent[4]; idx <= this->DataExtent[5]; ++idx) + { + this->ComputeInternalFileName(idx); + vtkDebugMacro("Adding file " << this->InternalFileName); + this->AddInternalFileName(this->InternalFileName); + } + } } //---------------------------------------------------------------------------- @@ -210,7 +222,7 @@ int vtkGdcmReader::CheckFileCoherence() fclose(fp); // Stage 1.2: check for Gdcm parsability - gdcmHeader GdcmHeader(FileName->c_str()); + gdcmHeaderHelper GdcmHeader(FileName->c_str()); if (!GdcmHeader.IsReadable()) { vtkErrorMacro("Gdcm cannot parse file " << FileName->c_str()); @@ -295,6 +307,18 @@ int vtkGdcmReader::CheckFileCoherence() ReturnedTotalNumberOfPlanes += NZ - 1; // First plane already added this->ImageType = type; this->PixelSize = GdcmHeader.GetPixelSize(); + this->NumComponents = GdcmHeader.GetNumberOfScalarComponents(); //rgb or mono + + //Set image spacing + this->DataSpacing[0] = GdcmHeader.GetXSpacing(); + this->DataSpacing[1] = GdcmHeader.GetYSpacing(); + this->DataSpacing[2] = GdcmHeader.GetZSpacing(); + + //Set image origin + this->DataOrigin[0] = GdcmHeader.GetXOrigin(); + this->DataOrigin[1] = GdcmHeader.GetYOrigin(); + this->DataOrigin[2] = GdcmHeader.GetZOrigin(); + } } // End of loop on FileName @@ -368,11 +392,8 @@ void vtkGdcmReader::ExecuteInformation() this->DataExtent[1] = this->NumColumns - 1; this->DataExtent[2] = 0; this->DataExtent[3] = this->NumLines - 1; - if(this->InternalFileNameList.size() > 1) - { - this->DataExtent[4] = 0; - this->DataExtent[5] = this->TotalNumberOfPlanes - 1; - } + this->DataExtent[4] = 0; + this->DataExtent[5] = this->TotalNumberOfPlanes - 1; // We don't need to positionate the Endian related stuff (by using // this->SetDataByteOrderToBigEndian() or SetDataByteOrderToLittleEndian() @@ -411,6 +432,9 @@ void vtkGdcmReader::ExecuteInformation() this->SetDataScalarTypeToInt(); } + //Set number of scalar components: + this->SetNumberOfScalarComponents(this->NumComponents); + vtkImageReader::ExecuteInformation(); } @@ -423,7 +447,7 @@ size_t vtkGdcmReader::LoadImageInMemory( const unsigned long UpdateProgressTarget, unsigned long & UpdateProgressCount) { - vtkDebugMacro("Copying to memmory image" << FileName.c_str()); + vtkDebugMacro("Copying to memory image" << FileName.c_str()); gdcmFile GdcmFile(FileName.c_str()); size_t size = GdcmFile.GetImageDataSize(); @@ -436,7 +460,7 @@ size_t vtkGdcmReader::LoadImageInMemory( int NumColumns = GdcmFile.GetXSize(); int NumLines = GdcmFile.GetYSize(); int NumPlanes = GdcmFile.GetZSize(); - int LineSize = NumColumns * GdcmFile.GetPixelSize(); + int LineSize = NumComponents * NumColumns * GdcmFile.GetPixelSize(); unsigned char * Source = (unsigned char*)GdcmFile.GetImageData(); unsigned char * pSource = Source; //pointer for later deletion unsigned char * Destination = Dest + size - LineSize; @@ -491,7 +515,7 @@ void vtkGdcmReader::ExecuteData(vtkDataObject *output) // The memory size for a full stack of images of course depends // on the number of planes and the size of each image: size_t StackNumPixels = this->NumColumns * this->NumLines - * this->TotalNumberOfPlanes; + * this->TotalNumberOfPlanes * this->NumComponents; size_t stack_size = StackNumPixels * this->PixelSize; // Allocate pixel data space itself. unsigned char *mem = new unsigned char [stack_size]; @@ -540,7 +564,8 @@ void vtkGdcmReader::ExecuteData(vtkDataObject *output) // The "size" of the vtkScalars data is expressed in number of points, // and is not the memory size representing those points: data->GetPointData()->GetScalars()->SetVoidArray(mem, StackNumPixels, 0); - this->Modified(); + //don't know why it's here, it's calling one more time ExecuteInformation: + //this->Modified(); } }