NurbsUtils.h
Go to the documentation of this file.
1 // This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2 // Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3 // License: BSD 3-Clause License; see the LICENSE file in the root directory.
4 
5 #ifndef MERCURYDPM_NURBSUTILS_H
6 #define MERCURYDPM_NURBSUTILS_H
7 
8 #include <vector>
9 #include <algorithm>
10 #include "Math/Vector.h"
11 
12 namespace NurbsUtils
13 {
14 
15 
19 template <typename T>
20 class array2 {
21 public:
22  array2(size_t nRows, size_t nCols, T fillValue = 0.0)
23  : rows(nRows), cols(nCols) {
24  data.resize(rows * cols, fillValue);
25  }
26 
27  T operator()(size_t row, size_t col) const {
28  return data[row*cols + col];
29  }
30 
31  T& operator()(size_t row, size_t col) {
32  return data[row*cols + col];
33  }
34 
35 private:
36  size_t rows, cols;
37  std::vector<T> data;
38 };
39 
40 bool isKnotVectorMonotonic(const std::vector<double>& knots);
41 
42 
43 bool close(double a, double b, double eps = std::numeric_limits<double>::epsilon());
44 
52 int findSpan(int degree, const std::vector<double>& knots, double u);
53 
54 
63 double bsplineOneBasis(int i, int deg, const std::vector<double>& U, double u);
64 
73 void bsplineBasis(int deg, int span, const std::vector<double>& knots, double u, std::vector<double>& N);
74 
84 void bsplineDerBasis(int deg, int span, const std::vector<double>& knots, double u,
85  int nDers, std::vector<std::vector<double>>& ders);
86 
95 std::vector<Mdouble> createUniformKnotVector(unsigned int numberOfControlPoints, unsigned int degree, bool clampedAtStart, bool clampedAtEnd);
96 
101 void normalizeKnotVector(std::vector<Mdouble>& knots);
102 
111 void extendKnotVector(std::vector<Mdouble>& knots, unsigned int degree, unsigned int numStart, unsigned int numEnd, bool forceBothEndsUniform = false);
112 
123 Vec3D evaluate(Mdouble u, Mdouble v, std::vector<Mdouble> knotsU, std::vector<Mdouble> knotsV,
124  std::vector<std::vector<Vec3D>> controlPoints, std::vector<std::vector<Mdouble>> weights);
125 }
126 
127 #endif //MERCURYDPM_NURBSUTILS_H
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
int i
Definition: BiCGSTAB_step_by_step.cpp:9
m col(1)
m row(1)
Scalar * b
Definition: benchVecAdd.cpp:17
Definition: NurbsUtils.h:20
array2(size_t nRows, size_t nCols, T fillValue=0.0)
Definition: NurbsUtils.h:22
size_t cols
Definition: NurbsUtils.h:36
size_t rows
Definition: NurbsUtils.h:36
std::vector< T > data
Definition: NurbsUtils.h:37
T operator()(size_t row, size_t col) const
Definition: NurbsUtils.h:27
T & operator()(size_t row, size_t col)
Definition: NurbsUtils.h:31
Definition: Kernel/Math/Vector.h:30
@ N
Definition: constructor.cpp:22
const Scalar * a
Definition: level2_cplx_impl.h:32
double eps
Definition: crbond_bessel.cc:24
Definition: NurbsUtils.cc:10
int findSpan(int degree, const std::vector< double > &knots, double u)
Definition: NurbsUtils.cc:22
std::vector< Mdouble > createUniformKnotVector(unsigned int numberOfControlPoints, unsigned int degree, bool clampedAtStart, bool clampedAtEnd)
Creates a uniform (clamped) knot vector.
Definition: NurbsUtils.cc:233
double bsplineOneBasis(int i, int deg, const std::vector< double > &U, double u)
Definition: NurbsUtils.cc:63
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:283
void bsplineBasis(int deg, int span, const std::vector< double > &knots, double u, std::vector< double > &N)
Definition: NurbsUtils.cc:108
void bsplineDerBasis(int deg, int span, const std::vector< double > &knots, double u, int nDers, std::vector< std::vector< double >> &ders)
Definition: NurbsUtils.cc:134
void normalizeKnotVector(std::vector< Mdouble > &knots)
Resets the knot vector to the interval [0, 1].
Definition: NurbsUtils.cc:267
bool close(double a, double b, double eps)
Definition: NurbsUtils.cc:17
bool isKnotVectorMonotonic(const std::vector< double > &knots)
Definition: NurbsUtils.cc:12
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:355
double U
Swimming speed.
Definition: two_d_variable_diff_adapt.cc:53
list weights
Definition: calibrate.py:94
const Mdouble degree
Definition: ExtendedMath.h:32
double epsilon
Definition: osc_ring_sarah_asymptotics.h:43