]> Creatis software - clitk.git/blob - itk/clitkAddRelativePositionConstraintToLabelImageFilter.h
Merge branch 'master' of /home/dsarrut/clitk3.server
[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);
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 AddAngles(double a, double b);
96     int GetNumberOfAngles();
97     std::string GetOrientationTypeString(int i) { return m_OrientationTypeString[i]; }
98     std::vector<std::string> & GetOrientationTypeString() { return m_OrientationTypeString; }
99
100     itkGetConstMacro(IntermediateSpacingFlag, bool);
101     itkSetMacro(IntermediateSpacingFlag, bool);
102     itkBooleanMacro(IntermediateSpacingFlag);
103
104     itkGetConstMacro(IntermediateSpacing, double);
105     itkSetMacro(IntermediateSpacing, double);
106
107     itkGetConstMacro(FuzzyThreshold, double);
108     itkSetMacro(FuzzyThreshold, double);
109
110     itkGetConstMacro(BackgroundValue, PixelType);
111     itkSetMacro(BackgroundValue, PixelType);
112
113     itkGetConstMacro(ObjectBackgroundValue, PixelType);
114     itkSetMacro(ObjectBackgroundValue, PixelType);
115
116     itkGetConstMacro(AutoCropFlag, bool);
117     itkSetMacro(AutoCropFlag, bool);
118     itkBooleanMacro(AutoCropFlag);
119
120     itkGetConstMacro(InverseOrientationFlag, bool);
121     itkSetMacro(InverseOrientationFlag, bool);
122     itkBooleanMacro(InverseOrientationFlag);
123
124     itkGetConstMacro(RemoveObjectFlag, bool);
125     itkSetMacro(RemoveObjectFlag, bool);
126     itkBooleanMacro(RemoveObjectFlag);
127
128     itkGetConstMacro(CombineWithOrFlag, bool);
129     itkSetMacro(CombineWithOrFlag, bool);
130     itkBooleanMacro(CombineWithOrFlag);
131
132     itkGetConstMacro(FuzzyMapOnlyFlag, bool);
133     itkSetMacro(FuzzyMapOnlyFlag, bool);
134     itkBooleanMacro(FuzzyMapOnlyFlag);
135
136     typename FloatImageType::Pointer GetFuzzyMap() { return m_FuzzyMap; }
137
138     // I dont want to verify inputs information
139     virtual void VerifyInputInformation() { }
140     
141     // For debug
142     void PrintOptions();
143
144   protected:
145     AddRelativePositionConstraintToLabelImageFilter();
146     virtual ~AddRelativePositionConstraintToLabelImageFilter() {}
147     
148     std::vector<OrientationTypeEnumeration> m_OrientationType;
149     std::vector<std::string> m_OrientationTypeString;
150     double m_IntermediateSpacing;
151     double m_FuzzyThreshold;
152     PixelType m_BackgroundValue;
153     PixelType m_ObjectBackgroundValue;
154     std::vector<double> m_Angle1;
155     std::vector<double> m_Angle2;
156     bool m_IntermediateSpacingFlag;
157     bool m_AutoCropFlag;
158     bool m_InverseOrientationFlag;
159     bool m_RemoveObjectFlag;
160     bool m_CombineWithOrFlag;
161     bool m_FuzzyMapOnlyFlag;
162
163     virtual void GenerateOutputInformation();
164     virtual void GenerateInputRequestedRegion();
165     virtual void GenerateData();
166
167     typedef itk::PasteImageFilter<ImageType,ImageType> PasteFilterType;
168     typename ImageType::Pointer working_image;
169     typename ImageType::Pointer object_resampled;
170     typename FloatImageType::Pointer relPos;
171     typename FloatImageType::Pointer m_FuzzyMap;
172     ImagePointer input;
173     ImagePointer object;
174
175   private:
176     AddRelativePositionConstraintToLabelImageFilter(const Self&); //purposely not implemented
177     void operator=(const Self&); //purposely not implemented
178     
179   }; // end class
180   //--------------------------------------------------------------------
181
182 } // end namespace clitk
183 //--------------------------------------------------------------------
184
185 #ifndef ITK_MANUAL_INSTANTIATION
186 #include "clitkAddRelativePositionConstraintToLabelImageFilter.txx"
187 #endif
188
189 #endif