--- IO/vtkImageReader2.h.orig 2013-05-13 14:12:40.000000000 +0200 +++ IO/vtkImageReader2.h 2013-05-13 14:58:17.000000000 +0200 @@ -171,6 +171,15 @@ vtkSetMacro(FileNameSliceSpacing,int); vtkGetMacro(FileNameSliceSpacing,int); + // Description: + // Set/Get whether the whole file should be completely read into + // memory. This causes reads over network shares (especially CIFS) + // to be much faster, but also has the side effect of temporarily + // doubling the memory used for each file. + vtkSetMacro(BufferWholeFile,bool); + vtkGetMacro(BufferWholeFile,bool); + vtkBooleanMacro(BufferWholeFile,bool); + // Description: // Set/Get the byte swapping to explicitly swap the bytes of a file. @@ -240,6 +249,9 @@ int FileLowerLeft; ifstream *File; + bool BufferWholeFile; + char *buffer; // Used if BufferWholeFile is true + unsigned long DataIncrements[4]; int DataExtent[6]; int SwapBytes; --- IO/vtkImageReader2.cxx.orig 2013-05-13 14:12:39.000000000 +0200 +++ IO/vtkImageReader2.cxx 2013-05-13 14:56:01.000000000 +0200 @@ -69,6 +69,8 @@ this->FileNameSliceOffset = 0; this->FileNameSliceSpacing = 1; + this->BufferWholeFile = 0; + // Left over from short reader this->SwapBytes = 0; this->FileLowerLeft = 0; @@ -84,6 +86,8 @@ this->File->close(); delete this->File; this->File = NULL; + delete[] this->buffer; + this->buffer = NULL; } if (this->FileNames) @@ -441,6 +445,8 @@ os << indent << "FileNameSliceSpacing: " << this->FileNameSliceSpacing << "\n"; + os << indent << "BufferWholeFile: " << (this->BufferWholeFile ? "On\n" : "Off\n"); + os << indent << "DataScalarType: " << vtkImageScalarTypeNameMacro(this->DataScalarType) << "\n"; os << indent << "NumberOfScalarComponents: " @@ -606,6 +612,8 @@ this->File->close(); delete this->File; this->File = NULL; + delete[] this->buffer; + this->buffer = NULL; } // Open the new file @@ -618,6 +626,21 @@ #else this->File = new ifstream(this->InternalFileName, ios::in); #endif + + if ( this->BufferWholeFile ) + { + // Allocate a buffer to hold the whole file's contents + long size; + size = this->File->rdbuf()->pubseekoff(0, ios::end,ios::in); + this->File->rdbuf()->pubseekpos(0, ios::in); + + buffer = new char[size]; + this->File->rdbuf()->pubsetbuf(buffer, size); + + // Read all the file (doesn't matter where the file is read) + this->File->read(buffer, size); + this->File->rdbuf()->pubseekpos(0, ios::in); + } } if (! this->File || this->File->fail()) {