]> Creatis software - clitk.git/blob - itk/clitkAddRelativePositionConstraintToLabelImageFilter.h
constraint a binary image to be at a relative position of an object
[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://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 CLITKADDRELATIVEPOSITIONCONSTRAINTTOLABELIMAGEFILTER_H
20 #define CLITKADDRELATIVEPOSITIONCONSTRAINTTOLABELIMAGEFILTER_H
21
22 // clitk
23 #include "clitkFilterBase.h"
24
25 // itk
26 #include "itkPasteImageFilter.h"
27
28 // itk ENST
29 #include "RelativePositionPropImageFilter.h"
30
31 namespace clitk {
32   
33   //--------------------------------------------------------------------
34   /*
35     Let A be an initial label image.
36     Let B be a label image with an object. 
37     Let o be an orientation relatively to the B object (for example RightTo, AntTo, InferiorTo ...)
38
39     This filter removes (=set background) from A all points that are
40     not in the wanted o orientation. It uses downsampled version for
41     faster processing, and (try to) take into account discretization
42     problem. Uses [Bloch 1999].
43   */
44   //--------------------------------------------------------------------
45   
46   template <class TImageType>
47   class ITK_EXPORT AddRelativePositionConstraintToLabelImageFilter:
48     public clitk::FilterBase, 
49     public itk::ImageToImageFilter<TImageType, TImageType> 
50   {
51
52   public:
53     /** Standard class typedefs. */
54     typedef itk::ImageToImageFilter<TImageType, TImageType> Superclass;
55     typedef AddRelativePositionConstraintToLabelImageFilter    Self;
56     typedef itk::SmartPointer<Self>                            Pointer;
57     typedef itk::SmartPointer<const Self>                      ConstPointer;
58        
59     /** Method for creation through the object factory. */
60     itkNewMacro(Self);
61     
62     /** Run-time type information (and related methods). */
63     itkTypeMacro(AddRelativePositionConstraintToLabelImageFilter, ImageToImageFilter);
64     FILTERBASE_INIT;
65
66     /** Some convenient typedefs. */
67     typedef TImageType                      ImageType;
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     
75     /** ImageDimension constants */
76     itkStaticConstMacro(ImageDimension, unsigned int, TImageType::ImageDimension);
77     typedef itk::Image<float, ImageDimension> FloatImageType;
78
79     /** Orientation types */
80     typedef enum { RightTo = 0, LeftTo = 1,
81                    AntTo = 2,   PostTo = 3, 
82                    InfTo = 4,   SupTo = 5, Angle = 6
83     } OrientationTypeEnumeration;
84
85     /** Input : initial image and object */
86     void SetInput(const ImageType * image);
87     void SetInputObject(const ImageType * image);
88     
89     // Options
90     void SetOrientationType(OrientationTypeEnumeration orientation);
91     itkGetConstMacro(OrientationType, OrientationTypeEnumeration);
92     void SetAngle1(double a);
93     void SetAngle2(double a);
94     itkGetConstMacro(Angle1, double);
95     itkGetConstMacro(Angle2, double);
96     itkGetConstMacro(ResampleBeforeRelativePositionFilter, bool);
97     itkSetMacro(ResampleBeforeRelativePositionFilter, bool);
98     itkBooleanMacro(ResampleBeforeRelativePositionFilter);
99     itkGetConstMacro(IntermediateSpacing, double);
100     itkSetMacro(IntermediateSpacing, double);
101     itkGetConstMacro(FuzzyThreshold, double);
102     itkSetMacro(FuzzyThreshold, double);
103     itkGetConstMacro(BackgroundValue, PixelType);
104     itkSetMacro(BackgroundValue, PixelType);
105     itkGetConstMacro(ObjectBackgroundValue, PixelType);
106     itkSetMacro(ObjectBackgroundValue, PixelType);
107
108   protected:
109     AddRelativePositionConstraintToLabelImageFilter();
110     virtual ~AddRelativePositionConstraintToLabelImageFilter() {}
111     
112     OrientationTypeEnumeration m_OrientationType;
113     double m_IntermediateSpacing;
114     double m_FuzzyThreshold;
115     PixelType m_BackgroundValue;
116     PixelType m_ObjectBackgroundValue;
117     double m_Angle1;
118     double m_Angle2;
119     bool m_ResampleBeforeRelativePositionFilter;
120
121     virtual void GenerateOutputInformation();
122     virtual void GenerateInputRequestedRegion();
123     virtual void GenerateData();
124
125     typedef itk::PasteImageFilter<ImageType,ImageType> PadFilterType;
126     typename ImageType::Pointer working_image;
127     typename ImageType::Pointer object_resampled;
128     typename FloatImageType::Pointer relPos;
129     ImagePointer input;
130     ImagePointer object;
131
132   private:
133     AddRelativePositionConstraintToLabelImageFilter(const Self&); //purposely not implemented
134     void operator=(const Self&); //purposely not implemented
135     
136   }; // end class
137   //--------------------------------------------------------------------
138
139 } // end namespace clitk
140 //--------------------------------------------------------------------
141
142 #ifndef ITK_MANUAL_INSTANTIATION
143 #include "clitkAddRelativePositionConstraintToLabelImageFilter.txx"
144 #endif
145
146 #endif