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