+
+/*
+ * Adds a file name to the internal list of images to read.
+ */
+void vtkGdcmReader::AddInternalFileName(const char *name)
+{
+ char *LocalName = new char[strlen(name) + 1];
+ strcpy(LocalName, name);
+ this->InternalFileNameList.push_back(LocalName);
+ delete[] LocalName;
+}
+
+/*
+ * Remove all file names to the internal list of images to read.
+ */
+void vtkGdcmReader::RemoveAllInternalFile(void)
+{
+ if(this->OwnFile)
+ {
+ for(gdcmFileList::iterator it=InternalFileList.begin();
+ it!=InternalFileList.end();
+ ++it)
+ {
+ (*it)->Delete();
+ }
+ }
+ this->InternalFileList.clear();
+}
+
+void vtkGdcmReader::IncrementProgress(const unsigned long updateProgressTarget,
+ unsigned long &updateProgressCount)
+{
+ // Update progress related for bad files:
+ updateProgressCount += this->NumLines;
+ if (updateProgressTarget > 0)
+ {
+ if (!(updateProgressCount%updateProgressTarget))
+ {
+ this->UpdateProgress(updateProgressCount/(50.0*updateProgressTarget));
+ }
+ }
+}
+
+/*
+ * Loads the contents of the image/volume contained by char *fileName at
+ * the dest memory address. Returns the size of the data loaded.
+ */
+/*void vtkGdcmReader::LoadImageInMemory(
+ std::string fileName,
+ unsigned char *dest,
+ const unsigned long updateProgressTarget,
+ unsigned long &updateProgressCount)
+{
+ vtkDebugMacro(<< "Copying to memory image [" << fileName.c_str() << "]");
+
+ gdcm::File *f;
+ f = new gdcm::File();
+ f->SetLoadMode( LoadMode );
+ f->SetFileName( fileName.c_str() );
+ f->Load( );
+
+ LoadImageInMemory(f,dest,
+ updateProgressTarget,
+ updateProgressCount);
+ delete f;
+}*/
+
+/*
+ * Loads the contents of the image/volume contained by gdcm::File* f at
+ * the Dest memory address. Returns the size of the data loaded.
+ * \ param f File to consider. NULL if the file must be skiped
+ * \remarks Assume that if (f != NULL) then its caracteristics match
+ * with the previous ones
+ */
+void vtkGdcmReader::LoadImageInMemory(
+ gdcm::File *f,
+ unsigned char *dest,
+ const unsigned long updateProgressTarget,
+ unsigned long &updateProgressCount)
+{
+ if(!f)
+ return;
+
+ gdcm::FileHelper *fileH = gdcm::FileHelper::New( f );
+ fileH->SetUserFunction( UserFunction );
+
+ int numColumns = f->GetXSize();
+ int numLines = f->GetYSize();
+ int numPlanes = f->GetZSize();
+ int numComponents;
+
+ if( f->HasLUT() && this->AllowLookupTable )
+ numComponents = f->GetNumberOfScalarComponentsRaw();
+ else
+ numComponents = f->GetNumberOfScalarComponents(); //rgb or mono
+ vtkDebugMacro(<< "numComponents:" << numComponents);
+ vtkDebugMacro(<< "Copying to memory image [" << f->GetFileName().c_str() << "]");
+ //size_t size;
+
+ // If the data structure of vtk for image/volume representation
+ // were straigthforwards the following would be enough:
+ // GdcmFile.GetImageDataIntoVector((void*)Dest, size);
+ // But vtk chooses 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 = NumComponents * numColumns * f->GetPixelSize();
+ int planeSize = lineSize * numLines;
+
+ unsigned char *src;
+
+ if( fileH->GetFile()->HasLUT() && AllowLookupTable )
+ {
+ // to avoid bcc 5.5 w
+ /*size = */ fileH->GetImageDataSize();
+ src = (unsigned char*) fileH->GetImageDataRaw();
+ unsigned char *lut = (unsigned char*) fileH->GetLutRGBA();
+
+ if(!this->LookupTable)
+ {
+ this->LookupTable = vtkLookupTable::New();
+ }
+
+ this->LookupTable->SetNumberOfTableValues(256);
+ for (int tmp=0; tmp<256; tmp++)
+ {
+ this->LookupTable->SetTableValue(tmp,
+ (float)lut[4*tmp+0]/255.0,
+ (float)lut[4*tmp+1]/255.0,
+ (float)lut[4*tmp+2]/255.0,
+ 1);
+ }
+ this->LookupTable->SetRange(0,255);
+ vtkDataSetAttributes *a = this->GetOutput()->GetPointData();
+ a->GetScalars()->SetLookupTable(this->LookupTable);
+ free(lut);
+ }
+ else
+ {
+ //size = fileH->GetImageDataSize();
+ // useless - just an accessor; 'size' unused
+ src = (unsigned char*)fileH->GetImageData();
+ }
+
+ unsigned char *dst = dest + planeSize - lineSize;
+ for (int plane = 0; plane < numPlanes; plane++)
+ {
+ for (int line = 0; line < numLines; line++)
+ {
+ // Copy one line at proper destination:
+ memcpy((void*)dst, (void*)src, lineSize);
+ src += lineSize;
+ dst -= lineSize;
+ // Update progress related:
+ if (!(updateProgressCount%updateProgressTarget))
+ {
+ this->UpdateProgress(updateProgressCount/(50.0*updateProgressTarget));
+ }
+ updateProgressCount++;
+ }
+ dst += 2 * planeSize;
+ }
+
+ fileH->Delete();
+}
+
+//-----------------------------------------------------------------------------