]> Creatis software - clitk.git/blob - common/clitkImageToImageGenericFilterBase.h
change GetScalarTypeAsString to GetScalarTypeAsITKString to make explicit that type...
[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 #ifndef CLITKIMAGETOIMAGEGENERICFILTERBASE_H
19 #define CLITKIMAGETOIMAGEGENERICFILTERBASE_H
20
21 // clitk 
22 #include "clitkCommon.h"
23 #include "clitkImageCommon.h"
24 #include "clitkCommonGenericFilter.h"
25
26 // itk 
27 #include <itkImage.h>
28
29 // vv 
30 #include "vvImage.h"
31 #include "vvFromITK.h"
32 #include "vvToITK.h"
33
34 namespace clitk {
35   
36   //--------------------------------------------------------------------
37   class ImageToImageGenericFilterBase: public itk::Object {
38     
39   public: 
40     // constructor - destructor
41     ImageToImageGenericFilterBase(std::string filterName);
42     virtual ~ImageToImageGenericFilterBase();
43
44     // Types
45     typedef ImageToImageGenericFilterBase Self;
46     typedef Object                        Superclass;
47     typedef itk::SmartPointer<Self>       Pointer;
48     typedef itk::SmartPointer<const Self> ConstPointer;
49
50     // Filters information
51     const std::string & GetFilterName();
52     void SetFilterName(std::string & n);
53     
54     // Error management
55     itkSetMacro(LastError, std::string);
56     itkGetConstMacro(LastError, std::string);
57     bool HasError() { return (GetLastError() != ""); }
58
59     // Generic IO
60     /// Returns the dimension and pixel type of the *first* input
61     void GetInputImageDimensionAndPixelType(unsigned int& dim, std::string& pixeltype,
62                                             unsigned int & components);
63
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   protected:  
93     bool m_ReadOnDisk;
94     /// Call this function to dispatch an output towards the correct sink
95     template<class ImageType> 
96     void SetNextOutput(typename ImageType::Pointer output);
97
98     /// Call this function to get the nth itk input image, regardless of input source
99     template<class ImageType> 
100     typename ImageType::Pointer GetInput(unsigned int n);
101
102     std::vector<std::string> m_InputFilenames;
103     std::list<std::string> m_OutputFilenames;
104
105     bool m_IOVerbose;
106     unsigned int m_Dim;
107     std::string m_PixelTypeName;
108     unsigned int m_NbOfComponents;
109     std::string m_FilterName;
110
111     std::vector<vvImage::Pointer> m_InputVVImages;
112     std::vector<vvImage::Pointer> m_OutputVVImages;
113
114     void ImageTypeError();
115     void SetImageTypeError();
116     bool m_FailOnImageTypeError;
117     
118     std::string m_LastError;
119
120   }; // end class clitk::ImageToImageGenericFilter
121
122 #define ADD_VEC_IMAGE_TYPE(DIM, COMP, PT) this->mImageTypesManager.template AddNewDimensionAndPixelType<DIM,COMP, PT>();
123 #define ADD_IMAGE_TYPE(DIM, PT) this->mImageTypesManager.template AddNewDimensionAndPixelType<DIM, PT>();
124 #define ADD_DEFAULT_IMAGE_TYPES(DIM) ADD_IMAGE_TYPE(DIM, char);   \
125                                      ADD_IMAGE_TYPE(DIM, uchar);  \
126                                      ADD_IMAGE_TYPE(DIM, short);  \
127                                      ADD_IMAGE_TYPE(DIM, ushort); \
128                                      ADD_IMAGE_TYPE(DIM, int);    \
129                                      ADD_IMAGE_TYPE(DIM, float);  \
130                                      ADD_IMAGE_TYPE(DIM, double);
131
132   //#include "clitkImageToImageGenericFilterBase.txx"
133
134 } // end namespace
135
136 #endif /* end #define CLITKIMAGETOIMAGEGENERICFILTERBASE_H */
137