Analyzing TopoDS_Shape with OpenCASCADE Shape Healing Tools
Analysis Module
Shape Validity Verification
The ShapeAnalysis package contains utilities for examining topological shapes. While these utilities are primarily designed for internal use with in repair tools, they can also be employed independently to detect specific geometric or topological defects in shapes before any remediation takes place.
Utilizing these analysis tools typically involves three steps:
Instantiate an analysis utility Initialize it with the target shape and tolerance parameters Execute targeted checks based on your requirements
TopoDS_Face targetFace = ...;
// initialize edge analyzer
ShapeAnalysis_Edge edgeInspector;
for (TopExp_Explorer explorer(targetFace, TopAbs_EDGE); explorer.More(); explorer.Next())
{
TopoDS_Edge currentEdge = TopoDS::Edge(explorer.Current());
if (!edgeInspector.HasCurve3d(currentEdge))
{
std::cout << "Edge lacks 3D representation\n";
}
}
Face Boundary Orientation Check
Use ShapeAnalysis::IsOuterBound to determine whether a face possesses an outer boundary:
TopoDS_Face targetFace = ...;
if (!ShapeAnalysis::IsOuterBound(targetFace))
{
std::cout << "Missing outer boundary on face\n";
}
Wire Validity Verification
The ShapeAnalysis_Wire class provides comprehensive wire inspection capabilities, including:
Validation of edge ordering within the wire Detection of undersized edges below threshold length Verification of edge curve consistency Identification of degenerate edges Recognition of self-intersecting or crossing edges (based on 2D curve intersection) Detection of missing edges creating gaps in surface parameterization Assessment of wire orientation for surface boundary determination Orientation verification of appended shapes (edges or wires)
Important: Most validation methods assume edges are properly sorted. When unsorted wires are detected, sorting must occur before invoking additional checks. The ShapeFix_Wire::FixOrder() method can address this issue.
The analyzer requires initialization with a wire, face (or surface with location), and precision value. After initialization, individual checks can be performed. The Perform() method executes all available validation operations simultaneously.
API methods return boolean values indicating whether issue were detected (setting ShapeExtend_DONE status). Each method maintains its execution state, queryable through Status...() methods.
Key methods in this class:
CheckOrder - Verifies proper edge sequencing CheckConnected - Detects disconnected edge sequences CheckSmall - Identifies edges shorter than specified threshold CheckSelfIntersection - Finds self-intersecting or adjacent intersecting edges (non-adjacent edge intersections remain undetected)
TopoDS_Wire targetWire = ...;
Standard_Real tolerance = 1e-04;
ShapeAnalysis_Wire wireInspector(targetWire, targetFace, tolerance);
if (wireInspector.CheckOrder())
{
std::cout << "Edge reordering required\n"
<< "Verify correct ordering prior to further inspection\n";
return;
}
if (wireInspector.CheckSmall(tolerance))
{
std::cout << "Wire contains edges below length threshold: " << tolerance << std::endl;
}
if (wireInspector.CheckConnected())
{
std::cout << "Wire contains disconnected segments\n";
}
if (wireInspector.CheckSelfIntersection())
{
std::cout << "Self-intersection detected among adjacent edges\n";
}
Edge Validity Verification
The ShapeAnalysis_Edge class offers extensive edge examination capabilities:
Retrieval of geometric representations (3D curves and 2D parametric curves on specified faces) Query of topological sub-elements (boundary vertices) Detection of overlapping edges Curve consistency analysis:
Mutual orientation verification between 3D and 2D curves
Correspondence validation between curves and vertices
This class follows the same status management pattern described previously.
TopoDS_Face workingFace = ...;
ShapeAnalysis_Edge edgeAnalyzer;
for (TopExp_Explorer ex(workingFace, TopAbs_EDGE); ex.More(); ex.Next())
{
TopoDS_Edge currentEdge = TopoDS::Edge(ex.Current());
if (!edgeAnalyzer.HasCurve3d(currentEdge))
{
std::cout << "3D curve missing on edge\n";
}
Handle(Geom2d_Curve) paramCurve;
Standard_Real curveStart = 0.0, curveEnd = 0.0;
if (edgeAnalyzer.PCurve(currentEdge, workingFace, paramCurve,
curveStart, curveEnd, Standard_False))
{
std::cout << "Parametric curve bounds [" << curveStart << ", " << curveEnd << "]\n";
}
Standard_Real maxDeviation = 0.0;
if (edgeAnalyzer.CheckSameParameter(currentEdge, maxDeviation))
{
std::cout << "SameParameter flag inconsistency found\n";
}
std::cout << "Deviation: " << maxDeviation << ", Tolerance: "
<< BRep_Tool::Tolerance(currentEdge) << std::endl;
}
TopoDS_Edge edgeA = ...;
TopoDS_Edge edgeB = ...;
Standard_Real overlapDistance = 0.0;
ShapeAnalysis_Edge edgeChecker;
Standard_Real toleranceThreshold = 0.0;
if (edgeChecker.CheckOverlapping(edgeA, edgeB, toleranceThreshold, overlapDistance))
{
std::cout << "Edge overlap detected, tolerance: " << toleranceThreshold << std::endl;
std::cout << "Overlapping domain span: " << overlapDistance << std::endl;
}