+ // 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();