I am using pythonOCC (very latest RC) to write a CAD/CAM program. One of the algorithms involve sectioning the Workpiece with Planes, and evaluating the resulting Curves on the Workpiece surfaces (to get normal/tangent information).
This the code I use:
# Section Shape
section = BRepAlgoAPI_Section(shape, plane)
for edge in Topo(section.Shape()).edges():
# Look for parent Face
face = TopoDS.TopoDS_face(TopoDS.TopoDS_Shape())
if section.HasAncestorFaceOn1(edge, face):
# Get Geometric Surface
surfHandle = BRep_Tool_Surface(face)
surf = surfHandle.GetObject()
# Extract Surface-Curve
curve2DHandle, uMin, uMax = BRep_Tool_CurveOnSurface(edge, face)
curve2D = curve2DHandle.GetObject()
# Compute Curve Points
uRef = linspace(uMin, uMax, 99)
for u in range(cLen):
# Eval UV-space Point
# Eval XYZ-space Point+Tangents+Normal
surf.D1(evalPnt2d.X(), evalPnt2d.Y(), evalPnt, evalUTan, evalVTan)
evalNor = evalUTan.Crossed(evalVTan)
It works fine when dealing with primitives (sphere, box, cylinder), but BRep_Tool_CurveOnSurface() returns empty Geom2D_Curves when dealing with Revolved Shapes or IGES/STEP Shapes (when strangely the Geom_Curve looks perfectly fine).
I found a way round by replacing use of Geom2D_Curve() with instead evaluating Geom_Curve() + GeomAPI_ProjectPointOnSurf(Point,Surf). But this method is atrociously slow by comparison!!!
I have not tried to replicate this code in C++, but my guess is that something is wrong with BRep_Tool_CurveOnSurface(). Has anyone experience something similar before?