]> Creatis software - clitk.git/blob - common/clitkImageToImageGenericFilterBase.h
Functionality to Delete Last Image
[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 "clitkCommon.h"
24 #include "clitkImageCommon.h"
25 #include "clitkCommonGenericFilter.h"
26 #include "clitkFilterBase.h"
27
28 // itk 
29 #include <itkImage.h>
30
31 // vv 
32 #include "vvImage.h"
33 #include "vvFromITK.h"
34 #include "vvToITK.h"
35
36 namespace clitk {
37   
38   //--------------------------------------------------------------------
39   class ImageToImageGenericFilterBase: public itk::Object {
40     
41   public: 
42     // constructor - destructor
43     ImageToImageGenericFilterBase(std::string filterName);
44     virtual ~ImageToImageGenericFilterBase();
45
46     // Types
47     typedef ImageToImageGenericFilterBase Self;
48     typedef Object                        Superclass;
49     typedef itk::SmartPointer<Self>       Pointer;
50     typedef itk::SmartPointer<const Self> ConstPointer;
51
52     // Filters information
53     const std::string & GetFilterName();
54     void SetFilterName(std::string & n);
55     
56     // Error management
57     itkSetMacro(LastError, std::string);
58     itkGetConstMacro(LastError, std::string);
59     bool HasError() { return (GetLastError() != ""); }
60
61     // Generic IO
62     /// Returns the dimension and pixel type of the *first* input
63     void GetInputImageDimensionAndPixelType(unsigned int& dim, std::string& pixeltype,
64                                             unsigned int & components);
65     // File IO
66     void SetInputFilename(const std::string & filename);
67     void AddInputFilename(const std::string & filename);
68     void SetInputFilenames(const std::vector<std::string> & filenames);
69     void EnableReadOnDisk(bool b);
70     void SetOutputFilename(const std::string & filename);
71     void AddOutputFilename(const std::string & filename);
72     void SetOutputFilenames(const std::vector<std::string> & filenames);
73     std::string GetOutputFilename();
74     void SetIOVerbose(bool b);
75
76     // VVImage IO
77     void SetInputVVImage (vvImage::Pointer input);
78     void SetInputVVImages (std::vector<vvImage::Pointer> input);
79     void AddInputVVImage (vvImage::Pointer input);
80     vvImage::Pointer GetOutputVVImage ();
81     std::vector<vvImage::Pointer> GetOutputVVImages ();
82
83     // Information on available image types
84     void PrintAvailableImageTypes();
85     virtual std::string GetAvailableImageTypes() = 0;
86
87     virtual bool CheckImageType(unsigned int dim,unsigned int ncomp, std::string pixeltype) = 0;
88     virtual bool CheckImageType() = 0;
89
90     // Main function to call for using the filter. 
91     virtual bool Update() = 0;
92
93     // Get the associated filter
94     FilterBase * GetFilterBase() { return m_FilterBase; }
95     
96     // Indicate that the filter must stop as soon as possible (if threaded)
97     void MustStop();
98     void DeleteLastOutputImage();
99     itkSetMacro(StopOnError, bool);
100     itkGetConstMacro(StopOnError, bool);
101     itkBooleanMacro(StopOnError);    
102
103   protected:  
104     bool m_ReadOnDisk;
105     /// Call this function to dispatch an output towards the correct sink
106     template<class ImageType> 
107     void SetNextOutput(typename ImageType::Pointer output);
108
109     /// Call this function to get the nth itk input image, regardless of input source
110     template<class ImageType> 
111     typename ImageType::Pointer GetInput(unsigned int n);
112
113     std::vector<std::string> m_InputFilenames;
114     std::list<std::string> m_OutputFilenames;
115
116     bool m_IOVerbose;
117     unsigned int m_Dim;
118     std::string m_PixelTypeName;
119     unsigned int m_NbOfComponents;
120     std::string m_FilterName;
121
122     std::vector<vvImage::Pointer> m_InputVVImages;
123     std::vector<vvImage::Pointer> m_OutputVVImages;
124
125     void ImageTypeError();
126     void SetImageTypeError();
127     bool m_FailOnImageTypeError;
128     
129     std::string m_LastError;
130     void SetFilterBase(FilterBase * f) { m_FilterBase = f; }
131     FilterBase * m_FilterBase;
132     bool m_StopOnError;
133
134   }; // end class clitk::ImageToImageGenericFilter
135
136 #define ADD_VEC_IMAGE_TYPE(DIM, COMP, PT) this->mImageTypesManager.template AddNewDimensionAndPixelType<DIM,COMP, PT>();
137 #define ADD_IMAGE_TYPE(DIM, PT) this->mImageTypesManager.template AddNewDimensionAndPixelType<DIM, PT>();
138 #define ADD_DEFAULT_IMAGE_TYPES(DIM) ADD_IMAGE_TYPE(DIM, char);   \
139                                      ADD_IMAGE_TYPE(DIM, uchar);  \
140                                      ADD_IMAGE_TYPE(DIM, short);  \
141                                      ADD_IMAGE_TYPE(DIM, ushort); \
142                                      ADD_IMAGE_TYPE(DIM, int);    \
143                                      ADD_IMAGE_TYPE(DIM, float);  \
144                                      ADD_IMAGE_TYPE(DIM, double);
145
146   //#include "clitkImageToImageGenericFilterBase.txx"
147
148 } // end namespace
149
150 #endif /* end #define CLITKIMAGETOIMAGEGENERICFILTERBASE_H */
151