]> Creatis software - clitk.git/blob - common/clitkImageToImageGenericFilterBase.h
revived old fast_make script / clean some dependencies
[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://oncora1.lyon.fnclcc.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     // Error management
56     // itkSetMacro(LastError, std::string);
57     // itkGetConstMacro(LastError, std::string);
58     // bool HasError() { return (GetLastError() != ""); }
59
60     // Generic IO
61     /// Returns the dimension and pixel type of the *first* input
62     void GetInputImageDimensionAndPixelType(unsigned int& dim, std::string& pixeltype,
63                                             unsigned int & components);
64     // File IO
65     void SetInputFilename(const std::string & filename);
66     void AddInputFilename(const std::string & filename);
67     void SetInputFilenames(const std::vector<std::string> & filenames);
68     void EnableReadOnDisk(bool b);
69     void SetOutputFilename(const std::string & filename);
70     void AddOutputFilename(const std::string & filename);
71     void SetOutputFilenames(const std::vector<std::string> & filenames);
72     std::string GetOutputFilename();
73     void SetIOVerbose(bool b);
74
75     // VVImage IO
76     void SetInputVVImage (vvImage::Pointer input);
77     void SetInputVVImages (std::vector<vvImage::Pointer> input);
78     void AddInputVVImage (vvImage::Pointer input);
79     vvImage::Pointer GetOutputVVImage ();
80     std::vector<vvImage::Pointer> GetOutputVVImages ();
81
82     // Information on available image types
83     void PrintAvailableImageTypes();
84     virtual std::string GetAvailableImageTypes() = 0;
85
86     virtual bool CheckImageType(unsigned int dim,unsigned int ncomp, std::string pixeltype) = 0;
87     virtual bool CheckImageType() = 0;
88
89     // Main function to call for using the filter. 
90     virtual bool Update() = 0;
91
92     // Get the associated filter
93     FilterBase * GetFilterBase() { return m_FilterBase; }
94     
95     // Indicate that the filter must stop as soon as possible (if threaded)
96     // void MustStop();
97     void DeleteLastOutputImage();
98     // itkSetMacro(StopOnError, bool);
99     // itkGetConstMacro(StopOnError, bool);
100     // itkBooleanMacro(StopOnError);    
101
102   protected:  
103     bool m_ReadOnDisk;
104     /// Call this function to dispatch an output towards the correct sink
105     template<class ImageType> 
106     void SetNextOutput(typename ImageType::Pointer output);
107
108     /// Call this function to get the nth itk input image, regardless of input source
109     template<class ImageType> 
110     typename ImageType::Pointer GetInput(unsigned int n);
111
112     std::vector<std::string> m_InputFilenames;
113     std::list<std::string> m_OutputFilenames;
114
115     bool m_IOVerbose;
116     unsigned int m_Dim;
117     std::string m_PixelTypeName;
118     unsigned int m_NbOfComponents;
119     std::string m_FilterName;
120
121     std::vector<vvImage::Pointer> m_InputVVImages;
122     std::vector<vvImage::Pointer> m_OutputVVImages;
123
124     void ImageTypeError();
125     void SetImageTypeError();
126     bool m_FailOnImageTypeError;
127     
128     // std::string m_LastError;
129     void SetFilterBase(FilterBase * f) { m_FilterBase = f; }
130     FilterBase * m_FilterBase;
131     // bool m_StopOnError;
132
133   }; // end class clitk::ImageToImageGenericFilter
134
135 #define ADD_VEC_IMAGE_TYPE(DIM, COMP, PT) this->mImageTypesManager.template AddNewDimensionAndPixelType<DIM,COMP, PT>();
136 #define ADD_IMAGE_TYPE(DIM, PT) this->mImageTypesManager.template AddNewDimensionAndPixelType<DIM, PT>();
137 #define ADD_DEFAULT_IMAGE_TYPES(DIM) ADD_IMAGE_TYPE(DIM, char);   \
138                                      ADD_IMAGE_TYPE(DIM, uchar);  \
139                                      ADD_IMAGE_TYPE(DIM, short);  \
140                                      ADD_IMAGE_TYPE(DIM, ushort); \
141                                      ADD_IMAGE_TYPE(DIM, int);    \
142                                      ADD_IMAGE_TYPE(DIM, float);  \
143                                      ADD_IMAGE_TYPE(DIM, double);
144
145   //#include "clitkImageToImageGenericFilterBase.txx"
146
147 } // end namespace
148
149 #endif /* end #define CLITKIMAGETOIMAGEGENERICFILTERBASE_H */
150