]> Creatis software - clitk.git/blob - common/clitkImageToImageGenericFilter.h
645fe9b550817305506013b3efa2af582be81ee9
[clitk.git] / common / clitkImageToImageGenericFilter.h
1 /*=========================================================================
2
3   Program:   clitk
4   Module:    $RCSfile: clitkImageToImageGenericFilter.h,v $
5   Language:  C++
6   Date:      $Date: 2010/01/29 13:53:15 $
7   Version:   $Revision: 1.3 $
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
44 namespace clitk {
45   
46   //--------------------------------------------------------------------
47   class ImageToImageGenericFilterBase: public itk::Object {
48     
49   public: 
50     // constructor - destructor
51     ImageToImageGenericFilterBase(std::string filterName);
52     virtual ~ImageToImageGenericFilterBase() {}
53
54     // Types
55     typedef ImageToImageGenericFilterBase Self;
56     typedef Object                        Superclass;
57     typedef itk::SmartPointer<Self>       Pointer;
58     typedef itk::SmartPointer<const Self> ConstPointer;
59
60     // Filters information
61     const std::string & GetFilterName() { return mFilterName; }
62     void SetFilterName(std::string & n) { mFilterName = n; }
63
64     // Generic IO
65     /// Returns the dimension and pixel type of the *first* input
66     void GetInputImageDimensionAndPixelType(unsigned int& dim, std::string& pixeltype,unsigned int & components);
67
68     // File IO
69     void SetInputFilename(const std::string & filename);
70     void AddInputFilename(const std::string & filename);
71     void SetInputFilenames(const std::vector<std::string> & filenames);
72     void SetOutputFilename(const std::string & filename);
73     void AddOutputFilename(const std::string & filename);
74     void SetOutputFilenames(const std::vector<std::string> & filenames);
75     std::string GetOutputFilename();
76     void SetIOVerbose(bool b) { mIOVerbose = b; }
77
78     // VVImage IO
79     void SetInputVVImage (vvImage::Pointer input);
80     void SetInputVVImages (std::vector<vvImage::Pointer> input);
81     void AddInputVVImage (vvImage::Pointer input);
82     vvImage::Pointer GetOutputVVImage ();
83     std::vector<vvImage::Pointer> GetOutputVVImages ();
84
85     // Information on available image types
86     void PrintAvailableImageTypes();
87     std::string GetAvailableImageTypes();
88     bool CheckDimension(unsigned int d);
89     bool CheckPixelType(std::string pt);
90
91     // Main function to call for using the filter. 
92     virtual bool Update() = 0;
93
94     // Use internally only (TO PUT PROTECTED !!!)
95     void AddImageType(unsigned int d, std::string p);
96
97   protected:  
98     /// Call this function to dispatch an output towards the correct sink
99     template<class ImageType> 
100     void SetNextOutput(typename ImageType::Pointer output);
101
102     /// Call this function to get the nth itk input image, regardless of input source
103     template<class ImageType> 
104     typename ImageType::Pointer GetInput(unsigned int n);
105
106     std::vector<std::string> mInputFilenames;
107     std::list<std::string> mOutputFilenames;
108
109     bool mIOVerbose;
110     unsigned int mDim;
111     std::string mPixelTypeName;
112     unsigned int mNbOfComponents;
113     std::string mFilterName;
114
115     std::vector<vvImage::Pointer> mInputVVImages;
116     std::vector<vvImage::Pointer> mOutputVVImages;
117
118     std::vector<std::string> mListOfAllowedPixelType;
119     std::vector<unsigned int> mListOfAllowedDimension;    
120     bool CheckImageType();
121     bool CheckDimension();
122     bool CheckPixelType();
123     void ImageTypeError();
124     void SetImageTypeError();
125     bool mFailOnImageTypeError;
126
127   }; // end class clitk::ImageToImageGenericFilter
128
129
130   //--------------------------------------------------------------------
131   template<class FilterType>
132   class ImageToImageGenericFilter: public ImageToImageGenericFilterBase {
133     
134   public: 
135     
136     typedef ImageToImageGenericFilter<FilterType> Self;
137
138     // constructor - destructor
139     ImageToImageGenericFilter(std::string filterName);
140     virtual ~ImageToImageGenericFilter() { delete mImageTypesManager; }
141
142     // Main function to call for using the filter. 
143     virtual bool Update();
144
145   protected:
146     // Object that will manage the list of templatized function for
147     // each image type.
148     ImageTypesManager<FilterType> * mImageTypesManager;
149     
150   }; // end class clitk::ImageToImageGenericFilter
151
152   // #define ADD_IMAGE_DIMENSION(DIM) Initialize<DIM>();
153
154 #define ADD_IMAGE_TYPE(DIM, PT) this->mImageTypesManager->template AddNewDimensionAndPixelType<DIM, PT>();
155
156
157 #include "clitkImageToImageGenericFilter.txx"
158
159 } // end namespace
160
161 #endif /* end #define CLITKIMAGETOIMAGEGENERICFILTER_H */
162