1 // Copyright (C) 2019-2022 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <GeomAPI_BSpline.h>
21 #include <GeomAPI_Pnt.h>
23 #include <Geom_BSplineCurve.hxx>
25 #include <GeomConvert.hxx>
27 #define MY_BSPLINE (*(implPtr<Handle_Geom_BSplineCurve>()))
29 GeomAPI_BSpline::GeomAPI_BSpline (const GeomCurvePtr& theCurve)
31 GeomCurvePtr anUntrimmedCurve = theCurve->basisCurve();
32 Handle(Geom_Curve) aCurve = anUntrimmedCurve->impl<Handle(Geom_Curve)>();
33 Handle(Geom_BSplineCurve) aBSpl = Handle(Geom_BSplineCurve)::DownCast(aCurve);
35 throw Standard_ConstructionError("GeomAPI_BSpline: Curve is not a B-spline");
36 setImpl(new Handle_Geom_BSplineCurve(aBSpl));
39 int GeomAPI_BSpline::degree() const
41 return MY_BSPLINE->Degree();
44 std::list<GeomPointPtr> GeomAPI_BSpline::poles() const
46 const TColgp_Array1OfPnt& aBSplPoles = MY_BSPLINE->Poles();
48 std::list<GeomPointPtr> aPoles;
49 for (int anIndex = aBSplPoles.Lower(); anIndex <= aBSplPoles.Upper(); ++anIndex) {
50 const gp_Pnt& aPoint = aBSplPoles.Value(anIndex);
51 aPoles.push_back(GeomPointPtr(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z())));
56 std::list<double> GeomAPI_BSpline::weights() const
58 std::list<double> aWeights;
59 const TColStd_Array1OfReal* aBSplWeights = MY_BSPLINE->Weights();
61 aWeights.assign(aBSplWeights->begin(), aBSplWeights->end());
65 std::list<double> GeomAPI_BSpline::knots() const
67 const TColStd_Array1OfReal& aBSplKnots = MY_BSPLINE->Knots();
68 return std::list<double>(aBSplKnots.begin(), aBSplKnots.end());
71 std::list<int> GeomAPI_BSpline::mults() const
73 const TColStd_Array1OfInteger& aBSplMults = MY_BSPLINE->Multiplicities();
74 return std::list<int>(aBSplMults.begin(), aBSplMults.end());
77 bool GeomAPI_BSpline::isPeriodic() const
79 return MY_BSPLINE->IsPeriodic();
82 GeomBSplinePtr GeomAPI_BSpline::convertToBSpline (const GeomCurvePtr& theCurve)
84 GeomCurvePtr anUntrimmedCurve = theCurve->basisCurve();
85 Handle(Geom_Curve) aCurve = anUntrimmedCurve->impl<Handle(Geom_Curve)>();
86 Handle(Geom_BSplineCurve) aBSpl = Handle(Geom_BSplineCurve)::DownCast(aCurve);
88 // convert to b-spline
89 aBSpl = GeomConvert::CurveToBSplineCurve(aCurve);
92 throw Standard_ConstructionError("GeomAPI_BSpline: Conversion to B-spline failed");
93 GeomCurvePtr aResCurve (new GeomAPI_Curve());
94 aResCurve->setImpl(new Handle_Geom_BSplineCurve(aBSpl));
95 GeomBSplinePtr aResult (new GeomAPI_BSpline(aResCurve));