From: Simon Rit Date: Wed, 24 Jul 2013 22:06:59 +0000 (+0200) Subject: Allow reading .elx file for rigid transformations, i.e. the result of X-Git-Tag: v1.4.0~164^2~38^2~3 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=59d984978e620f78b60435ef88269e4ea468bd6a;p=clitk.git Allow reading .elx file for rigid transformations, i.e. the result of Elastix' registration. --- diff --git a/common/vvImageReader.cxx b/common/vvImageReader.cxx index ddc4ad3..23c78f1 100644 --- a/common/vvImageReader.cxx +++ b/common/vvImageReader.cxx @@ -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 itkMat; + bool itkMatRead = false; if(f.is_open()) { - f.close(); + itkMatRead = true; - itk::Matrix 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 l; + l.push_back(filename); + itkMat = clitk::createMatrixFromElastixFile<3>(l, true); + } + f.close(); + if(itkMatRead) { vtkSmartPointer matrix = vtkSmartPointer::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 ; iGetTransform().size() ; i++) - { - mImage->GetTransform()[i]->PreMultiply(); - mImage->GetTransform()[i]->Concatenate(matrix); - mImage->GetTransform()[i]->Update(); - } + for (unsigned i = 1 ; iGetTransform().size() ; i++) + { + mImage->GetTransform()[i]->PreMultiply(); + mImage->GetTransform()[i]->Concatenate(matrix); + mImage->GetTransform()[i]->Update(); + } } }