DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
DigitalShapesDecorator.h
1
16
17
#pragma once
18
29
30
#if defined(DigitalShapesDecorator_RECURSES)
31
#error Recursive header files inclusion detected in DigitalShapesDecorator.h
32
#else
// defined(DigitalShapesDecorator_RECURSES)
34
#define DigitalShapesDecorator_RECURSES
35
36
#if !defined DigitalShapesDecorator_h
38
#define DigitalShapesDecorator_h
39
41
// Inclusions
42
#include <iostream>
43
#include "DGtal/base/Common.h"
44
#include "DGtal/base/ConstAlias.h"
45
46
#include "DGtal/shapes/CDigitalBoundedShape.h"
47
#include "DGtal/shapes/CDigitalOrientedShape.h"
49
50
namespace
DGtal
51
{
52
54
// template class DigitalShapesCSG
66
template
<
typename
ShapeA,
typename
ShapeB>
67
class
DigitalShapesCSG
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::CDigitalBoundedShape< ShapeA >
));
79
BOOST_CONCEPT_ASSERT
((
concepts::CDigitalOrientedShape< ShapeA >
));
80
81
typedef
typename
ShapeA::Space
Space
;
82
typedef
typename
ShapeA::Point
Point
;
83
88
DigitalShapesCSG
( )
89
:
bIsValid
(false)
90
{}
91
97
DigitalShapesCSG
(
const
DigitalShapesCSG
& other )
98
:
myShapeA
(other.
myShapeA
),
v_shapes
(other.
v_shapes
),
99
myLowerBound
(other.
myLowerBound
),
myUpperBound
(other.
myUpperBound
),
100
bIsValid
(other.
bIsValid
)
101
{}
102
103
109
DigitalShapesCSG
(
ConstAlias<ShapeA>
a )
110
:
myShapeA
( a )
111
{
112
myLowerBound
=
myShapeA
->getLowerBound();
113
myUpperBound
=
myShapeA
->getUpperBound();
114
115
bIsValid
=
true
;
116
}
117
125
DigitalShapesCSG
&
operator=
(
const
DigitalShapesCSG
& other )
126
{
127
myShapeA
= other.
myShapeA
;
128
v_shapes
= other.
v_shapes
;
129
130
myLowerBound
= other.
myLowerBound
;
131
myUpperBound
= other.
myUpperBound
;
132
133
bIsValid
= other.
bIsValid
;
134
135
return
*
this
;
136
}
137
143
void
setParams
(
ConstAlias<ShapeA>
a )
144
{
145
myShapeA
= a;
146
147
myLowerBound
=
myShapeA
->getLowerBound();
148
myUpperBound
=
myShapeA
->getUpperBound();
149
150
bIsValid
=
true
;
151
}
152
159
void
plus
(
ConstAlias<ShapeB>
b )
160
{
161
BOOST_CONCEPT_ASSERT
((
concepts::CDigitalBoundedShape< ShapeB >
));
162
BOOST_CONCEPT_ASSERT
((
concepts::CDigitalOrientedShape< ShapeB >
));
163
164
FATAL_ERROR_MSG(
isValid
(),
"Operation invalid. Maybe you don't set a ShapeA object."
);
165
166
std::pair<e_operator, CountedConstPtrOrConstPtr< ShapeB > > shape(
e_plus
, b );
167
168
for
(
Dimension
i =0; i <
Space::dimension
; ++i)
169
{
170
myLowerBound
[i] = std::min(
myLowerBound
[i], b->getLowerBound()[i]);
171
myUpperBound
[i] = std::max(
myUpperBound
[i], b->getUpperBound()[i]);
172
}
173
174
v_shapes
.push_back(shape);
175
}
176
183
void
intersection
(
ConstAlias<ShapeB>
b )
184
{
185
BOOST_CONCEPT_ASSERT
((
concepts::CDigitalBoundedShape< ShapeB >
));
186
BOOST_CONCEPT_ASSERT
((
concepts::CDigitalOrientedShape< ShapeB >
));
187
188
FATAL_ERROR_MSG(
isValid
(),
"Operation invalid. Maybe you don't set a ShapeA object."
);
189
190
std::pair<e_operator, CountedConstPtrOrConstPtr< ShapeB > > shape(
e_intersection
, b );
191
192
for
(
Dimension
i=0; i <
Space::dimension
; ++i)
193
{
194
myLowerBound
[i] = std::max(
myLowerBound
[i], b->getLowerBound()[i]);
195
myUpperBound
[i] = std::min(
myUpperBound
[i], b->getUpperBound()[i]);
196
}
197
198
v_shapes
.push_back(shape);
199
}
200
207
void
minus
(
ConstAlias<ShapeB>
b )
208
{
209
BOOST_CONCEPT_ASSERT
((
concepts::CDigitalBoundedShape< ShapeB >
));
210
BOOST_CONCEPT_ASSERT
((
concepts::CDigitalOrientedShape< ShapeB >
));
211
212
FATAL_ERROR_MSG(
isValid
(),
"Operation invalid. Maybe you don't set a ShapeA object."
);
213
214
std::pair<e_operator, CountedConstPtrOrConstPtr< ShapeB > > shape(
e_minus
, b );
215
216
v_shapes
.push_back(shape);
217
218
}
219
224
Point
getLowerBound
()
const
225
{
226
FATAL_ERROR_MSG(
isValid
(),
"Operation invalid. Maybe you don't set a ShapeA object."
);
227
228
return
myLowerBound
;
229
}
230
235
Point
getUpperBound
()
const
236
{
237
FATAL_ERROR_MSG(
isValid
(),
"Operation invalid. Maybe you don't set a ShapeA object."
);
238
239
return
myUpperBound
;
240
}
241
250
Orientation
orientation
(
const
Point
& p )
const
251
{
252
FATAL_ERROR_MSG(
isValid
(),
"Operation invalid. Maybe you don't set a ShapeA object."
);
253
254
Orientation
orient =
myShapeA
->orientation( p );
255
256
for
(
unsigned
int
i = 0; i <
v_shapes
.size(); ++i)
257
{
258
if
(
v_shapes
[i].first ==
e_minus
)
259
{
260
if
((
v_shapes
[i].second->orientation( p ) ==
INSIDE
) || (
v_shapes
[i].second->orientation( p ) ==
ON
))
261
{
262
orient =
OUTSIDE
;
263
}
264
}
265
else
if
(
v_shapes
[i].first ==
e_intersection
)
266
{
267
if
(( orient ==
ON
) && (
v_shapes
[i].second->orientation( p ) !=
OUTSIDE
))
268
{
269
orient =
ON
;
270
}
271
else
if
((
v_shapes
[i].second->orientation( p ) ==
ON
) && ( orient !=
OUTSIDE
))
272
{
273
orient =
ON
;
274
}
275
else
if
(( orient ==
INSIDE
) && (
v_shapes
[i].second->orientation( p ) ==
INSIDE
))
276
{
277
orient =
INSIDE
;
278
}
279
else
280
{
281
orient =
OUTSIDE
;
282
}
283
}
284
else
285
{
286
if
(( orient ==
INSIDE
) || (
v_shapes
[i].second->orientation( p ) ==
INSIDE
))
287
{
288
orient =
INSIDE
;
289
}
290
else
if
(( orient ==
ON
) || (
v_shapes
[i].second->orientation( p ) ==
ON
))
291
{
292
orient =
ON
;
293
}
294
else
295
{
296
orient =
OUTSIDE
;
297
}
298
}
299
}
300
301
return
orient;
302
}
303
304
public
:
305
310
void
selfDisplay
( std::ostream & out )
const
;
311
316
bool
isValid
()
const
317
{
318
return
bIsValid
;
319
}
320
321
// ------------------------- Internals ------------------------------------
322
private
:
323
325
CountedConstPtrOrConstPtr< ShapeA >
myShapeA
;
326
328
std::vector< std::pair<e_operator, CountedConstPtrOrConstPtr< ShapeB > > >
v_shapes
;
329
331
Point
myLowerBound
;
332
334
Point
myUpperBound
;
335
337
bool
bIsValid
;
338
339
};
340
}
// namespace DGtal
341
342
343
344
#endif
// !defined DigitalShapesDecorator_h
345
346
#undef DigitalShapesDecorator_RECURSES
347
#endif
// else defined(DigitalShapesDecorator_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::DigitalShapesCSG::plus
void plus(ConstAlias< ShapeB > b)
Definition
DigitalShapesDecorator.h:159
DGtal::DigitalShapesCSG::operator=
DigitalShapesCSG & operator=(const DigitalShapesCSG &other)
Definition
DigitalShapesDecorator.h:125
DGtal::DigitalShapesCSG::Point
ShapeA::Point Point
Definition
DigitalShapesDecorator.h:82
DGtal::DigitalShapesCSG::v_shapes
std::vector< std::pair< e_operator, CountedConstPtrOrConstPtr< ShapeB > > > v_shapes
Vector of all operations (ordered) of ShapeB.
Definition
DigitalShapesDecorator.h:328
DGtal::DigitalShapesCSG::e_operator
e_operator
Definition
DigitalShapesDecorator.h:71
DGtal::DigitalShapesCSG::e_minus
@ e_minus
Definition
DigitalShapesDecorator.h:74
DGtal::DigitalShapesCSG::e_plus
@ e_plus
Definition
DigitalShapesDecorator.h:72
DGtal::DigitalShapesCSG::e_intersection
@ e_intersection
Definition
DigitalShapesDecorator.h:73
DGtal::DigitalShapesCSG::myShapeA
CountedConstPtrOrConstPtr< ShapeA > myShapeA
Base Shape.
Definition
DigitalShapesDecorator.h:325
DGtal::DigitalShapesCSG::DigitalShapesCSG
DigitalShapesCSG()
Definition
DigitalShapesDecorator.h:88
DGtal::DigitalShapesCSG::selfDisplay
void selfDisplay(std::ostream &out) const
DGtal::DigitalShapesCSG::getLowerBound
Point getLowerBound() const
Definition
DigitalShapesDecorator.h:224
DGtal::DigitalShapesCSG::DigitalShapesCSG
DigitalShapesCSG(ConstAlias< ShapeA > a)
Definition
DigitalShapesDecorator.h:109
DGtal::DigitalShapesCSG::myUpperBound
Point myUpperBound
Domain upper bound.
Definition
DigitalShapesDecorator.h:334
DGtal::DigitalShapesCSG::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CDigitalOrientedShape< ShapeA >))
DGtal::DigitalShapesCSG::orientation
Orientation orientation(const Point &p) const
Definition
DigitalShapesDecorator.h:250
DGtal::DigitalShapesCSG::myLowerBound
Point myLowerBound
Domain lower bound.
Definition
DigitalShapesDecorator.h:331
DGtal::DigitalShapesCSG::DigitalShapesCSG
DigitalShapesCSG(const DigitalShapesCSG &other)
Definition
DigitalShapesDecorator.h:97
DGtal::DigitalShapesCSG::minus
void minus(ConstAlias< ShapeB > b)
Definition
DigitalShapesDecorator.h:207
DGtal::DigitalShapesCSG::Space
ShapeA::Space Space
Definition
DigitalShapesDecorator.h:81
DGtal::DigitalShapesCSG::intersection
void intersection(ConstAlias< ShapeB > b)
Definition
DigitalShapesDecorator.h:183
DGtal::DigitalShapesCSG::setParams
void setParams(ConstAlias< ShapeA > a)
Definition
DigitalShapesDecorator.h:143
DGtal::DigitalShapesCSG::bIsValid
bool bIsValid
if the CSG is valid.
Definition
DigitalShapesDecorator.h:337
DGtal::DigitalShapesCSG::getUpperBound
Point getUpperBound() const
Definition
DigitalShapesDecorator.h:235
DGtal::DigitalShapesCSG::isValid
bool isValid() const
Definition
DigitalShapesDecorator.h:316
DGtal::DigitalShapesCSG::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CDigitalBoundedShape< ShapeA >))
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::CDigitalBoundedShape
Aim: designs the concept of bounded shapes in DGtal (shape for which upper and lower bounding bounds ...
Definition
CDigitalBoundedShape.h:91
DGtal::concepts::CDigitalOrientedShape
Aim: characterizes models of digital oriented shapes. For example, models should provide an orientati...
Definition
CDigitalOrientedShape.h:91
src
DGtal
shapes
DigitalShapesDecorator.h
Generated on
for DGtal by
1.18.0