]> Creatis software - clitk.git/commitdiff
Now reads in ASCII matrix file to set the image transform (filename +".mat").
authorsrit <srit>
Mon, 7 Jun 2010 13:09:41 +0000 (13:09 +0000)
committersrit <srit>
Mon, 7 Jun 2010 13:09:41 +0000 (13:09 +0000)
vv/vvImageReader.cxx
vv/vvImageReader.h
vv/vvImageReader.txx

index e3e01a3b72076634293edfb0fe473a701116be83..17ed757b7af7a13b904c53ed1deb9984a7f39afe 100644 (file)
@@ -22,6 +22,7 @@
 #include <itkImageFileReader.h>
 #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<vtkTransform> pt = vtkSmartPointer<vtkTransform>::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<double, 4, 4> 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();
   }
 }
 //------------------------------------------------------------------------------
index 72d7708711e2fda11e14ae6d74bb1ff4ed18b399..99d302ae385a35f3150dd13877c95350fba656dc 100644 (file)
@@ -76,6 +76,7 @@ protected:
 
     //====================================================================
     void ReadNkiImageTransform();
+    void ReadMatImageTransform();
 private:
     vvImage::Pointer mImage;
 
index dde83af1172fe686fc82bea36d122ddc049e98d7..de8da61c5c8305467b12bf032a9640e3f970dee6 100644 (file)
@@ -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();
+  }
 }
 //----------------------------------------------------------------------------