WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit bef6058

Browse files
committed
important improvement!
1 parent 24d0afb commit bef6058

22 files changed

+566
-365
lines changed

src/LNLib/Geometry/Curve/NurbsCurve.cpp

Lines changed: 76 additions & 65 deletions
Large diffs are not rendered by default.

src/LNLib/Geometry/Surface/NurbsSurface.cpp

Lines changed: 140 additions & 125 deletions
Large diffs are not rendered by default.

src/LNLib/include/BezierCurve.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "ValidationUtils.h"
1515
#include "LNLibDefinitions.h"
1616
#include "LNLibExceptions.h"
17+
#include "LNObject.h"
1718
#include <vector>
1819

1920
namespace LNLib
@@ -25,8 +26,11 @@ namespace LNLib
2526
public:
2627

2728
template <typename T>
28-
static void Check(int degree, const std::vector<T>& controlPoints)
29+
static void Check(const LN_BezierCurve<T>& curve)
2930
{
31+
int degree = curve.Degree;
32+
std::vector<T> controlPoints = curve.ControlPoints;
33+
3034
VALIDATE_ARGUMENT(degree > 0, "degree", "Degree must greater than zero.");
3135
VALIDATE_ARGUMENT(controlPoints.size() > 0, "controlPoints", "ControlPoints must contains one point at least.");
3236
VALIDATE_ARGUMENT(ValidationUtils::IsValidBezier(degree, controlPoints.size()), "controlPoints", "ControlPoints count equals degree plus one.");
@@ -40,10 +44,13 @@ namespace LNLib
4044
/// Rational Bezier Curve:Use XYZW
4145
/// </summary>
4246
template <typename T>
43-
static T GetPointOnCurveByBernstein(int degree, const std::vector<T>& controlPoints, double paramT)
47+
static T GetPointOnCurveByBernstein(const LN_BezierCurve<T>& curve, double paramT)
4448
{
4549
VALIDATE_ARGUMENT_RANGE(paramT, 0.0, 1.0);
4650

51+
int degree = curve.Degree;
52+
std::vector<T> controlPoints = curve.ControlPoints;
53+
4754
std::vector<double> bernsteinArray = Polynomials::AllBernstein(degree, paramT);
4855
T temp;
4956
for (int k = 0; k <= degree; k++)
@@ -61,11 +68,12 @@ namespace LNLib
6168
/// Rational Bezier Curve:Use XYZW
6269
/// </summary>
6370
template <typename T>
64-
static T GetPointOnCurveByDeCasteljau(int degree, const std::vector<T>& controlPoints, double paramT)
71+
static T GetPointOnCurveByDeCasteljau(const LN_BezierCurve<T>& curve, double paramT)
6572
{
6673
VALIDATE_ARGUMENT_RANGE(paramT, 0.0, 1.0);
6774

68-
std::vector<T> temp = controlPoints;
75+
int degree = curve.Degree;
76+
std::vector<T> temp = curve.ControlPoints;
6977
for (int k = 1; k <= degree; k++)
7078
{
7179
for (int i = 0; i <= degree - k; i++)

src/LNLib/include/BezierSurface.h

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "BezierSurface.h"
1414
#include "BezierCurve.h"
1515
#include "LNLibDefinitions.h"
16+
#include "LNObject.h"
1617
#include <vector>
1718

1819
namespace LNLib {
@@ -25,8 +26,12 @@ namespace LNLib {
2526
public:
2627

2728
template <typename T>
28-
static void Check(int degreeU, int degreeV, const std::vector<std::vector<T>>& controlPoints)
29+
static void Check(const LN_BezierSurface<T>& surface)
2930
{
31+
int degreeU = surface.DegreeU;
32+
int degreeV = surface.DegreeV;
33+
std::vector<T> controlPoints = surface.ControlPoints;
34+
3035
VALIDATE_ARGUMENT(degreeU > 0, "degreeU", "Degree must greater than zero.");
3136
VALIDATE_ARGUMENT(degreeV > 0, "degreeV", "Degree must greater than zero.");
3237
VALIDATE_ARGUMENT(controlPoints.size() > 0, "controlPoints", "ControlPoints must contains one point at least.");
@@ -51,18 +56,31 @@ namespace LNLib {
5156
/// Rational Bezier Surface:Use XYZW
5257
/// </summary>
5358
template <typename T>
54-
static T GetPointOnSurfaceByDeCasteljau(int degreeU, int degreeV, const std::vector<std::vector<T>>& controlPoints, UV uv)
59+
static T GetPointOnSurfaceByDeCasteljau(const LN_BezierSurface<T>& surface, UV uv)
5560
{
5661
VALIDATE_ARGUMENT_RANGE(uv.GetU(), 0.0, 1.0);
5762
VALIDATE_ARGUMENT_RANGE(uv.GetV(), 0.0, 1.0);
5863

64+
int degreeU = surface.DegreeU;
65+
int degreeV = surface.DegreeV;
66+
std::vector<std::vector<T>> controlPoints = surface.ControlPoints;
67+
5968
T point;
6069
std::vector<T> temp(degreeU + 1);
6170
for (int i = 0; i <= degreeU; i++)
6271
{
63-
temp[i] = BezierCurve::GetPointOnCurveByDeCasteljau(degreeV, controlPoints[i], uv.GetV());
72+
LN_BezierCurve<T> b;
73+
b.Degree = degreeV;
74+
b.ControlPoints = controlPoints[i];
75+
76+
temp[i] = BezierCurve::GetPointOnCurveByDeCasteljau(b, uv.GetV());
6477
}
65-
point = BezierCurve::GetPointOnCurveByDeCasteljau(degreeU, temp, uv.GetU());
78+
79+
LN_BezierCurve<T> bezierCurve;
80+
bezierCurve.Degree = degreeU;
81+
bezierCurve.ControlPoints = temp;
82+
83+
point = BezierCurve::GetPointOnCurveByDeCasteljau(bezierCurve, uv.GetU());
6684
return point;
6785
}
6886
};

src/LNLib/include/BsplineCurve.h

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "Polynomials.h"
1515
#include "ValidationUtils.h"
1616
#include "LNLibExceptions.h"
17+
#include "LNObject.h"
1718
#include <vector>
1819

1920
namespace LNLib
@@ -25,8 +26,12 @@ namespace LNLib
2526
public:
2627

2728
template <typename T>
28-
static void Check(int degree, const std::vector<double>& knotVector, const std::vector<T>& controlPoints)
29+
static void Check(const LN_BsplineCurve<T>& curve)
2930
{
31+
int degree = curve.Degree;
32+
std::vector<double> knotVectors = curve.KnotVector;
33+
std::vector<T> controlPoints = curve.ControlPoints;
34+
3035
VALIDATE_ARGUMENT(degree > 0, "degree", "Degree must greater than zero.");
3136
VALIDATE_ARGUMENT(knotVector.size() > 0, "knotVector", "KnotVector size must greater than zero.");
3237
VALIDATE_ARGUMENT(ValidationUtils::IsValidKnotVector(knotVector), "knotVector", "KnotVector must be a nondecreasing sequence of real numbers.");
@@ -40,8 +45,12 @@ namespace LNLib
4045
/// Compute Bspline curve point.
4146
/// </summary>
4247
template <typename T>
43-
static T GetPointOnCurve(int degree, const std::vector<double>& knotVector, double paramT, const std::vector<T>& controlPoints)
48+
static T GetPointOnCurve(const LN_BsplineCurve<T>& curve, double paramT)
4449
{
50+
int degree = curve.Degree;
51+
std::vector<double> knotVector = curve.KnotVector;
52+
std::vector<T> controlPoints = curve.ControlPoints;
53+
4554
VALIDATE_ARGUMENT_RANGE(paramT, knotVector[0], knotVector[knotVector.size() - 1]);
4655

4756
T point;
@@ -61,10 +70,14 @@ namespace LNLib
6170
/// Compute curve derivatives. (Usually Use)
6271
/// </summary>
6372
template<typename T>
64-
static std::vector<T> ComputeDerivatives(int degree, int derivative, const std::vector<double>& knotVector, double paramT, const std::vector<T>& controlPoints)
73+
static std::vector<T> ComputeDerivatives(const LN_BsplineCurve<T>& curve, int derivative, double paramT)
6574
{
75+
int degree = curve.Degree;
76+
std::vector<double> knotVector = curve.KnotVector;
77+
std::vector<T> controlPoints = curve.ControlPoints;
78+
6679
VALIDATE_ARGUMENT(derivative > 0, "derivative", "derivative must greater than zero.");
67-
VALIDATE_ARGUMENT_RANGE(paramT, knotVector[0], knotVector[knotVector.size() - 1]);
80+
VALIDATE_ARGUMENT_RANGE(paramT, knotVector[0], knotVector[knotVector.size() - 1]);
6881

6982
std::vector<T> derivatives(derivative + 1);
7083

@@ -89,11 +102,15 @@ namespace LNLib
89102
/// Compute control points of curve derivatives.
90103
/// </summary>
91104
template<typename T>
92-
static std::vector<std::vector<T>> ComputeControlPointsOfDerivatives(int degree, int derivative, int minSpanIndex, int maxSpanIndex, const std::vector<double>& knotVector, const std::vector<T>& controlPoints)
105+
static std::vector<std::vector<T>> ComputeControlPointsOfDerivatives(const LN_BsplineCurve<T>& curve, int derivative, int minSpanIndex, int maxSpanIndex)
93106
{
94107
VALIDATE_ARGUMENT(derivative > 0, "derivative", "derivative must greater than zero.");
95108
VALIDATE_ARGUMENT_RANGE(minSpanIndex, 0, maxSpanIndex);
96109

110+
int degree = curve.Degree;
111+
std::vector<double> knotVector = curve.KnotVector;
112+
std::vector<T> controlPoints = curve.ControlPoints;
113+
97114
int range = maxSpanIndex - minSpanIndex;
98115
std::vector<std::vector<T>> PK(derivative + 1, std::vector<T>(range + 1));
99116

@@ -118,8 +135,12 @@ namespace LNLib
118135
/// Compute curve detivatives.
119136
/// </summary>
120137
template<typename T>
121-
static std::vector<T> ComputeDerivativesByAllBasisFunctions(int degree, int derivative, const std::vector<double>& knotVector, double paramT, const std::vector<T>& controlPoints)
138+
static std::vector<T> ComputeDerivativesByAllBasisFunctions(const LN_BsplineCurve<T>& curve, int derivative, double paramT)
122139
{
140+
int degree = curve.Degree;
141+
std::vector<double> knotVector = curve.KnotVector;
142+
std::vector<T> controlPoints = curve.ControlPoints;
143+
123144
VALIDATE_ARGUMENT(derivative > 0, "derivative", "derivative must greater than zero.");
124145
VALIDATE_ARGUMENT_RANGE(paramT, knotVector[0], knotVector[knotVector.size() - 1]);
125146

@@ -128,7 +149,13 @@ namespace LNLib
128149
std::vector<std::vector<double>> N = Polynomials::AllBasisFunctions(spanIndex, degree, knotVector, paramT);
129150

130151
int du = std::min(derivative, degree);
131-
std::vector<std::vector<T>> PK = ComputeControlPointsOfDerivatives(degree, du, spanIndex - degree, spanIndex, knotVector, controlPoints);
152+
153+
LN_BsplineCurve<T> bsplineCurve;
154+
bsplineCurve.Degree = degree;
155+
bsplineCurve.KnotVector = knotVector;
156+
bsplineCurve.ControlPoints = controlPoints;
157+
158+
std::vector<std::vector<T>> PK = ComputeControlPointsOfDerivatives(bsplineCurve, du, spanIndex - degree, spanIndex);
132159

133160
for (int k = 0; k <= du; k++)
134161
{

src/LNLib/include/BsplineSurface.h

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "BsplineCurve.h"
1616
#include "ValidationUtils.h"
1717
#include "LNLibExceptions.h"
18+
#include "LNObject.h"
1819
#include <vector>
1920

2021
namespace 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);

src/LNLib/include/LNObject.h

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,53 @@
1010

1111
#pragma once
1212
#include "LNLibDefinitions.h"
13+
#include "XYZ.h"
1314
#include "XYZW.h"
1415
#include <vector>
1516

1617
namespace LNLib
1718
{
18-
struct LNLIB_EXPORT LN_Curve
19+
template <typename T>
20+
struct LN_BezierCurve
21+
{
22+
int Degree;
23+
std::vector<T> ControlPoints;
24+
};
25+
26+
template <typename T>
27+
struct LN_BezierSurface
28+
{
29+
int DegreeU;
30+
int DegreeV;
31+
std::vector<std::vector<T>> ControlPoints;
32+
};
33+
34+
template <typename T>
35+
struct LN_BsplineCurve
36+
{
37+
int Degree;
38+
std::vector<double> KnotVector;
39+
std::vector<T> ControlPoints;
40+
};
41+
42+
template <typename T>
43+
struct LN_BsplineSurface
44+
{
45+
int DegreeU;
46+
int DegreeV;
47+
std::vector<double> KnotVectorU;
48+
std::vector<double> KnotVectorV;
49+
std::vector<std::vector<T>> ControlPoints;
50+
};
51+
52+
struct LNLIB_EXPORT LN_NurbsCurve
1953
{
2054
int Degree;
2155
std::vector<double> KnotVector;
2256
std::vector<XYZW> ControlPoints;
2357
};
2458

25-
struct LNLIB_EXPORT LN_Surface
59+
struct LNLIB_EXPORT LN_NurbsSurface
2660
{
2761
int DegreeU;
2862
int DegreeV;

0 commit comments

Comments
 (0)