Easy3D 2.6.1
Loading...
Searching...
No Matches
SplineCurveFitting< Point, N, T > Class Template Reference

Spline curve fitting for arbitrary dimensions. More...

#include <easy3d/core/spline_curve_fitting.h>

Public Types

enum  Node_e { eUNIFORM , eOPEN_UNIFORM }
 The nodal vector (or knot vector) type. More...
 

Public Member Functions

 SplineCurveFitting (int k=2, Node_e node_type=eOPEN_UNIFORM)
 Constructor.
 
void set_ctrl_points (const std::vector< Point< N, T > > &points)
 Sets the positions of the spline control points.
 
void get_ctrl_points (std::vector< Point< N, T > > &points) const
 Gets the control points of the spline.
 
void set_node_type (Node_e type)
 Sets the nodal vector type.
 
Point< N, T > eval_f (T u) const
 Evaluates position of the spline.
 
Point< N, T > eval_df (T u) const
 Evaluates speed of the spline.
 
int get_order () const
 Gets the order of the spline.
 
std::vector< T > get_equally_spaced_parameters (std::size_t steps) const
 Gets parameters such that evaluation of the curve positions using these parameters results in equally spaced points along the curve.
 

Detailed Description

template<template< size_t, class > class Point, size_t N, typename T>
class easy3d::SplineCurveFitting< Point, N, T >

Spline curve fitting for arbitrary dimensions.

This class uses the efficient blossom algorithm to compute a position on the curve. It allows to set the order of the spline and the end points behavior (passing or not). The class can be instantiated with any point type (1D (float), 2D, 3D etc.) as long as the necessary operator overloads are implemented.

Template Parameters
PointA templated point class that supports basic arithmetic operations (addition and scalar multiplication). It must be parameterized as Point<N, T>, where N is the number of dimensions, and T is the data type.
NThe number of dimensions (e.g., 2 for 2D, 3 for 3D).
TThe scalar type (e.g., float or double).

Example usage:

const int resolution = 1000; // Number of line subdivisions to display the spline
const int order = 3; // Smoothness of the spline (min 2)
fitter.set_ctrl_points(points);
for(int i = 0; i < resolution; ++i) {
const vec3 p = fitter.eval_f( float(i) / float(resolution-1) );
std::cout << p << std::endl;
}
SplineCurveFitting(int k=2, Node_e node_type=eOPEN_UNIFORM)
Constructor.
Definition spline_curve_fitting.h:209
@ eOPEN_UNIFORM
Open uniform nodal vector.
Definition spline_curve_fitting.h:85
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44
Examples
Tutorial_603_Curves/main.cpp.

Member Enumeration Documentation

◆ Node_e

template<template< size_t, class > class Point, size_t N, typename T>
enum Node_e

The nodal vector (or knot vector) type.

In spline curve fitting, the nodal vector (or knot vector) plays a crucial role in defining how the spline curve is constructed. The type of nodal vector determines how the control points influence the shape of the curve.

  • Uniform Knot Vector: A uniform knot vector means that the knot values are evenly spaced. This results in a B-spline where every segment between knots contributes equally to the overall curve. However, this type of knot vector does not guarantee that the curve passes through the first and last control points. Example of a uniform knot vector for a cubic B-spline (degree 3, 5 control points): t=[0,1,2,3,4,5,6].
  • Open Uniform Knot Vector: An open uniform knot vector is a special type of uniform knot vector where the first and last knots are repeated degree + 1 times. This ensures that the curve starts at the first control point and ends at the last control point, making it more intuitive for curve fitting applications. Example of an open uniform knot vector for a cubic B-spline (degree 3, 5 control points): t=[0,0,0,0,1,2,3,3,3,3].
Enumerator
eUNIFORM 

Uniform nodal vector.

eOPEN_UNIFORM 

Open uniform nodal vector.

Constructor & Destructor Documentation

◆ SplineCurveFitting()

template<template< size_t, class > class Point, size_t N, typename T>
SplineCurveFitting ( int k = 2,
Node_e node_type = eOPEN_UNIFORM )
explicit

Constructor.

Parameters
kOrder of the spline (minimum is two)
node_typeNodal vector type (uniform, open_uniform). This will define the behavior of the spline with its control points as well as its speed according to its parameter.

Member Function Documentation

◆ eval_df()

template<template< size_t, class > class Point, size_t N, typename T>
Point< N, T > eval_df ( T u) const

Evaluates speed of the spline.

Parameters
uCurve parameter ranging from [0, 1].
Returns
The evaluated speed on the spline.

◆ eval_f()

template<template< size_t, class > class Point, size_t N, typename T>
Point< N, T > eval_f ( T u) const

Evaluates position of the spline.

Parameters
uCurve parameter ranging from [0, 1].
Note
Calling this with equally distributed u will result in non-uniformly distributed points on the curves (because some input points are closely spaced but others may not). To get points at fixed distances along the curve, use the parameter generated from get_equally_spaced_parameters().
Returns
The evaluated position on the spline.

◆ get_ctrl_points()

template<template< size_t, class > class Point, size_t N, typename T>
void get_ctrl_points ( std::vector< Point< N, T > > & points) const

Gets the control points of the spline.

Parameters
pointsThe control points of the spline.

◆ get_equally_spaced_parameters()

template<template< size_t, class > class Point, size_t N, typename T>
std::vector< T > get_equally_spaced_parameters ( std::size_t steps) const

Gets parameters such that evaluation of the curve positions using these parameters results in equally spaced points along the curve.

Parameters
stepsThe number of steps.

Calling eval_f() with equal intervals will result in non-uniformly distributed points on the curves. This method first evaluates the spline curve at equally spaced values in the parameter domain, and then does linear interpolation to compute the parameters that result in points uniformly spaced along the curve.

Returns
The parameters for equally spaced points along the curve.

◆ get_order()

template<template< size_t, class > class Point, size_t N, typename T>
int get_order ( ) const
inline

Gets the order of the spline.

Returns
The order of the spline.

◆ set_ctrl_points()

template<template< size_t, class > class Point, size_t N, typename T>
void set_ctrl_points ( const std::vector< Point< N, T > > & points)

Sets the positions of the spline control points.

Parameters
pointsThe control points of the spline.

◆ set_node_type()

template<template< size_t, class > class Point, size_t N, typename T>
void set_node_type ( Node_e type)

Sets the nodal vector type.

The nodal vector type.

Parameters
typeThe nodal vector type.

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