ImFusion SDK 4.3
Spline Class Reference

#include <ImFusion/Base/Spline.h>

Uniform Catmull-Rom spline. More...

Detailed Description

Uniform Catmull-Rom spline.

Public Member Functions

 Spline (const std::vector< vec3 > &points)
 
void addPoint (const vec3 &p, int position=-1)
 Add control point.
 
void removePoint (int index)
 Remove control point.
 
void setPoints (const std::vector< vec3 > &points)
 Set control points.
 
void getPoints (std::vector< vec3 > &points) const
 Get control points.
 
const std::vector< vec3 > & points () const
 Get control points.
 
void evaluate (double t, vec3 &res) const
 Evaluates spline.
 
void evaluateTangent (double t, vec3 &res) const
 Evaluates spline tangent.
 
void evaluateNormal (double t, int axis, vec3 &res) const
 Evaluates spline normal orthogonal to the tangent and the specified axis.
 
void evaluateNormal (double t, const vec3 &dir, vec3 &res) const
 Evaluates spline normal orthogonal to the tangent and the specified direction.
 
double getCurveLength (double t1=0.0, double t2=1.0) const
 Computes the length of the spline between t1 and t2.
 
double getProjectedCurveLength (int axis, double t1=0.0, double t2=1.0) const
 Computes the length of the spline between t1 and t2 when projected onto an axis plane.
 
double getProjectedCurveLength (const vec3 &normal, double t1=0.0, double t2=1.0) const
 Computes the length of the spline between t1 and t2 when projected onto a plane.
 
void getUniformSamples (int n, std::vector< std::pair< double, vec3 > > &samples) const
 Returns sort-of uniformly spaced sample points on the spline (in terms of distance).
 
std::vector< vec3 > getParametricUniformSamples (int n) const
 Returns t-uniformly-spaced sample points on the spline.
 
void getUniformSamplesX (int n, std::vector< vec3 > &samples) const
 Sample spline uniformly along x-axis.
 
void getUniformSamples (int n, std::vector< vec3 > &samples, double eps=1e-10) const
 Returns uniformly spaced sample points on the spline (in terms of arc length).
 
void getProjectedUniformSamples (int n, int axis, std::vector< std::pair< double, vec3 > > &samples) const
 Returns uniformly spaced points on the spline (in terms of distance on the given axis plane)
 
void getProjectedUniformSamples (int n, const vec3 &normal, std::vector< std::pair< double, vec3 > > &samples) const
 Returns uniformly spaced points on the spline (in terms of distance on the given plane)
 
double arcLengthToSplineCoord (double pos) const
 Converts a position on the spline given in arc length parameterization (in world units) to the corresponding position in the spline parameterization.
 
double splineCoordToArcLength (double t) const
 Converts a position on the spline given in spline parameterization to the corresponding position in arc length parameterization (in world units)
 
void convertToLabelMap (unsigned char *buffer, int width, int height, const vec3 &spacing, unsigned char inValue=1, unsigned char outValue=0, bool skipInterpolation=false) const
 Fills a label map from the spline with inside/outside values.
 
void setClosed (bool v)
 
bool closed () const
 
double calculateNearestPointArcLength (const Eigen::Vector3d &pos, const std::vector< Eigen::Vector3d > pointsApproximation=std::vector< Eigen::Vector3d >(), Eigen::Vector3d *nearestPoint=nullptr, bool *outsideCurve=nullptr) const
 Calculates the arc length of the point nearest to pos.
 
std::unique_ptr< SplinegetApproximateSpline (double eps) const
 Get a spline that approximates the current spline up to an error eps.
 
std::unique_ptr< SplinegetApproximateClosedSpline (int skipFactor, bool optimizePositions) const
 Get a closed spline that approximates the current closed spline.
 
void evaluateLoop (double t_, vec3 &res) const
 This version of evaluate scraps the padding points at each end and cycles around instead to produce a closed loop.
 

Member Function Documentation

◆ evaluate()

void evaluate ( double t,
vec3 & res ) const

Evaluates spline.

The spline is parametrized in the range t = [0;1]

Parameters
tspline parameter
resposition at t (output parameter)

◆ evaluateTangent()

void evaluateTangent ( double t,
vec3 & res ) const

Evaluates spline tangent.

The spline is parametrized in the range t = [0;1]

Parameters
tspline parameter
restangent at t (output parameter)

◆ evaluateNormal() [1/2]

void evaluateNormal ( double t,
int axis,
vec3 & res ) const

Evaluates spline normal orthogonal to the tangent and the specified axis.

The spline is parametrized in the range t = [0;1]

Parameters
tspline parameter
resnormal at t (output parameter)

◆ evaluateNormal() [2/2]

void evaluateNormal ( double t,
const vec3 & dir,
vec3 & res ) const

Evaluates spline normal orthogonal to the tangent and the specified direction.

The spline is parametrized in the range t = [0;1]

Parameters
tspline parameter
dirorthogonal direction
resnormal at t (output parameter)

◆ getCurveLength()

double getCurveLength ( double t1 = 0.0,
double t2 = 1.0 ) const

Computes the length of the spline between t1 and t2.

Does not consider and thus does not work with closed splines!

Parameters
t1start parameter
t2stop parameter
Returns
spline length between t1 and t2

◆ getProjectedCurveLength() [1/2]

double getProjectedCurveLength ( int axis,
double t1 = 0.0,
double t2 = 1.0 ) const

Computes the length of the spline between t1 and t2 when projected onto an axis plane.

Parameters
axisaxis (0 = z, 1 = y, 2 = x)
t1start parameter
t2stop parameter
Returns
length of spline between t1 and t2 projected on axis axis

◆ getProjectedCurveLength() [2/2]

double getProjectedCurveLength ( const vec3 & normal,
double t1 = 0.0,
double t2 = 1.0 ) const

Computes the length of the spline between t1 and t2 when projected onto a plane.

Parameters
normalplane normal
t1start parameter
t2stop parameter
Returns
length of spline between t1 and t2 projected on axis axis

◆ getUniformSamples() [1/2]

void getUniformSamples ( int n,
std::vector< std::pair< double, vec3 > > & samples ) const

Returns sort-of uniformly spaced sample points on the spline (in terms of distance).

Works for open splines only.

Parameters
nupper bound for number of sample points
samplesspline samples (output parameter)

◆ getParametricUniformSamples()

std::vector< vec3 > getParametricUniformSamples ( int n) const

Returns t-uniformly-spaced sample points on the spline.

The curve parameter t is uniformly sampled. This gives the guarantee of an equal number of samples within segments (in-between control points) which are sort-of uniformly sampled within a segment. Works for closed and open splines.

Parameters
nnumber of sample points
Returns
Spline samples

◆ getUniformSamplesX()

void getUniformSamplesX ( int n,
std::vector< vec3 > & samples ) const

Sample spline uniformly along x-axis.

Assumes that spline is a graph in the xy-plane.

◆ getUniformSamples() [2/2]

void getUniformSamples ( int n,
std::vector< vec3 > & samples,
double eps = 1e-10 ) const

Returns uniformly spaced sample points on the spline (in terms of arc length).

Doesn't work with closed splines

Parameters
nnumber of sample points
samplesspline samples (output parameter)
epsthreshold on max deviation of the sample's arc length

◆ getProjectedUniformSamples() [1/2]

void getProjectedUniformSamples ( int n,
int axis,
std::vector< std::pair< double, vec3 > > & samples ) const

Returns uniformly spaced points on the spline (in terms of distance on the given axis plane)

Parameters
nnumber of sample points
samplesspline samples (output parameter)

◆ getProjectedUniformSamples() [2/2]

void getProjectedUniformSamples ( int n,
const vec3 & normal,
std::vector< std::pair< double, vec3 > > & samples ) const

Returns uniformly spaced points on the spline (in terms of distance on the given plane)

Parameters
nnumber of sample points
normalplane normal
samplesspline samples (output parameter)

◆ arcLengthToSplineCoord()

double arcLengthToSplineCoord ( double pos) const

Converts a position on the spline given in arc length parameterization (in world units) to the corresponding position in the spline parameterization.

Parameters
posarc length position
Returns
spline parameterization position

◆ splineCoordToArcLength()

double splineCoordToArcLength ( double t) const
inline

Converts a position on the spline given in spline parameterization to the corresponding position in arc length parameterization (in world units)

Parameters
tspline parameterization position
Returns
arc length position

◆ calculateNearestPointArcLength()

double calculateNearestPointArcLength ( const Eigen::Vector3d & pos,
const std::vector< Eigen::Vector3d > pointsApproximation = std::vector< Eigen::Vector3d >(),
Eigen::Vector3d * nearestPoint = nullptr,
bool * outsideCurve = nullptr ) const

Calculates the arc length of the point nearest to pos.

First the nearest point to pos on the spline is determined and the arc length from the start of the spline to this point returned. The calculation pretends that the first and last segment of the spline extend to infinity. This means that the returned arc length can be negative (before the first point) or larger than the overall arc length (after the last point).

Parameters
posworldspace position of a point on the view
optionallist of approximated points used intead of the control points
optionalnearestPoint world position of the nearest point on the spline

◆ getApproximateClosedSpline()

std::unique_ptr< Spline > getApproximateClosedSpline ( int skipFactor,
bool optimizePositions ) const

Get a closed spline that approximates the current closed spline.

Parameters
skipFactorThe factor by which to skip points in the approximation. A skipFactor of 1 will result in the same number of points as the original spline.
optimizePositionsWhether or not to run a post optimization after the skipping step

◆ evaluateLoop()

void evaluateLoop ( double t_,
vec3 & res ) const

This version of evaluate scraps the padding points at each end and cycles around instead to produce a closed loop.

It is called in evaluate when the spline is set to be closed.

Deprecated
"Use Spline::evaluate instead"

The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close