DGtal 1.4.0
Loading...
Searching...
No Matches
DGtal::EuclideanShapesCSG< ShapeA, ShapeB > Class Template Reference

Aim: Constructive Solid Geometry (CSG) between models of CEuclideanBoundedShape and CEuclideanOrientedShape Use CSG operation (union, intersection, minus) from a shape of Type ShapeA with one (or more) shapes of Type ShapeB. Can combine differents operations. Limitations: Since we don't have a class derived by all shapes, operations can be done by only one type of shapes. Use CSG of CSG to go beyond this limitation. More...

#include <DGtal/shapes/EuclideanShapesDecorator.h>

Public Types

typedef ShapeA::Space Space
 
typedef ShapeA::RealPoint RealPoint
 

Public Member Functions

 BOOST_CONCEPT_ASSERT ((concepts::CEuclideanBoundedShape< ShapeA >))
 
 BOOST_CONCEPT_ASSERT ((concepts::CEuclideanOrientedShape< ShapeA >))
 
 EuclideanShapesCSG ()
 
 EuclideanShapesCSG (const EuclideanShapesCSG &other)
 
 EuclideanShapesCSG (ConstAlias< ShapeA > a)
 
EuclideanShapesCSGoperator= (const EuclideanShapesCSG &other)
 
void setParams (ConstAlias< ShapeA > a)
 
void plus (ConstAlias< ShapeB > b)
 
void intersection (ConstAlias< ShapeB > b)
 
void minus (ConstAlias< ShapeB > b)
 
RealPoint getLowerBound () const
 
RealPoint getUpperBound () const
 
Orientation orientation (const RealPoint &p) const
 
void selfDisplay (std::ostream &out) const
 
bool isValid () const
 

Protected Types

enum  e_operator { e_plus , e_intersection , e_minus }
 

Private Attributes

CountedConstPtrOrConstPtr< ShapeA > myShapeA
 Base Shape.
 
std::vector< std::pair< e_operator, CountedConstPtrOrConstPtr< ShapeB > > > v_shapes
 Vector of all operations (ordered) of ShapeB.
 
RealPoint myLowerBound
 Domain lower bound.
 
RealPoint myUpperBound
 Domain upper bound.
 
bool bIsValid
 if the CSG is valid.
 

Detailed Description

template<typename ShapeA, typename ShapeB>
class DGtal::EuclideanShapesCSG< ShapeA, ShapeB >

Aim: Constructive Solid Geometry (CSG) between models of CEuclideanBoundedShape and CEuclideanOrientedShape Use CSG operation (union, intersection, minus) from a shape of Type ShapeA with one (or more) shapes of Type ShapeB. Can combine differents operations. Limitations: Since we don't have a class derived by all shapes, operations can be done by only one type of shapes. Use CSG of CSG to go beyond this limitation.

Description of template class 'EuclideanShapesCSG'

Template Parameters
ShapeAtype of a first shape. Must be a model of CEuclideanBoundedShape and CEuclideanOrientedShape
ShapeBtype of a second shape. Must be a model of CEuclideanBoundedShape and CEuclideanOrientedShape
Examples
shapes/exampleEuclideanShapesDecorator.cpp.

Definition at line 67 of file EuclideanShapesDecorator.h.

Member Typedef Documentation

◆ RealPoint

template<typename ShapeA , typename ShapeB >
typedef ShapeA::RealPoint DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::RealPoint

Definition at line 82 of file EuclideanShapesDecorator.h.

◆ Space

template<typename ShapeA , typename ShapeB >
typedef ShapeA::Space DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::Space

Definition at line 81 of file EuclideanShapesDecorator.h.

Member Enumeration Documentation

◆ e_operator

template<typename ShapeA , typename ShapeB >
enum DGtal::EuclideanShapesCSG::e_operator
protected
Enumerator
e_plus 
e_intersection 
e_minus 

Definition at line 70 of file EuclideanShapesDecorator.h.

Constructor & Destructor Documentation

◆ EuclideanShapesCSG() [1/3]

template<typename ShapeA , typename ShapeB >
DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::EuclideanShapesCSG ( )
inline

Default constructor. EuclideanShapesCSG will be not valid without setParams(ShapeA).

Definition at line 88 of file EuclideanShapesDecorator.h.

89 : bIsValid(false)
90 {}
bool bIsValid
if the CSG is valid.

◆ EuclideanShapesCSG() [2/3]

template<typename ShapeA , typename ShapeB >
DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::EuclideanShapesCSG ( const EuclideanShapesCSG< ShapeA, ShapeB > & other)
inline

Copy constructor.

Parameters
[in]othera EuclideanShapesCSG to copy

Definition at line 97 of file EuclideanShapesDecorator.h.

98 : myShapeA(other.myShapeA), v_shapes(other.v_shapes),
99 myLowerBound(other.myLowerBound), myUpperBound(other.myUpperBound),
100 bIsValid(other.bIsValid)
101 {}
std::vector< std::pair< e_operator, CountedConstPtrOrConstPtr< ShapeB > > > v_shapes
Vector of all operations (ordered) of ShapeB.
RealPoint myLowerBound
Domain lower bound.
RealPoint myUpperBound
Domain upper bound.
CountedConstPtrOrConstPtr< ShapeA > myShapeA
Base Shape.

◆ EuclideanShapesCSG() [3/3]

template<typename ShapeA , typename ShapeB >
DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::EuclideanShapesCSG ( ConstAlias< ShapeA > a)
inline

Constructor. EuclideanShapesCSG will be valid.

Parameters
[in]aa model of CEuclideanBoundedShape and CEuclideanOrientedShape

Definition at line 108 of file EuclideanShapesDecorator.h.

109 : myShapeA( a )
110 {
111 myLowerBound = myShapeA->getLowerBound();
112 myUpperBound = myShapeA->getUpperBound();
113
114 bIsValid = true;
115 }

References DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::bIsValid, DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::myLowerBound, DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::myShapeA, and DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::myUpperBound.

Member Function Documentation

◆ BOOST_CONCEPT_ASSERT() [1/2]

◆ BOOST_CONCEPT_ASSERT() [2/2]

template<typename ShapeA , typename ShapeB >
DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::BOOST_CONCEPT_ASSERT ( (concepts::CEuclideanOrientedShape< ShapeA >) )

◆ getLowerBound()

template<typename ShapeA , typename ShapeB >
RealPoint DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::getLowerBound ( ) const
inline
Returns
the lower bound of the shape bounding box.

Definition at line 222 of file EuclideanShapesDecorator.h.

223 {
224 FATAL_ERROR_MSG( isValid(), "Operation invalid. Maybe you don't set a ShapeA object." );
225
226 return myLowerBound;
227 }

References DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::isValid(), and DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::myLowerBound.

◆ getUpperBound()

template<typename ShapeA , typename ShapeB >
RealPoint DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::getUpperBound ( ) const
inline
Returns
the upper bound of the shape bounding box.

Definition at line 233 of file EuclideanShapesDecorator.h.

234 {
235 FATAL_ERROR_MSG( isValid(), "Operation invalid. Maybe you don't set a ShapeA object." );
236
237 return myUpperBound;
238 }

References DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::isValid(), and DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::myUpperBound.

◆ intersection()

template<typename ShapeA , typename ShapeB >
void DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::intersection ( ConstAlias< ShapeB > b)
inline

Intersection between a (ShapeA) and b (ShapeB). If an operation was already set, the intersection will be between the CSG shape and b (ShapeB).

Parameters
[in]ba ShapeB, model of CEuclideanBoundedShape and CEuclideanOrientedShape

Definition at line 182 of file EuclideanShapesDecorator.h.

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 }
BOOST_CONCEPT_ASSERT((concepts::CEuclideanBoundedShape< ShapeA >))
static const Dimension dimension
static constants to store the dimension.
Definition SpaceND.h:132
DGtal::uint32_t Dimension
Definition Common.h:136

References DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::BOOST_CONCEPT_ASSERT(), DGtal::SpaceND< dim, TInteger >::dimension, DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::e_intersection, DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::isValid(), DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::myLowerBound, DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::myUpperBound, and DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::v_shapes.

◆ isValid()

◆ minus()

template<typename ShapeA , typename ShapeB >
void DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::minus ( ConstAlias< ShapeB > b)
inline

Minus between a (ShapeA) and b (ShapeB). If an operation was already set, the minus will be between the CSG shape and b (ShapeB).

Parameters
[in]ba ShapeB, model of CEuclideanBoundedShape and CEuclideanOrientedShape

Definition at line 206 of file EuclideanShapesDecorator.h.

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 }

References DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::BOOST_CONCEPT_ASSERT(), DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::e_minus, DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::isValid(), and DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::v_shapes.

◆ operator=()

template<typename ShapeA , typename ShapeB >
EuclideanShapesCSG & DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::operator= ( const EuclideanShapesCSG< ShapeA, ShapeB > & other)
inline

Copy operator.

Parameters
[in]othera EuclideanShapesCSG to copy
Returns
this

Definition at line 124 of file EuclideanShapesDecorator.h.

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 }

References DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::bIsValid, DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::myLowerBound, DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::myShapeA, DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::myUpperBound, and DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::v_shapes.

◆ orientation()

template<typename ShapeA , typename ShapeB >
Orientation DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::orientation ( const RealPoint & p) const
inline

Return the orientation of a point with respect to a shape. Resolve all operations done with operators in the order they are set.

Parameters
[in]pinput point
Returns
the orientation of the point (0 = INSIDE, 1 = ON, 2 = OUTSIDE)

e_plus

Definition at line 248 of file EuclideanShapesDecorator.h.

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 }
Orientation
Definition Common.h:141
@ INSIDE
Definition Common.h:141
@ OUTSIDE
Definition Common.h:141
@ ON
Definition Common.h:141

References DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::e_intersection, DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::e_minus, DGtal::INSIDE, DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::isValid(), DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::myShapeA, DGtal::ON, DGtal::OUTSIDE, and DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::v_shapes.

◆ plus()

template<typename ShapeA , typename ShapeB >
void DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::plus ( ConstAlias< ShapeB > b)
inline

Union between a shape (ShapeA, gived at construction) and b (ShapeB). If an operation was already set, the union will be between the CSG shape and b (ShapeB).

Parameters
[in]ba ShapeB, model of CEuclideanBoundedShape and CEuclideanOrientedShape

Definition at line 158 of file EuclideanShapesDecorator.h.

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 }

References DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::BOOST_CONCEPT_ASSERT(), DGtal::SpaceND< dim, TInteger >::dimension, DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::e_plus, DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::isValid(), DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::myLowerBound, DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::myUpperBound, and DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::v_shapes.

◆ selfDisplay()

template<typename ShapeA , typename ShapeB >
void DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::selfDisplay ( std::ostream & out) const

Writes/Displays the object on an output stream.

Parameters
outthe output stream where the object is written.

◆ setParams()

template<typename ShapeA , typename ShapeB >
void DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::setParams ( ConstAlias< ShapeA > a)
inline

Add a (unique) ShapeA for the CSG computation. EuclideanShapesCSG will be valid after. If a ShapeA was already set, the previous one will be override.

Parameters
[in]aa ShapeA, model of CEuclideanBoundedShape and CEuclideanOrientedShape

Definition at line 142 of file EuclideanShapesDecorator.h.

143 {
144 myShapeA = a;
145
146 myLowerBound = myShapeA->getLowerBound();
147 myUpperBound = myShapeA->getUpperBound();
148
149 bIsValid = true;
150 }

References DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::bIsValid, DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::myLowerBound, DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::myShapeA, and DGtal::EuclideanShapesCSG< ShapeA, ShapeB >::myUpperBound.

Field Documentation

◆ bIsValid

◆ myLowerBound

◆ myShapeA

◆ myUpperBound

◆ v_shapes


The documentation for this class was generated from the following file: