]> Creatis software - clitk.git/commitdiff
Added ReadNkiImageTransform to read XVI image transforms (only enabled in CLITK_EXPER...
authorsrit <srit>
Thu, 22 Apr 2010 13:04:21 +0000 (13:04 +0000)
committersrit <srit>
Thu, 22 Apr 2010 13:04:21 +0000 (13:04 +0000)
vv/vvImageReader.cxx
vv/vvImageReader.h
vv/vvImageReader.txx

index 7cc0e569856b160276385b1f7c81d7e9ecba03ec..a61c3669c5dc2ef6c5fc0b5c967079e0e9eafb2d 100644 (file)
@@ -117,5 +117,43 @@ void vvImageReader::SetInputFilenames(const std::vector<std::string> & filenames
 }
 //------------------------------------------------------------------------------
 
+
+//------------------------------------------------------------------------------
+//Read transformation in NKI format (Xdr, transposed, cm)
+void vvImageReader::ReadNkiImageTransform()
+{
+    bool bRead=true;
+    typedef itk::ImageFileReader< itk::Image< double, 2 > > MatrixReaderType;
+    MatrixReaderType::Pointer readerTransfo = MatrixReaderType::New();
+    readerTransfo->SetFileName(mInputFilenames[0]+".MACHINEORIENTATION");
+DD(mInputFilenames[0]+".MACHINEORIENTATION");
+    try
+    {   readerTransfo->Update();
+    }
+    catch( itk::ExceptionObject & err )
+    {   bRead=false;
+    }
+        
+    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];
+
+        //From cm to mm
+        for(int i=0; i<3; i++)
+            mat[4*i+3]*=10;
+
+        //Set Transformation
+        vtkSmartPointer<vtkTransform> pt = vtkSmartPointer<vtkTransform>::New();
+        pt->SetMatrix( mat );
+        pt->Inverse();
+DD(*pt);
+        mImage->SetTransform( pt );
+    }
+}
+//------------------------------------------------------------------------------
 #endif
 
index 702af66dc18777bfb04eb15d890410bfa7b8b056..72d7708711e2fda11e14ae6d74bb1ff4ed18b399 100644 (file)
@@ -74,6 +74,8 @@ protected:
     int mDim;
     std::string mInputPixelType;
 
+    //====================================================================
+    void ReadNkiImageTransform();
 private:
     vvImage::Pointer mImage;
 
index cfa389a7154e5cf803469d6b9da39030536b3949..b6539b8bf37b7c850983134d443cfe4eef628393 100644 (file)
 #include <string>
 #include <itkImageFileReader.h>
 #include <itkImageSeriesReader.h>
+#include <itkImageToVTKImageFilter.h>
+
+#include <vtkTransform.h>
+
 #include "clitkCommon.h"
-#include "itkImageToVTKImageFilter.h"
 #include "vvFromITK.h"
 #include "vvConstants.h"
 
@@ -48,6 +51,10 @@ void vvImageReader::UpdateWithDim(std::string InputPixelType) {
     UpdateWithDimAndInputPixelType<float,VImageDimension>();
   else
     std::cerr << "Error, input pixel type : " << InputPixelType << " unknown !" << std::endl;
+
+  if (CLITK_EXPERIMENTAL)
+    if (mLastError.size()==0)
+      ReadNkiImageTransform();
 }
 //----------------------------------------------------------------------------