DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
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
50
namespace
DGtal
51
{
52
54
// template class EuclideanShapesCSG
66
template
<
typename
ShapeA,
typename
ShapeB>
67
class
EuclideanShapesCSG
68
{
69
protected
:
70
enum
e_operator
71
{
72
e_plus
,
73
e_intersection
,
74
e_minus
75
};
76
77
public
:
78
BOOST_CONCEPT_ASSERT
((
concepts::CEuclideanBoundedShape< ShapeA >
));
79
BOOST_CONCEPT_ASSERT
((
concepts::CEuclideanOrientedShape< ShapeA >
));
80
81
typedef
typename
ShapeA::Space
Space
;
82
typedef
typename
ShapeA::RealPoint
RealPoint
;
83
88
EuclideanShapesCSG
( )
89
:
bIsValid
(false)
90
{}
91
97
EuclideanShapesCSG
(
const
EuclideanShapesCSG
& other )
98
:
myShapeA
(other.
myShapeA
),
v_shapes
(other.
v_shapes
),
99
myLowerBound
(other.
myLowerBound
),
myUpperBound
(other.
myUpperBound
),
100
bIsValid
(other.
bIsValid
)
101
{}
102
108
EuclideanShapesCSG
(
ConstAlias<ShapeA>
a )
109
:
myShapeA
( a )
110
{
111
myLowerBound
=
myShapeA
->getLowerBound();
112
myUpperBound
=
myShapeA
->getUpperBound();
113
114
bIsValid
=
true
;
115
}
116
124
EuclideanShapesCSG
&
operator=
(
const
EuclideanShapesCSG
& other )
125
{
126
myShapeA
= other.
myShapeA
;
127
v_shapes
= other.
v_shapes
;
128
129
myLowerBound
= other.
myLowerBound
;
130
myUpperBound
= other.
myUpperBound
;
131
132
bIsValid
= other.
bIsValid
;
133
134
return
*
this
;
135
}
136
142
void
setParams
(
ConstAlias<ShapeA>
a )
143
{
144
myShapeA
= a;
145
146
myLowerBound
=
myShapeA
->getLowerBound();
147
myUpperBound
=
myShapeA
->getUpperBound();
148
149
bIsValid
=
true
;
150
}
151
158
void
plus
(
ConstAlias<ShapeB>
b )
159
{
160
BOOST_CONCEPT_ASSERT
((
concepts::CEuclideanBoundedShape< ShapeB >
));
161
BOOST_CONCEPT_ASSERT
((
concepts::CEuclideanOrientedShape< ShapeB >
));
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
182
void
intersection
(
ConstAlias<ShapeB>
b )
183
{
184
BOOST_CONCEPT_ASSERT
((
concepts::CEuclideanBoundedShape< ShapeB >
));
185
BOOST_CONCEPT_ASSERT
((
concepts::CEuclideanOrientedShape< ShapeB >
));
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
206
void
minus
(
ConstAlias<ShapeB>
b )
207
{
208
BOOST_CONCEPT_ASSERT
((
concepts::CEuclideanBoundedShape< ShapeB >
));
209
BOOST_CONCEPT_ASSERT
((
concepts::CEuclideanOrientedShape< ShapeB >
));
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
222
RealPoint
getLowerBound
()
const
223
{
224
FATAL_ERROR_MSG(
isValid
(),
"Operation invalid. Maybe you don't set a ShapeA object."
);
225
226
return
myLowerBound
;
227
}
228
233
RealPoint
getUpperBound
()
const
234
{
235
FATAL_ERROR_MSG(
isValid
(),
"Operation invalid. Maybe you don't set a ShapeA object."
);
236
237
return
myUpperBound
;
238
}
239
248
Orientation
orientation
(
const
RealPoint
& p )
const
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
323
CountedConstPtrOrConstPtr< ShapeA >
myShapeA
;
324
326
std::vector< std::pair<e_operator, CountedConstPtrOrConstPtr< ShapeB > > >
v_shapes
;
327
329
RealPoint
myLowerBound
;
330
332
RealPoint
myUpperBound
;
333
335
bool
bIsValid
;
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)
DGtal::ConstAlias
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition
ConstAlias.h:187
DGtal::CountedConstPtrOrConstPtr< ShapeA >
DGtal::EuclideanShapesCSG< KernelSupport, KernelSupport >::v_shapes
std::vector< std::pair< e_operator, CountedConstPtrOrConstPtr< KernelSupport > > > v_shapes
Definition
EuclideanShapesDecorator.h:326
DGtal::EuclideanShapesCSG< KernelSupport, KernelSupport >::bIsValid
bool bIsValid
Definition
EuclideanShapesDecorator.h:335
DGtal::EuclideanShapesCSG::selfDisplay
void selfDisplay(std::ostream &out) const
DGtal::EuclideanShapesCSG::orientation
Orientation orientation(const RealPoint &p) const
Definition
EuclideanShapesDecorator.h:248
DGtal::EuclideanShapesCSG::intersection
void intersection(ConstAlias< ShapeB > b)
Definition
EuclideanShapesDecorator.h:182
DGtal::EuclideanShapesCSG::EuclideanShapesCSG
EuclideanShapesCSG()
Definition
EuclideanShapesDecorator.h:88
DGtal::EuclideanShapesCSG::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CEuclideanOrientedShape< ShapeA >))
DGtal::EuclideanShapesCSG::EuclideanShapesCSG
EuclideanShapesCSG(ConstAlias< ShapeA > a)
Definition
EuclideanShapesDecorator.h:108
DGtal::EuclideanShapesCSG::setParams
void setParams(ConstAlias< ShapeA > a)
Definition
EuclideanShapesDecorator.h:142
DGtal::EuclideanShapesCSG< KernelSupport, KernelSupport >::Space
KernelSupport::Space Space
Definition
EuclideanShapesDecorator.h:81
DGtal::EuclideanShapesCSG::getLowerBound
RealPoint getLowerBound() const
Definition
EuclideanShapesDecorator.h:222
DGtal::EuclideanShapesCSG< KernelSupport, KernelSupport >::myLowerBound
RealPoint myLowerBound
Definition
EuclideanShapesDecorator.h:329
DGtal::EuclideanShapesCSG< KernelSupport, KernelSupport >::myUpperBound
RealPoint myUpperBound
Definition
EuclideanShapesDecorator.h:332
DGtal::EuclideanShapesCSG::plus
void plus(ConstAlias< ShapeB > b)
Definition
EuclideanShapesDecorator.h:158
DGtal::EuclideanShapesCSG::operator=
EuclideanShapesCSG & operator=(const EuclideanShapesCSG &other)
Definition
EuclideanShapesDecorator.h:124
DGtal::EuclideanShapesCSG< KernelSupport, KernelSupport >::RealPoint
KernelSupport::RealPoint RealPoint
Definition
EuclideanShapesDecorator.h:82
DGtal::EuclideanShapesCSG< KernelSupport, KernelSupport >::isValid
bool isValid() const
Definition
EuclideanShapesDecorator.h:314
DGtal::EuclideanShapesCSG::e_operator
e_operator
Definition
EuclideanShapesDecorator.h:71
DGtal::EuclideanShapesCSG< KernelSupport, KernelSupport >::e_intersection
@ e_intersection
Definition
EuclideanShapesDecorator.h:73
DGtal::EuclideanShapesCSG< KernelSupport, KernelSupport >::e_plus
@ e_plus
Definition
EuclideanShapesDecorator.h:72
DGtal::EuclideanShapesCSG< KernelSupport, KernelSupport >::e_minus
@ e_minus
Definition
EuclideanShapesDecorator.h:74
DGtal::EuclideanShapesCSG::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CEuclideanBoundedShape< ShapeA >))
DGtal::EuclideanShapesCSG::getUpperBound
RealPoint getUpperBound() const
Definition
EuclideanShapesDecorator.h:233
DGtal::EuclideanShapesCSG< KernelSupport, KernelSupport >::myShapeA
CountedConstPtrOrConstPtr< KernelSupport > myShapeA
Definition
EuclideanShapesDecorator.h:323
DGtal::EuclideanShapesCSG::EuclideanShapesCSG
EuclideanShapesCSG(const EuclideanShapesCSG &other)
Definition
EuclideanShapesDecorator.h:97
DGtal::EuclideanShapesCSG::minus
void minus(ConstAlias< ShapeB > b)
Definition
EuclideanShapesDecorator.h:206
DGtal::SpaceND< 3, Integer >::dimension
static const Dimension dimension
Definition
SpaceND.h:132
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::Dimension
DGtal::uint32_t Dimension
Definition
Common.h:119
DGtal::Orientation
Orientation
Definition
Common.h:124
DGtal::INSIDE
@ INSIDE
Definition
Common.h:124
DGtal::OUTSIDE
@ OUTSIDE
Definition
Common.h:124
DGtal::ON
@ ON
Definition
Common.h:124
DGtal::concepts::CEuclideanBoundedShape
Definition
CEuclideanBoundedShape.h:97
DGtal::concepts::CEuclideanOrientedShape
Aim: characterizes models of digital oriented shapes. For example, models should provide an orientati...
Definition
CEuclideanOrientedShape.h:92
src
DGtal
shapes
EuclideanShapesDecorator.h
Generated on
for DGtal by
1.18.0