1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
18 #ifndef VVIMAGEREADER_CXX
19 #define VVIMAGEREADER_CXX
21 #include <QApplication>
22 #include <itkImageFileReader.h>
23 #include "vvImageReader.h"
24 #include "vvImageReader.txx"
26 //------------------------------------------------------------------------------
27 vvImageReader::vvImageReader()
30 mInputFilenames.resize(0);
32 mType = UNDEFINEDIMAGETYPE;
34 //------------------------------------------------------------------------------
37 //------------------------------------------------------------------------------
38 vvImageReader::~vvImageReader() { }
39 //------------------------------------------------------------------------------
42 //------------------------------------------------------------------------------
43 void vvImageReader::Update()
47 //------------------------------------------------------------------------------
50 //------------------------------------------------------------------------------
51 void vvImageReader::Update(LoadedImageType type)
53 itk::ImageIOBase::Pointer reader = itk::ImageIOFactory::CreateImageIO(mInputFilenames[0].c_str(), itk::ImageIOFactory::ReadMode);
55 mLastError="Unable to read file.";
57 reader->SetFileName(mInputFilenames[0]);
58 reader->ReadImageInformation();
59 if (mInputFilenames.size() > 1)
60 Update(reader->GetNumberOfDimensions()+1,reader->GetComponentTypeAsString(reader->GetComponentType()),type);
62 Update(reader->GetNumberOfDimensions(),reader->GetComponentTypeAsString(reader->GetComponentType()),type);
65 //------------------------------------------------------------------------------
68 //------------------------------------------------------------------------------
69 void vvImageReader::Update(int dim,std::string inputPixelType, LoadedImageType type)
71 //CALL_FOR_ALL_DIMS(dim,UpdateWithDim,inputPixelType);
74 mInputPixelType=inputPixelType;
75 this->start(); //Start heavy read operation in a separate thread
76 while (this->isRunning()) {
77 qApp->processEvents();
81 //------------------------------------------------------------------------------
84 //------------------------------------------------------------------------------
85 void vvImageReader::run()
89 UpdateWithDim<2>(mInputPixelType);
92 UpdateWithDim<3>(mInputPixelType);
95 UpdateWithDim<4>(mInputPixelType);
98 std::cerr << "dimension unknown in Update ! " << std::endl;
101 //------------------------------------------------------------------------------
104 //------------------------------------------------------------------------------
105 void vvImageReader::SetInputFilename(const std::string & filename)
107 mInputFilenames.resize(0);
108 mInputFilenames.push_back(filename);
110 //------------------------------------------------------------------------------
113 //------------------------------------------------------------------------------
114 void vvImageReader::SetInputFilenames(const std::vector<std::string> & filenames)
116 mInputFilenames = filenames;
118 //------------------------------------------------------------------------------
121 //------------------------------------------------------------------------------
122 //Read transformation in NKI format (Xdr, transposed, cm)
123 void vvImageReader::ReadNkiImageTransform()
126 typedef itk::ImageFileReader< itk::Image< double, 2 > > MatrixReaderType;
127 MatrixReaderType::Pointer readerTransfo = MatrixReaderType::New();
128 readerTransfo->SetFileName(mInputFilenames[0]+".MACHINEORIENTATION");
130 readerTransfo->Update();
131 } catch( itk::ExceptionObject & err ) {
138 //Transpose matrix (NKI format)
139 for(int j=0; j<4; j++)
140 for(int i=0; i<4; i++)
141 mat[4*j+i]=readerTransfo->GetOutput()->GetBufferPointer()[4*i+j];
144 for(int i=0; i<3; i++)
148 vtkSmartPointer<vtkTransform> pt = vtkSmartPointer<vtkTransform>::New();
149 pt->SetMatrix( mat );
151 mImage->SetTransform( pt );
154 //------------------------------------------------------------------------------