1515#include " BsplineCurve.h"
1616#include " ValidationUtils.h"
1717#include " LNLibExceptions.h"
18+ #include " LNObject.h"
1819#include < vector>
1920
2021namespace LNLib
@@ -26,8 +27,14 @@ namespace LNLib
2627 public:
2728
2829 template <typename T>
29- static void Check (int degreeU, int degreeV, const std::vector< double >& knotVectorU, const std::vector< double >& knotVectorV, const std::vector<std::vector<T>>& controlPoints )
30+ static void Check (const LN_BsplineSurface<T>& surface )
3031 {
32+ int degreeU = surface.DegreeU ;
33+ int degreeV = surface.DegreeV ;
34+ std::vector<double > knotVectorU = surface.KnotVectorU ;
35+ std::vector<double > knotVectorV = surface.KnotVectorV ;
36+ std::vector<std::vector<T>> controlPoints = surface.ControlPoints ;
37+
3138 VALIDATE_ARGUMENT (degreeU > 0 , " degreeU" , " Degree must greater than zero." );
3239 VALIDATE_ARGUMENT (degreeV > 0 , " degreeV" , " Degree must greater than zero." );
3340 VALIDATE_ARGUMENT (knotVectorU.size () > 0 , " knotVectorU" , " KnotVector size must greater than zero." );
@@ -45,8 +52,14 @@ namespace LNLib
4552 // / Compute surface point.
4653 // / </summary>
4754 template <typename T>
48- static T GetPointOnSurface (int degreeU, int degreeV, const std::vector< double >& knotVectorU, const std::vector< double >& knotVectorV, UV uv, const std::vector<std::vector<T>>& controlPoints )
55+ static T GetPointOnSurface (const LN_BsplineSurface<T >& surface, UV uv)
4956 {
57+ int degreeU = surface.DegreeU ;
58+ int degreeV = surface.DegreeV ;
59+ std::vector<double > knotVectorU = surface.KnotVectorU ;
60+ std::vector<double > knotVectorV = surface.KnotVectorV ;
61+ std::vector<std::vector<T>> controlPoints = surface.ControlPoints ;
62+
5063 VALIDATE_ARGUMENT_RANGE (uv.GetU (), knotVectorU[0 ], knotVectorU[knotVectorU.size () - 1 ]);
5164 VALIDATE_ARGUMENT_RANGE (uv.GetV (), knotVectorV[0 ], knotVectorV[knotVectorV.size () - 1 ]);
5265
@@ -77,8 +90,14 @@ namespace LNLib
7790 // / Compute surface derivatives. (Usually Use)
7891 // / </summary>
7992 template <typename T>
80- static std::vector<std::vector<T>> ComputeDerivatives (int degreeU, int degreeV, int derivative, const std::vector< double >& knotVectorU, const std::vector< double >& knotVectorV , UV uv, const std::vector<std::vector<T>>& controlPoints )
93+ static std::vector<std::vector<T>> ComputeDerivatives (const LN_BsplineSurface<T >& surface, int derivative , UV uv)
8194 {
95+ int degreeU = surface.DegreeU ;
96+ int degreeV = surface.DegreeV ;
97+ std::vector<double > knotVectorU = surface.KnotVectorU ;
98+ std::vector<double > knotVectorV = surface.KnotVectorV ;
99+ std::vector<std::vector<T>> controlPoints = surface.ControlPoints ;
100+
82101 VALIDATE_ARGUMENT (derivative > 0 , " derivative" , " derivative must greater than zero." );
83102 VALIDATE_ARGUMENT_RANGE (uv.GetU (), knotVectorU[0 ], knotVectorU[knotVectorU.size () - 1 ]);
84103 VALIDATE_ARGUMENT_RANGE (uv.GetV (), knotVectorV[0 ], knotVectorV[knotVectorV.size () - 1 ]);
@@ -124,8 +143,14 @@ namespace LNLib
124143 // / Compute control points of derivative surfaces.
125144 // / </summary>
126145 template <typename T>
127- static std::vector<std::vector<std::vector<std::vector<T>>>> ComputeControlPointsOfDerivatives (int degreeU, int degreeV , int derivative, int minSpanIndexU, int maxSpanIndexU, int minSpanIndexV, int maxSpanIndexV, const std::vector< double >& knotVectorU, const std::vector< double >& knotVectorV, UV uv, const std::vector<std::vector<T>>& controlPoints )
146+ static std::vector<std::vector<std::vector<std::vector<T>>>> ComputeControlPointsOfDerivatives (const LN_BsplineSurface<T>& surface , int derivative, int minSpanIndexU, int maxSpanIndexU, int minSpanIndexV, int maxSpanIndexV, UV uv)
128147 {
148+ int degreeU = surface.DegreeU ;
149+ int degreeV = surface.DegreeV ;
150+ std::vector<double > knotVectorU = surface.KnotVectorU ;
151+ std::vector<double > knotVectorV = surface.KnotVectorV ;
152+ std::vector<std::vector<T>> controlPoints = surface.ControlPoints ;
153+
129154 VALIDATE_ARGUMENT (derivative > 0 , " derivative" , " derivative must greater than zero." );
130155 VALIDATE_ARGUMENT_RANGE (minSpanIndexU, 0 , maxSpanIndexU);
131156 VALIDATE_ARGUMENT_RANGE (minSpanIndexV, 0 , maxSpanIndexV);
@@ -149,7 +174,12 @@ namespace LNLib
149174 points.emplace_back (controlPoints[i][j]);
150175 }
151176
152- std::vector<std::vector<T>> temp = BsplineCurve::ComputeControlPointsOfDerivatives (degreeU, du, minSpanIndexU, maxSpanIndexU, knotVectorU, points);
177+ LN_BsplineCurve<T> bsplineCurve;
178+ bsplineCurve.Degree = degreeU;
179+ bsplineCurve.KnotVector = knotVectorU;
180+ bsplineCurve.ControlPoints = points;
181+
182+ std::vector<std::vector<T>> temp = BsplineCurve::ComputeControlPointsOfDerivatives (bsplineCurve, du, minSpanIndexU, maxSpanIndexU);
153183 for (int k = 0 ; k <= du; k++)
154184 {
155185 for (int i = 0 ; i <= rangeU - k; i++)
@@ -164,7 +194,13 @@ namespace LNLib
164194 for (int i = 0 ; i <= rangeU - k; i++)
165195 {
166196 int dd = std::min (derivative - k, dv);
167- std::vector<std::vector<T>> temp = BsplineCurve::ComputeControlPointsOfDerivatives (degreeV, dd, 0 , rangeV, tempKv, PKL[k][0 ][i]);
197+
198+ LN_BsplineCurve<T> bsplineCurve;
199+ bsplineCurve.Degree = degreeV;
200+ bsplineCurve.KnotVector = tempKv;
201+ bsplineCurve.ControlPoints = PKL[k][0 ][i];
202+
203+ std::vector<std::vector<T>> temp = BsplineCurve::ComputeControlPointsOfDerivatives (bsplineCurve, dd, 0 , rangeV);
168204 for (int l = 1 ; l <= dd; l++)
169205 {
170206 for (int j = 0 ; j < rangeV - l; j++)
@@ -183,8 +219,14 @@ namespace LNLib
183219 // / Compute surface derivatives.
184220 // / </summary>
185221 template <typename T>
186- static std::vector<std::vector<T>> ComputeDerivativesByAllBasisFunctions (int degreeU, int degreeV, int derivative, const std::vector< double >& knotVectorU, const std::vector< double >& knotVectorV , UV uv, const std::vector<std::vector<T>>& controlPoints )
222+ static std::vector<std::vector<T>> ComputeDerivativesByAllBasisFunctions (const LN_BsplineSurface<T >& surface, int derivative , UV uv)
187223 {
224+ int degreeU = surface.DegreeU ;
225+ int degreeV = surface.DegreeV ;
226+ std::vector<double > knotVectorU = surface.KnotVectorU ;
227+ std::vector<double > knotVectorV = surface.KnotVectorV ;
228+ std::vector<std::vector<T>> controlPoints = surface.ControlPoints ;
229+
188230 VALIDATE_ARGUMENT (derivative > 0 , " derivative" , " derivative must greater than zero." );
189231 VALIDATE_ARGUMENT_RANGE (uv.GetU (), knotVectorU[0 ], knotVectorU[knotVectorU.size () - 1 ]);
190232 VALIDATE_ARGUMENT_RANGE (uv.GetV (), knotVectorV[0 ], knotVectorV[knotVectorV.size () - 1 ]);
@@ -196,7 +238,14 @@ namespace LNLib
196238 std::vector<std::vector<double >> Nu = Polynomials::AllBasisFunctions (uSpanIndex, degreeU, knotVectorU, uv.GetU ());
197239 std::vector<std::vector<double >> Nv = Polynomials::AllBasisFunctions (vSpanIndex, degreeV, knotVectorV, uv.GetV ());
198240
199- std::vector<std::vector<std::vector<std::vector<T>>>> PKL = ComputeControlPointsOfDerivatives (degreeU, degreeV, derivative, uSpanIndex - degreeU, uSpanIndex, vSpanIndex - degreeV, vSpanIndex, knotVectorU, knotVectorV, uv, controlPoints);
241+ LN_BsplineSurface<T> bsplineSurface;
242+ bsplineSurface.DegreeU = degreeU;
243+ bsplineSurface.DegreeV = degreeV;
244+ bsplineSurface.KnotVectorU = knotVectorU;
245+ bsplineSurface.KnotVectorV = knotVectorV;
246+ bsplineSurface.ControlPoints = controlPoints;
247+
248+ std::vector<std::vector<std::vector<std::vector<T>>>> PKL = ComputeControlPointsOfDerivatives (bsplineSurface, derivative, uSpanIndex - degreeU, uSpanIndex, vSpanIndex - degreeV, vSpanIndex, uv);
200249
201250 int du = std::min (derivative, degreeU);
202251 int dv = std::min (derivative, degreeV);
0 commit comments