https://mooseframework.inl.gov
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Moose::BSpline Class Reference

Class implementing a uniform clamped B-Spline curve. More...

#include <BSpline.h>

Public Member Functions

 BSpline (const unsigned int degree, const libMesh::Point &start_point, const libMesh::Point &end_point, const libMesh::RealVectorValue &start_direction, const libMesh::RealVectorValue &end_direction, const unsigned int cps_per_half, const libMesh::Real sharpness)
 
libMesh::Point getPoint (const libMesh::Real t) const
 Evaluate the BSpline interpolation at given value of t. More...
 

Private Member Functions

std::vector< libMesh::RealbuildKnotVector () const
 Internal method for building the knot vector given the degree and control points. More...
 
std::vector< libMesh::PointcreateControlPoints () const
 Creates a vector control points from the SplineUtils set of functions. More...
 
libMesh::Real CdBBasis (const libMesh::Real t, const unsigned int i, const unsigned int j) const
 Evaluates the the basis function for a B-Spline according to the Cox-de-Boor recursive formula. More...
 
libMesh::Real firstCoeff (const libMesh::Real t, const unsigned int i, const unsigned int j) const
 Submethod used in CdBBasis routine. More...
 
libMesh::Real secondCoeff (const libMesh::Real t, const unsigned int i, const unsigned int j) const
 Submethod used in CdBBasis routine. More...
 

Private Attributes

const unsigned int _degree
 The polynomial degree of the B-Spline. More...
 
const libMesh::Point _start_point
 starting point of spline More...
 
const libMesh::Point _end_point
 ending point of spline More...
 
const libMesh::RealVectorValue _start_dir
 starting direction of spline More...
 
const libMesh::RealVectorValue _end_dir
 ending direction of spline More...
 
const unsigned int _cps_per_half
 number of control points per half of the spline (vertex is auto-included) More...
 
const libMesh::Real _sharpness
 sharpness of the curve More...
 
const std::vector< libMesh::Point_control_points
 The control points. More...
 
const std::vector< libMesh::Real_knot_vector
 The knot vector. More...
 

Detailed Description

Class implementing a uniform clamped B-Spline curve.

Reference used for implementation: https://mat.fsv.cvut.cz/gcg/sbornik/prochazkova.pdf The B-Spline is uniform because of the spacings in the knot vector The B-Spline is clamped because the knot vector starts (and ends) with (degree + 1) 0s (and 1s) Clamped means that it passes through the specified start and end points with specified slopes

Definition at line 25 of file BSpline.h.

Constructor & Destructor Documentation

◆ BSpline()

Moose::BSpline::BSpline ( const unsigned int  degree,
const libMesh::Point start_point,
const libMesh::Point end_point,
const libMesh::RealVectorValue start_direction,
const libMesh::RealVectorValue end_direction,
const unsigned int  cps_per_half,
const libMesh::Real  sharpness 
)

Definition at line 20 of file BSpline.C.

27  : _degree(degree),
28  _start_point(start_point),
29  _end_point(end_point),
30  _start_dir(start_direction),
31  _end_dir(end_direction),
32  _cps_per_half(cps_per_half),
33  _sharpness(sharpness),
36 {
37 }
const libMesh::Real _sharpness
sharpness of the curve
Definition: BSpline.h:96
const unsigned int _cps_per_half
number of control points per half of the spline (vertex is auto-included)
Definition: BSpline.h:94
const libMesh::RealVectorValue _end_dir
ending direction of spline
Definition: BSpline.h:92
const libMesh::RealVectorValue _start_dir
starting direction of spline
Definition: BSpline.h:90
const libMesh::Point _end_point
ending point of spline
Definition: BSpline.h:88
std::vector< libMesh::Real > buildKnotVector() const
Internal method for building the knot vector given the degree and control points. ...
Definition: BSpline.C:63
const std::vector< libMesh::Point > _control_points
The control points.
Definition: BSpline.h:98
std::vector< libMesh::Point > createControlPoints() const
Creates a vector control points from the SplineUtils set of functions.
Definition: BSpline.C:53
const libMesh::Point _start_point
starting point of spline
Definition: BSpline.h:86
const std::vector< libMesh::Real > _knot_vector
The knot vector.
Definition: BSpline.h:102
const unsigned int _degree
The polynomial degree of the B-Spline.
Definition: BSpline.h:84

Member Function Documentation

◆ buildKnotVector()

std::vector< libMesh::Real > Moose::BSpline::buildKnotVector ( ) const
private

Internal method for building the knot vector given the degree and control points.

Definition at line 63 of file BSpline.C.

64 {
65  std::vector<libMesh::Real> knot_vector(_degree, 0); // initialize bottom to zeros
66 
67  const unsigned int num_points_left = _control_points.size() + 1 - _degree;
68  if (_control_points.size() < _degree + 1)
69  mooseError("Number of control points must be greater than or equal to degree + 1!");
70 
71  for (const auto i : make_range(num_points_left))
72  {
73  knot_vector.push_back(i); // count up
74  mooseAssert(i < _control_points.size(),
75  "i must be less than the number of control points because of 0 indexing.");
76  }
77 
78  // Filling with int(degree + 1) 0s at the beginning and 1s at the end makes the B-spline go
79  // through the start and end point Note: the "+1" comes from the loop above which starts at 0 and
80  // ends at num_points_left - 1
81  for (const auto i : make_range(_degree))
82  {
83  libmesh_ignore(i);
84  knot_vector.push_back(num_points_left - 1);
85  }
86 
87  // Normalize values s.t. the the max value is 1.
88  // This must be done to have a constant domain of t to be between 0 and 1 (inclusive).
89  // NOTE: the spacing is uniform, making this a uniform BSpline
90  for (auto & value : knot_vector)
91  {
92  value /= (num_points_left - 1);
93  mooseAssert(value <= 1.0 && value >= 0.0,
94  "knot_vector must be normalized to 1 with minimum value 0.");
95  }
96 
97  return knot_vector;
98 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
void libmesh_ignore(const Args &...)
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
const std::vector< libMesh::Point > _control_points
The control points.
Definition: BSpline.h:98
IntRange< T > make_range(T beg, T end)
const unsigned int _degree
The polynomial degree of the B-Spline.
Definition: BSpline.h:84

◆ CdBBasis()

libMesh::Real Moose::BSpline::CdBBasis ( const libMesh::Real  t,
const unsigned int  i,
const unsigned int  j 
) const
private

Evaluates the the basis function for a B-Spline according to the Cox-de-Boor recursive formula.

Parameters
tparameter t in [0,1]
iindex corresponding to which control point
jdegree of the basis funtion
Returns
scalar quantity for the contribution of the basis function at i in the sum.

Definition at line 101 of file BSpline.C.

Referenced by getPoint().

102 {
103  mooseAssert(i + 1 < _knot_vector.size(), "Out of bounds access in knot vector");
104  mooseAssert(_knot_vector[i] <= _knot_vector[i + 1],
105  "Knot vector is ill-formatted. Ensure values are increasing." +
107  if (j == 0)
108  return ((t < _knot_vector[i + 1]) && (_knot_vector[i] <= t)) ? 1 : 0;
109  else
110  return BSpline::firstCoeff(t, i, j) * BSpline::CdBBasis(t, i, j - 1) +
111  BSpline::secondCoeff(t, i, j) * BSpline::CdBBasis(t, i + 1, j - 1);
112 }
libMesh::Real secondCoeff(const libMesh::Real t, const unsigned int i, const unsigned int j) const
Submethod used in CdBBasis routine.
Definition: BSpline.C:127
libMesh::Real CdBBasis(const libMesh::Real t, const unsigned int i, const unsigned int j) const
Evaluates the the basis function for a B-Spline according to the Cox-de-Boor recursive formula...
Definition: BSpline.C:101
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:64
const std::vector< libMesh::Real > _knot_vector
The knot vector.
Definition: BSpline.h:102
libMesh::Real firstCoeff(const libMesh::Real t, const unsigned int i, const unsigned int j) const
Submethod used in CdBBasis routine.
Definition: BSpline.C:115

◆ createControlPoints()

std::vector< libMesh::Point > Moose::BSpline::createControlPoints ( ) const
private

Creates a vector control points from the SplineUtils set of functions.

call SplineUtils function

Definition at line 53 of file BSpline.C.

54 {
55  std::vector<libMesh::Point> cps;
59  return cps;
60 }
const libMesh::Real _sharpness
sharpness of the curve
Definition: BSpline.h:96
const unsigned int _cps_per_half
number of control points per half of the spline (vertex is auto-included)
Definition: BSpline.h:94
const libMesh::RealVectorValue _end_dir
ending direction of spline
Definition: BSpline.h:92
const libMesh::RealVectorValue _start_dir
starting direction of spline
Definition: BSpline.h:90
const libMesh::Point _end_point
ending point of spline
Definition: BSpline.h:88
std::vector< Point > bSplineControlPoints(const libMesh::Point &start_point, const libMesh::Point &end_point, const libMesh::RealVectorValue &start_direction, const libMesh::RealVectorValue &end_direction, const unsigned int cps_per_half, const libMesh::Real sharpness)
Creates control points for an open uniform BSpline.
Definition: SplineUtils.C:67
const libMesh::Point _start_point
starting point of spline
Definition: BSpline.h:86

◆ firstCoeff()

libMesh::Real Moose::BSpline::firstCoeff ( const libMesh::Real  t,
const unsigned int  i,
const unsigned int  j 
) const
private

Submethod used in CdBBasis routine.

Parameters
tparameter t in [0,1]
iindex corresponding to which control point
jdegree of the basis funtion

Definition at line 115 of file BSpline.C.

Referenced by CdBBasis().

116 {
117  mooseAssert(i + j < _knot_vector.size(), "Out of bounds access in knot vector");
118  const auto ti = _knot_vector[i];
119  const auto tij = _knot_vector[i + j];
120  if (ti != tij)
121  return (t - ti) / (tij - ti);
122  else
123  return 0;
124 }
const std::vector< libMesh::Real > _knot_vector
The knot vector.
Definition: BSpline.h:102

◆ getPoint()

libMesh::Point Moose::BSpline::getPoint ( const libMesh::Real  t) const

Evaluate the BSpline interpolation at given value of t.

Parameters
tthe parameter value, must lie in [0,1]
Returns
libMesh::Point type with format (x,y,z)

Definition at line 40 of file BSpline.C.

Referenced by BSplineCurveGenerator::generate().

41 {
42  mooseAssert((t >= 0) && (t <= 1), "t should be in [0, 1]. t=" + std::to_string(t));
43  libMesh::Point returnPoint(0, 0, 0);
44  if (t == 1.0)
45  return _control_points.back();
46  for (const auto i : index_range(_control_points))
47  returnPoint += BSpline::CdBBasis(t, i, _degree) * _control_points[i];
48 
49  return returnPoint;
50 }
libMesh::Real CdBBasis(const libMesh::Real t, const unsigned int i, const unsigned int j) const
Evaluates the the basis function for a B-Spline according to the Cox-de-Boor recursive formula...
Definition: BSpline.C:101
const std::vector< libMesh::Point > _control_points
The control points.
Definition: BSpline.h:98
auto index_range(const T &sizable)
const unsigned int _degree
The polynomial degree of the B-Spline.
Definition: BSpline.h:84

◆ secondCoeff()

libMesh::Real Moose::BSpline::secondCoeff ( const libMesh::Real  t,
const unsigned int  i,
const unsigned int  j 
) const
private

Submethod used in CdBBasis routine.

Parameters
tparameter t in [0,1]
iindex corresponding to which control point
jdegree of the basis funtion

Definition at line 127 of file BSpline.C.

Referenced by CdBBasis().

128 {
129  mooseAssert(i + j + 1 < _knot_vector.size(), "Out of bounds access in knot vector");
130  libMesh::Real ti1 = _knot_vector[i + 1];
131  libMesh::Real tij1 = _knot_vector[i + j + 1];
132  if (ti1 != tij1)
133  return (tij1 - t) / (tij1 - ti1);
134  else
135  return 0;
136 }
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const std::vector< libMesh::Real > _knot_vector
The knot vector.
Definition: BSpline.h:102

Member Data Documentation

◆ _control_points

const std::vector<libMesh::Point> Moose::BSpline::_control_points
private

The control points.

Definition at line 98 of file BSpline.h.

Referenced by buildKnotVector(), and getPoint().

◆ _cps_per_half

const unsigned int Moose::BSpline::_cps_per_half
private

number of control points per half of the spline (vertex is auto-included)

Definition at line 94 of file BSpline.h.

Referenced by createControlPoints().

◆ _degree

const unsigned int Moose::BSpline::_degree
private

The polynomial degree of the B-Spline.

Definition at line 84 of file BSpline.h.

Referenced by buildKnotVector(), and getPoint().

◆ _end_dir

const libMesh::RealVectorValue Moose::BSpline::_end_dir
private

ending direction of spline

Definition at line 92 of file BSpline.h.

Referenced by createControlPoints().

◆ _end_point

const libMesh::Point Moose::BSpline::_end_point
private

ending point of spline

Definition at line 88 of file BSpline.h.

Referenced by createControlPoints().

◆ _knot_vector

const std::vector<libMesh::Real> Moose::BSpline::_knot_vector
private

The knot vector.

Size: degree + n_control_points + 1 The multiplicity of each knot influences the continuity of the spline

Definition at line 102 of file BSpline.h.

Referenced by CdBBasis(), firstCoeff(), and secondCoeff().

◆ _sharpness

const libMesh::Real Moose::BSpline::_sharpness
private

sharpness of the curve

Definition at line 96 of file BSpline.h.

Referenced by createControlPoints().

◆ _start_dir

const libMesh::RealVectorValue Moose::BSpline::_start_dir
private

starting direction of spline

Definition at line 90 of file BSpline.h.

Referenced by createControlPoints().

◆ _start_point

const libMesh::Point Moose::BSpline::_start_point
private

starting point of spline

Definition at line 86 of file BSpline.h.

Referenced by createControlPoints().


The documentation for this class was generated from the following files: