X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=vtk%2FvtkGdcmReader.cxx;h=03368d4146286cf15996b5e31c0103a9d1228d7a;hb=00bc08e9b8fd5aadac41221a071783ef3d485f94;hp=eaba22fe655e3b7cbf7a4ce250da8e55aa3e8488;hpb=90a2b8eeadb9d5afb2bc165b080f8a4622f5deb4;p=gdcm.git diff --git a/vtk/vtkGdcmReader.cxx b/vtk/vtkGdcmReader.cxx index eaba22fe..03368d41 100644 --- a/vtk/vtkGdcmReader.cxx +++ b/vtk/vtkGdcmReader.cxx @@ -1,4 +1,4 @@ -// $Header: /cvs/public/gdcm/vtk/vtkGdcmReader.cxx,v 1.1 2003/05/05 14:13:59 frog Exp $ +// $Header: /cvs/public/gdcm/vtk/vtkGdcmReader.cxx,v 1.3 2003/05/21 08:21:17 frog Exp $ #include "vtkGdcmReader.h" #include "vtkByteSwap.h" #include @@ -159,27 +159,41 @@ void vtkGdcmReader::ExecuteData(vtkDataObject *output) data->SetExtent(this->DataExtent); data->GetPointData()->GetScalars()->SetName("ImageFile"); - int size = - (this->DataExtent[1] - this->DataExtent[0]+1) * - (this->DataExtent[3] - this->DataExtent[2]+1) * - (this->DataExtent[5] - this->DataExtent[4]+1) * - 2; + // First check the coherence between the DataExtent and the + // size of the pixel data as annouced by gdcm (looks a bit paranoid). gdcmFile GdcmFile(this->InternalFileName); - size = GdcmFile.GetImageDataSize(); - unsigned char *mem = new unsigned char [size]; + int NumColumns = this->DataExtent[1] - this->DataExtent[0] + 1; + int NumLines = this->DataExtent[3] - this->DataExtent[2] + 1; + int NumPlanes = this->DataExtent[5] - this->DataExtent[4] + 1; + int size = NumColumns * NumLines * NumPlanes * GdcmFile.GetPixelSize(); if ( size != GdcmFile.GetImageDataSize() ) { vtkDebugMacro("Inconsistency with GetImageDataSize"); vtkDebugMacro("Number of scalar components" << this->NumberOfScalarComponents); } - GdcmFile.GetImageDataIntoVector((void*)mem, size); + // Allocate pixel data space itself. + unsigned char *mem = new unsigned char [size]; + + // If the data structure of vtk for image/volume representation + // were straigthforwards the following would suffice: + // GdcmFile.GetImageDataIntoVector((void*)mem, size); + // But vtk chose to invert the lines of an image, that is the last + // line comes first (for some axis related reasons?). Hence we need + // to load the image line by line, starting from the end: + int LineSize = NumColumns * GdcmFile.GetPixelSize(); + unsigned char * Source = (unsigned char*)GdcmFile.GetImageData(); + unsigned char * Destination = mem + size - LineSize; + for (int i = 0; i < NumLines; i++) + { + memcpy((void*)Destination, (void*)Source, LineSize); + Source += LineSize; + Destination -= LineSize; + } + // The "size" of the vtkScalars data is expressed in number of points, + // and is not the memory size representing those points: + size = size / GdcmFile.GetPixelSize(); data->GetPointData()->GetScalars()->SetVoidArray(mem, size, 0); - //vtkImageFlip * Flip = vtkImageFlip::New(); - //Flip->SetInput(data); - //Flip->Update(); - //data = Flip->GetOutput(); - //Flip->SetInput(NULL); this->Modified(); }