DGtal 1.3.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Types | Private Attributes
DGtal::DigitalShapesCSG< ShapeA, ShapeB > Class Template Reference

Aim: Constructive Solid Geometry (CSG) between models of CDigitalBoundedShape and CDigitalOrientedShape 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/DigitalShapesDecorator.h>

Public Types

typedef ShapeA::Space Space
 
typedef ShapeA::Point Point
 

Public Member Functions

 BOOST_CONCEPT_ASSERT ((concepts::CDigitalBoundedShape< ShapeA >))
 
 BOOST_CONCEPT_ASSERT ((concepts::CDigitalOrientedShape< ShapeA >))
 
 DigitalShapesCSG ()
 
 DigitalShapesCSG (const DigitalShapesCSG &other)
 
 DigitalShapesCSG (ConstAlias< ShapeA > a)
 
DigitalShapesCSGoperator= (const DigitalShapesCSG &other)
 
void setParams (ConstAlias< ShapeA > a)
 
void plus (ConstAlias< ShapeB > b)
 
void intersection (ConstAlias< ShapeB > b)
 
void minus (ConstAlias< ShapeB > b)
 
Point getLowerBound () const
 
Point getUpperBound () const
 
Orientation orientation (const Point &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. More...
 
std::vector< std::pair< e_operator, CountedConstPtrOrConstPtr< ShapeB > > > v_shapes
 Vector of all operations (ordered) of ShapeB. More...
 
Point myLowerBound
 Domain lower bound. More...
 
Point myUpperBound
 Domain upper bound. More...
 
bool bIsValid
 if the CSG is valid. More...
 

Detailed Description

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

Aim: Constructive Solid Geometry (CSG) between models of CDigitalBoundedShape and CDigitalOrientedShape 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 'DigitalShapesCSG'

Template Parameters
ShapeAtype of a first shape. Must be a model of CDigitalBoundedShape and CDigitalOrientedShape
ShapeBtype of a second shape. Must be a model of CDigitalBoundedShape and CDigitalOrientedShape

Definition at line 67 of file DigitalShapesDecorator.h.

Member Typedef Documentation

◆ Point

template<typename ShapeA , typename ShapeB >
typedef ShapeA::Point DGtal::DigitalShapesCSG< ShapeA, ShapeB >::Point

Definition at line 82 of file DigitalShapesDecorator.h.

◆ Space

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

Definition at line 81 of file DigitalShapesDecorator.h.

Member Enumeration Documentation

◆ e_operator

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

Definition at line 70 of file DigitalShapesDecorator.h.

Constructor & Destructor Documentation

◆ DigitalShapesCSG() [1/3]

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

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

Definition at line 88 of file DigitalShapesDecorator.h.

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

◆ DigitalShapesCSG() [2/3]

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

Copy constructor.

Parameters
[in]othera DigitalShapesCSG to copy

Definition at line 97 of file DigitalShapesDecorator.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.
CountedConstPtrOrConstPtr< ShapeA > myShapeA
Base Shape.
Point myUpperBound
Domain upper bound.
Point myLowerBound
Domain lower bound.

◆ DigitalShapesCSG() [3/3]

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

Constructor. DigitalShapesCSG will be valid.

Parameters
[in]aa model of CDigitalBoundedShape and CDigitalOrientedShape

Definition at line 109 of file DigitalShapesDecorator.h.

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

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

Member Function Documentation

◆ BOOST_CONCEPT_ASSERT() [1/2]

template<typename ShapeA , typename ShapeB >
DGtal::DigitalShapesCSG< ShapeA, ShapeB >::BOOST_CONCEPT_ASSERT ( (concepts::CDigitalBoundedShape< ShapeA >)  )

◆ BOOST_CONCEPT_ASSERT() [2/2]

template<typename ShapeA , typename ShapeB >
DGtal::DigitalShapesCSG< ShapeA, ShapeB >::BOOST_CONCEPT_ASSERT ( (concepts::CDigitalOrientedShape< ShapeA >)  )

◆ getLowerBound()

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

Definition at line 224 of file DigitalShapesDecorator.h.

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

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

◆ getUpperBound()

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

Definition at line 235 of file DigitalShapesDecorator.h.

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

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

◆ intersection()

template<typename ShapeA , typename ShapeB >
void DGtal::DigitalShapesCSG< 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 CDigitalBoundedShape and CDigitalOrientedShape

Definition at line 183 of file DigitalShapesDecorator.h.

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

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

◆ isValid()

template<typename ShapeA , typename ShapeB >
bool DGtal::DigitalShapesCSG< ShapeA, ShapeB >::isValid ( ) const
inline

◆ minus()

template<typename ShapeA , typename ShapeB >
void DGtal::DigitalShapesCSG< 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 CDigitalBoundedShape and CDigitalOrientedShape

Definition at line 207 of file DigitalShapesDecorator.h.

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 }

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

◆ operator=()

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

Copy operator.

Parameters
[in]othera DigitalShapesCSG to copy
Returns
this

Definition at line 125 of file DigitalShapesDecorator.h.

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 }

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

◆ orientation()

template<typename ShapeA , typename ShapeB >
Orientation DGtal::DigitalShapesCSG< ShapeA, ShapeB >::orientation ( const Point 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 250 of file DigitalShapesDecorator.h.

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

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

◆ plus()

template<typename ShapeA , typename ShapeB >
void DGtal::DigitalShapesCSG< 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 CDigitalBoundedShape and CDigitalOrientedShape

Definition at line 159 of file DigitalShapesDecorator.h.

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 }

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

◆ selfDisplay()

template<typename ShapeA , typename ShapeB >
void DGtal::DigitalShapesCSG< 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::DigitalShapesCSG< ShapeA, ShapeB >::setParams ( ConstAlias< ShapeA >  a)
inline

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

Parameters
[in]aa ShapeA, model of CDigitalBoundedShape and CDigitalOrientedShape

Definition at line 143 of file DigitalShapesDecorator.h.

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

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

Field Documentation

◆ bIsValid

template<typename ShapeA , typename ShapeB >
bool DGtal::DigitalShapesCSG< ShapeA, ShapeB >::bIsValid
private

◆ myLowerBound

template<typename ShapeA , typename ShapeB >
Point DGtal::DigitalShapesCSG< ShapeA, ShapeB >::myLowerBound
private

◆ myShapeA

template<typename ShapeA , typename ShapeB >
CountedConstPtrOrConstPtr< ShapeA > DGtal::DigitalShapesCSG< ShapeA, ShapeB >::myShapeA
private

◆ myUpperBound

template<typename ShapeA , typename ShapeB >
Point DGtal::DigitalShapesCSG< ShapeA, ShapeB >::myUpperBound
private

◆ v_shapes

template<typename ShapeA , typename ShapeB >
std::vector< std::pair<e_operator, CountedConstPtrOrConstPtr< ShapeB > > > DGtal::DigitalShapesCSG< ShapeA, ShapeB >::v_shapes
private

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