- }
-
- // Positionate the Extent.
- 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 positionate 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();
- //vtkErrorMacro("Cannot handle 16 bit signed files");
- }
- 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();
- }
-
- //Set number of scalar components:
- this->SetNumberOfScalarComponents(this->NumComponents);
-
- vtkImageReader::ExecuteInformation();
+ }
+}
+
+/**
+ * Get the informations from a file.
+ * These informations are required to specify the output image
+ * caracteristics
+ */
+void vtkGdcmReader::GetFileInformation(GDCM_NAME_SPACE::File *file)
+{
+ // Get the image caracteristics
+ this->NumColumns = file->GetXSize();
+ this->NumLines = file->GetYSize();
+ this->NumPlanes = file->GetZSize();
+
+ if (CoherentFileList == 0)
+ this->TotalNumberOfPlanes = this->NumPlanes*InternalFileNameList.size();
+ else
+ this->TotalNumberOfPlanes = this->NumPlanes*CoherentFileList->size();
+
+ this->ImageType = file->GetPixelType();
+ this->PixelSize = file->GetPixelSize();
+
+ this->DataSpacing[0] = file->GetXSpacing();
+ this->DataSpacing[1] = file->GetYSpacing();
+
+ // Most of the file headers have NO z spacing
+ // It must be calculated from the whole GDCM_NAME_SPACE::Serie (if any)
+ // using Jolinda Smith's algoritm.
+ // see GDCM_NAME_SPACE::SerieHelper::ImagePositionPatientOrdering()
+ if (CoherentFileList == 0)
+ this->DataSpacing[2] = file->GetZSpacing();
+ else
+ {
+ // Just because OrderFileList() is a member of GDCM_NAME_SPACE::SerieHelper
+ // we need to instanciate sh.
+ GDCM_NAME_SPACE::SerieHelper *sh = GDCM_NAME_SPACE::SerieHelper::New();
+ sh->OrderFileList(CoherentFileList); // calls ImagePositionPatientOrdering()
+ this->DataSpacing[2] = sh->GetZSpacing();
+ sh->Delete();
+ }
+
+ // Get the image data caracteristics
+ if( file->HasLUT() && this->AllowLookupTable )
+ {
+ // I could raise an error is AllowLookupTable is on and HasLUT() off
+ this->NumComponents = file->GetNumberOfScalarComponentsRaw();
+ }
+ else
+ {
+ this->NumComponents = file->GetNumberOfScalarComponents(); //rgb or mono
+ }
+}
+
+/*
+ * When more than one filename is specified (i.e. we expect loading
+ * a stack or volume) we need to check that the corresponding images/volumes
+ * to be loaded are coherent i.e. to make sure:
+ * - they all share the same X dimensions
+ * - they all share the same Y dimensions
+ * - they all share the same ImageType ( 8 bit signed, or unsigned...)
+ *
+ * Eventually, we emit a warning when all the files do NOT share the
+ * Z dimension, since we can still build a stack but the
+ * files are not coherent in Z, which is probably a source a trouble...
+ * When files are not readable (either the file cannot be opened or
+ * because gdcm cannot parse it), they are flagged as "GDCM_UNREADABLE".
+ * This method returns the total number of planar images to be loaded
+ * (i.e. an image represents one plane, but a volume represents many planes)
+ */
+/**
+ * Test the coherent informations of the file with the reference informations
+ * used as image caracteristics. The tested informations are :
+ * - they all share the same X dimensions
+ * - they all share the same Y dimensions
+ * - they all share the same Z dimensions
+ * - they all share the same number of components
+ * - they all share the same ImageType ( 8 bit signed, or unsigned...)
+ *
+ * \return True if the file match, False otherwise
+ */
+bool vtkGdcmReader::TestFileInformation(GDCM_NAME_SPACE::File *file)
+{
+ int numColumns = file->GetXSize();
+ int numLines = file->GetYSize();
+ int numPlanes = file->GetZSize();
+ int numComponents;
+ unsigned int pixelSize = file->GetPixelSize();
+
+ if( file->HasLUT() && this->AllowLookupTable )
+ numComponents = file->GetNumberOfScalarComponentsRaw();
+ else
+ numComponents = file->GetNumberOfScalarComponents(); //rgb or mono
+
+ if( numColumns != this->NumColumns )
+ {
+ vtkErrorMacro(<< "File X value doesn't match with the previous ones: "
+ << file->GetFileName().c_str()
+ << ". Found " << numColumns << ", must be "
+ << this->NumColumns);
+ return false;
+ }
+ if( numLines != this->NumLines )
+ {
+ vtkErrorMacro(<< "File Y value doesn't match with the previous ones: "
+ << file->GetFileName().c_str()
+ << ". Found " << numLines << ", must be "
+ << this->NumLines);
+ return false;
+ }
+ if( numPlanes != this->NumPlanes )
+ {
+ vtkErrorMacro(<< "File Z value doesn't match with the previous ones: "
+ << file->GetFileName().c_str()
+ << ". Found " << numPlanes << ", must be "
+ << this->NumPlanes);
+ return false;
+ }
+ if( numComponents != this->NumComponents )
+ {
+ vtkErrorMacro(<< "File Components count doesn't match with the previous ones: "
+ << file->GetFileName().c_str()
+ << ". Found " << numComponents << ", must be "
+ << this->NumComponents);
+ return false;
+ }
+ if( pixelSize != this->PixelSize )
+ {
+ vtkErrorMacro(<< "File pixel size doesn't match with the previous ones: "
+ << file->GetFileName().c_str()
+ << ". Found " << pixelSize << ", must be "
+ << this->PixelSize);
+ return false;
+ }
+
+ return true;