+//----------------------------------------------------------------------------
+// Loads the contents of the image/volume contained by Filename at
+// the Dest memory address. Returns the size of the data loaded.
+size_t vtkGdcmReader::LoadImageInMemory(
+ std::string FileName,
+ unsigned char * Dest,
+ const unsigned long UpdateProgressTarget,
+ unsigned long & UpdateProgressCount)
+{
+ vtkDebugMacro("Copying to memmory image" << FileName.c_str());
+ gdcmFile GdcmFile(FileName.c_str());
+ size_t size = GdcmFile.GetImageDataSize();
+
+ // If the data structure of vtk for image/volume representation
+ // were straigthforwards the following would suffice:
+ // GdcmFile.GetImageDataIntoVector((void*)Dest, 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 NumColumns = GdcmFile.GetXSize();
+ int NumLines = GdcmFile.GetYSize();
+ int NumPlanes = GdcmFile.GetZSize();
+ int LineSize = NumColumns * GdcmFile.GetPixelSize();
+ unsigned char * Source = (unsigned char*)GdcmFile.GetImageData();
+ unsigned char * Destination = Dest + size - 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;
+ // Update progress related:
+ if (!(UpdateProgressCount%UpdateProgressTarget))
+ {
+ this->UpdateProgress(UpdateProgressCount/(50.0*UpdateProgressTarget));
+ }
+ UpdateProgressCount++;
+ }
+ }
+ return size;
+}
+