Fairing Interpolated or approximated curves

Dear all,

I read there is curve fairing package in Opencascade. As stated here http://dev.opencascade.org/doc/refman/html/package_faircurve.html.

But i couldn't find any example tutorial or guide to used this package. I have an interpolated or approximated curves ( Handle_Geom_BSplineCurve) from points. I wanted to fair those curves. How can I use FairCurve_MinimalVariation or FairCurve_Batten or other methods to get faired curves.
Can any one share, i peace of code?

Thank you for your help in advance!

Game

jelle's picture
Andrey Pozdeev's picture

Hi Game,

if you look at the samples provided.... there is an MFC/Geometry sample in the sample folder. something like this \opencascade-6.7.1\samples\mfc\standard\01_Geometry

if you run the example there are two fair curve buttons that show the fair curve in action...

it will show the code used to make the geometry.

there are two classes for making fair curves, FairCurve_Batten and FairCurve_MinimalVariation
however, you should take into consideration that these are 2dimensional curves... to display them in a 3d viewport you would have to convert it to a 3d curve... in the end of this post I show how you do that.

1- Batten Curve:

gp_Pnt2d P1(-184, 101);
gp_Pnt2d P2(20 ,84);
Standard_Real aheight = 1;
FairCurve_Batten B (P1,P2,aheight);
B.SetAngle1(22*PI180);
B.SetAngle2(44*PI180);
FairCurve_AnalysisCode anAnalysisCode;
B.Compute(anAnalysisCode);
Handle(Geom2d_BSplineCurve) C = B.Curve();

2- MinimalVariation:

gp_Pnt2d P1(-184, 41);
gp_Pnt2d P2(20 ,24);
Standard_Real aheight = 1;
FairCurve_MinimalVariation MV (P1,P2,aheight);
MV.SetAngle1(22*PI180);
MV.SetAngle2(44*PI180);

FairCurve_AnalysisCode anAnalysisCode;
MV.Compute(anAnalysisCode);

Handle(Geom2d_BSplineCurve) C = MV.Curve();

------------------------------------------------------------------------

how to convert a 2d curve to a 3d curve:

a- create a plane in which to mount the 2d curve... for example by creating an average plane from 3 points by passing the start,mid,end points of where you want the fair curve to be in 3d space.

Handle_Geom_Plane myplane = GC_MakePlane (startp, midp, endp);
gp_Pln avrgplane = myplane->Pln();

b- convert the 2d start (P1) and 2d endpoint (P2) to 3d points, you will need this to use as limits during BRepBuilderAPI_MakeEdge construction:

gp_Pnt tp13d,tp23d;
plane3d->D0(P1.X(),P1.Y(),tp13d);
plane3d->D0(P2.X(),P2.Y(),tp23d);

Handle(Geom_Curve) C3D = GeomAPI::To3d(C,avrgplane);
TopoDS_Edge faircurveedge = BRepBuilderAPI_MakeEdge(C3D,tp13d,tp23d);

Andrey Pozdeev's picture

typo: replace "plane3d" with "avrgplane" in the post above...