NurbsUtils.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2023, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #ifndef MERCURYDPM_NURBSUTILS_H
27 #define MERCURYDPM_NURBSUTILS_H
28 
29 #include <vector>
30 #include <algorithm>
31 #include "Math/Vector.h"
32 
33 namespace NurbsUtils
34 {
35 
36 
40 template <typename T>
41 class array2 {
42 public:
43  array2(size_t nRows, size_t nCols, T fillValue = 0.0)
44  : rows(nRows), cols(nCols) {
45  data.resize(rows * cols, fillValue);
46  }
47 
48  T operator()(size_t row, size_t col) const {
49  return data[row*cols + col];
50  }
51 
52  T& operator()(size_t row, size_t col) {
53  return data[row*cols + col];
54  }
55 
56 private:
57  size_t rows, cols;
58  std::vector<T> data;
59 };
60 
61 bool isKnotVectorMonotonic(const std::vector<double>& knots);
62 
63 
64 bool close(double a, double b, double eps = std::numeric_limits<double>::epsilon());
65 
73 int findSpan(int degree, const std::vector<double>& knots, double u);
74 
75 
84 double bsplineOneBasis(int i, int deg, const std::vector<double>& U, double u);
85 
94 void bsplineBasis(int deg, int span, const std::vector<double>& knots, double u, std::vector<double>& N);
95 
105 void bsplineDerBasis(int deg, int span, const std::vector<double>& knots, double u,
106  int nDers, std::vector<std::vector<double>>& ders);
107 
116 std::vector<Mdouble> createUniformKnotVector(unsigned int numberOfControlPoints, unsigned int degree, bool clampedAtStart, bool clampedAtEnd);
117 
122 void normalizeKnotVector(std::vector<Mdouble>& knots);
123 
132 void extendKnotVector(std::vector<Mdouble>& knots, unsigned int degree, unsigned int numStart, unsigned int numEnd, bool forceBothEndsUniform = false);
133 
144 Vec3D evaluate(Mdouble u, Mdouble v, std::vector<Mdouble> knotsU, std::vector<Mdouble> knotsV,
145  std::vector<std::vector<Vec3D>> controlPoints, std::vector<std::vector<Mdouble>> weights);
146 }
147 
148 #endif //MERCURYDPM_NURBSUTILS_H
double Mdouble
Definition: GeneralDefine.h:34
Definition: NurbsUtils.h:41
array2(size_t nRows, size_t nCols, T fillValue=0.0)
Definition: NurbsUtils.h:43
size_t cols
Definition: NurbsUtils.h:57
size_t rows
Definition: NurbsUtils.h:57
std::vector< T > data
Definition: NurbsUtils.h:58
T operator()(size_t row, size_t col) const
Definition: NurbsUtils.h:48
T & operator()(size_t row, size_t col)
Definition: NurbsUtils.h:52
Definition: Vector.h:51
Definition: NurbsUtils.cc:31
int findSpan(int degree, const std::vector< double > &knots, double u)
Definition: NurbsUtils.cc:43
std::vector< Mdouble > createUniformKnotVector(unsigned int numberOfControlPoints, unsigned int degree, bool clampedAtStart, bool clampedAtEnd)
Creates a uniform (clamped) knot vector.
Definition: NurbsUtils.cc:254
double bsplineOneBasis(int i, int deg, const std::vector< double > &U, double u)
Definition: NurbsUtils.cc:84
void extendKnotVector(std::vector< Mdouble > &knots, unsigned int degree, unsigned int numStart, unsigned int numEnd, bool forceBothEndsUniform)
Extends the knot vector for when control points have been added at the start or end.
Definition: NurbsUtils.cc:304
void bsplineBasis(int deg, int span, const std::vector< double > &knots, double u, std::vector< double > &N)
Definition: NurbsUtils.cc:129
void bsplineDerBasis(int deg, int span, const std::vector< double > &knots, double u, int nDers, std::vector< std::vector< double >> &ders)
Definition: NurbsUtils.cc:155
void normalizeKnotVector(std::vector< Mdouble > &knots)
Resets the knot vector to the interval [0, 1].
Definition: NurbsUtils.cc:288
bool close(double a, double b, double eps)
Definition: NurbsUtils.cc:38
bool isKnotVectorMonotonic(const std::vector< double > &knots)
Definition: NurbsUtils.cc:33
Vec3D evaluate(Mdouble u, Mdouble v, std::vector< Mdouble > knotsU, std::vector< Mdouble > knotsV, std::vector< std::vector< Vec3D >> controlPoints, std::vector< std::vector< Mdouble >> weights)
Evaluate point on a NURBS surface.
Definition: NurbsUtils.cc:376
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
const Mdouble degree
Definition: ExtendedMath.h:52