MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NurbsUtils.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2020, 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 MERCURY_NURBSUTILS_H
27 #define MERCURY_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 
108 }
109 
110 #endif //MERCURY_NURBSUTILS_H
int findSpan(int degree, const std::vector< double > &knots, double u)
Find the span of the given parameter in the knot vector.
Definition: NurbsUtils.cc:43
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
T operator()(size_t row, size_t col) const
Definition: NurbsUtils.h:48
std::vector< T > data
Definition: NurbsUtils.h:58
double bsplineOneBasis(int i, int deg, const std::vector< double > &U, double u)
Compute a single B-spline basis function.
Definition: NurbsUtils.cc:84
A simple class for representing 2D runtime arrays.
Definition: NurbsUtils.h:41
T & operator()(size_t row, size_t col)
Definition: NurbsUtils.h:52
bool isKnotVectorMonotonic(const std::vector< double > &knots)
Definition: NurbsUtils.cc:33
bool close(double a, double b, double eps)
Definition: NurbsUtils.cc:38
array2(size_t nRows, size_t nCols, T fillValue=0.0)
Definition: NurbsUtils.h:43
void bsplineDerBasis(int deg, int span, const std::vector< double > &knots, double u, int nDers, std::vector< std::vector< double >> &ders)
Compute all non-zero derivatives of B-spline basis functions.
Definition: NurbsUtils.cc:155
void bsplineBasis(int deg, int span, const std::vector< double > &knots, double u, std::vector< double > &N)
Compute all non-zero B-spline basis functions.
Definition: NurbsUtils.cc:129