]> Creatis software - clitk.git/blob - itk/clitkAddRelativePositionConstraintToLabelImageFilter.h
45f331ed9d7cf5e55989a1852a54f9737bdccc90
[clitk.git] / itk / clitkAddRelativePositionConstraintToLabelImageFilter.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 CLITKADDRELATIVEPOSITIONCONSTRAINTTOLABELIMAGEFILTER_H
20 #define CLITKADDRELATIVEPOSITIONCONSTRAINTTOLABELIMAGEFILTER_H
21
22 // clitk
23 #include "clitkFilterBase.h"
24 #include "clitkCropLikeImageFilter.h"
25
26 // itk
27 #include <itkPasteImageFilter.h>
28
29 // itk ENST
30 #include "RelativePositionPropImageFilter.h"
31
32 namespace clitk {
33   
34   //--------------------------------------------------------------------
35   /*
36     Let A be an initial label image.
37     Let B be a label image with an object. 
38     Let o be an orientation relatively to the B object (for example RightTo, AntTo, InferiorTo ...)
39
40     This filter removes (=set background) from A all points that are
41     not in the wanted o orientation. It uses downsampled version for
42     faster processing, and (try to) take into account discretization
43     problem. Uses [Bloch 1999].
44   */
45   //--------------------------------------------------------------------
46   
47   template <class ImageType>
48   class ITK_EXPORT AddRelativePositionConstraintToLabelImageFilter:
49     public clitk::FilterBase, 
50     public itk::ImageToImageFilter<ImageType, ImageType> 
51   {
52
53   public:
54     /** Standard class typedefs. */
55     typedef itk::ImageToImageFilter<ImageType, ImageType>      Superclass;
56     typedef AddRelativePositionConstraintToLabelImageFilter    Self;
57     typedef itk::SmartPointer<Self>                            Pointer;
58     typedef itk::SmartPointer<const Self>                      ConstPointer;
59        
60     /** Method for creation through the object factory. */
61     itkNewMacro(Self);
62     
63     /** Run-time type information (and related methods). */
64     itkTypeMacro(AddRelativePositionConstraintToLabelImageFilter, ImageToImageFilter);
65     FILTERBASE_INIT;
66
67     /** Some convenient typedefs. */
68     typedef typename ImageType::ConstPointer ImageConstPointer;
69     typedef typename ImageType::Pointer      ImagePointer;
70     typedef typename ImageType::RegionType   RegionType; 
71     typedef typename ImageType::PixelType    PixelType;
72     typedef typename ImageType::SpacingType  SpacingType;
73     typedef typename ImageType::SizeType     SizeType;
74     typedef typename ImageType::IndexType    IndexType;
75     typedef typename ImageType::PointType    PointType;
76     
77     /** ImageDimension constants */
78     itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension);
79     typedef itk::Image<float, ImageDimension> FloatImageType;
80
81     /** Orientation types */
82     typedef enum { RightTo = 0, LeftTo = 1,
83                    AntTo = 2,   PostTo = 3, 
84                    InfTo = 4,   SupTo = 5, Angle = 6
85     } OrientationTypeEnumeration;
86
87     /** Input : initial image and object */
88     void SetInput(const ImageType * image) ITK_OVERRIDE;
89     void SetInputObject(const ImageType * image);
90     
91     // Options
92     void AddOrientationType(OrientationTypeEnumeration orientation);
93     void AddOrientationTypeString(std::string s);
94     void ClearOrientationType();
95     void AddAnglesInRad(double a, double b);
96     void AddAnglesInDeg(double a, double b);
97     double GetAngle1InRad(int i) { return m_Angle1[i]; }
98     double GetAngle2InRad(int i) { return m_Angle2[i]; }
99     int GetNumberOfAngles();
100     std::string GetOrientationTypeString(int i) { return m_OrientationTypeString[i]; }
101     std::vector<std::string> & GetOrientationTypeString() { return m_OrientationTypeString; }
102
103     itkGetConstMacro(IntermediateSpacingFlag, bool);
104     itkSetMacro(IntermediateSpacingFlag, bool);
105     itkBooleanMacro(IntermediateSpacingFlag);
106
107     itkGetConstMacro(IntermediateSpacing, double);
108     itkSetMacro(IntermediateSpacing, double);
109
110     itkGetConstMacro(FuzzyThreshold, double);
111     itkSetMacro(FuzzyThreshold, double);
112
113     itkGetConstMacro(BackgroundValue, PixelType);
114     itkSetMacro(BackgroundValue, PixelType);
115
116     itkGetConstMacro(ObjectBackgroundValue, PixelType);
117     itkSetMacro(ObjectBackgroundValue, PixelType);
118
119     itkGetConstMacro(AutoCropFlag, bool);
120     itkSetMacro(AutoCropFlag, bool);
121     itkBooleanMacro(AutoCropFlag);
122
123     itkGetConstMacro(InverseOrientationFlag, bool);
124     itkSetMacro(InverseOrientationFlag, bool);
125     itkBooleanMacro(InverseOrientationFlag);
126
127     itkGetConstMacro(RemoveObjectFlag, bool);
128     itkSetMacro(RemoveObjectFlag, bool);
129     itkBooleanMacro(RemoveObjectFlag);
130
131     itkGetConstMacro(CombineWithOrFlag, bool);
132     itkSetMacro(CombineWithOrFlag, bool);
133     itkBooleanMacro(CombineWithOrFlag);
134
135     itkGetConstMacro(FuzzyMapOnlyFlag, bool);
136     itkSetMacro(FuzzyMapOnlyFlag, bool);
137     itkBooleanMacro(FuzzyMapOnlyFlag);
138
139     itkGetConstMacro(FastFlag, bool);
140     itkSetMacro(FastFlag, bool);
141     itkBooleanMacro(FastFlag);
142
143     itkGetConstMacro(Radius, double);
144     itkSetMacro(Radius, double);
145
146     itkSetMacro(K1, double);
147     itkGetMacro(K1, double);
148
149     typename FloatImageType::Pointer GetFuzzyMap() { return m_FuzzyMap; }
150
151     // I dont want to verify inputs information
152     virtual void VerifyInputInformation() ITK_OVERRIDE { }
153     
154     // For debug
155     void PrintOptions();
156
157   protected:
158     AddRelativePositionConstraintToLabelImageFilter();
159     virtual ~AddRelativePositionConstraintToLabelImageFilter() {}
160     
161     std::vector<OrientationTypeEnumeration> m_OrientationType;
162     std::vector<std::string> m_OrientationTypeString;
163     double m_IntermediateSpacing;
164     double m_FuzzyThreshold;
165     PixelType m_BackgroundValue;
166     PixelType m_ObjectBackgroundValue;
167     std::vector<double> m_Angle1;
168     std::vector<double> m_Angle2;
169     bool m_IntermediateSpacingFlag;
170     bool m_AutoCropFlag;
171     bool m_InverseOrientationFlag;
172     bool m_RemoveObjectFlag;
173     bool m_CombineWithOrFlag;
174     bool m_FuzzyMapOnlyFlag;
175     bool m_FastFlag;
176     double m_Radius;
177     double m_K1;
178
179     virtual void GenerateOutputInformation() ITK_OVERRIDE;
180     virtual void GenerateInputRequestedRegion() ITK_OVERRIDE;
181     virtual void GenerateData() ITK_OVERRIDE;
182
183     typedef itk::PasteImageFilter<ImageType,ImageType> PasteFilterType;
184     typedef itk::PasteImageFilter<FloatImageType,FloatImageType> PasteFloatFilterType;
185     typename ImageType::Pointer working_image;
186     typename ImageType::Pointer object_resampled;
187     typename FloatImageType::Pointer relPos;
188     typename FloatImageType::Pointer m_FuzzyMap;
189     ImagePointer input;
190     ImagePointer object;
191
192   private:
193     AddRelativePositionConstraintToLabelImageFilter(const Self&); //purposely not implemented
194     void operator=(const Self&); //purposely not implemented
195     
196   }; // end class
197   //--------------------------------------------------------------------
198
199 } // end namespace clitk
200 //--------------------------------------------------------------------
201
202 #ifndef ITK_MANUAL_INSTANTIATION
203 #include "clitkAddRelativePositionConstraintToLabelImageFilter.txx"
204 #endif
205
206 #endif