RobWorkProject  23.9.11-
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
BREP Class Referenceabstract

Boundary representation (or B-Rep) of a geometric shape, using a collection of connected surfaces, edges and vertices. More...

#include <BREP.hpp>

Inherits GeometryData.

Inherited by ImplicitBREP, and QuadraticBREP.

Classes

class  CommonCurveSet
 Convenience type for a set of curves in a BREP. More...
 
struct  Face
 Face concept in the half-edge structure. More...
 
struct  HalfEdge
 Half-edge structure. More...
 
struct  Vertex
 Vertex for the half-edge structure. More...
 

Public Types

typedef rw::core::Ptr< BREPPtr
 Smart pointer type to BREP.
 
typedef rw::core::Ptr< const BREPCPtr
 Smart pointer type to const BREP.
 
- Public Types inherited from GeometryData
enum  GeometryType {
  PointCloud , LineMesh , PlainTriMesh , IdxTriMesh ,
  SpherePrim , BoxPrim , OBBPrim , AABBPrim ,
  LinePrim , PointPrim , PyramidPrim , ConePrim ,
  TrianglePrim , CylinderPrim , TubePrim , PlanePrim ,
  RayPrim , Implicit , Quadratic , UserType
}
 geometry data types
 
typedef rw::core::Ptr< GeometryDataPtr
 smart pointer type to this class
 
typedef rw::core::Ptr< const GeometryDataCPtr
 const smart pointer type to this class
 

Public Member Functions

virtual ~BREP ()
 Destructor.
 
virtual GeometryType getType () const =0
 the type of this primitive More...
 
virtual rw::core::Ptr< TriMeshgetTriMesh (bool forceCopy=true)
 Create a TriMesh representation from this boundary representation. More...
 
virtual bool isConvex ()
 test if this geometry data is convex More...
 
virtual bool isConvex () const
 test if this geometry data is convex More...
 
virtual const rw::geometry::SurfacegetSurface (std::size_t surfaceIndex) const =0
 Get surface. More...
 
virtual const rw::geometry::CurvegetCurve (std::size_t curveIndex) const =0
 Get curve. More...
 
virtual void scale (double factor)=0
 Scale the object. More...
 
BREP::Ptr clone () const
 Make a deep copy of the BREP. More...
 
rw::core::Ptr< const rw::geometry::ShellshellProxy () const
 Get a Shell representation as a proxy to the BREP. More...
 
std::vector< rw::core::Ptr< rw::geometry::Curve > > getCurves (std::size_t loopIdx) const
 Get the curves in a given loop. More...
 
CommonCurveSet::CPtr getCommonCurves (const std::set< std::size_t > &faces) const
 Get a set of common curves between a set of faces. More...
 
std::size_t faceCount () const
 The number of faces. More...
 
std::size_t loopCount () const
 The number of loops. More...
 
std::size_t edgeCount () const
 The number of edges. More...
 
std::size_t verticeCount () const
 The number of vertices. More...
 
const rw::math::Vector3D< double > & getVertex (std::size_t vertexIndex) const
 Get vertex. More...
 
std::vector< rw::math::Vector3D< double > > getVertices (std::size_t loopIdx) const
 Get the vertices in a given loop. More...
 
bool hasSurfaceSet (std::size_t loop)
 Check if a certain loop has a surface set. More...
 
std::size_t getSurfaceIndex (std::size_t loop)
 Get the surface index of a loop. More...
 
rw::geometry::OBB obb (const rw::math::Rotation3D<> &R)
 Create Oriented Bounding Box with certain principal directions. More...
 
rw::geometry::OBB obb ()
 Create Oriented Bounding Box where the directions are estimated. More...
 
void addVertex (const rw::math::Vector3D< double > &point)
 Add a vertex to the BREP. More...
 
void makeLoop (int singleEdgeId)
 Create a loop containing a single edge (typically for circles and ellipses and similar). More...
 
template<typename T >
int makeLoop (T first, T second)
 Create a loop containing two edges. More...
 
template<typename T , typename... Args>
int makeLoop (T first, Args... args)
 Create a loop with a variable number of edges. More...
 
void stitchEdges (std::size_t first, std::size_t second)
 Connect two half-edges. More...
 
void stitchAuto (double eps)
 Try to stitch edges automatically. More...
 
rw::geometry::OBB faceOBB (std::size_t faceIndex)
 Create Oriented Bounding Box for a face. More...
 
rw::geometry::OBB edgeOBR (std::size_t edge) const
 Create Oriented Bounding Rectangle for an edge. More...
 
std::pair< double, double > faceExtremums (std::size_t faceIndex, const rw::math::Vector3D< double > &dir) const
 Find the extent of the surface along a specific direction. More...
 
rw::core::Ptr< rw::geometry::TriMeshfaceTriMesh (std::size_t faceIndex)
 Construct a Triangle Mesh for a face. More...
 
void setMeshResolution (double resolution=10)
 Set the resolution used for discretization in the getTriMesh and faceTriMesh functions. More...
 
virtual void print ()
 Print the structure of the BREP for debugging purposes.
 
- Public Member Functions inherited from GeometryData
virtual ~GeometryData ()
 Destructor.
 

Protected Member Functions

 BREP ()
 Constructor.
 
void copyTopologyTo (BREP::Ptr brep) const
 Copy the topology of this BREP to another brep. More...
 
void addBREPEdge (std::size_t curveIndex, std::size_t vertex1, std::size_t vertex2)
 Add a edge (will insert a pair of half-edges). More...
 
void setBREPFace (std::size_t surfaceIndex, std::size_t loop)
 Attach a surface to a loop. More...
 

Protected Attributes

std::vector< Vertex * > _vertices
 The vertices in the BREP.
 
std::vector< std::pair< HalfEdge *, HalfEdge * > > _edges
 The half-edges in the BREP.
 
std::vector< Face * > _faces
 The faces in the BREP. A face is added for each loop constructed.
 
double _resolution
 Resolution used for discretization functions.
 

Additional Inherited Members

- Static Public Member Functions inherited from GeometryData
static std::string toString (GeometryType type)
 format GeometryType to string More...
 

Detailed Description

Boundary representation (or B-Rep) of a geometric shape, using a collection of connected surfaces, edges and vertices.

In the Shell representation, the geometric shape is formed as a collection of disconnected faces. The BREP representation adds more information about the topology, as surface and curve elements are connected. For a certain surface, curve or vertex, it is possible to find information about the directly connected neighbouring surfaces, edges and vertices. From a BREP it is also possible to retrieve a Shell representation, but in the Shell representation information about connectedness is lost.

The half-edge data structure is used internally to store the topological information about the faces, edges and vertices, and how they are connected. Subtypes of BREP implements the concrete Surface and Curve geometries that can be attached to the faces and edges.

In general, the procedure for forming a BREP is the following:

  1. Add all the needed vertices by using the addVertex function. Each vertex is given an index starting, increasing from zero.
  2. Add the edges. An edge is added between two vertices using their vertex indexes. Addition of edges is documented under the specific BREP implementation (depending on the type of Curve that is expected). The edge is in general added with a Curve and two vertex indices. Notice that the curve must have limits, such that it starts in the first vertex and ends in the second vertex (the curve has a direction). Each edge is given an index, increasing from zero.
  3. Use the makeLoop function to form loops, based on the edges just added. The makeLoop takes an arbitrary number of edge indices. Notice that makeLoop expects the edge indexing to start at 1, and supports negative indices to indicate opposite direction of the edge. To form a loop, a list of these indexes is given, to form a counter clockwise loop of edges. Each loop is given a loop index, increasing from zero.
  4. Attach a Surface to each loop. Again, the addition of surfaces is documented under the specific BREP implementation (depending on the type of Surface that is expected). Each surface is given an increasing surface index, starting from zero. Notice that this index is not necessarily the same as the loop index.

Member Function Documentation

◆ addBREPEdge()

void addBREPEdge ( std::size_t  curveIndex,
std::size_t  vertex1,
std::size_t  vertex2 
)
protected

Add a edge (will insert a pair of half-edges).

Notice that a curve has direction, so it should start in vertex1 and end in vertex2.

Parameters
curveIndex[in] index of the curve data for the edge.
vertex1[in] the first vertex.
vertex2[in] the end vertex.

◆ addVertex()

void addVertex ( const rw::math::Vector3D< double > &  point)

Add a vertex to the BREP.

Parameters
point[in] the vertex to add.

◆ clone()

BREP::Ptr clone ( ) const
inline

Make a deep copy of the BREP.

Returns
a copy of the BREP.

◆ copyTopologyTo()

void copyTopologyTo ( BREP::Ptr  brep) const
protected

Copy the topology of this BREP to another brep.

Parameters
brep[in/out] the other brep to copy data to.

◆ edgeCount()

std::size_t edgeCount ( ) const
inline

The number of edges.

Returns
the number of edges.

◆ edgeOBR()

rw::geometry::OBB edgeOBR ( std::size_t  edge) const

Create Oriented Bounding Rectangle for an edge.

Parameters
edge[in] the edge index, which should be less than edgeCount().
Returns
OBB for the given edge (with third half-length set to zero).

◆ faceCount()

std::size_t faceCount ( ) const

The number of faces.

The number of faces is the number of loops, where a surface has been attached.

Returns
the number of faces.

◆ faceExtremums()

std::pair<double, double> faceExtremums ( std::size_t  faceIndex,
const rw::math::Vector3D< double > &  dir 
) const

Find the extent of the surface along a specific direction.

If the surface has no lower bound, the value -std::numeric_limits<double>::max() can be returned to indicate that the surface has unbounded minimum value in the given direction.

If the surface has no upper bound, the value std::numeric_limits<double>::max() can be returned to indicate that the surface has unbounded maximum value in the given direction.

Parameters
faceIndex[in] the face index, which should be less than loopCount().
dir[in] a normalized direction vector.
Returns
the minimum and maximum values along the given direction.

◆ faceOBB()

rw::geometry::OBB faceOBB ( std::size_t  faceIndex)

Create Oriented Bounding Box for a face.

Parameters
faceIndex[in] the face index, which should be less than loopCount().
Returns
OBB for the given face.

◆ faceTriMesh()

rw::core::Ptr<rw::geometry::TriMesh> faceTriMesh ( std::size_t  faceIndex)

Construct a Triangle Mesh for a face.

Parameters
faceIndex[in] the face index, which should be less than loopCount().
Returns
a triangle mesh.

◆ getCommonCurves()

CommonCurveSet::CPtr getCommonCurves ( const std::set< std::size_t > &  faces) const

Get a set of common curves between a set of faces.

Parameters
faces[in] loop indexes for the faces to consider.
Returns
set of common curves as a CommonCurveSet.

◆ getCurve()

virtual const rw::geometry::Curve& getCurve ( std::size_t  curveIndex) const
pure virtual

Get curve.

Parameters
curveIndex[in] index of the curve. Should be less than the number returned by edgeCount().
Returns
a reference to the curve.

Implemented in QuadraticBREP, and ImplicitBREP.

◆ getCurves()

std::vector<rw::core::Ptr<rw::geometry::Curve> > getCurves ( std::size_t  loopIdx) const

Get the curves in a given loop.

The curves will be traversed in an ordered way, and curves will have a direction that leads to the next curve.

Parameters
loopIdx[in] the loop index.
Returns
an ordered vector of curves.

◆ getSurface()

virtual const rw::geometry::Surface& getSurface ( std::size_t  surfaceIndex) const
pure virtual

Get surface.

Parameters
surfaceIndex[in] the index of the surface. Should be less than the number returned by size().
Returns
a reference to the surface.

Implemented in QuadraticBREP, and ImplicitBREP.

◆ getSurfaceIndex()

std::size_t getSurfaceIndex ( std::size_t  loop)

Get the surface index of a loop.

Parameters
loop[in] the loop index.
Returns
the corresponding surface index.

◆ getTriMesh()

virtual rw::core::Ptr<TriMesh> getTriMesh ( bool  forceCopy = true)
virtual

Create a TriMesh representation from this boundary representation.

This function relies on the resolution set with setMeshResolution. The resolution is passed on to Curve::discretizeAdaptive and Surface::setDiscretizationResolution.

Parameters
forceCopy[in] generate a new copy, or use a cached TriMesh.
Returns
a new TriMesh if forceCopy is true, or a shared cached TriMesh if forceCopy is false.

Implements GeometryData.

◆ getType()

virtual GeometryType getType ( ) const
pure virtual

the type of this primitive

Implements GeometryData.

Implemented in QuadraticBREP, and ImplicitBREP.

◆ getVertex()

const rw::math::Vector3D<double>& getVertex ( std::size_t  vertexIndex) const
inline

Get vertex.

Parameters
vertexIndex[in] index of the vertex. Should be less than the number returned by vertices().
Returns
reference to the vertex.

◆ getVertices()

std::vector<rw::math::Vector3D<double> > getVertices ( std::size_t  loopIdx) const

Get the vertices in a given loop.

The curves will be traversed in an ordered way around the loop.

Parameters
loopIdx[in] the loop index.
Returns
a collection of vertices.

◆ hasSurfaceSet()

bool hasSurfaceSet ( std::size_t  loop)
inline

Check if a certain loop has a surface set.

Parameters
loop[in] index of the loop, which should be less than loopCount().
Returns
true if a surface is set, false otherwise.

◆ isConvex() [1/2]

virtual bool isConvex ( )
virtual

test if this geometry data is convex

Returns
true if convex

Reimplemented from GeometryData.

◆ isConvex() [2/2]

virtual bool isConvex ( ) const
virtual

test if this geometry data is convex

Returns
true if convex

◆ loopCount()

std::size_t loopCount ( ) const
inline

The number of loops.

Returns
the number of loops.

◆ makeLoop() [1/3]

void makeLoop ( int  singleEdgeId)

Create a loop containing a single edge (typically for circles and ellipses and similar).

The half-edge structure requires that an edge must start and end in a vertex. Sometimes it is possible to have an edge without any vertices. This is, for example, the case for a circular or elliptic cylinder, where there will be two circular or elliptic edges. It is necessary to place one vertex on the circle or ellipse that can act as both the start and end vertex for the curve.

Parameters
singleEdgeId[in] id of the edge to create loop for. 1-indexing is expected, with a sign that indicates the edge direction.

◆ makeLoop() [2/3]

int makeLoop ( first,
Args...  args 
)
inline

Create a loop with a variable number of edges.

Parameters
first[in] id of the first edge. 1-indexing is expected, with a sign that indicates the edge direction.
args[in] id of the following edges. Any number of arguments can be given.
Returns
the first index, first.

◆ makeLoop() [3/3]

int makeLoop ( first,
second 
)
inline

Create a loop containing two edges.

Parameters
first[in] id of the first edge. 1-indexing is expected, with a sign that indicates the edge direction.
second[in] id of the following edge. 1-indexing is expected, with a sign that indicates the edge direction.
Returns
the first index, first.

◆ obb() [1/2]

Create Oriented Bounding Box where the directions are estimated.

This method is more expensive than obb(const rw::math::Rotation3D<>&), because a TriMesh is formed to estimated the principal directions of the OBB.

Returns
an OBB around the BREP.

◆ obb() [2/2]

Create Oriented Bounding Box with certain principal directions.

Parameters
R[in] the directions for the bounding box.
Returns
an OBB around the BREP.

◆ scale()

virtual void scale ( double  factor)
pure virtual

Scale the object.

Parameters
factor[in] the factor to scale with.

Implemented in QuadraticBREP, and ImplicitBREP.

◆ setBREPFace()

void setBREPFace ( std::size_t  surfaceIndex,
std::size_t  loop 
)
protected

Attach a surface to a loop.

Parameters
surfaceIndex[in] index of the surface data for the loop.
loop[in] the loop index.

◆ setMeshResolution()

void setMeshResolution ( double  resolution = 10)
inline

Set the resolution used for discretization in the getTriMesh and faceTriMesh functions.

The meaning of this parameter depends on the type of surface.

Parameters
resolution[in] the resolution parameter.

◆ shellProxy()

rw::core::Ptr<const rw::geometry::Shell> shellProxy ( ) const
inline

Get a Shell representation as a proxy to the BREP.

Returns
smart pointer to a Shell proxy object.

◆ stitchAuto()

void stitchAuto ( double  eps)

Try to stitch edges automatically.

Parameters
eps[in] distance threshold for vertices and curves.

◆ stitchEdges()

void stitchEdges ( std::size_t  first,
std::size_t  second 
)

Connect two half-edges.

Parameters
first[in] id of the first edge. 0-indexing is expected, with a sign that indicates the edge direction.
second[in] id of the second edge. 0-indexing is expected, with a sign that indicates the edge direction.
Note
Implementations calling this function should remember to delete the curve associated to the second half-edge if it is different than the curve set for the first half-edge.
Exceptions
rw::core::Exceptionif one of the given half-edges is already connected to another half-edge.

◆ verticeCount()

std::size_t verticeCount ( ) const
inline

The number of vertices.

Returns
the number of vertices.

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