]> Creatis software - clitk.git/blob - itk/RelativePositionPropImageFilter.h
fca49f68000236d75cf7865319970cf185a27946
[clitk.git] / itk / RelativePositionPropImageFilter.h
1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: RelativePositionPropImageFilter.h,v $
5   Language:  C++
6   Date:      $Date: 2010/07/12 06:57:25 $
7   Version:   $Revision: 1.2 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12   This software is distributed WITHOUT ANY WARRANTY; without even 
13   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14   PURPOSE.  See the above copyright notices for more information.
15
16   =========================================================================*/
17
18 #ifndef __RelativePositionPropImageFilter_h
19 #define __RelativePositionPropImageFilter_h
20
21 #include "itkImageToImageFilter.h"
22 #include "itkImage.h"
23 #include "itkConceptChecking.h"
24 #include "itkPointSet.h"
25 #include "itkImageRegionConstIteratorWithIndex.h"
26 #include "itkImageRegionIteratorWithIndex.h"
27 #include "itkMinimumImageFilter.h"
28
29 namespace itk
30 {
31
32
33   /** \class RelativePositionPropImageFilter
34    * \brief Compute the fuzzy subset of an image which satisfies some directional relative position.
35    * \author Jamal Atif and Olivier Nempont
36    * 
37    * This filter computes a fuzzy subset of an image satisfying a particular directionnal relative position from an object (crisp or fuzzy).
38    *
39    * 
40    *    \par INPUT / OUTPUT
41    *    This filter takes a crisp or a fuzzy object as input. 
42    *  In fuzzy case, the values have to be defined between 0 and 1. 
43    *  
44    *  The result is a fuzzy subset which values are defined between
45    *  0 if the relation isn't fulfilled in this point to 1 is the relation is 
46    *  fully satisfied.
47    *  WARNING: the output image type as to be decimal.
48    *  
49    *    \par PARAMETERS
50    *  \par
51    *  The Alpha1 and Alpha2 parameters are used to specify the direction.
52    *  Alpha1 is the angle in 'xy' plane from 'x' unit vector.
53    *  Alpha2 is used in 3D to specify the angle with 'xy' plane
54    *  
55    *  \par
56    *    K is an opening parameter. Higher value enlarge the support of the result.
57    *  By default it is fixed at PI/2  
58    * 
59    *  \par REFERENCE
60    *   Fuzzy Relative Position Between Objects in Image Processing: A Morphological Approach
61    *     Isabelle Bloch
62    *   IEEE TRANSACTIONS ON PATTERN ANALYSIS AND MACHINE INTELLIGENCE, VOL. 21, NO. 7, JULY 1999
63    *   
64    *   This filter is implemented using the propagation algorithm
65    */
66  
67   template <class TInputImage, class TOutputImage, class TtNorm=Function::Minimum<
68                                                      typename TOutputImage::PixelType,
69                                                      typename TOutputImage::PixelType,
70                                                      typename TOutputImage::PixelType>  >
71   class ITK_EXPORT RelativePositionPropImageFilter :
72     public ImageToImageFilter< TInputImage, TOutputImage > 
73   {
74   public:
75     /** Standard class typedefs. */
76     typedef RelativePositionPropImageFilter Self;
77     typedef ImageToImageFilter< TInputImage, TOutputImage > Superclass;
78     typedef SmartPointer<Self> Pointer;
79     typedef SmartPointer<const Self>  ConstPointer;
80
81     /** Extract some information from the image types.  Dimensionality
82      * of the two images is assumed to be the same. */
83     typedef typename TOutputImage::PixelType OutputPixelType;
84     typedef typename TOutputImage::InternalPixelType OutputInternalPixelType;
85     typedef typename TInputImage::PixelType InputPixelType;
86     typedef typename TInputImage::InternalPixelType InputInternalPixelType;
87
88     /** Extract some information from the image types.  Dimensionality
89      * of the two images is assumed to be the same. */
90     itkStaticConstMacro(ImageDimension, unsigned int,
91                         TOutputImage::ImageDimension);
92   
93
94     typedef typename itk::Image<typename TInputImage::IndexType , ImageDimension>
95       CorrespondanceMapType;
96     typedef float TabulationPixelType;
97     typedef typename itk::Image<TabulationPixelType , ImageDimension> TabulationImageType;
98   
99   
100     /** Image typedef support. */
101     typedef TInputImage  InputImageType;
102     typedef TOutputImage OutputImageType;
103   
104     typedef TtNorm TNormType;
105   
106     typedef itk::Vector<double, ImageDimension> VectorType;
107
108
109     /** Method for creation through the object factory. */
110     itkNewMacro(Self);
111
112     /** Run-time type information (and related methods). */
113     itkTypeMacro(RelativePositionPropImageFilter, ImageToImageFilter);
114
115     /** The output pixel type must be signed. */
116     itkConceptMacro(SignedOutputPixelType, (Concept::Signed<OutputPixelType>));
117   
118     /** Standard get/set macros for filter parameters. */
119
120   
121     itkSetMacro(Alpha1, double);
122     itkGetMacro(Alpha1, double);
123     itkSetMacro(Alpha2, double);
124     itkGetMacro(Alpha2, double);
125   
126     itkSetMacro(K1, double);
127     itkGetMacro(K1, double);
128     //   itkSetMacro(K2, double);
129     //   itkGetMacro(K2, double);
130
131     itkSetMacro(Radius, double);
132     itkGetMacro(Radius, double);
133
134     itkSetMacro(VerboseProgress, bool);
135     itkGetMacro(VerboseProgress, bool);
136     itkBooleanMacro(VerboseProgress);
137
138     itkSetMacro(Fast, bool);
139     itkGetMacro(Fast, bool);
140     itkBooleanMacro(Fast);
141   
142     void computeDirection()
143     {
144       if (ImageDimension == 2) {
145           m_DirectionVector[0]=cos(m_Alpha1);
146           m_DirectionVector[1]=sin(m_Alpha1);           
147         }
148       else { // 3D
149         m_DirectionVector[0]=cos(m_Alpha1)*cos(m_Alpha2);
150         m_DirectionVector[1]=cos(m_Alpha2)*sin(m_Alpha1);
151         m_DirectionVector[2]=sin(m_Alpha2);
152       }
153     }
154   
155
156     virtual void GenerateInputRequestedRegion() throw(InvalidRequestedRegionError);
157     void EnlargeOutputRequestedRegion (DataObject * output);
158
159   protected:
160     RelativePositionPropImageFilter()
161       {
162         m_Alpha1 = 0;
163         m_Alpha2 = 0;
164         m_K1 = vcl_acos(-1.0)/2;
165         // m_K2 = 3.1417/2;
166         m_Radius = 2; // DS
167         m_Fast = true; // DS
168         m_VerboseProgress = false;
169       }
170     virtual ~RelativePositionPropImageFilter() {}
171     void PrintSelf(std::ostream& os, Indent indent) const;
172
173     //void GenerateThreadedData(const typename TOutputImage::RegionType& outputRegionForThread, int threadId);
174     void GenerateData();
175
176   private:
177     RelativePositionPropImageFilter(const Self&); //purposely not implemented
178     void operator=(const Self&); //purposely not implemented
179
180
181     /** The angles*/
182     double m_Alpha1; 
183     double m_Alpha2; 
184     double m_K1;
185     // double m_K2;
186   
187     unsigned int m_Radius;
188     TNormType m_TNorm;
189     bool m_VerboseProgress;
190      
191     VectorType m_DirectionVector; 
192
193     /**
194      * 2 pass instead of 2^NDimension. Warning this may cause some artifacts 
195      */
196     bool m_Fast;
197
198     //allocation et initialisation de la carte de correspondance
199     typename CorrespondanceMapType::Pointer InitCorrespondanceMap();
200   
201     //compute the tabulation map
202     typename TabulationImageType::Pointer ComputeAngleTabulation();
203   
204   
205   };
206   
207 } // end namespace itk
208
209 #ifndef ITK_MANUAL_INSTANTIATION
210 #include "RelativePositionPropImageFilter.txx"
211 #endif
212
213 #endif