]> Creatis software - clitk.git/blob - vv/vvImageReader.cxx
Initial revision
[clitk.git] / vv / vvImageReader.cxx
1 /*=========================================================================
2
3  Program:   vv
4  Module:    $RCSfile: vvImageReader.cxx,v $
5  Language:  C++
6  Date:      $Date: 2010/01/06 13:31:57 $
7  Version:   $Revision: 1.1 $
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(LoadedImageType type)
48 {
49     itk::ImageIOBase::Pointer reader = itk::ImageIOFactory::CreateImageIO(mInputFilenames[0].c_str(), itk::ImageIOFactory::ReadMode);
50     if (!reader) {
51         mLastError="Unable to read file.";
52     }
53     else {
54         reader->SetFileName(mInputFilenames[0]);
55         reader->ReadImageInformation();
56         if (mInputFilenames.size() > 1)
57             Update(reader->GetNumberOfDimensions()+1,reader->GetComponentTypeAsString(reader->GetComponentType()),type);
58         else
59             Update(reader->GetNumberOfDimensions(),reader->GetComponentTypeAsString(reader->GetComponentType()),type);
60     }
61 }
62
63 //====================================================================
64 void vvImageReader::Update(int dim,std::string inputPixelType, LoadedImageType type) {
65     //CALL_FOR_ALL_DIMS(dim,UpdateWithDim,inputPixelType);
66     mType = type;
67     mDim = dim;
68     mInputPixelType=inputPixelType;
69     this->start(); //Start heavy read operation in a separate thread
70     while (this->isRunning())
71     {
72         qApp->processEvents();
73         this->wait(50);
74     }
75 }
76
77 void vvImageReader::run()
78 {
79     switch(mDim)
80     {
81         case 2:
82             UpdateWithDim<2>(mInputPixelType);
83             break;;
84         case 3:
85             UpdateWithDim<3>(mInputPixelType);
86             break;;
87         case 4:
88             UpdateWithDim<4>(mInputPixelType);
89             break;;
90         default:
91             std::cerr << "dimension unknown in Update ! " << std::endl;
92     }
93 }
94 //====================================================================
95
96 //====================================================================
97 /*void vvImageReader::Extract(int dim, std::string inputPixelType, int slice) {
98   CALL_FOR_ALL_DIMS(dim, ExtractWithDim, inputPixelType, slice);
99 }*/
100 //====================================================================
101 void vvImageReader::SetInputFilename(const std::string & filename)
102 {
103     mInputFilenames.resize(0);
104     mInputFilenames.push_back(filename);
105 }
106
107 //====================================================================
108 void vvImageReader::SetInputFilenames(const std::vector<std::string> & filenames) {
109     mInputFilenames = filenames;
110 }
111 //====================================================================
112
113 #endif
114