CVB++ 15.0
Cvb::Foundation::Curve Namespace Reference

Namespace for collection of 2D curve functions from the Foundation package. More...

Classes

class  AlignmentConfiguration
 A set of parameters that configures an alignment operation. More...
 
class  AlignmentResult2D
 A set of parameters that stores the result of alignment operation. More...
 

Enumerations

enum class  PreAlignmentMode { Off , On }
 Specifies if the pre-alignment is required. More...
 
enum class  StartSelectionMode { AsIs , Best }
 Decides which start point should be used for the new curve. More...
 

Functions

std::vector< Point2D< double > > ResampleCurve (const std::vector< Point2D< double > > &curve, int resampledCurveLength)
 Resamples a 2-dimensional curve via linear interpolation assuming that the "speed" of the time mapping is constant. More...
 
AlignmentResult2D AlignCurve (const std::vector< Point2D< double > > &curve, const std::vector< Point2D< double > > &curveToBeAligned, const AlignmentConfiguration &config=AlignmentConfiguration())
 Aligns two 2D curves via an iterative closest point method considering consensus correspondence for better shape alignment. More...
 
std::vector< double > CalculateSignedDifferences (const std::vector< Point2D< double > > &curve, const std::vector< Point2D< double > > &points)
 Calculates signed differences along the y axis of given points to curve (curve - points). More...
 
std::vector< Point2D< double > > IntersectWithLine (const std::vector< Point2D< double > > &curve, const Line2D &line)
 Intersects a 2D curve with a line. More...
 
double CalculateEnclosedArea (const std::vector< Point2D< double > > &curve)
 Calculates the enclosed area of the given curve. More...
 
Matrix2D CalculateQuadraticDifferencesToClosestPoint (const std::vector< Point2D< double > > &curve, const std::vector< Point2D< double > > &points)
 Calculates the quadratic distance of the points to the closest point of the given curve. More...
 
std::vector< Point2D< double > > MergeTwoCurves (const std::vector< Point2D< double > > &curveLHS, const std::vector< Point2D< double > > &curveRHS, const StartSelectionMode &mode)
 Merges two curves into one curve with interpolation. More...
 

Detailed Description

Namespace for collection of 2D curve functions from the Foundation package.

Remarks
CMake users: Link to imported target CVB::CvbFoundationCurve2D

Enumeration Type Documentation

◆ PreAlignmentMode

enum class PreAlignmentMode
strong

Specifies if the pre-alignment is required.

Enumerator
Off 

The target will not be pre-aligned.

On 

The target will be pre-aligned by moving it to the mean of the source set as a first alignment step.

◆ StartSelectionMode

enum class StartSelectionMode
strong

Decides which start point should be used for the new curve.

Enumerator
AsIs 

Use start point of first curve.

Best 

Calculate start point that will give the "smoothest" curve.

Function Documentation

◆ AlignCurve()

AlignmentResult2D AlignCurve ( const std::vector< Point2D< double > > &  curve,
const std::vector< Point2D< double > > &  curveToBeAligned,
const AlignmentConfiguration config = AlignmentConfiguration() 
)
inline

Aligns two 2D curves via an iterative closest point method considering consensus correspondence for better shape alignment.

Parameters
[in]curveReference curve.
[in]curveToBeAlignedCurve to be aligned to curve.
[in]configConfiguration of alignment.
Returns
Alignment result.
Exceptions
Anyexception derived from std::exception including CvbException.

The method used here is a version of the ICP (iterative closest point) method. It uses a consensus metric to find the correspondence between points to stabilize the iterations needed in the alignment method. It supports only rigid transformations for the alignment.

If not enough points within a given consent are found a classical ICP step is performed by finding correspondences solely based on nearest neighbours without any feasibility check.

◆ CalculateEnclosedArea()

double CalculateEnclosedArea ( const std::vector< Point2D< double > > &  curve)
inline

Calculates the enclosed area of the given curve.

Parameters
[in]curveCurve.
Returns
The enclosed area of the given curve.
Exceptions
Anyexception derived from std::exception including CvbException.

Uses the shoelace algorithm to calculate the enclosed area of the given curve. All points are assumed to be in order, clockwise or anti clockwise will not affect the outcome. This algorithm can only handle not self intersecting curves, e.g. a figure eight curve will not work with this algorithm.

For numerical stabilization all points are shifted to be centered around the origin.

If the curve is not closed, i.e. the first and last point in the given point set don't match, the curve is closed automatically by connecting the first and last point.

Note
The points on the curve are evaluated in the order in which they are listed. We assume an ordered point set (not ordered by axis, but ordered according to the curve).

◆ CalculateQuadraticDifferencesToClosestPoint()

Matrix2D CalculateQuadraticDifferencesToClosestPoint ( const std::vector< Point2D< double > > &  curve,
const std::vector< Point2D< double > > &  points 
)
inline

Calculates the quadratic distance of the points to the closest point of the given curve.

Parameters
[in]curveCurve.
[in]pointsPoints.
Returns
The closest point of the given curve
Exceptions
Anyexception derived from std::exception including CvbException.
Note
The points have to be ordered by time, i.e. two consecutive points must adjoin another on the curve.

For the calculation of the signed differences the curve is assumed to be infinite. It is extended at the starting and endpoint.

◆ CalculateSignedDifferences()

std::vector< double > CalculateSignedDifferences ( const std::vector< Point2D< double > > &  curve,
const std::vector< Point2D< double > > &  points 
)
inline

Calculates signed differences along the y axis of given points to curve (curve - points).

Parameters
[in]curveCurve.
[in]pointsPoints.
Returns
Array of signed differences, the length is given be the size of the points.
Exceptions
Anyexception derived from std::exception including CvbException.
Note
The points have to be ordered by time, i.e. two consecutive points must adjoin another on the curve.

For the calculation of the signed differences the curve is assumed to be infinite. It is extended at the starting and endpoint.

◆ IntersectWithLine()

std::vector< Point2D< double > > IntersectWithLine ( const std::vector< Point2D< double > > &  curve,
const Line2D line 
)
inline

Intersects a 2D curve with a line.

Parameters
[in]curveCurve to be intersected.
[in]lineLine to intersect with.
Returns
Calculated intersection points.
Exceptions
Anyexception derived from std::exception including CvbException.

The line is defined by the Hessian normal form:

Normal * x = d, with | Normal | = 1 and d > 0.

Note
The points have to be ordered by time, i.e. two consecutive points must adjoin another on the curve.

The curve is finite. It starts and ends at the first and last point respectively.

Attention
The number of intersection points will be calculated with this function and will be lower than the points defined by curve.

◆ MergeTwoCurves()

std::vector< Point2D< double > > MergeTwoCurves ( const std::vector< Point2D< double > > &  curveLHS,
const std::vector< Point2D< double > > &  curveRHS,
const StartSelectionMode mode 
)
inline

Merges two curves into one curve with interpolation.

Parameters
[in]curveLHSLeft hand side curve. This curve is assumed starting point if sorting is executed.
[in]curveRHSRight hand side curve.
[in]modeSpecifies if left and right order of the two curves is to be found by the algorithm.
Returns
Merged curve.
Exceptions
Anyexception derived from std::exception including CvbException.

Takes two curves and merges them into one combined curve. If they overlap, an interpolation method is used to find a suitable approximation. This interpolation is done when switching between the two curves while the points are interleaved. The order in which the points are interleaved is defined by the closest neighbour for each point from CurveRHS to CurveLHS.

This method works with curves in 2D.

If sorting is executed, then the pair of curves curveLHS and curveRHS are sorted from left to right. This means, the algorithm checks which starting point from the two staring points is the best starting point for the merged curve. To make this decision the distance from each possible starting point to the other given curve is calculated and the point with the highest distance is taken as the overall starting point for the new generated merged curve. This method does work well for regular curves (not self intercepting curves). It can be switched off to save computation time if the caller is sure about the correct order.

Note
The points on the curve are evaluated in the order in which they are listed. We assume an ordered point set (not ordered by axis, but ordered according to the curve).

◆ ResampleCurve()

std::vector< Point2D< double > > ResampleCurve ( const std::vector< Point2D< double > > &  curve,
int  resampledCurveLength 
)
inline

Resamples a 2-dimensional curve via linear interpolation assuming that the "speed" of the time mapping is constant.

Parameters
[in]curveCurve to be resampled.
[in]resampledCurveLengthLength of the resulting curve.
Returns
Resampled curve.
Exceptions
Anyexception derived from std::exception including CvbException.
Note
The points have to be ordered by time, i.e. two consecutive points must adjoin another on the curve.