]> Creatis software - clitk.git/commitdiff
Allow reading .elx file for rigid transformations, i.e. the result of
authorSimon Rit <simon.rit@creatis.insa-lyon.fr>
Wed, 24 Jul 2013 22:06:59 +0000 (00:06 +0200)
committerSimon Rit <simon.rit@creatis.insa-lyon.fr>
Wed, 24 Jul 2013 22:06:59 +0000 (00:06 +0200)
Elastix' registration.

common/vvImageReader.cxx

index ddc4ad3833ae2e60050fee3debd5c58e106ee4c7..23c78f155dd9e4c51ddad251cf87c549e6d7b70c 100644 (file)
@@ -22,6 +22,7 @@
 #include "vvImageReader.h"
 #include "vvImageReader.txx"
 #include "clitkTransformUtilities.h"
+#include "clitkElastix.h"
 
 //------------------------------------------------------------------------------
 vvImageReader::vvImageReader()
@@ -150,18 +151,20 @@ void vvImageReader::ReadMatImageTransform()
 {
   std::string filename(mInputFilenames[0]);
   std::string ext(itksys::SystemTools::GetFilenameLastExtension(filename));
+
+  // Try a ".mat" extension
   if (ext.length() > 0) {
     size_t pos = filename.rfind(ext);
     filename.replace(pos, ext.length(), ".mat");
   }
   else
     filename += ".mat";
-    
   std::ifstream f(filename.c_str());
+  itk::Matrix<double, 4, 4> itkMat;
+  bool itkMatRead = false;
   if(f.is_open()) {
-    f.close();
+    itkMatRead = true;
 
-    itk::Matrix<double, 4, 4> itkMat;
     itkMat.SetIdentity();
     try {
       itkMat = clitk::ReadMatrix3D(filename);
@@ -169,8 +172,29 @@ void vvImageReader::ReadMatImageTransform()
     catch (itk::ExceptionObject & err) {
       itkWarningMacro(<< "Found " << filename
                       << " but this is not a 4x4 matrix so it is ignored.");
+      itkMatRead = false;
     }
+  }
+  f.close();
+
+  // Try a ".elx" extension
+  filename = mInputFilenames[0];
+  if (ext.length() > 0) {
+    size_t pos = filename.rfind(ext);
+    filename.replace(pos, ext.length(), ".elx");
+  }
+  else
+    filename += ".elx";
+  f.open(filename.c_str());
+  if(!itkMatRead && f.is_open()) {
+    itkMatRead = true;
+    std::vector<std::string> l;
+    l.push_back(filename);
+    itkMat = clitk::createMatrixFromElastixFile<3>(l, true);
+  }
+  f.close();
 
+  if(itkMatRead) {
     vtkSmartPointer<vtkMatrix4x4> matrix = vtkSmartPointer<vtkMatrix4x4>::New();
     matrix->Identity();
     for(int j=0; j<4; j++)
@@ -208,12 +232,12 @@ void vvImageReader::ReadMatImageTransform()
     //for image sequences, apply the transform to each images of the sequence
     if (mImage->IsTimeSequence())
     {
-       for (unsigned i = 1 ; i<mImage->GetTransform().size() ; i++)
-        {
-            mImage->GetTransform()[i]->PreMultiply();
-            mImage->GetTransform()[i]->Concatenate(matrix);
-            mImage->GetTransform()[i]->Update();
-        }
+      for (unsigned i = 1 ; i<mImage->GetTransform().size() ; i++)
+      {
+        mImage->GetTransform()[i]->PreMultiply();
+        mImage->GetTransform()[i]->Concatenate(matrix);
+        mImage->GetTransform()[i]->Update();
+      }
     }
 
   }