TopoDS_Edge built from Geom2d_Curve and Geom_Surface has not PCurve on face

Dear Sirs,

There is something I am not able to understand. I have a Handle(Geom2d_Curve) and an Handle(Geom_Surface)from which I create a TopoDS_Edge using the corresponding constructor from the BRepBuilderAPI_MakeEdge class. Note that the Handle(Geom2d_Curve) has been computed by projecting a Geom_Curve onto a Geom_Surface. The Geom_Surface is obtained from a TopoDS_Face using the BRep_Tool::Surface method.

Once the TopoDS_Edge has been built, I add to it a 3D curve using the ShapeFix_Edge::FixAddCurve3d( TopoDS_Edge) method. Such function returns Standard_True which makes me think that the computation is successful. As last stage I extract the Geom2d_Curve of the edge by using the BRep_Tool::CurveOnSurface function using the egde and the face generating the Geom_Surface I mentioned before. The CurveOnSurface method returns a null pointer. How is that possible? I first built the edge using a Handle(Geom2d_Curve) so I do not see why the pointer is null.

Can anyone explain me this result I get?

Thank you very much,

Regards,

Paolo

Benjamin Bihler's picture

Hi Paolo,

I have also found it to be like you explained here. It seems to me as if a curve on surface is only present, if the edge is a bounding edge of the face.

I use this code to create curves for edges that are not part of a face:

const Handle(Geom_Surface) surface = BRep_Tool::Surface(face);
Handle(Geom2d_Curve) curve = BRep_Tool::CurveOnSurface(edge, face, first,
last);

if (curve.IsNull())
{
// This code was adapted from BOPTools_AlgoTools2D::Make2D
TopLoc_Location location;
Handle(Geom_Curve) rawCurve3d = BRep_Tool::Curve(edge, location, first,
last);

if (rawCurve3d.IsNull())
{
throw Exception("Curve for edge is null.", __TRACE__);
}

Handle(Geom_Curve) curve3d;

if (location.IsIdentity())
{
curve3d = rawCurve3d;
}
else
{
curve3d = Handle(Geom_Curve)::DownCast(
rawCurve3d->Transformed(location.Transformation()));
}

// Set tolerance such that an example does not fail!
double tolerance = 1.0;

BOPTools_AlgoTools2D::MakePCurveOnFace(face, curve3d, first, last, curve,
tolerance);
}

Setting the tolerance to 1.0 before the last call is necessary because of issue "0026230: Segmentation fault because a NULL curve is used without precaution in case of a projection failure".

I hope this helps!

Benjamin

Paolo Tricerri's picture

Hello Benjamin,

thanks very much! I will try your example. The other method I came up with is the following:

0 - Having the 2dCurve and the Geom_Surface (extracted from a TopoDS_Face), I build a TopoDS_Edge and then I create all the ingredients needed to build a Geom_Curve using the GeomLib::BuildCurve3D.
1 - Using the created curve3d, I build an edge (let's call it edge3D) which is not guaranteed to have a pcurve on the surface.
2 - I project, using the NormalProjection algorithm, the edge3D onto the face and check the projection (which now should be very close to the original edge) has got a Geom2d_Curve on the face.
3 - In the worst case scenario, I think that using the projected edge onto the face and the face itself, a pcurve can be computed using the ShapeFix_Edge clas..

Thanks!
Paolo