CurveOnSurface

"BRep_Tool::CurveOnSurface" yields a Geom2d_Curve form a Geom_Surface and a TopoDSEdge. I am looking for an inverse function: Get a Geom_Curve from a Surface and a Geom2d_Curve, where the Geom2d_Curve represents a curve in the parametric coordinate system of the surface.
I also know "BRepBuilderAPI_MakeEdge" which yields a TopdDS_Edge, but this is not a Curve3D or Geom_Curve. I would also be happy with a Geom_BSplineCurve.
Any hint would be appreciated. Thanks!

Rob Bachrach's picture

Why not use BRep_Tool::Curve to get the Geom_Curve from
the edge after using BRepBuilderAPI_MakeEdge. This will
also give you the parametric extents of the curve on the
surface.

Gerhard Hofmann's picture

Hello Rob,
I dont know why, but BRep_Tool::Curve doesnt yield a valid Geom_Curve.
Very simple testcode in the following lines:

gp_Pln pln(0.0,0.0,1.0,0.0); // standard x/y-plane
TopoDS_Face patch = BRepBuilderAPI_MakeFace(pln,0.0,10.0,0.0,10.0);
// patch is a square part of the standard plane
double umin,umax,vmin,vmax;
BRepTools::UVBounds(patch,umin,umax,vmin,vmax);
// u and v run (ofcourse) from 0..10.0
gp_Pnt2d l1(5.0,0.0);
gp_Pnt2d l2(5.0,10.0);
GCE2d_MakeLine ml(l1,l2); // simple Line (exactly dividing the square patch)
TopLoc_Location L;
Handle(Geom_Surface) PatchAsGeomSurface = BRep_Tool::Surface(patch,L);
TopoDS_Edge EdgeOnPlane = BRepBuilderAPI_MakeEdge(ml.Value(),PatchAsGeomSurface);
// EdgeOnPlane should be a Line from (5,0,0) to (5,10,0)
double start,end;
Handle(Geom_Curve) EdgeAsGeomCurve = BRep_Tool::Curve(EdgeOnPlane,start,end);
// start and end are invalid here, also EdgeAsGeomCurve seems to be invalid
try
{
gp_Pnt p0 = EdgeAsGeomCurve->Value(0.5);
// crashes and I don't even get a Standard_Failure exception
} catch (Standard_Failure &f)
{
char *errormessage = f.GetMessageString();
} catch (...)
{
}

Thanks alot for looking at the code!
Gerhard

CTav's picture

Hi,

Perhaps the 3D curve doesn't exist yet. Try to computes it before.

Add,
BRepLib::BuilCurve3d(EdgeOnPlane);

Before,
Handle(Geom_Curve) EdgeAsGeomCurve = BRep_Tool::Curve(EdgeOnPlane,start,end);

Good luck,
Christian

Gerhard Hofmann's picture

Thanks Christian,
BuilCurve3d solved the problem!
BuilCurve3d cannot use an infinite Geom2d_Curve (except when the face is a plane), I had to use a Geom2d_TrimmedCurve instead.
Thanks alot!
Gerhard