]> Creatis software - clitk.git/blob - common/clitkImageToImageGenericFilterBase.h
Merge branch 'master' of git.creatis.insa-lyon.fr:clitk
[clitk.git] / common / clitkImageToImageGenericFilterBase.h
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://www.centreleonberard.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18
19 #ifndef CLITKIMAGETOIMAGEGENERICFILTERBASE_H
20 #define CLITKIMAGETOIMAGEGENERICFILTERBASE_H
21
22 // clitk 
23 #include "clitkImageCommon.h"
24 #include "clitkCommonGenericFilter.h"
25 #include "clitkFilterBase.h"
26
27 // itk 
28 #include <itkImage.h>
29
30 // vv 
31 #include "vvImage.h"
32 #include "vvFromITK.h"
33 #include "vvToITK.h"
34
35 namespace clitk {
36   
37   //--------------------------------------------------------------------
38   class ImageToImageGenericFilterBase: public itk::Object {
39     
40   public: 
41     // constructor - destructor
42     ImageToImageGenericFilterBase(std::string filterName);
43     virtual ~ImageToImageGenericFilterBase();
44
45     // Types
46     typedef ImageToImageGenericFilterBase Self;
47     typedef Object                        Superclass;
48     typedef itk::SmartPointer<Self>       Pointer;
49     typedef itk::SmartPointer<const Self> ConstPointer;
50
51     // Filters information
52     const std::string & GetFilterName();
53     void SetFilterName(std::string & n);
54     
55     // Generic IO
56     /// Returns the dimension and pixel type of the *first* input
57     void GetInputImageDimensionAndPixelType(unsigned int& dim, std::string& pixeltype,
58                                             unsigned int & components);
59     // File IO
60     void SetInputFilename(const std::string & filename);
61     void AddInputFilename(const std::string & filename);
62     void SetInputFilenames(const std::vector<std::string> & filenames);
63     void EnableReadOnDisk(bool b);
64     void EnableWriteOnDisk(bool b);
65     void EnableWriteCompression(bool b);
66     void SetOutputFilename(const std::string & filename);
67     void AddOutputFilename(const std::string filename);
68     void SetOutputFilenames(const std::vector<std::string> & filenames);
69     std::string GetOutputFilename();
70     void SetIOVerbose(bool b);
71
72     // VVImage IO
73     void SetInputVVImage (vvImage::Pointer input);
74     void SetInputVVImages (std::vector<vvImage::Pointer> input);
75     void AddInputVVImage (vvImage::Pointer input);
76     vvImage::Pointer GetOutputVVImage ();
77     std::vector<vvImage::Pointer> GetOutputVVImages ();
78
79     // Information on available image types
80     void PrintAvailableImageTypes();
81     virtual std::string GetAvailableImageTypes() = 0;
82
83     virtual bool CheckImageType(unsigned int dim,unsigned int ncomp, std::string pixeltype) = 0;
84     virtual bool CheckImageType() = 0;
85
86     // Main function to call for using the filter. 
87     virtual bool Update() = 0;
88
89     // Get the associated filter
90     FilterBase * GetFilterBase() { return m_FilterBase; }
91     
92     // Indicate that the filter must stop as soon as possible (if threaded)
93     void DeleteLastOutputImage();
94
95   protected:  
96     bool m_ReadOnDisk;
97     bool m_WriteOnDisk;
98     bool m_WriteCompression;
99
100     /// Call this function to dispatch an output towards the correct sink
101     template<class ImageType> 
102     void SetNextOutput(typename ImageType::Pointer output);
103
104     /// Call this function to get the nth itk input image, regardless of input source
105     template<class ImageType> 
106     typename ImageType::Pointer GetInput(unsigned int n);
107
108     std::vector<std::string> m_InputFilenames;
109     std::list<std::string> m_OutputFilenames;
110     
111     bool m_IOVerbose;
112     unsigned int m_Dim;
113     std::string m_PixelTypeName;
114     unsigned int m_NbOfComponents;
115     std::string m_FilterName;
116
117     std::vector<vvImage::Pointer> m_InputVVImages;
118     std::vector<vvImage::Pointer> m_OutputVVImages;
119
120     void ImageTypeError();
121     void SetImageTypeError();
122     bool m_FailOnImageTypeError;
123     
124     // std::string m_LastError;
125     void SetFilterBase(FilterBase * f) { m_FilterBase = f; }
126     FilterBase * m_FilterBase;
127     // bool m_StopOnError;
128
129   }; // end class clitk::ImageToImageGenericFilter
130
131 #define ADD_VEC_IMAGE_TYPE(DIM, COMP, PT) this->mImageTypesManager.template AddNewDimensionAndPixelType<DIM,COMP, PT>();
132 #define ADD_IMAGE_TYPE(DIM, PT) this->mImageTypesManager.template AddNewDimensionAndPixelType<DIM, PT>();
133 #define ADD_DEFAULT_IMAGE_TYPES(DIM) ADD_IMAGE_TYPE(DIM, char);   \
134                                      ADD_IMAGE_TYPE(DIM, uchar);  \
135                                      ADD_IMAGE_TYPE(DIM, short);  \
136                                      ADD_IMAGE_TYPE(DIM, ushort); \
137                                      ADD_IMAGE_TYPE(DIM, int);    \
138                                      ADD_IMAGE_TYPE(DIM, float);  \
139                                      ADD_IMAGE_TYPE(DIM, double);
140 #define ADD_DEFAULT_VEC_IMAGE_TYPES ADD_VEC_IMAGE_TYPE(2,2,float); \
141                                     ADD_VEC_IMAGE_TYPE(2,3,float); \
142                                     ADD_VEC_IMAGE_TYPE(3,3,float);
143
144   //#include "clitkImageToImageGenericFilterBase.txx"
145
146 } // end namespace
147
148 #endif /* end #define CLITKIMAGETOIMAGEGENERICFILTERBASE_H */
149