]> Creatis software - clitk.git/blob - common/clitkImageToImageGenericFilter.h
preliminary fixes for multi-component images
[clitk.git] / common / clitkImageToImageGenericFilter.h
1 /*=========================================================================
2
3   Program:   clitk
4   Module:    $RCSfile: clitkImageToImageGenericFilter.h,v $
5   Language:  C++
6   Date:      $Date: 2010/02/08 15:45:17 $
7   Version:   $Revision: 1.5 $
8   Author :   Joel Schaerer <joel.schaerer@creatis.insa-lyon.fr>
9              David Sarrut <david.sarrut@creatis.insa-lyon.fr>
10
11   Copyright (C) 2008
12   Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
13   CREATIS-LRMN http://www.creatis.insa-lyon.fr
14
15   This program is free software: you can redistribute it and/or modify
16   it under the terms of the GNU General Public License as published by
17   the Free Software Foundation, version 3 of the License.
18
19   This program is distributed in the hope that it will be useful,
20   but WITHOUT ANY WARRANTY; without even the implied warranty of
21   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22   GNU General Public License for more details.
23
24   You should have received a copy of the GNU General Public License
25   along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
27   =========================================================================*/
28
29 #ifndef CLITKIMAGETOIMAGEGENERICFILTER_H
30 #define CLITKIMAGETOIMAGEGENERICFILTER_H
31
32 // clitk include
33 #include "clitkCommon.h"
34 #include "clitkImageCommon.h"
35 #include "clitkCommonGenericFilter.h"
36 #include <itkImage.h>
37
38 // vv include
39 #include <vvImage.h>
40 #include <vvFromITK.h>
41 #include <vvToITK.h>
42 #include <list>
43 #include <set>
44
45 namespace clitk {
46   
47   //--------------------------------------------------------------------
48   class ImageToImageGenericFilterBase: public itk::Object {
49     
50   public: 
51     // constructor - destructor
52     ImageToImageGenericFilterBase(std::string filterName);
53     virtual ~ImageToImageGenericFilterBase() {}
54
55     // Types
56     typedef ImageToImageGenericFilterBase Self;
57     typedef Object                        Superclass;
58     typedef itk::SmartPointer<Self>       Pointer;
59     typedef itk::SmartPointer<const Self> ConstPointer;
60
61     // Filters information
62     const std::string & GetFilterName() { return mFilterName; }
63     void SetFilterName(std::string & n) { mFilterName = n; }
64
65     // Generic IO
66     /// Returns the dimension and pixel type of the *first* input
67     void GetInputImageDimensionAndPixelType(unsigned int& dim, std::string& pixeltype,unsigned int & components);
68
69     // File IO
70     void SetInputFilename(const std::string & filename);
71     void AddInputFilename(const std::string & filename);
72     void SetInputFilenames(const std::vector<std::string> & filenames);
73     void SetOutputFilename(const std::string & filename);
74     void AddOutputFilename(const std::string & filename);
75     void SetOutputFilenames(const std::vector<std::string> & filenames);
76     std::string GetOutputFilename();
77     void SetIOVerbose(bool b) { mIOVerbose = b; }
78
79     // VVImage IO
80     void SetInputVVImage (vvImage::Pointer input);
81     void SetInputVVImages (std::vector<vvImage::Pointer> input);
82     void AddInputVVImage (vvImage::Pointer input);
83     vvImage::Pointer GetOutputVVImage ();
84     std::vector<vvImage::Pointer> GetOutputVVImages ();
85
86     // Information on available image types
87     void PrintAvailableImageTypes();
88     std::string GetAvailableImageTypes();
89     bool CheckDimension(unsigned int d);
90     bool CheckPixelType(std::string pt);
91
92     // Main function to call for using the filter. 
93     virtual bool Update() = 0;
94
95     // Use internally only (TO PUT PROTECTED !!!)
96     void AddImageType(unsigned int d, std::string p);
97
98   protected:  
99     /// Call this function to dispatch an output towards the correct sink
100     template<class ImageType> 
101     void SetNextOutput(typename ImageType::Pointer output);
102
103     /// Call this function to get the nth itk input image, regardless of input source
104     template<class ImageType> 
105     typename ImageType::Pointer GetInput(unsigned int n);
106
107     std::vector<std::string> mInputFilenames;
108     std::list<std::string> mOutputFilenames;
109
110     bool mIOVerbose;
111     unsigned int mDim;
112     std::string mPixelTypeName;
113     unsigned int mNbOfComponents;
114     std::string mFilterName;
115
116     std::vector<vvImage::Pointer> mInputVVImages;
117     std::vector<vvImage::Pointer> mOutputVVImages;
118
119     std::set<std::string> mListOfAllowedPixelTypes;
120     std::set<unsigned int> mListOfAllowedDimensions;
121     bool CheckImageType();
122     bool CheckDimension();
123     bool CheckPixelType();
124     void ImageTypeError();
125     void SetImageTypeError();
126     bool mFailOnImageTypeError;
127
128   }; // end class clitk::ImageToImageGenericFilter
129
130
131   //--------------------------------------------------------------------
132   template<class FilterType>
133   class ImageToImageGenericFilter: public ImageToImageGenericFilterBase {
134     
135   public: 
136     
137     typedef ImageToImageGenericFilter<FilterType> Self;
138
139     // constructor - destructor
140     ImageToImageGenericFilter(std::string filterName);
141     virtual ~ImageToImageGenericFilter() { delete mImageTypesManager; }
142
143     // Main function to call for using the filter. 
144     virtual bool Update();
145
146   protected:
147     // Object that will manage the list of templatized function for
148     // each image type.
149     ImageTypesManager<FilterType> * mImageTypesManager;
150     
151   }; // end class clitk::ImageToImageGenericFilter
152
153   // #define ADD_IMAGE_DIMENSION(DIM) Initialize<DIM>();
154
155 #define ADD_VEC_IMAGE_TYPE(DIM, COMP, PT) this->mImageTypesManager->template AddNewDimensionAndPixelType<DIM,COMP, PT>();
156 #define ADD_IMAGE_TYPE(DIM, PT) this->mImageTypesManager->template AddNewDimensionAndPixelType<DIM, PT>();
157
158
159 #include "clitkImageToImageGenericFilter.txx"
160
161 } // end namespace
162
163 #endif /* end #define CLITKIMAGETOIMAGEGENERICFILTER_H */
164