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