AXOM
Axom provides a robust, flexible software infrastructure for the development of multi-physics applications and computational tools.
axom::primal::BezierCurve< T, NDIMS > Class Template Reference

Represents a Bezier curve defined by an array of control points. More...

#include </home/docs/checkouts/readthedocs.org/user_builds/axom/checkouts/main/src/axom/primal/geometry/BezierCurve.hpp>

Public Types

using NumericType = T
 
using PointType = Point< T, NDIMS >
 
using VectorType = Vector< T, NDIMS >
 
using SegmentType = Segment< T, NDIMS >
 
using WeightsVec = axom::Array< T >
 
using CoordsVec = axom::Array< PointType >
 
using BoundingBoxType = BoundingBox< T, NDIMS >
 
using OrientedBoundingBoxType = OrientedBoundingBox< T, NDIMS >
 

Public Member Functions

 AXOM_STATIC_ASSERT_MSG ((NDIMS==1)||(NDIMS==2)||(NDIMS==3), "A Bezier Curve object may be defined in 1-, 2-, or 3-D")
 
 AXOM_STATIC_ASSERT_MSG (std::is_arithmetic< T >::value, "A Bezier Curve must be defined using an arithmetic type")
 
std::ostream & print (std::ostream &os) const
 Simple formatted print of a Bezier Curve instance. More...
 
Constructors for polynomial and rational Bezier curves

The constructors allow for flexible initialization of BezierCurve objects from:

  • 1D arrays of control points and weights,
  • C-style arrays of control points and weights,
  • Specified polynomial orders,
  • Rational or polynomial (nonrational) curves, depending on the presence of weights.

The curve is parametrized from t=0 to t=1.

Rational curves are identified by a non-empty weights array, and nonrational curves by an empty weights array. All weights must be greater than 0 in a rational curve.

 BezierCurve (axom::ArrayView< const PointType > controlPoints, axom::ArrayView< const T > weights, int ord)
 Constructor for a Bezier Curve from ArrayViews of control points and weights. More...
 
 BezierCurve (axom::ArrayView< PointType > pts, axom::ArrayView< T > weights, int ord)
 Constructor for a Bezier Curve from ArrayViews of (non-const) control points and weights. More...
 
 BezierCurve (int ord=-1)
 Constructor for a polynomial Bezier Curve that reserves space for the control points. More...
 
 BezierCurve (const PointType *pts, int ord)
 Constructor for a polynomial Bezier Curve from an array of coordinates. More...
 
 BezierCurve (const PointType *pts, const T *weights, int ord)
 Constructor for a rational Bezier Curve from an array of coordinates and weights. More...
 
 BezierCurve (const axom::Array< PointType > &pts, int ord)
 Constructor for a Bezier Curve from an array of coordinates. More...
 
 BezierCurve (const axom::Array< PointType > &pts, const axom::Array< T > &weights, int ord)
 Constructor for a rational Bezier Curve from arrays of coordinates and weights. More...
 
Query/modify curve properties (order, rationality, ...)
void setOrder (int ord)
 Sets the order of the Bezier Curve. More...
 
int getOrder () const
 Returns the order of the Bezier Curve. More...
 
int getNumControlPoints () const
 Returns the number of control points of the Bezier Curve. More...
 
void clear ()
 Clears the list of control points, make nonrational. More...
 
bool isRational () const
 Use array size as flag for rationality. More...
 
void makeRational ()
 Make trivially rational. If already rational, do nothing. More...
 
void makeNonrational ()
 Make nonrational by shrinking array of weights. More...
 
Query/modify curve's geometry (control points, weights, bounding box, ...)
PointTypeoperator[] (int idx)
 Retrieves the control point at index idx. More...
 
const PointTypeoperator[] (int idx) const
 Retrieves the control point at index idx. More...
 
const PointTypegetInitPoint () const
 
const PointTypegetEndPoint () const
 
CoordsVecgetControlPoints ()
 Returns a reference to the Bezier curve's control points. More...
 
const CoordsVecgetControlPoints () const
 Returns a const reference to the Bezier curve's control points. More...
 
const T & getWeight (int idx) const
 Get a specific weight. More...
 
void setWeight (int idx, T weight)
 Set the weight at a specific index. More...
 
WeightsVecgetWeights ()
 Returns a reference of the Bezier curve's weights. More...
 
const WeightsVecgetWeights () const
 Returns a const reference of the Bezier curve's weights. More...
 
BoundingBoxType boundingBox () const
 Returns an axis-aligned bounding box containing the Bezier curve. More...
 
OrientedBoundingBoxType orientedBoundingBox () const
 Returns an oriented bounding box containing the Bezier curve. More...
 
bool isLinear (double tol=1e-8, bool useStrictLinear=false) const
 Predicate to check if the Bezier curve is approximately linear. More...
 
Query/modify curve parametrization
void reverseOrientation ()
 Reverses the order of the Bezier curve's control points and weights. More...
 
Functions to evaluate curve and its derivatives and normals
PointType evaluate (T t) const
 Evaluates a Bezier curve at a particular parameter value t. More...
 
void evaluateFirstDerivative (T t, PointType &eval, VectorType &Dt) const
 Computes the 0th and 1st derivative of a Bezier curve. More...
 
VectorType dt (T t) const
 Computes the tangent of a Bezier curve at a particular parameter value t. More...
 
void evaluateSecondDerivative (T t, PointType &eval, VectorType &Dt, VectorType &DtDt) const
 Computes the 0th, 1st, and 2nd derivatives of a Bezier curve. More...
 
VectorType dtdt (T t) const
 Computes the second derivative of a Bezier curve at a particular parameter value t. More...
 
Functions dealing with curve subdivision
void split (T t, BezierCurve &c1, BezierCurve &c2) const
 Splits a Bezier curve into two Bezier curves at a given parameter value. More...
 

Friends

bool operator== (const BezierCurve< T, NDIMS > &lhs, const BezierCurve< T, NDIMS > &rhs)
 Checks equality of two Bezier Curve. More...
 
bool operator!= (const BezierCurve< T, NDIMS > &lhs, const BezierCurve< T, NDIMS > &rhs)
 

Detailed Description

template<typename T, int NDIMS>
class axom::primal::BezierCurve< T, NDIMS >

Represents a Bezier curve defined by an array of control points.

Template Parameters
Tthe coordinate type, e.g., double, float, etc.
NDIMSthe number of dimensions

The order of a Bezier curve with N+1 control points is N. The curve is approximated by the control points, parametrized from t=0 to t=1.

Contains an array of positive weights to represent a rational Bezier curve. Nonrational Bezier curves are identified by an empty weights array. Algorithms for Rational Bezier curves derived from Gerald Farin, "Algorithms for rational Bezier curves" Computer-Aided Design, Volume 15, Number 2, 1983,

Member Typedef Documentation

◆ NumericType

template<typename T , int NDIMS>
using axom::primal::BezierCurve< T, NDIMS >::NumericType = T

◆ PointType

template<typename T , int NDIMS>
using axom::primal::BezierCurve< T, NDIMS >::PointType = Point<T, NDIMS>

◆ VectorType

template<typename T , int NDIMS>
using axom::primal::BezierCurve< T, NDIMS >::VectorType = Vector<T, NDIMS>

◆ SegmentType

template<typename T , int NDIMS>
using axom::primal::BezierCurve< T, NDIMS >::SegmentType = Segment<T, NDIMS>

◆ WeightsVec

template<typename T , int NDIMS>
using axom::primal::BezierCurve< T, NDIMS >::WeightsVec = axom::Array<T>

◆ CoordsVec

template<typename T , int NDIMS>
using axom::primal::BezierCurve< T, NDIMS >::CoordsVec = axom::Array<PointType>

◆ BoundingBoxType

template<typename T , int NDIMS>
using axom::primal::BezierCurve< T, NDIMS >::BoundingBoxType = BoundingBox<T, NDIMS>

◆ OrientedBoundingBoxType

template<typename T , int NDIMS>
using axom::primal::BezierCurve< T, NDIMS >::OrientedBoundingBoxType = OrientedBoundingBox<T, NDIMS>

Constructor & Destructor Documentation

◆ BezierCurve() [1/7]

template<typename T , int NDIMS>
axom::primal::BezierCurve< T, NDIMS >::BezierCurve ( axom::ArrayView< const PointType controlPoints,
axom::ArrayView< const T >  weights,
int  ord 
)
inline

Constructor for a Bezier Curve from ArrayViews of control points and weights.

Parameters
[in]controlPointsArrayView with zero or ord+1 control points
[in]weightsArrayView with zero or ord+1 positive weights
[in]ordThe Curve's polynomial order

If controlPoints is empty, we still allocate space for ord+1 control points

Precondition
order ord is greater than or equal to -1
controlPoints is either empty or has size ord+1
weights is either empty or has size ord+1
controlPoints cannot be empty if weights are supplied

References axom::ArrayView< T, DIM, SPACE >::data(), axom::ArrayView< T, DIM, SPACE >::empty(), axom::primal::BezierCurve< T, NDIMS >::isRational(), axom::utilities::max(), axom::Array< T, DIM, SPACE, StoragePolicy >::resize(), axom::ArrayView< T, DIM, SPACE >::size(), and SLIC_ASSERT.

◆ BezierCurve() [2/7]

template<typename T , int NDIMS>
axom::primal::BezierCurve< T, NDIMS >::BezierCurve ( axom::ArrayView< PointType pts,
axom::ArrayView< T >  weights,
int  ord 
)
inline

Constructor for a Bezier Curve from ArrayViews of (non-const) control points and weights.

◆ BezierCurve() [3/7]

template<typename T , int NDIMS>
axom::primal::BezierCurve< T, NDIMS >::BezierCurve ( int  ord = -1)
inlineexplicit

Constructor for a polynomial Bezier Curve that reserves space for the control points.

Parameters
[in]orderthe order of the resulting Bezier curve
Precondition
order is greater than or equal to -1.

◆ BezierCurve() [4/7]

template<typename T , int NDIMS>
axom::primal::BezierCurve< T, NDIMS >::BezierCurve ( const PointType pts,
int  ord 
)
inline

Constructor for a polynomial Bezier Curve from an array of coordinates.

Parameters
[in]ptsa vector with ord+1 control points
[in]ordThe Curve's polynomial order
Precondition
order is greater than or equal to zero

◆ BezierCurve() [5/7]

template<typename T , int NDIMS>
axom::primal::BezierCurve< T, NDIMS >::BezierCurve ( const PointType pts,
const T *  weights,
int  ord 
)
inline

Constructor for a rational Bezier Curve from an array of coordinates and weights.

Parameters
[in]ptsa vector with ord+1 control points
[in]weightsa vector with ord+1 positive weights
[in]ordThe Curve's polynomial order
Precondition
order is greater than or equal to zero

◆ BezierCurve() [6/7]

template<typename T , int NDIMS>
axom::primal::BezierCurve< T, NDIMS >::BezierCurve ( const axom::Array< PointType > &  pts,
int  ord 
)
inline

Constructor for a Bezier Curve from an array of coordinates.

Parameters
[in]ptsan array with ord+1 control points
[in]ordThe Curve's polynomial order
Precondition
order is greater than or equal to zero

◆ BezierCurve() [7/7]

template<typename T , int NDIMS>
axom::primal::BezierCurve< T, NDIMS >::BezierCurve ( const axom::Array< PointType > &  pts,
const axom::Array< T > &  weights,
int  ord 
)
inline

Constructor for a rational Bezier Curve from arrays of coordinates and weights.

Parameters
[in]ptsan array with ord+1 control points
[in]weightsan array with ord+1 positive weights
[in]ordThe Curve's polynomial order
Precondition
order is greater than or equal to zero

Member Function Documentation

◆ AXOM_STATIC_ASSERT_MSG() [1/2]

template<typename T , int NDIMS>
axom::primal::BezierCurve< T, NDIMS >::AXOM_STATIC_ASSERT_MSG ( (NDIMS==1)||(NDIMS==2)||(NDIMS==3)  ,
"A Bezier Curve object may be defined in 1-  ,
2-  ,
or 3-D"   
)

◆ AXOM_STATIC_ASSERT_MSG() [2/2]

template<typename T , int NDIMS>
axom::primal::BezierCurve< T, NDIMS >::AXOM_STATIC_ASSERT_MSG ( std::is_arithmetic< T >::value  ,
"A Bezier Curve must be defined using an arithmetic type"   
)

◆ setOrder()

template<typename T , int NDIMS>
void axom::primal::BezierCurve< T, NDIMS >::setOrder ( int  ord)
inline

◆ getOrder()

template<typename T , int NDIMS>
int axom::primal::BezierCurve< T, NDIMS >::getOrder ( ) const
inline

Returns the order of the Bezier Curve.

References axom::Array< T, DIM, SPACE, StoragePolicy >::size().

◆ getNumControlPoints()

template<typename T , int NDIMS>
int axom::primal::BezierCurve< T, NDIMS >::getNumControlPoints ( ) const
inline

Returns the number of control points of the Bezier Curve.

References axom::Array< T, DIM, SPACE, StoragePolicy >::size().

◆ clear()

template<typename T , int NDIMS>
void axom::primal::BezierCurve< T, NDIMS >::clear ( )
inline

Clears the list of control points, make nonrational.

References axom::Array< T, DIM, SPACE, StoragePolicy >::clear(), and axom::primal::BezierCurve< T, NDIMS >::makeNonrational().

◆ isRational()

template<typename T , int NDIMS>
bool axom::primal::BezierCurve< T, NDIMS >::isRational ( ) const
inline

Use array size as flag for rationality.

References axom::Array< T, DIM, SPACE, StoragePolicy >::empty().

◆ makeRational()

template<typename T , int NDIMS>
void axom::primal::BezierCurve< T, NDIMS >::makeRational ( )
inline

◆ makeNonrational()

template<typename T , int NDIMS>
void axom::primal::BezierCurve< T, NDIMS >::makeNonrational ( )
inline

Make nonrational by shrinking array of weights.

References axom::Array< T, DIM, SPACE, StoragePolicy >::resize().

◆ operator[]() [1/2]

template<typename T , int NDIMS>
PointType& axom::primal::BezierCurve< T, NDIMS >::operator[] ( int  idx)
inline

Retrieves the control point at index idx.

◆ operator[]() [2/2]

template<typename T , int NDIMS>
const PointType& axom::primal::BezierCurve< T, NDIMS >::operator[] ( int  idx) const
inline

Retrieves the control point at index idx.

◆ getInitPoint()

template<typename T , int NDIMS>
const PointType& axom::primal::BezierCurve< T, NDIMS >::getInitPoint ( ) const
inline

◆ getEndPoint()

template<typename T , int NDIMS>
const PointType& axom::primal::BezierCurve< T, NDIMS >::getEndPoint ( ) const
inline

◆ getControlPoints() [1/2]

template<typename T , int NDIMS>
CoordsVec& axom::primal::BezierCurve< T, NDIMS >::getControlPoints ( )
inline

Returns a reference to the Bezier curve's control points.

◆ getControlPoints() [2/2]

template<typename T , int NDIMS>
const CoordsVec& axom::primal::BezierCurve< T, NDIMS >::getControlPoints ( ) const
inline

Returns a const reference to the Bezier curve's control points.

◆ getWeight()

template<typename T , int NDIMS>
const T& axom::primal::BezierCurve< T, NDIMS >::getWeight ( int  idx) const
inline

Get a specific weight.

Parameters
[in]idxThe index of the weight
Precondition
Requires that the curve be rational

References axom::primal::BezierCurve< T, NDIMS >::isRational(), and SLIC_ASSERT.

◆ setWeight()

template<typename T , int NDIMS>
void axom::primal::BezierCurve< T, NDIMS >::setWeight ( int  idx,
weight 
)
inline

Set the weight at a specific index.

Parameters
[in]idxThe index of the weight
[in]weightThe updated value of the weight
Precondition
Requires that the curve be rational
Requires that the weight be positive

References axom::primal::BezierCurve< T, NDIMS >::isRational(), and SLIC_ASSERT.

◆ getWeights() [1/2]

template<typename T , int NDIMS>
WeightsVec& axom::primal::BezierCurve< T, NDIMS >::getWeights ( )
inline

Returns a reference of the Bezier curve's weights.

◆ getWeights() [2/2]

template<typename T , int NDIMS>
const WeightsVec& axom::primal::BezierCurve< T, NDIMS >::getWeights ( ) const
inline

Returns a const reference of the Bezier curve's weights.

◆ boundingBox()

template<typename T , int NDIMS>
BoundingBoxType axom::primal::BezierCurve< T, NDIMS >::boundingBox ( ) const
inline

Returns an axis-aligned bounding box containing the Bezier curve.

References axom::Array< T, DIM, SPACE, StoragePolicy >::data(), and axom::Array< T, DIM, SPACE, StoragePolicy >::size().

◆ orientedBoundingBox()

template<typename T , int NDIMS>
OrientedBoundingBoxType axom::primal::BezierCurve< T, NDIMS >::orientedBoundingBox ( ) const
inline

Returns an oriented bounding box containing the Bezier curve.

References axom::Array< T, DIM, SPACE, StoragePolicy >::data(), and axom::Array< T, DIM, SPACE, StoragePolicy >::size().

◆ isLinear()

template<typename T , int NDIMS>
bool axom::primal::BezierCurve< T, NDIMS >::isLinear ( double  tol = 1e-8,
bool  useStrictLinear = false 
) const
inline

Predicate to check if the Bezier curve is approximately linear.

This function checks if the internal control points of the BezierCurve are approximately on the line defined by its two endpoints

Parameters
[in]tolThreshold for sum of squared distances
[in]useStrictLinearIf true, checks that the control points are evenly spaced along the line and not too far from the line
Returns
True if curve is near-linear

References axom::primal::BezierCurve< T, NDIMS >::getOrder(), axom::primal::Point< T, NDIMS >::lerp(), and axom::primal::squared_distance().

◆ reverseOrientation()

template<typename T , int NDIMS>
void axom::primal::BezierCurve< T, NDIMS >::reverseOrientation ( )
inline

Reverses the order of the Bezier curve's control points and weights.

References axom::primal::BezierCurve< T, NDIMS >::getOrder(), axom::primal::BezierCurve< T, NDIMS >::isRational(), and axom::utilities::swap().

◆ evaluate()

template<typename T , int NDIMS>
PointType axom::primal::BezierCurve< T, NDIMS >::evaluate ( t) const
inline

Evaluates a Bezier curve at a particular parameter value t.

Parameters
[in]tparameter value at which to evaluate
Returns
p the value of the Bezier curve at t
Note
We typically evaluate the curve at t between 0 and 1

References axom::utilities::annotations::end(), axom::primal::BezierCurve< T, NDIMS >::evaluate(), axom::primal::BezierCurve< T, NDIMS >::getOrder(), axom::primal::BezierCurve< T, NDIMS >::isRational(), and axom::utilities::lerp().

◆ evaluateFirstDerivative()

template<typename T , int NDIMS>
void axom::primal::BezierCurve< T, NDIMS >::evaluateFirstDerivative ( t,
PointType eval,
VectorType Dt 
) const
inline

Computes the 0th and 1st derivative of a Bezier curve.

Parameters
[in]tParameter value at which to compute tangent
[out]evalThe value of the curve at t
[out]DtThe tangent vector of the curve at t

References axom::utilities::annotations::end(), axom::primal::BezierCurve< T, NDIMS >::evaluateFirstDerivative(), axom::primal::BezierCurve< T, NDIMS >::getOrder(), axom::primal::BezierCurve< T, NDIMS >::isRational(), and axom::utilities::lerp().

◆ dt()

template<typename T , int NDIMS>
VectorType axom::primal::BezierCurve< T, NDIMS >::dt ( t) const
inline

Computes the tangent of a Bezier curve at a particular parameter value t.

Parameters
[in]tparameter value at which to compute tangent
Returns
p the tangent vector of the Bezier curve at t
Note
We typically find the tangent of the curve at t between 0 and 1

References axom::utilities::annotations::end(), axom::primal::BezierCurve< T, NDIMS >::evaluateFirstDerivative(), axom::primal::BezierCurve< T, NDIMS >::getOrder(), axom::primal::BezierCurve< T, NDIMS >::isRational(), and axom::utilities::lerp().

◆ evaluateSecondDerivative()

template<typename T , int NDIMS>
void axom::primal::BezierCurve< T, NDIMS >::evaluateSecondDerivative ( t,
PointType eval,
VectorType Dt,
VectorType DtDt 
) const
inline

Computes the 0th, 1st, and 2nd derivatives of a Bezier curve.

Parameters
[in]tParameter value at which to compute tangent
[out]evalThe value of the curve at t
[out]DtThe tangent vector of the curve at t

References axom::utilities::annotations::end(), axom::primal::BezierCurve< T, NDIMS >::evaluateSecondDerivative(), axom::primal::BezierCurve< T, NDIMS >::getOrder(), axom::primal::BezierCurve< T, NDIMS >::isRational(), and axom::utilities::lerp().

◆ dtdt()

template<typename T , int NDIMS>
VectorType axom::primal::BezierCurve< T, NDIMS >::dtdt ( t) const
inline

Computes the second derivative of a Bezier curve at a particular parameter value t.

Parameters
[in]tparameter value at which to compute tangent
Returns
p the 2nd derivative vector of the Bezier curve at t
Note
We typically find the second derivative of the curve at t between 0 and 1

References axom::utilities::annotations::end(), axom::primal::BezierCurve< T, NDIMS >::evaluateSecondDerivative(), axom::primal::BezierCurve< T, NDIMS >::getOrder(), axom::primal::BezierCurve< T, NDIMS >::isRational(), and axom::utilities::lerp().

◆ split()

template<typename T , int NDIMS>
void axom::primal::BezierCurve< T, NDIMS >::split ( t,
BezierCurve< T, NDIMS > &  c1,
BezierCurve< T, NDIMS > &  c2 
) const
inline

Splits a Bezier curve into two Bezier curves at a given parameter value.

Parameters
[in]tparameter value between 0 and 1 at which to evaluate
[out]c1First output Bezier curve
[out]c2Second output Bezier curve
Precondition
Parameter t must be between 0 and 1

References axom::utilities::annotations::end(), axom::primal::BezierCurve< T, NDIMS >::getOrder(), axom::primal::BezierCurve< T, NDIMS >::getWeight(), axom::primal::BezierCurve< T, NDIMS >::isRational(), axom::primal::Point< T, NDIMS >::lerp(), axom::utilities::lerp(), axom::primal::BezierCurve< T, NDIMS >::makeRational(), axom::primal::BezierCurve< T, NDIMS >::setOrder(), axom::primal::BezierCurve< T, NDIMS >::setWeight(), and SLIC_ASSERT.

◆ print()

template<typename T , int NDIMS>
std::ostream& axom::primal::BezierCurve< T, NDIMS >::print ( std::ostream &  os) const
inline

Simple formatted print of a Bezier Curve instance.

Parameters
osThe output stream to write to
Returns
A reference to the modified ostream

References axom::primal::BezierCurve< T, NDIMS >::getOrder(), and axom::primal::BezierCurve< T, NDIMS >::isRational().

Friends And Related Function Documentation

◆ operator==

template<typename T , int NDIMS>
bool operator== ( const BezierCurve< T, NDIMS > &  lhs,
const BezierCurve< T, NDIMS > &  rhs 
)
friend

Checks equality of two Bezier Curve.

◆ operator!=

template<typename T , int NDIMS>
bool operator!= ( const BezierCurve< T, NDIMS > &  lhs,
const BezierCurve< T, NDIMS > &  rhs 
)
friend

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