]> Creatis software - clitk.git/commitdiff
Improved robustness of ImagX xml file reader
authorSimon Rit <simon.rit@creatis.insa-lyon.fr>
Tue, 25 Nov 2014 06:51:24 +0000 (07:51 +0100)
committerSimon Rit <simon.rit@creatis.insa-lyon.fr>
Tue, 25 Nov 2014 06:51:24 +0000 (07:51 +0100)
common/rtkImagXImageIO.cxx

index d197ed7d122c9a702befd5b0fd33bac2cd14a8fc..09cb910558dc9e9eabedfb81be6c23b0bee42bef 100644 (file)
@@ -57,7 +57,7 @@ void rtk::ImagXImageIO::ReadImageInformation()
   if(pixelType=="Type_float")
     SetComponentType(itk::ImageIOBase::FLOAT);
 
-  if(dic["dimensions"].GetPointer()==NULL)
+  if( dic["dimensions"].GetPointer() == NULL )
     SetNumberOfDimensions(3);
   else
     SetNumberOfDimensions( ( dynamic_cast<MetaDataIntType *>(dic["dimensions"].GetPointer() )->GetMetaDataObjectValue() ) );
@@ -73,15 +73,22 @@ void rtk::ImagXImageIO::ReadImageInformation()
     {
     SetDimensions(2, dynamic_cast<MetaDataIntType *>(dic["z"].GetPointer() )->GetMetaDataObjectValue() );
     SetSpacing(2, dynamic_cast<MetaDataDoubleType *>(dic["spacing_z"].GetPointer() )->GetMetaDataObjectValue() );
+    if(GetSpacing(2) == 0)
+      SetSpacing(2, 1);
     }
 
-  std::istringstream iss(
-    dynamic_cast<MetaDataStringType*>(dic["matrixTransform"].GetPointer() )->GetMetaDataObjectValue() );
   itk::Matrix<double, 4, 4> matrix;
-  for(unsigned int j=0; j<4; j++)
-    for(unsigned int i=0; i<4; i++)
-      iss >> matrix[j][i];
-  matrix /= matrix[3][3];
+  if(dic["matrixTransform"].GetPointer() == NULL)
+    matrix.SetIdentity();
+  else
+    {
+    std::istringstream iss(
+      dynamic_cast<MetaDataStringType*>(dic["matrixTransform"].GetPointer() )->GetMetaDataObjectValue() );
+    for(unsigned int j=0; j<4; j++)
+      for(unsigned int i=0; i<4; i++)
+        iss >> matrix[j][i];
+    matrix /= matrix[3][3];
+    }
 
   std::vector<double> direction;
   for(unsigned int i=0; i<GetNumberOfDimensions(); i++)
@@ -173,20 +180,19 @@ void rtk::ImagXImageIO::Read(void * buffer)
 
 //--------------------------------------------------------------------
 // Write Image Information
-void rtk::ImagXImageIO::WriteImageInformation(bool keepOfStream)
+void rtk::ImagXImageIO::WriteImageInformation( bool itkNotUsed(keepOfStream) )
 {
 }
 
 //--------------------------------------------------------------------
 // Write Image Information
-bool rtk::ImagXImageIO::CanWriteFile(const char* FileNameToWrite)
+bool rtk::ImagXImageIO::CanWriteFile( const char* itkNotUsed(FileNameToWrite) )
 {
   return false;
 }
 
 //--------------------------------------------------------------------
 // Write Image
-void rtk::ImagXImageIO::Write(const void * buffer)
+void rtk::ImagXImageIO::Write( const void * itkNotUsed(buffer) )
 {
 } ////
-