]> Creatis software - clitk.git/blob - vv/vvImageReader.cxx
Synergy projections file format
[clitk.git] / vv / vvImageReader.cxx
1 /*=========================================================================
2
3  Program:   vv
4  Language:  C++
5  Author :   Pierre Seroul (pierre.seroul@gmail.com)
6
7 Copyright (C) 2008
8 Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
9 CREATIS-LRMN http://www.creatis.insa-lyon.fr
10
11 This program is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, version 3 of the License.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
23 =========================================================================*/
24 #ifndef vvImageReader_CXX
25 #define vvImageReader_CXX
26
27 #include <QApplication>
28 #include <itkImageFileReader.h>
29 #include "vvImageReader.h"
30 #include "vvImageReader.txx"
31
32
33 //====================================================================
34 vvImageReader::vvImageReader()
35 {
36     mImage = NULL;
37     mInputFilenames.resize(0);
38     mLastError = "";
39     mType = UNDEFINEDIMAGETYPE;
40 }
41
42 vvImageReader::~vvImageReader() { }
43
44 void vvImageReader::Update()
45 {
46     Update(mType);
47 }
48
49 void vvImageReader::Update(LoadedImageType type)
50 {
51     itk::ImageIOBase::Pointer reader = itk::ImageIOFactory::CreateImageIO(mInputFilenames[0].c_str(), itk::ImageIOFactory::ReadMode);
52     if (!reader) {
53         mLastError="Unable to read file.";
54     }
55     else {
56         reader->SetFileName(mInputFilenames[0]);
57         reader->ReadImageInformation();
58         if (mInputFilenames.size() > 1)
59             Update(reader->GetNumberOfDimensions()+1,reader->GetComponentTypeAsString(reader->GetComponentType()),type);
60         else
61             Update(reader->GetNumberOfDimensions(),reader->GetComponentTypeAsString(reader->GetComponentType()),type);
62     }
63 }
64
65 //====================================================================
66 void vvImageReader::Update(int dim,std::string inputPixelType, LoadedImageType type) {
67     //CALL_FOR_ALL_DIMS(dim,UpdateWithDim,inputPixelType);
68     mType = type;
69     mDim = dim;
70     mInputPixelType=inputPixelType;
71     this->start(); //Start heavy read operation in a separate thread
72     while (this->isRunning())
73     {
74         qApp->processEvents();
75         this->wait(50);
76     }
77 }
78
79 void vvImageReader::run()
80 {
81     switch(mDim)
82     {
83         case 2:
84             UpdateWithDim<2>(mInputPixelType);
85             break;;
86         case 3:
87             UpdateWithDim<3>(mInputPixelType);
88             break;;
89         case 4:
90             UpdateWithDim<4>(mInputPixelType);
91             break;;
92         default:
93             std::cerr << "dimension unknown in Update ! " << std::endl;
94     }
95 }
96 //====================================================================
97
98 //====================================================================
99 /*void vvImageReader::Extract(int dim, std::string inputPixelType, int slice) {
100   CALL_FOR_ALL_DIMS(dim, ExtractWithDim, inputPixelType, slice);
101 }*/
102 //====================================================================
103 void vvImageReader::SetInputFilename(const std::string & filename)
104 {
105     mInputFilenames.resize(0);
106     mInputFilenames.push_back(filename);
107 }
108
109 //====================================================================
110 void vvImageReader::SetInputFilenames(const std::vector<std::string> & filenames) {
111     mInputFilenames = filenames;
112 }
113 //====================================================================
114
115 #endif
116