Salome HOME
Correct projection for periodic B-spline. Update unit tests.
[modules/shaper.git] / src / GeomAPI / GeomAPI_BSpline.cpp
1 // Copyright (C) 2019-2020  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include <GeomAPI_BSpline.h>
21 #include <GeomAPI_Pnt.h>
22
23 #include <Geom_BSplineCurve.hxx>
24
25 #define MY_BSPLINE (*(implPtr<Handle_Geom_BSplineCurve>()))
26
27 GeomAPI_BSpline::GeomAPI_BSpline(const GeomCurvePtr& theCurve)
28 {
29   GeomCurvePtr anUntrimmedCurve = theCurve->basisCurve();
30   Handle(Geom_Curve) aCurve = anUntrimmedCurve->impl<Handle(Geom_Curve)>();
31   Handle(Geom_BSplineCurve) aBSpl = Handle(Geom_BSplineCurve)::DownCast(aCurve);
32   if (aBSpl.IsNull())
33     throw Standard_ConstructionError("GeomAPI_BSpline: Curve is not a B-spline");
34   setImpl(new Handle_Geom_BSplineCurve(aBSpl));
35 }
36
37 int GeomAPI_BSpline::degree() const
38 {
39   return MY_BSPLINE->Degree();
40 }
41
42 std::list<GeomPointPtr> GeomAPI_BSpline::poles() const
43 {
44   const TColgp_Array1OfPnt& aBSplPoles = MY_BSPLINE->Poles();
45
46   std::list<GeomPointPtr> aPoles;
47   for (int anIndex = aBSplPoles.Lower(); anIndex <= aBSplPoles.Upper(); ++anIndex) {
48     const gp_Pnt& aPoint = aBSplPoles.Value(anIndex);
49     aPoles.push_back(GeomPointPtr(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z())));
50   }
51   return aPoles;
52 }
53
54 std::list<double> GeomAPI_BSpline::weights() const
55 {
56   std::list<double> aWeights;
57   const TColStd_Array1OfReal* aBSplWeights = MY_BSPLINE->Weights();
58   if (aBSplWeights)
59     aWeights.assign(aBSplWeights->begin(), aBSplWeights->end());
60   return aWeights;
61 }
62
63 std::list<double> GeomAPI_BSpline::knots() const
64 {
65   const TColStd_Array1OfReal& aBSplKnots = MY_BSPLINE->Knots();
66   return std::list<double>(aBSplKnots.begin(), aBSplKnots.end());
67 }
68
69 std::list<int> GeomAPI_BSpline::mults() const
70 {
71   const TColStd_Array1OfInteger& aBSplMults = MY_BSPLINE->Multiplicities();
72   return std::list<int>(aBSplMults.begin(), aBSplMults.end());
73 }
74
75 bool GeomAPI_BSpline::isPeriodic() const
76 {
77   return MY_BSPLINE->IsPeriodic();
78 }