This page is intended to collect recipes to do various things in Open CASCADE

Get the coordinates of a TopoDS_Vertex

You have a Vertex and you want to retrieve its position.

  1. If you're starting with a more general TopoDS_Shape reference shape to your vertex, you have to downcast to a TopoDS_Vertex object using the following code snippet 1
  2. If you start with a TopoDS_Vertex vertex, you can proceed directly to code snippet 2

Code snippet 1

TopoDS_Vertex vertex = TopoDS::Vertex(shape);

Code snippet 2

gp_Pnt pnt = BRep_Tool::Pnt(vertex);

(code is known to work with Open CASCADE versions: 6.3.0)

You can do the same thing by adding the vertex's coordinate transformation and the referenced point's coordinates.

gp_Pnt xyzlcs = shape.Location().Transformation().TranslationPart();
Handle(BRep_TVertex) tvertex = Handle(BRep_TVertex)::DownCast(shape.TShape());
gp_Pnt xyzpp = tvertex->Pnt().Coord();
gp_Pnt pnt = xyzlcs + xyzpp;

(code is known to work with Open CASCADE versions: 6.3.0)

Decide, whether a point lies inside or outside face/body

Open CASCADE provides services to classify a point with respect to a face or a body using the following classes

  • BRepClass3d_SolidClassifier
  • BRepClass_FaceClassifier


Triangulate a face

TopoDS_Face face;
double const deflection = 0.0001;
double const angulardeflection = 0.0001;
BRepMesh_IncrementalMesh discr(face, deflection, false, angulardeflection);
TopoDS_Face meshFace = TopoDS::Face(discr.Shape());
TopLoc_Location loc;
Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation(meshFace, loc);

(code is known to work with OCC versions: 6.3.0)

Compute the length of a curve

GeomAdaptor_Curve adapt(yourcurve);
double length=GCPnts_AbscissaPoint::Length(adapt);

(code is known to work with OCC versions: 6.3.0)

Get UV coordinates of a 3d point on a surface

gp_Pnt pnt = ...; //the point
Handle(Geom_Surface) surf = ...; //the surface
GeomAPI_ProjectPointOnSurf projpnta(pnt, surf);
double au, av; //the u- and v-coordinates of the projected point
projpnta.LowerDistanceParameters(au, av); //get the nearest projection
gp_Pnt2d pnta2d(au, av); //equivalent 2d description of pnt on surf

(code is known to work with OCC versions: 6.3.0, 6.5.0)

Displaying image in 3D view

Check this blog post and attached file.

Extract entity names from STEP/IGES files

Extract entity names from STEP/IGES files

Identify inner wire

bool IsInnerWire(const TopoDS_Wire& wire, const TopoDS_Face& face)
    TopoDS_Face newface = TopoDS::Face(face.EmptyCopied().Oriented(TopAbs_FORWARD));
    BRep_Builder b;
    b.Add(newface, wire);
    BRepTopAdaptor_FClass2d FClass2d(newface, Precision::PConfusion());
    return FClass2d.PerformInfinitePoint() != TopAbs_OUT;