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