]> Creatis software - clitk.git/blobdiff - vv/vvImageReader.cxx
vv now builds even with all options turned off
[clitk.git] / vv / vvImageReader.cxx
index 7cc0e569856b160276385b1f7c81d7e9ecba03ec..17ed757b7af7a13b904c53ed1deb9984a7f39afe 100644 (file)
@@ -1,7 +1,7 @@
 /*=========================================================================
   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
 
-  Authors belong to: 
+  Authors belong to:
   - University of LYON              http://www.universite-lyon.fr/
   - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
@@ -22,6 +22,7 @@
 #include <itkImageFileReader.h>
 #include "vvImageReader.h"
 #include "vvImageReader.txx"
+#include "clitkTransformUtilities.h"
 
 //------------------------------------------------------------------------------
 vvImageReader::vvImageReader()
@@ -53,8 +54,7 @@ void vvImageReader::Update(LoadedImageType type)
   itk::ImageIOBase::Pointer reader = itk::ImageIOFactory::CreateImageIO(mInputFilenames[0].c_str(), itk::ImageIOFactory::ReadMode);
   if (!reader) {
     mLastError="Unable to read file.";
-  }
-  else {
+  } else {
     reader->SetFileName(mInputFilenames[0]);
     reader->ReadImageInformation();
     if (mInputFilenames.size() > 1)
@@ -67,17 +67,17 @@ void vvImageReader::Update(LoadedImageType type)
 
 
 //------------------------------------------------------------------------------
-void vvImageReader::Update(int dim,std::string inputPixelType, LoadedImageType type) {
+void vvImageReader::Update(int dim,std::string inputPixelType, LoadedImageType type)
+{
   //CALL_FOR_ALL_DIMS(dim,UpdateWithDim,inputPixelType);
   mType = type;
   mDim = dim;
   mInputPixelType=inputPixelType;
   this->start(); //Start heavy read operation in a separate thread
-  while (this->isRunning())
-    {
-      qApp->processEvents();
-      this->wait(50);
-    }
+  while (this->isRunning()) {
+    qApp->processEvents();
+    this->wait(50);
+  }
 }
 //------------------------------------------------------------------------------
 
@@ -112,10 +112,60 @@ void vvImageReader::SetInputFilename(const std::string & filename)
 
 
 //------------------------------------------------------------------------------
-void vvImageReader::SetInputFilenames(const std::vector<std::string> & filenames) {
+void vvImageReader::SetInputFilenames(const std::vector<std::string> & filenames)
+{
   mInputFilenames = 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");
+  try {
+    readerTransfo->Update();
+  } catch( itk::ExceptionObject & err ) {
+    bRead=false;
+  }
+
+  if (bRead) {
+    //Transpose matrix (NKI format)
+    for(int j=0; j<4; j++)
+      for(int i=0; i<4; i++)
+        mImage->GetTransform()->GetMatrix()->SetElement(j,i,readerTransfo->GetOutput()->GetBufferPointer()[4*i+j]);
+
+    //From cm to mm
+    for(int i=0; i<3; i++)
+      mImage->GetTransform()->GetMatrix()->SetElement(i,3,10*mImage->GetTransform()->GetMatrix()->GetElement(i,3));
+
+    mImage->GetTransform()->Inverse();
+    mImage->UpdateReslice();
+  }
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+//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();
+  }
+}
+//------------------------------------------------------------------------------
 #endif