+//-----------------------------------------------------------------------------
+// Protected
+/*
+ * Configure the output e.g. WholeExtent, spacing, origin, scalar type...
+ */
+void vtkGdcmReader::ExecuteInformation()
+{
+// if(this->Execution) // For VTK5.0
+// return;
+//
+// this->Execution=true; // end For VTK5.0
+ this->RemoveAllInternalFile();
+ if(this->MTime>this->fileTime)
+ {
+ this->TotalNumberOfPlanes = 0;
+
+ if ( this->CoherentFileList != 0 )
+ {
+ this->UpdateFileInformation();
+ }
+ else
+ {
+ this->BuildFileListFromPattern();
+ this->LoadFileInformation();
+ }
+
+ if ( this->TotalNumberOfPlanes == 0)
+ {
+ vtkErrorMacro(<< "File set is not coherent. Exiting...");
+ return;
+ }
+
+ // if the user has not set the extent, but has set the VOI
+ // set the z axis extent to the VOI z axis
+ if (this->DataExtent[4]==0 && this->DataExtent[5] == 0 &&
+ (this->DataVOI[4] || this->DataVOI[5]))
+ {
+ this->DataExtent[4] = this->DataVOI[4];
+ this->DataExtent[5] = this->DataVOI[5];
+ }
+
+ // When the user has set the VOI, check it's coherence with the file content.
+ if (this->DataVOI[0] || this->DataVOI[1] ||
+ this->DataVOI[2] || this->DataVOI[3] ||
+ this->DataVOI[4] || this->DataVOI[5])
+ {
+ if ((this->DataVOI[0] < 0) ||
+ (this->DataVOI[1] >= this->NumColumns) ||
+ (this->DataVOI[2] < 0) ||
+ (this->DataVOI[3] >= this->NumLines) ||
+ (this->DataVOI[4] < 0) ||
+ (this->DataVOI[5] >= this->TotalNumberOfPlanes ))
+ {
+ vtkWarningMacro(<< "The requested VOI is larger than expected extent.");
+ this->DataVOI[0] = 0;
+ this->DataVOI[1] = this->NumColumns - 1;
+ this->DataVOI[2] = 0;
+ this->DataVOI[3] = this->NumLines - 1;
+ this->DataVOI[4] = 0;
+ this->DataVOI[5] = this->TotalNumberOfPlanes - 1;
+ }
+ }
+
+ // Set the Extents.
+ this->DataExtent[0] = 0;
+ this->DataExtent[1] = this->NumColumns - 1;
+ this->DataExtent[2] = 0;
+ this->DataExtent[3] = this->NumLines - 1;
+ this->DataExtent[4] = 0;
+ this->DataExtent[5] = this->TotalNumberOfPlanes - 1;
+
+ // We don't need to set the Endian related stuff (by using
+ // this->SetDataByteOrderToBigEndian() or SetDataByteOrderToLittleEndian()
+ // since the reading of the file is done by gdcm.
+ // But we do need to set up the data type for downstream filters:
+ if ( ImageType == "8U" )
+ {
+ vtkDebugMacro(<< "8 bits unsigned image");
+ this->SetDataScalarTypeToUnsignedChar();
+ }
+ else if ( ImageType == "8S" )
+ {
+ vtkErrorMacro(<< "Cannot handle 8 bit signed files");
+ return;
+ }
+ else if ( ImageType == "16U" )
+ {
+ vtkDebugMacro(<< "16 bits unsigned image");
+ this->SetDataScalarTypeToUnsignedShort();
+ }
+ else if ( ImageType == "16S" )
+ {
+ vtkDebugMacro(<< "16 bits signed image");
+ this->SetDataScalarTypeToShort();
+ }
+ else if ( ImageType == "32U" )
+ {
+ vtkDebugMacro(<< "32 bits unsigned image");
+ vtkDebugMacro(<< "WARNING: forced to signed int !");
+ this->SetDataScalarTypeToInt();
+ }
+ else if ( ImageType == "32S" )
+ {
+ vtkDebugMacro(<< "32 bits signed image");
+ this->SetDataScalarTypeToInt();
+ }
+ else if ( ImageType == "FD" ) // This is not genuine DICOM, but so usefull
+ {
+ vtkDebugMacro(<< "64 bits Double image");
+ this->SetDataScalarTypeToDouble();
+ }
+ //Set number of scalar components:
+ this->SetNumberOfScalarComponents(this->NumComponents);
+
+ this->fileTime=this->MTime;
+ }
+
+ this->Superclass::ExecuteInformation();
+
+ //this->GetOutput()->SetUpdateExtentToWholeExtent();// For VTK5.0
+ //this->BuildData(this->GetOutput());
+
+ //this->Execution=false;
+ //this->RemoveAllInternalFile(); // End For VTK5.0
+}
+
+/*
+ * Update => ouput->Update => UpdateData => Execute => ExecuteData
+ * (see vtkSource.cxx for last step).
+ * This function (redefinition of vtkImageReader::ExecuteData, see
+ * VTK/IO/vtkImageReader.cxx) reads a data from a file. The data
+ * extent/axes are assumed to be the same as the file extent/order.
+ */
+void vtkGdcmReader::ExecuteData(vtkDataObject *output)
+{
+ vtkImageData *data=vtkImageData::SafeDownCast(output);
+ data->SetExtent(this->DataExtent);
+
+/* if ( CoherentFileList != 0 ) // When a list of names is passed
+ {
+ if (this->CoherentFileList->empty())
+ {
+ vtkErrorMacro(<< "Coherent File List must have at least a valid File*.");
+ return;
+ }
+ }
+ else if (this->InternalFileNameList.empty())
+ {
+ vtkErrorMacro(<< "A least a valid FileName must be specified.");
+ return;
+ }
+*/
+
+ // data->AllocateScalars(); // For VTK5.0
+ // if (this->UpdateExtentIsEmpty(output))
+ // {
+ // return;
+ // }
+//} // end For VTK5.0
+
+ data->AllocateScalars(); // For VTK5.0
+
+#if (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2 )
+//#if (VTK_MAJOR_VERSION >= 5)
+ if (this->UpdateExtentIsEmpty(output))
+ {
+ return;
+ }
+#endif
+
+ data->GetPointData()->GetScalars()->SetName("DicomImage-Volume");
+
+ // Test if output has valid extent
+ // Prevent memory errors
+ if((this->DataExtent[1]-this->DataExtent[0]>=0) &&
+ (this->DataExtent[3]-this->DataExtent[2]>=0) &&
+ (this->DataExtent[5]-this->DataExtent[4]>=0))
+ {
+ // The memory size for a full stack of images of course depends
+ // on the number of planes and the size of each image:
+ //size_t StackNumPixels = this->NumColumns * this->NumLines
+ // * this->TotalNumberOfPlanes * this->NumComponents;
+ //size_t stack_size = StackNumPixels * this->PixelSize; //not used
+ // Allocate pixel data space itself.
+
+ // Variables for the UpdateProgress. We shall use 50 steps to signify
+ // the advance of the process:
+ unsigned long UpdateProgressTarget = (unsigned long) ceil (this->NumLines
+ * this->TotalNumberOfPlanes
+ / 50.0);
+ // The actual advance measure:
+ unsigned long UpdateProgressCount = 0;
+
+ // Filling the allocated memory space with each image/volume:
+
+ size_t size = this->NumColumns * this->NumLines * this->NumPlanes
+ * data->GetScalarSize() * this->NumComponents;
+ unsigned char *Dest = (unsigned char *)data->GetScalarPointer();
+ for (std::vector<GDCM_NAME_SPACE::File* >::iterator it = InternalFileList.begin();
+ it != InternalFileList.end();
+ ++it)
+ {
+ this->LoadImageInMemory(*it, Dest,
+ UpdateProgressTarget,
+ UpdateProgressCount);
+ Dest += size;
+ }
+ }
+ this->RemoveAllInternalFile(); // For VTK5.0
+}
+
+/*
+ * vtkGdcmReader can have the file names specified through two ways:
+ * (1) by calling the vtkImageReader2::SetFileName(), SetFilePrefix() and
+ * SetFilePattern()
+ * (2) By successive calls to vtkGdcmReader::AddFileName()
+ * When the first method was used by caller we need to update the local
+ * filename list
+ */