/*=========================================================================
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
#include <itkImageFileReader.h>
#include "vvImageReader.h"
#include "vvImageReader.txx"
+#include "clitkTransformUtilities.h"
//------------------------------------------------------------------------------
vvImageReader::vvImageReader()
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)
//------------------------------------------------------------------------------
-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);
+ }
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
-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");
-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 );
- }
+ 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