Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
EuclideanShapesDecorator.h
1
16
17#pragma once
18
29
30#if defined(EuclideanShapesDecorator_RECURSES)
31#error Recursive header files inclusion detected in EuclideanShapesDecorator.h
32#else // defined(EuclideanShapesDecorator_RECURSES)
34#define EuclideanShapesDecorator_RECURSES
35
36#if !defined EuclideanShapesDecorator_h
38#define EuclideanShapesDecorator_h
39
41// Inclusions
42#include <iostream>
43#include "DGtal/base/Common.h"
44#include "DGtal/base/ConstAlias.h"
45
46#include "DGtal/shapes/CEuclideanBoundedShape.h"
47#include "DGtal/shapes/CEuclideanOrientedShape.h"
49
50namespace DGtal
51{
52
54 // template class EuclideanShapesCSG
66 template <typename ShapeA, typename ShapeB>
68 {
69 protected:
76
77 public:
80
81 typedef typename ShapeA::Space Space;
82 typedef typename ShapeA::RealPoint RealPoint;
83
89 : bIsValid(false)
90 {}
91
102
109 : myShapeA( a )
110 {
111 myLowerBound = myShapeA->getLowerBound();
112 myUpperBound = myShapeA->getUpperBound();
113
114 bIsValid = true;
115 }
116
125 {
126 myShapeA = other.myShapeA;
127 v_shapes = other.v_shapes;
128
131
132 bIsValid = other.bIsValid;
133
134 return *this;
135 }
136
143 {
144 myShapeA = a;
145
146 myLowerBound = myShapeA->getLowerBound();
147 myUpperBound = myShapeA->getUpperBound();
148
149 bIsValid = true;
150 }
151
159 {
162
163 FATAL_ERROR_MSG( isValid(), "Operation invalid. Maybe you don't set a ShapeA object." );
164
165 std::pair<e_operator, CountedConstPtrOrConstPtr< ShapeB > > shape( e_plus, b );
166
167 for(Dimension i =0; i < Space::dimension; ++i)
168 {
169 myLowerBound[i] = std::min(myLowerBound[i], b->getLowerBound()[i]);
170 myUpperBound[i] = std::max(myUpperBound[i], b->getUpperBound()[i]);
171 }
172
173 v_shapes.push_back(shape);
174 }
175
183 {
186
187 FATAL_ERROR_MSG( isValid(), "Operation invalid. Maybe you don't set a ShapeA object." );
188
189 std::pair<e_operator, CountedConstPtrOrConstPtr< ShapeB > > shape( e_intersection, b );
190
191 for(Dimension i=0; i < Space::dimension; ++i)
192 {
193 myLowerBound[i] = std::max(myLowerBound[i], b->getLowerBound()[i]);
194 myUpperBound[i] = std::min(myUpperBound[i], b->getUpperBound()[i]);
195 }
196
197 v_shapes.push_back(shape);
198 }
199
207 {
210
211 FATAL_ERROR_MSG( isValid(), "Operation invalid. Maybe you don't set a ShapeA object." );
212
213 std::pair<e_operator, CountedConstPtrOrConstPtr< ShapeB > > shape( e_minus, b );
214
215 v_shapes.push_back(shape);
216 }
217
223 {
224 FATAL_ERROR_MSG( isValid(), "Operation invalid. Maybe you don't set a ShapeA object." );
225
226 return myLowerBound;
227 }
228
234 {
235 FATAL_ERROR_MSG( isValid(), "Operation invalid. Maybe you don't set a ShapeA object." );
236
237 return myUpperBound;
238 }
239
249 {
250 FATAL_ERROR_MSG( isValid(), "Operation invalid. Maybe you don't set a ShapeA object." );
251
252 Orientation orient = myShapeA->orientation( p );
253
254 for(unsigned int i = 0; i < v_shapes.size(); ++i)
255 {
256 if( v_shapes[i].first == e_minus )
257 {
258 if (( v_shapes[i].second->orientation( p ) == INSIDE ) || ( v_shapes[i].second->orientation( p ) == ON ))
259 {
260 orient = OUTSIDE;
261 }
262 }
263 else if( v_shapes[i].first == e_intersection )
264 {
265 if (( orient == ON ) && ( v_shapes[i].second->orientation( p ) != OUTSIDE ))
266 {
267 orient = ON;
268 }
269 else if (( v_shapes[i].second->orientation( p ) == ON ) && ( orient != OUTSIDE ))
270 {
271 orient = ON;
272 }
273 else if (( orient == INSIDE ) && ( v_shapes[i].second->orientation( p ) == INSIDE ))
274 {
275 orient = INSIDE;
276 }
277 else
278 {
279 orient = OUTSIDE;
280 }
281 }
282 else
283 {
284 if (( orient == INSIDE ) || ( v_shapes[i].second->orientation( p ) == INSIDE ))
285 {
286 orient = INSIDE;
287 }
288 else if (( orient == ON ) || ( v_shapes[i].second->orientation( p ) == ON ))
289 {
290 orient = ON;
291 }
292 else
293 {
294 orient = OUTSIDE;
295 }
296 }
297 }
298
299 return orient;
300 }
301
302 public:
303
308 void selfDisplay ( std::ostream & out ) const;
309
314 bool isValid() const
315 {
316 return bIsValid;
317 }
318
319 // ------------------------- Internals ------------------------------------
320 private:
321
324
326 std::vector< std::pair<e_operator, CountedConstPtrOrConstPtr< ShapeB > > > v_shapes;
327
330
333
336
337 };
338
339} // namespace DGtal
340
341
342// //
344
345#endif // !defined EuclideanShapesDecorator_h
346
347#undef EuclideanShapesDecorator_RECURSES
348#endif // else defined(EuclideanShapesDecorator_RECURSES)
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition ConstAlias.h:187
std::vector< std::pair< e_operator, CountedConstPtrOrConstPtr< KernelSupport > > > v_shapes
void selfDisplay(std::ostream &out) const
Orientation orientation(const RealPoint &p) const
void intersection(ConstAlias< ShapeB > b)
BOOST_CONCEPT_ASSERT((concepts::CEuclideanOrientedShape< ShapeA >))
EuclideanShapesCSG(ConstAlias< ShapeA > a)
void setParams(ConstAlias< ShapeA > a)
void plus(ConstAlias< ShapeB > b)
EuclideanShapesCSG & operator=(const EuclideanShapesCSG &other)
BOOST_CONCEPT_ASSERT((concepts::CEuclideanBoundedShape< ShapeA >))
EuclideanShapesCSG(const EuclideanShapesCSG &other)
void minus(ConstAlias< ShapeB > b)
static const Dimension dimension
Definition SpaceND.h:132
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::uint32_t Dimension
Definition Common.h:119
Orientation
Definition Common.h:124
@ INSIDE
Definition Common.h:124
@ OUTSIDE
Definition Common.h:124
@ ON
Definition Common.h:124
Aim: characterizes models of digital oriented shapes. For example, models should provide an orientati...