1 #include<HYDROOperations_BSpline.h>
3 #include<TColgp_HArray1OfPnt.hxx>
4 #include<GeomAPI_Interpolate.hxx>
5 #include<GeomConvert_BSplineCurveToBezierCurve.hxx>
6 #include<Geom_BezierCurve.hxx>
8 HYDROOperations_BSpline::HYDROOperations_BSpline(
9 QList<double>& thePoints)
11 // fill array for algorithm by the received coordinates
12 int aLen = thePoints.size() / 2;
13 Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt (1, aLen);
14 QList<double>::iterator aListIter = thePoints.begin();
15 for (int ind = 1; ind <= aLen; ind++) {
16 gp_Pnt aPnt(gp::Origin());
17 aPnt.SetX(*aListIter);
19 aPnt.SetY(*aListIter);
21 aHCurvePoints->SetValue(ind, aPnt);
24 GeomAPI_Interpolate aGBC(aHCurvePoints, Standard_False, gp::Resolution());
27 myCurve = aGBC.Curve();
31 QPainterPath HYDROOperations_BSpline::ComputePath() const
34 if (myCurve.IsNull()) // returns an empty Path if original curve is invalid
36 GeomConvert_BSplineCurveToBezierCurve aConverter(myCurve);
37 int a, aNumArcs = aConverter.NbArcs();
38 for(a = 1; a <= aNumArcs; a++) {
39 Handle(Geom_BezierCurve) anArc = aConverter.Arc(a);
40 if (a == 1) { // set a start point
41 gp_Pnt aStart = anArc->StartPoint();
42 aResult.moveTo(aStart.X(), aStart.Y());
44 gp_Pnt anEnd = anArc->EndPoint();
45 if (anArc->NbPoles() == 3) { // quadric segment in the path (pole 1 is start, pole 3 is end)
46 gp_Pnt aPole = anArc->Pole(2);
47 aResult.quadTo(aPole.X(), aPole.Y(), anEnd.X(), anEnd.Y());
48 } else if (anArc->NbPoles() == 4) { // cubic segment (usually this is used)
49 gp_Pnt aPole1 = anArc->Pole(2);
50 gp_Pnt aPole2 = anArc->Pole(3);
52 aPole1.X(), aPole1.Y(), aPole2.X(), aPole2.Y(), anEnd.X(), anEnd.Y());
53 } else { // error, another number of poles is not supported
54 return QPainterPath();