]> Creatis software - clitk.git/blob - vv/vvImageReader.cxx
added the new headers
[clitk.git] / vv / vvImageReader.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
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
8
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.
12
13   It is distributed under dual licence
14
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
20 #include <QApplication>
21 #include <itkImageFileReader.h>
22 #include "vvImageReader.h"
23 #include "vvImageReader.txx"
24
25
26 //====================================================================
27 vvImageReader::vvImageReader()
28 {
29     mImage = NULL;
30     mInputFilenames.resize(0);
31     mLastError = "";
32     mType = UNDEFINEDIMAGETYPE;
33 }
34
35 vvImageReader::~vvImageReader() { }
36
37 void vvImageReader::Update()
38 {
39     Update(mType);
40 }
41
42 void vvImageReader::Update(LoadedImageType type)
43 {
44     itk::ImageIOBase::Pointer reader = itk::ImageIOFactory::CreateImageIO(mInputFilenames[0].c_str(), itk::ImageIOFactory::ReadMode);
45     if (!reader) {
46         mLastError="Unable to read file.";
47     }
48     else {
49         reader->SetFileName(mInputFilenames[0]);
50         reader->ReadImageInformation();
51         if (mInputFilenames.size() > 1)
52             Update(reader->GetNumberOfDimensions()+1,reader->GetComponentTypeAsString(reader->GetComponentType()),type);
53         else
54             Update(reader->GetNumberOfDimensions(),reader->GetComponentTypeAsString(reader->GetComponentType()),type);
55     }
56 }
57
58 //====================================================================
59 void vvImageReader::Update(int dim,std::string inputPixelType, LoadedImageType type) {
60     //CALL_FOR_ALL_DIMS(dim,UpdateWithDim,inputPixelType);
61     mType = type;
62     mDim = dim;
63     mInputPixelType=inputPixelType;
64     this->start(); //Start heavy read operation in a separate thread
65     while (this->isRunning())
66     {
67         qApp->processEvents();
68         this->wait(50);
69     }
70 }
71
72 void vvImageReader::run()
73 {
74     switch(mDim)
75     {
76         case 2:
77             UpdateWithDim<2>(mInputPixelType);
78             break;;
79         case 3:
80             UpdateWithDim<3>(mInputPixelType);
81             break;;
82         case 4:
83             UpdateWithDim<4>(mInputPixelType);
84             break;;
85         default:
86             std::cerr << "dimension unknown in Update ! " << std::endl;
87     }
88 }
89 //====================================================================
90
91 //====================================================================
92 /*void vvImageReader::Extract(int dim, std::string inputPixelType, int slice) {
93   CALL_FOR_ALL_DIMS(dim, ExtractWithDim, inputPixelType, slice);
94 }*/
95 //====================================================================
96 void vvImageReader::SetInputFilename(const std::string & filename)
97 {
98     mInputFilenames.resize(0);
99     mInputFilenames.push_back(filename);
100 }
101
102 //====================================================================
103 void vvImageReader::SetInputFilenames(const std::vector<std::string> & filenames) {
104     mInputFilenames = filenames;
105 }
106 //====================================================================
107
108 #endif
109