Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
trax::Spline Struct Referenceabstract

\ brief Cubic Hermite Spline. More...

#include <C:/Trend/Development/Trax3/Code/trax/Curve.h>

Inheritance diagram for trax::Spline:

Public Types

enum class  WrapTypes { none = 0 , nonperiodic , periodic , pinned }
 Type of handling the ends:
using SegmentValueType = CubicData
using Data = std::vector<SegmentValueType>
 Data definig the curve.
Public Types inherited from trax::Curve
enum class  CurveType {
  none = 0 , Line , Arc , Helix ,
  LineP , ArcP , HelixP , Clothoid ,
  Cubic , Spline , Rotator , RotatorWithOffset ,
  RotatorChain , PolygonalChain , SampledCurve , Parallel ,
  EEPCurve , EEPResidual , EEPAlternative , Unknown ,
  UserDefined
}
 Curve type identification values. More...

Public Member Functions

virtual int CountControlPoints () const noexcept=0
virtual common::Interval< LengthResetControlPointAndTangent (int idx, const spat::VectorBundle< Length > &controlPointAndTangent)=0
 Resets a control point.
virtual spat::VectorBundle< LengthGetControlPointAndTangent (int idx) const =0
virtual Length GetParameter (int idx) const =0
virtual int UpperBound (Length s) const =0
 The index of the control point that is the first one to have greater parameter than s.
virtual bool HasGaps (Length epsilon=epsilon__length) const noexcept=0
 Check smoothness of the curve at the control points.
virtual bool HasKinks (Angle epsilon=epsilon__angle) const noexcept=0
 Check smoothness of the tangets of the curve at the control points.
virtual common::Interval< LengthShorten (common::Interval< Length > toRange)=0
 Transforms the Spline to one with the given parameter range.
virtual const DataGetData () const noexcept=0
 Retrieves the data to construct this curve type. A roundtrip is guaranteed to be invariant.
Creation
virtual common::Interval< LengthCreate (const Curve &originalCurve, common::Interval< Length > range, Length maxDeviation=epsilon__length, common::Interval< Length > sampleDistanceLimits={ 1_m, 1000_m })=0
 Creates a spline curve from an existing curve.
virtual common::Interval< LengthCreate (std::pair< std::shared_ptr< const Curve >, common::Interval< Length > > originalCurve, Length maxDeviation=epsilon__length, common::Interval< Length > sampleDistanceLimits={ 1_m, 1000_m })=0
virtual common::Interval< LengthCreate (const std::vector< spat::VectorBundle< Length > > &controlPointsAndTangents)=0
 Creates a Cubic Hermite Spline, guaranteed to be C1 (points and tangents match).
virtual common::Interval< LengthCreate (const std::vector< spat::Position< Length > > &controlPoints)=0
 Natural Cubic C2 - smooth Spline (points, tangent, normal and curvature of the segments match).
virtual common::Interval< LengthCreate (const std::vector< spat::Position< Length > > &controlPoints, bool bClampedAtStart, const spat::Vector< Length > &startTangent, bool bClampedAtEnd, const spat::Vector< Length > &endTangent)=0
 Clamped Cubic C2 - smooth Spline (points, tangent, normal and curvature of the segments match).
virtual common::Interval< LengthCreateCatmullRom (const std::vector< spat::Position< Length > > &controlPoints, One tension=0.5f, WrapTypes wrap=WrapTypes::nonperiodic)=0
 C1 Spline with Pi'th tangent being: tension * (Pi+1 - Pi-1).
virtual common::Interval< LengthCreateCatmullRom (const std::vector< spat::VectorBundle< Length, One > > &controlPoints, One tension=0.5f, WrapTypes wrap=WrapTypes::nonperiodic)=0
 C1 Spline with Pi'th tangent being: tension * (Pi+1 - Pi-1).Length() * Ti.
virtual common::Interval< LengthCreateBezier (const std::vector< spat::Position< Length > > &controlPoints, WrapTypes wrap=WrapTypes::nonperiodic)=0
 C0 Spline from Cubic Bezier control points.
virtual common::Interval< LengthCreate (const Data &data)=0
 Create the curve from data set for which it is guaranteed, that no calculational drift will happen, e.g. in write/read cycles.
Public Member Functions inherited from trax::Curve
virtual const char * TypeName () const noexcept=0
virtual CurveType GetCurveType () const noexcept=0
virtual bool IsValid () const noexcept=0
virtual AnglePerLength Curvature (Length s) const =0
virtual AnglePerLength Torsion (Length s) const =0
virtual bool IsFlat () const noexcept=0
virtual void Transition (Length s, spat::Position< Length > &pos) const =0
 Copies the 3D Position at the specified location to pos.
virtual void Transition (Length s, spat::Vector< One > &tan) const =0
 Copies the 3D tangential vector at the specified location to tan.
virtual void Transition (Length s, spat::VectorBundle< Length, One > &bundle) const =0
 Copies the 3D Position and tangential vector at the specified location to bundle.
virtual void Transition (Length s, spat::VectorBundle2< Length, One > &bundle) const =0
 Copies the 3D Position and tangential and normal vectors at the specified location to bundle.
virtual void Transition (Length s, spat::Frame< Length, One > &frame) const =0
 Copies the 3D TBN-Frame at the specified location to frame.
virtual std::vector< LengthZeroSet () const =0
 Returns a list of parameters at which the normal vector flips from one side to the other.
virtual common::Interval< LengthRange () const =0
virtual spat::Vector< OneLocalUp () const =0
 Gives the Curve's idiosyncratic up direction. Some curves maintain some idea about where they have their upside, either because of their form (e.g Helix) or because it is extra defined (e.g. for Line). Some curves maintain no such notion (e.g. many Cubics).
virtual spat::Frame< Length, OneGetCurveLocalTransformation () const =0
virtual std::unique_ptr< Curve > Clone () const =0
 make an exact copy of this curve.
virtual bool Mirror (const spat::VectorBundle< Length, One > &mirrorPlane)=0
 Make a Curve with mirrored geometry (but of course one thet returns right handed frames).
virtual bool Equals (const Curve &toCurve, common::Interval< Length > range, Length epsilon_length=epsilon__length, Angle epsilon_angle=epsilon__angle) const =0
 Comparison.
 Curve (Curve &&)=delete
Curve & operator= (const Curve &)=delete
Curve & operator= (Curve &&)=delete

Static Public Member Functions

static dclspc std::unique_ptr< SplineMake () noexcept
 Makes a Spline object.

Additional Inherited Members

Protected Member Functions inherited from trax::Curve
 Curve (const Curve &)=default

Detailed Description

\ brief Cubic Hermite Spline.

Member Typedef Documentation

◆ Data

using trax::Spline::Data = std::vector<SegmentValueType>

Data definig the curve.

This is used for persistence. GetData() receives the data and there is a Create() method to create the curve from this data set without any calculations made that might distort the values during many read/write cycles.

◆ SegmentValueType

Type of the segments.

Member Function Documentation

◆ CountControlPoints()

virtual int trax::Spline::CountControlPoints ( ) const
pure virtualnoexcept
Returns
the number of control points.

◆ Create() [1/6]

virtual common::Interval< Length > trax::Spline::Create ( const Curve & originalCurve,
common::Interval< Length > range,
Length maxDeviation = epsilon__length,
common::Interval< Length > sampleDistanceLimits = { 1_m, 1000_m } )
pure virtual

Creates a spline curve from an existing curve.

Parameters
originalCurvevalid template curve.
rangerange on the template curve
maxDeviationthe maximum positional deviation.
sampleDistanceLimitsThe minimum and maximum distance between the sample points
Exceptions
std::invalid_argumentif originalCurve is not a valid curve, or the range of the curve does not intersect with range, or maxDeviation <= 0_m.
std::runtime_errorif the curve could not get created.

◆ Create() [2/6]

virtual common::Interval< Length > trax::Spline::Create ( const Data & data)
pure virtual

Create the curve from data set for which it is guaranteed, that no calculational drift will happen, e.g. in write/read cycles.

Returns
The total curve range between start and end.
Exceptions
std::invalid_argumentif the creation fails.

◆ Create() [3/6]

virtual common::Interval< Length > trax::Spline::Create ( const std::vector< spat::Position< Length > > & controlPoints)
pure virtual

Natural Cubic C2 - smooth Spline (points, tangent, normal and curvature of the segments match).

These are used in railroading often (or better be). The curvatures at start and end are zero.

Parameters
controlPointsA series of points to be connected by the spline.
Returns
The total curve range between start and end.
Exceptions
std::invalid_argumentif there are less then two control points.

◆ Create() [4/6]

virtual common::Interval< Length > trax::Spline::Create ( const std::vector< spat::Position< Length > > & controlPoints,
bool bClampedAtStart,
const spat::Vector< Length > & startTangent,
bool bClampedAtEnd,
const spat::Vector< Length > & endTangent )
pure virtual

Clamped Cubic C2 - smooth Spline (points, tangent, normal and curvature of the segments match).

These are used in railroading often (or better be). The curvatures at start and end are given by the supplied tangent vectors. If both end are set to be not clamped, a Natural Cubic C2 spline will be generated.

Parameters
controlPointsA series of points to be connected by the spline.
bClampedAtStartIf true the start tangent will be used.
bClampedAtEndIf true the end tangent will be used.
startTangentTangent (and cubic overshoot) at start point.
endTangentTangent (and cubic overshoot) at end point.
Returns
The total curve range between start and end.
Exceptions
std::invalid_argumentif there are less then two control points.

◆ Create() [5/6]

virtual common::Interval< Length > trax::Spline::Create ( const std::vector< spat::VectorBundle< Length > > & controlPointsAndTangents)
pure virtual

Creates a Cubic Hermite Spline, guaranteed to be C1 (points and tangents match).

There are methods to yield these controlPoint-tangents by different interpolation methods. See below.

Returns
The total curve range between start and end.
Exceptions
std::invalid_argumentif there are less then two control points.

◆ Create() [6/6]

virtual common::Interval< Length > trax::Spline::Create ( std::pair< std::shared_ptr< const Curve >, common::Interval< Length > > originalCurve,
Length maxDeviation = epsilon__length,
common::Interval< Length > sampleDistanceLimits = { 1_m, 1000_m } )
pure virtual
Parameters
originalCurvevalid template curve.
maxDeviationthe maximum positional deviation.
sampleDistanceLimitsThe minimum and maximum distance between the sample points
Exceptions
std::invalid_argumentif originalCurve is not a valid curve, or the range of the curve does not intersect with range, or maxDeviation <= 0_m.
std::runtime_errorif the curve could not get created.

◆ CreateBezier()

virtual common::Interval< Length > trax::Spline::CreateBezier ( const std::vector< spat::Position< Length > > & controlPoints,
WrapTypes wrap = WrapTypes::nonperiodic )
pure virtual

C0 Spline from Cubic Bezier control points.

These are 4 control points (P0,P1,P2,P3) for the first segment and 3 control points (P4,P5,P6) for each following segment.

/// p1 = P0 
/// t1 = 3(P1-P0)
/// p2 = P3
/// t2 = 3(P3-P2)
/// 
/// p1 = P3
/// t1 = 3(P4-P3)
/// p2 = P6
/// t2 = 3(P6-P5)
/// 

etc...

If the wrap type is periodic, the last segment will be closed with the first segment by an additional segment. For this only two additional control points are expected, since the first and last control point are the same.

Parameters
controlPointsA series of points to define the spline. For nonperiodic splines the number of control points n is needed to define (n-4)/3 + 1 segments; for periodic it will be n/3 segments.
wrapType of wrapping the spline.
Returns
The total curve range between start and end.
Exceptions
std::invalid_argumentif the control points are not the right count.

◆ CreateCatmullRom() [1/2]

virtual common::Interval< Length > trax::Spline::CreateCatmullRom ( const std::vector< spat::Position< Length > > & controlPoints,
One tension = 0.5f,
WrapTypes wrap = WrapTypes::nonperiodic )
pure virtual

C1 Spline with Pi'th tangent being: tension * (Pi+1 - Pi-1).

This might match well with paths on top of terrains. The tangents at start and end are tension * (P1 - P0) and tension * (Pn - Pn-1) respectively.

Parameters
controlPointsA series of points to be connected by the spline.
tensionStreching value for the tangent's cubic overshoot. Must be > 0.
wrapType of wrapping the spline. If WrapTypes::periodic, the first and last control point will be connected by an additional segment.
Returns
The total curve range between start and end
Exceptions
std::invalid_argumentif there are less then two control points.
std::invalid_argumentif tension <= 0.

◆ CreateCatmullRom() [2/2]

virtual common::Interval< Length > trax::Spline::CreateCatmullRom ( const std::vector< spat::VectorBundle< Length, One > > & controlPoints,
One tension = 0.5f,
WrapTypes wrap = WrapTypes::nonperiodic )
pure virtual

C1 Spline with Pi'th tangent being: tension * (Pi+1 - Pi-1).Length() * Ti.

Modified Catmull-Rom for known tangent directions.

Parameters
controlPointsA series of points and tangents to be connected by the spline.
tensionStreching value for the tangent's cubic overshoot. Must be > 0.
wrapType of wrapping the spline. If WrapTypes::periodic, the first and last control point will be connected by an additional segment.
Returns
The total curve range between start and end
Exceptions
std::invalid_argumentif there are less then two control points.
std::invalid_argumentif tension <= 0.

◆ GetControlPointAndTangent()

virtual spat::VectorBundle< Length > trax::Spline::GetControlPointAndTangent ( int idx) const
pure virtual
Parameters
idxid of the control point to retrieve [0,CountControlPoints()[.
Returns
Position and tangent (including cubic overshoot) at control point.
Exceptions
std::out_of_rangeif idx is out of range.
std::logic_errorif the spline wasn't created before.

◆ GetParameter()

virtual Length trax::Spline::GetParameter ( int idx) const
pure virtual
Parameters
idxid of the control point to retrieve [0,CountControlPoints()[.
Returns
the arc length parameter at a control point.
Exceptions
std::out_of_rangeif idx is out of range.

◆ ResetControlPointAndTangent()

virtual common::Interval< Length > trax::Spline::ResetControlPointAndTangent ( int idx,
const spat::VectorBundle< Length > & controlPointAndTangent )
pure virtual

Resets a control point.

The methods will change the controlpoint only. Any property achieved by using specially interpolated data sets might get lost.

Parameters
idxid of the control point to reset [0,CountControlPoints()[.
controlPointAndTangent3D position and tangent including cubic overshoot.
Returns
The total curve range between start and end.
Exceptions
std::logic_errorif the spline wasn't created before.
std::out_of_rangeif idx is out of range.

◆ Shorten()

virtual common::Interval< Length > trax::Spline::Shorten ( common::Interval< Length > toRange)
pure virtual

Transforms the Spline to one with the given parameter range.

Shortens the curve in a way that it will run from the starting point of toRange to the end along the same path as the original, but with parameters running between {0_m,toRange.Length()}.

Parameters
toRangeParameter range of the original Spline, to transform the Spline to. If toRange is outside the original range it will get clipped.
Returns
{0_m,toRange.Length()}, the new parameter range.
Exceptions
std::invalid_argumentif the creation of the shorter spline fails.

◆ UpperBound()

virtual int trax::Spline::UpperBound ( Length s) const
pure virtual

The index of the control point that is the first one to have greater parameter than s.

The index might become greater than CountControlPoints() - 1, in what case s is beyond the curves range.

Returns
the index of the first control point that has a parameter value greater then s.

The documentation for this struct was generated from the following file:
  • C:/Trend/Development/Trax3/Code/trax/Curve.h