]> Creatis software - clitk.git/blob - segmentation/clitkMorphoMathFilter.h
Merge branch 'master' of tux.creatis.insa-lyon.fr:clitk
[clitk.git] / segmentation / clitkMorphoMathFilter.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 CLITKMORPHOMATHFILTER_H
20 #define CLITKMORPHOMATHFILTER_H
21
22 // clitk include
23 #include "clitkIO.h"
24 #include "clitkImageCommon.h"
25 #include "clitkMorphoMath_ggo.h"
26 #include "clitkConditionalBinaryErodeImageFilter.h"
27 #include "clitkConditionalBinaryDilateImageFilter.h"
28
29 // itk include
30 #include <itkLightObject.h>
31 #include <itkBinaryErodeImageFilter.h>
32 #include <itkBinaryDilateImageFilter.h>
33 #include <itkBinaryMorphologicalClosingImageFilter.h>
34 #include <itkBinaryMorphologicalOpeningImageFilter.h>
35 #include <itkBinaryBallStructuringElement.h>
36 #include <itkCastImageFilter.h>
37
38 namespace clitk {
39
40   //--------------------------------------------------------------------
41   template<class ImageType>
42   class ITK_EXPORT MorphoMathFilter: 
43     public clitk::FilterBase, 
44     public itk::ImageToImageFilter<ImageType, ImageType> 
45   {
46     
47   public: 
48     /** Standard class typedefs. */
49     typedef itk::ImageToImageFilter<ImageType, ImageType> Superclass;
50     typedef MorphoMathFilter<ImageType>                   Self;
51     typedef itk::SmartPointer<Self>                       Pointer;
52     typedef itk::SmartPointer<const Self>                 ConstPointer;
53
54     /** Method for creation through the object factory. */
55     itkNewMacro(Self);  
56     
57     /** Run-time type information (and related methods). */
58     itkTypeMacro(AddRelativePositionConstraintToLabelImageFilter, ImageToImageFilter);
59     FILTERBASE_INIT;
60
61     /** Some convenient typedefs. */
62     typedef typename ImageType::ConstPointer ImageConstPointer;
63     typedef typename ImageType::Pointer      ImagePointer;
64     typedef typename ImageType::RegionType   RegionType; 
65     typedef typename ImageType::PixelType    PixelType;
66     typedef typename ImageType::SpacingType  SpacingType;
67     typedef typename ImageType::SizeType     SizeType;
68     typedef typename ImageType::IndexType    IndexType;
69     typedef typename ImageType::PointType    PointType;
70     typedef float InternalPixelType;
71     typedef itk::Image<InternalPixelType, ImageType::ImageDimension> InternalImageType;
72     
73     /** ImageDimension constants */
74     itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension);
75     typedef itk::Image<float, ImageDimension> FloatImageType;
76
77     /** Operation types */
78     typedef enum { Erode     = 0, Dilate     = 1,
79                    Close     = 2, Open       = 3, 
80                    CondErode = 4, CondDilate = 5
81     } OperationTypeEnumeration;
82     
83     /** Options */
84     itkGetConstMacro(VerboseFlag, bool);
85     itkSetMacro(VerboseFlag, bool);
86     itkBooleanMacro(VerboseFlag);
87
88     itkGetConstMacro(BackgroundValue, PixelType);
89     itkSetMacro(BackgroundValue, PixelType);
90
91     itkGetConstMacro(ForegroundValue, PixelType);
92     itkSetMacro(ForegroundValue, PixelType);
93
94     void SetOperationType(int type);
95     
96     itkGetConstMacro(RadiusInMM, PointType);
97     void SetRadiusInMM(PointType & p);
98
99     itkGetConstMacro(Radius, SizeType);
100     void SetRadius(SizeType & r);
101     void SetRadius(int r);
102
103     itkGetConstMacro(BoundaryToForegroundFlag, bool);
104     itkSetMacro(BoundaryToForegroundFlag, bool);
105     itkBooleanMacro(BoundaryToForegroundFlag);
106     
107     itkGetConstMacro(ExtendSupportFlag, bool);
108     itkSetMacro(ExtendSupportFlag, bool);
109     itkBooleanMacro(ExtendSupportFlag);
110     
111   protected:
112     MorphoMathFilter();
113     virtual ~MorphoMathFilter();
114
115     bool m_VerboseFlag;
116     PixelType m_BackgroundValue;
117     PixelType m_ForegroundValue;
118     PointType m_RadiusInMM;
119     SizeType  m_Radius;
120     bool m_RadiusInMMIsSet;
121     bool m_RadiusIsSet;
122     OperationTypeEnumeration m_OperationType;
123     bool m_BoundaryToForegroundFlag;
124     bool m_ExtendSupportFlag;
125     typename InternalImageType::Pointer input;
126
127     virtual void GenerateOutputInformation();
128     virtual void GenerateInputRequestedRegion();
129     virtual void GenerateData();
130
131   private:
132     MorphoMathFilter(const Self&); //purposely not implemented
133     void operator=(const Self&); //purposely not implemented
134   };
135   
136 } // end namespace clitk
137 #ifndef ITK_MANUAL_INSTANTIATION
138 #include "clitkMorphoMathFilter.txx"
139 #endif
140   
141 #endif //#define CLITKMORPHOMATHFILTER_H