From: srit Date: Mon, 7 Jun 2010 13:09:41 +0000 (+0000) Subject: Now reads in ASCII matrix file to set the image transform (filename +".mat"). X-Git-Tag: v1.2.0~621 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=b29f225c9396ca737ce59bdf0d9ef50a6c1e9bc5;p=clitk.git Now reads in ASCII matrix file to set the image transform (filename +".mat"). --- diff --git a/vv/vvImageReader.cxx b/vv/vvImageReader.cxx index e3e01a3..17ed757 100644 --- a/vv/vvImageReader.cxx +++ b/vv/vvImageReader.cxx @@ -22,6 +22,7 @@ #include #include "vvImageReader.h" #include "vvImageReader.txx" +#include "clitkTransformUtilities.h" //------------------------------------------------------------------------------ vvImageReader::vvImageReader() @@ -133,22 +134,36 @@ void vvImageReader::ReadNkiImageTransform() } if (bRead) { - double mat[16]; - //Transpose matrix (NKI format) for(int j=0; j<4; j++) for(int i=0; i<4; i++) - mat[4*j+i]=readerTransfo->GetOutput()->GetBufferPointer()[4*i+j]; + mImage->GetTransform()->GetMatrix()->SetElement(j,i,readerTransfo->GetOutput()->GetBufferPointer()[4*i+j]); //From cm to mm for(int i=0; i<3; i++) - mat[4*i+3]*=10; + mImage->GetTransform()->GetMatrix()->SetElement(i,3,10*mImage->GetTransform()->GetMatrix()->GetElement(i,3)); + + mImage->GetTransform()->Inverse(); + mImage->UpdateReslice(); + } +} +//------------------------------------------------------------------------------ - //Set Transformation - vtkSmartPointer pt = vtkSmartPointer::New(); - pt->SetMatrix( mat ); - pt->Inverse(); - mImage->SetTransform( pt ); + +//------------------------------------------------------------------------------ +//Read transformation in ASCII format +void vvImageReader::ReadMatImageTransform() +{ + std::string filename(mInputFilenames[0]+".mat"); + std::ifstream f(filename.c_str()); + if(f.is_open()) { + f.close(); + + itk::Matrix itkMat = clitk::ReadMatrix3D(filename); + for(int j=0; j<4; j++) + for(int i=0; i<4; i++) + mImage->GetTransform()->GetMatrix()->SetElement(j,i,itkMat[j][i]); + mImage->UpdateReslice(); } } //------------------------------------------------------------------------------ diff --git a/vv/vvImageReader.h b/vv/vvImageReader.h index 72d7708..99d302a 100644 --- a/vv/vvImageReader.h +++ b/vv/vvImageReader.h @@ -76,6 +76,7 @@ protected: //==================================================================== void ReadNkiImageTransform(); + void ReadMatImageTransform(); private: vvImage::Pointer mImage; diff --git a/vv/vvImageReader.txx b/vv/vvImageReader.txx index dde83af..de8da61 100644 --- a/vv/vvImageReader.txx +++ b/vv/vvImageReader.txx @@ -53,9 +53,10 @@ void vvImageReader::UpdateWithDim(std::string InputPixelType) else std::cerr << "Error, input pixel type : " << InputPixelType << " unknown !" << std::endl; - if (CLITK_EXPERIMENTAL) - if (mLastError.size()==0) - ReadNkiImageTransform(); + if (CLITK_EXPERIMENTAL && mLastError.size()==0) { + ReadNkiImageTransform(); + ReadMatImageTransform(); + } } //----------------------------------------------------------------------------