Hide menu
Loading...
Searching...
No Matches

Base class of topological shapes. More...

#include <cadex/ModelData_Shape.hxx>

Inheritance diagram for cadex::ModelData_Shape:
cadex::ModelData_Body cadex::ModelData_BodyList cadex::ModelData_Edge cadex::ModelData_Face cadex::ModelData_Shell cadex::ModelData_Solid cadex::ModelData_Vertex cadex::ModelData_Wire

Classes

class  Iterator
 Iterates over subshapes in a shape. More...
 

Public Member Functions

 ModelData_Shape ()
 Constructor.
 
 ModelData_Shape (const ModelData_Shape &theOther)
 Constructor.
 
 ModelData_Shape (ModelData_Shape &&theOther)
 Move constructor.
 
 ~ModelData_Shape ()
 Destructor.
 
ModelData_Shapeoperator= (const ModelData_Shape &theOther)
 Assignment operator.
 
ModelData_Shapeoperator= (ModelData_Shape &&theOther)
 Move assignment operator.
 
 operator const TopoDS_Shape & () const
 Casts this object to TopoDS_Shape.
 
ModelData_ShapeType Type () const
 Returns a shape type.
 
ModelData_ShapeOrientation Orientation () const
 Returns orientation flag.
 
ModelData_Shape Reversed () const
 Returns a shape that shares the same geometry and subshape graph but has opposite orientation.
 
ModelData_Shape Oriented (ModelData_ShapeOrientation theOrientation) const
 Returns a shape that shares the same geometry and subshape graph and has specified orientation.
 
void Nullify ()
 Nullifies the object.
 
bool IsNull () const
 Returns true if the object has not been initialized yet.
 
 operator bool () const
 Returns true if the object is not null.
 
bool IsEqual (const ModelData_Shape &theOther) const
 Returns true if the shape shares the same geometry and subshape graph, and has equal orientation.
 
bool IsSame (const ModelData_Shape &theOther) const
 Returns true if the shape shares the same geometry and subshape graph.
 
internal::ModelData_ShapeImpl * Impl () const
 Returns internal implementation object.
 

Protected Member Functions

 ModelData_Shape (const TopoDS_Shape &theOther, bool)
 Constructor.
 
 ModelData_Shape (internal::ModelData_ShapeImpl *theImpl)
 Constructor.
 

Protected Attributes

internal::Base_Handle myImpl
 Internal implementation object.
 

Detailed Description

Base class of topological shapes.

Topological shapes define boundaries of the geometrical entities (curves and surfaces) in B-Rep representation.

Some topological entities refer to geometrical entities (e.g. edge refers to curve and face refers to surface), whereas some only refer to child topological entities (e.g. wire refers to edges it consists of or shell refers to faces it consists of).

Types

Refer to Shape Types for the list of supported shape types. Type() returns a type as enumeration value which can be used to downcast to a respective subclass type, for instance:

ModelData_Shape aShape = ...;
if (aShape.Type() == ModelData_ST_Face) {
const ModelData_Face& aFace = static_cast<const ModelData_Face&> (aShape);
ModelData_Surface aSurface = aFace.Surface();
...
}
Defines a topological face.
Definition: ModelData_Face.hxx:32
ModelData_Surface Surface() const
Returns underlying surface.
Definition: ModelData_Face.cxx:253
Base class of topological shapes.
Definition: ModelData_Shape.hxx:37
ModelData_ShapeType Type() const
Returns a shape type.
Definition: ModelData_Shape.cxx:358
Base class for geometrical surfaces.
Definition: ModelData_Surface.hxx:44

Orientation

Each shape can have either forward or reversed orientation as returned by the Orientation() method. Meaning of orientation depends on the shape type:

  • For vertex, orientation has a meaning only in context of a parent edge where forward vertex corresponds to smaller parameter on the edge curve and reversed vertex to greater parameter.
  • For edge, orientation specifies whether edge direction is aligned or is opposite to underlying curve orientation.
  • For face, orientation specifies whether face normal is aligned or is opposite to underlying surface normal.
  • For wire, shell, solid, or body, orientation simply specifies whether subshapes should be considered with their own or opposite orientations. For instance, a reversed wire would be similar to a forward wire consisting of original edges taken with opposite orientations.
  • For body list, orientation does not apply.

A shape with the opposite orientation can be returned with the Reversed() method. A shape with a specified orientation can be returned with the Oriented() method. Both methods create a shallow copy of the original shape, which shares a subshape graph but has a distinct orientation flag.

Equality and similarity relationships

Two shapes are considered equal if they share the same definition (i.e. geometry and subshape graph) and have equal orientations. The method IsEqual() and operator==() can be used to check equality.

Two shapes are considered same if they share the same definition (i.e. geometry and subshape graph). Orientations are not required to be same. The method IsSame() can be used to check this relationship. Obviously, the 'IsSame' relationship is less strict than 'IsEqual'.

The following code snippet demonstrates both relationships:

ModelData_Shape aShape1 = ...;
//shapes with equal orientations are IsSame() and are equal
ModelData_Shape aShape2 = aShape1;
assert (aShape2 == aShape1);
assert (aShape2.IsSame (aShape1));
//shapes with opposite orientations are IsSame() but are not equal
ModelData_Shape aShape3 = aShape1.Reversed();
assert (aShape3.IsSame (aShape1));
assert (aShape3 != aShape1);
ModelData_Shape Reversed() const
Returns a shape that shares the same geometry and subshape graph but has opposite orientation.
Definition: ModelData_Shape.cxx:402
bool IsSame(const ModelData_Shape &theOther) const
Returns true if the shape shares the same geometry and subshape graph.
Definition: ModelData_Shape.cxx:436

For example, a closed shell contains pairs of IsSame() edges but with opposite orientations.

For any ModelData_Body created from single shape (e.g., solid body created from ModelData_Solid), IsSame() and IsEqual() returns true, if called for body and it's underlying shape. I.e.,

ModelData_Solid aSolid = ...;
assert (aBody.IsSame (aSolid));
assert (aBody.IsEqual (aSolid));
Defines a root topological shape that can be owned by B-Rep representation.
Definition: ModelData_Body.hxx:28
static ModelData_Body Create(const ModelData_Shape &theShape)
Creates a body from an arbitrary shape.
Definition: ModelData_Body.cxx:223
bool IsEqual(const ModelData_Shape &theOther) const
Returns true if the shape shares the same geometry and subshape graph, and has equal orientation.
Definition: ModelData_Shape.cxx:429
Defines a topological solid.
Definition: ModelData_Solid.hxx:31

Exploration of Subshapes

Children subshapes can be retrieved using ModelData_Shape::Iterator. Iterator supports two usage scenarios:

  • iteration over direct children (e.g. faces of a shell);
  • iteration over subshapes of a specified type (e.g. all edges inside a shell).

Refer to ModelData_Shape::Iterator for detailed explanations of both scenarios.

Resulting orientation

Orientation of a returned subshape is product of own subshape orientation (stored inside a subshape) and of its parent. Thus, if the subshape and its parent both have the same orientation then the returned subshape will have forward orientation, if they have opposite orientations then the returned subshape will have reversed orientation.

When exploring nested subshapes the same rule applies at each level of the hierarchy:

Resulting_orientation = parent_orientation * subshape_orientation * subsubshape_orientation * ...

For instance, when exploring a forward face, which has a wire with reversed orientation, with an edge having forward orientation, exploring that edge will return an edge with reversed orientation.

Storing Shapes in Containers

ModelData_Shape has a single data member, a shared pointer pointing to internal implementation (i.e. follows a 'pimpl' design pattern). ModelData_Shape subclasses do not add any own data fields. Therefore it is safe to store objects (even of different subtypes) in containers by value:

std::list<ModelData_Shape> aShapeList;
while (anIt.HasNext()) {
aShapeList.push_back (anIt.Next());
}
Iterates over subshapes in a shape.
Definition: ModelData_Shape.hxx:41

Storing Shapes in Associative Containers

Shapes can be stored in associative containers (such as std::unordered_map or std::unordered_set) as keys. Hash and equality functors required for such containers can be selected depending on desired behavior, whether the container must ensure uniquness defined in terms of equality or similarity relationships (see above):

Refer to Equality and similarity relationships for relationship definitions.

The following code snippet demonstrates usage of both approaches:

typedef std::unordered_map<ModelData_Shape,
int,
ModelData_OrientedShapeEqual> OrientedShapeMap;
typedef std::unordered_set<ModelData_Shape,
ModelData_UnorientedShapeEqual> UnorientedShapeSet;
// Returns true if the shell is open, i.e. has edges belonging to single face only.
static bool HasFreeBoundaries (const ModelData_Shell& theShell)
{
UnorientedShapeSet aSet;
ModelData_Shape::Iterator i (theShell, ModelData_ST_Edge);
while (i.HasNext()) {
const auto& aShape = i.Next();
auto r = aSet.insert (aShape);
if (!r.second) { //if the same edge was already encountered then remove it
aSet.erase (r.first);
}
}
return !aSet.empty();
}
Compares shapes using 'IsEqual' relationship.
Definition: ModelData_Shape.hxx:128
Hasher for ModelData_Shape using 'IsEqual' relationship.
Definition: ModelData_Shape.hxx:116
ModelData_Shape()
Constructor.
Definition: ModelData_Shape.cxx:283
Defines a connected set of faces.
Definition: ModelData_Shell.hxx:31
Compares shapes using 'IsSame' relationship.
Definition: ModelData_Shape.hxx:122
Hasher for ModelData_Shape using 'IsSame' relationship.
Definition: ModelData_Shape.hxx:110
Examples
MTKConverter/Program.cs, MTKConverter/main.cxx, advgeom/brepsimplify/Program.cs, exploring/appearance/Program.cs, exploring/appearance/main.cxx, exploring/brepgeometry/Program.cs, exploring/brepgeometry/main.cxx, exploring/breprepresentation/Program.cs, exploring/breprepresentation/main.cxx, exploring/layers/Program.cs, exploring/layers/main.cxx, exploring/propertytable/Program.cs, exploring/propertytable/main.cxx, helpers/shape_processor.cs, machining/dfm_analyzer/Program.cs, machining/feature_recognizer/Program.cs, meshing/visualizationmesher/Program.cs, modeling/assembly/Program.cs, modeling/assembly/main.cxx, modeling/brep/Program.cs, modeling/brep/main.cxx, modeling/metadata/Program.cs, modeling/metadata/main.cxx, modification/coloring/Program.cs, modification/coloring/main.cxx, modification/renaming/Program.cs, modification/renaming/main.cxx, sheet_metal/dfm_analyzer/Program.cs, sheet_metal/dfm_analyzer/main.cxx, sheet_metal/feature_recognizer/Program.cs, sheet_metal/feature_recognizer/main.cxx, sheet_metal/unfolder/Program.cs, sheet_metal/unfolder/main.cxx, visualization/qtquick_qml/measurements/main.cxx, and wall_thickness/visualization/Program.cs.

Member Function Documentation

◆ IsEqual()

bool cadex::ModelData_Shape::IsEqual ( const ModelData_Shape theOther) const

Returns true if the shape shares the same geometry and subshape graph, and has equal orientation.

See also
Equality and similarity relationships, IsSame().

◆ IsSame()

bool cadex::ModelData_Shape::IsSame ( const ModelData_Shape theOther) const

Returns true if the shape shares the same geometry and subshape graph.

See also
Equality and similarity relationships, IsEqual().

◆ Nullify()

void cadex::ModelData_Shape::Nullify ( )
inline

Nullifies the object.

IsNull() will return true after calling this method.

◆ operator bool()

cadex::ModelData_Shape::operator bool ( ) const
inline

Returns true if the object is not null.

Returns the value opposite to IsNull().

◆ operator const TopoDS_Shape &()

cadex::ModelData_Shape::operator const TopoDS_Shape & ( ) const

Casts this object to TopoDS_Shape.

May only be used if IsNull() returns false. Otherwise behavior is undefined.

◆ Orientation()

◆ Oriented()

ModelData_Shape cadex::ModelData_Shape::Oriented ( ModelData_ShapeOrientation  theOrientation) const

Returns a shape that shares the same geometry and subshape graph and has specified orientation.

See also
IsSame(), Reversed().

◆ Reversed()

ModelData_Shape cadex::ModelData_Shape::Reversed ( ) const

Returns a shape that shares the same geometry and subshape graph but has opposite orientation.

See also
IsSame(), Oriented().
Examples
modeling/assembly/Program.cs, modeling/assembly/main.cxx, and modeling/brep/Program.cs.

◆ Type()