]> Creatis software - cpMesh.git/blob - lib/cpm/Algorithms/QuadEdge/DecimationCriteria.h
First commit
[cpMesh.git] / lib / cpm / Algorithms / QuadEdge / DecimationCriteria.h
1 #ifndef __CPM__ALGORITHMS__QUADEDGE__DECIMATIONCRITERIA__H__
2 #define __CPM__ALGORITHMS__QUADEDGE__DECIMATIONCRITERIA__H__
3
4 #include <itkIntTypes.h>
5 #include <itkPriorityQueueContainer.h>
6
7 namespace cpm
8 {
9   namespace Algorithms
10   {
11     namespace QuadEdge
12     {
13       /**
14        */
15       template< class M, class E  = unsigned long, class S = double, class Q = itk::MinPriorityQueueElementWrapper< class M::TPrimalEdge*, std::pair< bool, S > > >
16       class DecimationCriterion
17         : public itk::Object
18       {
19       public:
20         typedef DecimationCriterion             Self;
21         typedef itk::SmartPointer< Self >       Pointer;
22         typedef itk::SmartPointer< const Self > ConstPointer;
23         typedef itk::Object                     Superclass;
24
25         typedef M TMesh;
26         typedef E TElement;
27         typedef S TScalar;
28         typedef Q TQueueWrapper;
29         typedef typename Q::ElementPriorityType TPriority;
30
31       public:
32         itkTypeMacro( DecimationCriterion, itkObject );
33
34         itkBooleanMacro( TopologicalChange );
35         itkGetConstMacro( TopologicalChange, bool );
36         itkSetMacro( TopologicalChange, bool );
37
38         void SetNumberOfElements( const unsigned long& numberOfElements )
39           {
40             this->m_SizeCriterion = true;
41             this->m_NumberOfElements = numberOfElements;
42           }
43
44         void SetMeasureBound( const S& bound )
45           {
46             this->m_SizeCriterion = false;
47             this->m_MeasureBound = bound;
48           }
49
50         virtual bool is_satisfied( M* m, const E& e, const S& v ) const = 0;
51
52       protected:
53         DecimationCriterion( )
54           : Superclass( )
55           {
56             this->m_TopologicalChange = true;
57             this->m_SizeCriterion = true;
58             this->m_NumberOfElements = 0;
59             this->m_MeasureBound = itk::NumericTraits< TScalar >::Zero;
60           }
61         virtual ~DecimationCriterion( )
62           { }
63
64       protected:
65         bool          m_TopologicalChange;
66         bool          m_SizeCriterion;
67         unsigned long m_NumberOfElements;
68         S             m_MeasureBound;
69
70       private:
71         // Purposely not implemented
72         DecimationCriterion( const Self& );
73         void operator=( const Self& );
74       };
75
76       /**
77        */
78       template< class M, class E = unsigned long, class S = double, class Q = itk::MinPriorityQueueElementWrapper< class M::TPrimalEdge*, std::pair< bool, S > > >
79       class NumberOfPointsCriterion
80         : public DecimationCriterion< M, E, S, Q >
81       {
82       public:
83         typedef NumberOfPointsCriterion           Self;
84         typedef DecimationCriterion< M, E, S, Q > Superclass;
85         typedef itk::SmartPointer< Self >         Pointer;
86         typedef itk::SmartPointer< const Self >   ConstPointer;
87
88         typedef typename Superclass::TMesh         TMesh;
89         typedef typename Superclass::TElement      TElement;
90         typedef typename Superclass::TScalar       TScalar;
91         typedef typename Superclass::TQueueWrapper TQueueWrapper;
92         typedef typename Superclass::TPriority     TPriority;
93
94       public:
95         itkNewMacro( Self );
96         itkTypeMacro( NumberOfPointsCriterion, DecimationCriterion );
97
98       public:
99         inline bool is_satisfied( M* m, const E& e, const S& v ) const
100           {
101             return( m->GetNumberOfPoints( ) <= this->m_NumberOfElements );
102           }
103
104       protected:
105         NumberOfPointsCriterion( )
106           : Superclass( )
107           { }
108         virtual ~NumberOfPointsCriterion( )
109           { }
110
111       private:
112         // Purposely not implemented
113         NumberOfPointsCriterion( const Self& );
114         void operator=( const Self& );
115       };
116
117       /**
118        */
119       template< class M, class E = unsigned long, class S = double, class Q = itk::MinPriorityQueueElementWrapper< class M::TPrimalEdge*, std::pair< bool, S > > >
120       class NumberOfFacesCriterion
121         : public DecimationCriterion< M, E, S, Q >
122       {
123       public:
124         typedef NumberOfFacesCriterion            Self;
125         typedef DecimationCriterion< M, E, S, Q > Superclass;
126         typedef itk::SmartPointer< Self >         Pointer;
127         typedef itk::SmartPointer< const Self >   ConstPointer;
128
129         typedef typename Superclass::TMesh         TMesh;
130         typedef typename Superclass::TElement      TElement;
131         typedef typename Superclass::TScalar       TScalar;
132         typedef typename Superclass::TQueueWrapper TQueueWrapper;
133         typedef typename Superclass::TPriority     TPriority;
134
135       public:
136         itkNewMacro( Self );
137         itkTypeMacro( NumberOfFacesCriterion, DecimationCriterion );
138
139       public:
140         inline bool is_satisfied( M* m, const E& e, const S& v ) const
141           {
142             return( m->GetNumberOfFaces( ) <= this->m_NumberOfElements );
143           }
144
145       protected:
146         NumberOfFacesCriterion( )
147           : Superclass( )
148           { }
149         virtual ~NumberOfFacesCriterion( )
150           { }
151
152       private:
153         // Purposely not implemented
154         NumberOfFacesCriterion( const Self& );
155         void operator=( const Self& );
156       };
157
158       /**
159        */
160       template< class M, class E = unsigned long, class S = double, class Q = itk::MinPriorityQueueElementWrapper< class M::TPrimalEdge*, std::pair< bool, S > > >
161       class MaxMeasureBoundCriterion
162         : public DecimationCriterion< M, E, S, Q >
163       {
164       public:
165         typedef MaxMeasureBoundCriterion          Self;
166         typedef DecimationCriterion< M, E, S, Q > Superclass;
167         typedef itk::SmartPointer< Self >         Pointer;
168         typedef itk::SmartPointer< const Self >   ConstPointer;
169
170         typedef typename Superclass::TMesh         TMesh;
171         typedef typename Superclass::TElement      TElement;
172         typedef typename Superclass::TScalar       TScalar;
173         typedef typename Superclass::TQueueWrapper TQueueWrapper;
174         typedef typename Superclass::TPriority     TPriority;
175
176       public:
177         itkNewMacro( Self );
178         itkTypeMacro( MaxMeasureBoundCriterion, DecimationCriterion );
179
180         inline bool is_satisfied( M* m, const E& e, const S& v ) const
181           {
182             return( v <= this->m_MeasureBound );
183           }
184
185       protected:
186         MaxMeasureBoundCriterion( )
187           : Superclass( )
188           { }
189         virtual ~MaxMeasureBoundCriterion( )
190           { }
191
192       private:
193         // Purposely not implemented
194         MaxMeasureBoundCriterion( const Self& );
195         void operator=( const Self& );
196       };
197
198       /**
199        */
200       template< class M, class E = unsigned long, class S = double, class Q = itk::MaxPriorityQueueElementWrapper< class M::TPrimalEdge*, std::pair< bool, S > > >
201       class MinMeasureBoundCriterion
202         : public DecimationCriterion< M, E, S, Q >
203       {
204       public:
205         typedef MinMeasureBoundCriterion          Self;
206         typedef DecimationCriterion< M, E, S, Q > Superclass;
207         typedef itk::SmartPointer< Self >         Pointer;
208         typedef itk::SmartPointer< const Self >   ConstPointer;
209
210         typedef typename Superclass::TMesh         TMesh;
211         typedef typename Superclass::TElement      TElement;
212         typedef typename Superclass::TScalar       TScalar;
213         typedef typename Superclass::TQueueWrapper TQueueWrapper;
214         typedef typename Superclass::TPriority     TPriority;
215
216       public:
217         itkNewMacro( Self );
218         itkTypeMacro( MinMeasureBoundCriterion, DecimationCriterion );
219
220         inline bool is_satisfied( M* m, const E& e, const S& v ) const
221           {
222             return( v >= this->m_MeasureBound );
223           }
224
225       protected:
226         MinMeasureBoundCriterion( )
227           : Superclass( )
228           { }
229         virtual ~MinMeasureBoundCriterion( )
230           { }
231
232       private:
233         // Purposely not implemented
234         MinMeasureBoundCriterion( const Self& );
235         void operator=( const Self& );
236       };
237
238     } // ecapseman
239
240   } // ecapseman
241
242 } // ecapseman
243
244 #endif // __CPM__ALGORITHMS__QUADEDGE__DECIMATIONCRITERIA__H__
245
246 // eof - $RCSfile$