C# Class burningmime.curves.CurveFitBase

This is the base class containing implementations common to CurveFit and CurveBuilder. Most of this is ported from http://tog.acm.org/resources/GraphicsGems/gems/FitCurves.c
Exibir arquivo Open project: prepare/HTML-Renderer

Protected Properties

Property Type Description
_arclen List
_pts List
_squaredError System.Double
_u List

Protected Methods

Method Description
ArcLengthParamaterize ( int first, int last ) : void

Initializes the first (last - first) elements of u with scaled arc lengths.

FindMaxSquaredError ( int first, int last, CubicBezier curve, int &split ) : System.Double

Computes the maximum squared distance from a point to the curve using the current parameterization.

FitCurve ( int first, int last, System.Windows.Vector tanL, System.Windows.Vector tanR, CubicBezier &curve, int &split ) : bool

Tries to fit single Bezier curve to the points in [first ... last]. Destroys anything in _u in the process. Assumes there are at least two points to fit.

GenerateBezier ( int first, int last, System.Windows.Vector tanL, System.Windows.Vector tanR ) : CubicBezier

Generates a bezier curve for the segment using a least-squares approximation. for the derivation of this and why it works, see http://read.pudn.com/downloads141/ebook/610086/Graphics_Gems_I.pdf page 626 and beyond. tl;dr: math.

GetCenterTangent ( int first, int last, int split ) : System.Windows.Vector

Gets the tangent at a given point in the curve.

GetLeftTangent ( int last ) : System.Windows.Vector

Gets the tangent for the start of the cure.

GetRightTangent ( int first ) : System.Windows.Vector

Gets the tangent for the the end of the curve.

InitializeArcLengths ( ) : void

Builds the arc length array using the points array. Assumes _pts has points and _arclen is empty.

Reparameterize ( int first, int last, CubicBezier curve ) : void

Attempts to find a slightly better parameterization for u on the given curve.

Method Details

ArcLengthParamaterize() protected method

Initializes the first (last - first) elements of u with scaled arc lengths.
protected ArcLengthParamaterize ( int first, int last ) : void
first int
last int
return void

FindMaxSquaredError() protected method

Computes the maximum squared distance from a point to the curve using the current parameterization.
protected FindMaxSquaredError ( int first, int last, CubicBezier curve, int &split ) : System.Double
first int
last int
curve CubicBezier
split int
return System.Double

FitCurve() protected method

Tries to fit single Bezier curve to the points in [first ... last]. Destroys anything in _u in the process. Assumes there are at least two points to fit.
protected FitCurve ( int first, int last, System.Windows.Vector tanL, System.Windows.Vector tanR, CubicBezier &curve, int &split ) : bool
first int Index of first point to consider.
last int Index of last point to consider (inclusive).
tanL System.Windows.Vector Tangent at teh start of the curve ("left").
tanR System.Windows.Vector Tangent on the end of the curve ("right").
curve CubicBezier The fitted curve.
split int Point at which to split if this method returns false.
return bool

GenerateBezier() protected method

Generates a bezier curve for the segment using a least-squares approximation. for the derivation of this and why it works, see http://read.pudn.com/downloads141/ebook/610086/Graphics_Gems_I.pdf page 626 and beyond. tl;dr: math.
protected GenerateBezier ( int first, int last, System.Windows.Vector tanL, System.Windows.Vector tanR ) : CubicBezier
first int
last int
tanL System.Windows.Vector
tanR System.Windows.Vector
return CubicBezier

GetCenterTangent() protected method

Gets the tangent at a given point in the curve.
protected GetCenterTangent ( int first, int last, int split ) : System.Windows.Vector
first int
last int
split int
return System.Windows.Vector

GetLeftTangent() protected method

Gets the tangent for the start of the cure.
protected GetLeftTangent ( int last ) : System.Windows.Vector
last int
return System.Windows.Vector

GetRightTangent() protected method

Gets the tangent for the the end of the curve.
protected GetRightTangent ( int first ) : System.Windows.Vector
first int
return System.Windows.Vector

InitializeArcLengths() protected method

Builds the arc length array using the points array. Assumes _pts has points and _arclen is empty.
protected InitializeArcLengths ( ) : void
return void

Reparameterize() protected method

Attempts to find a slightly better parameterization for u on the given curve.
protected Reparameterize ( int first, int last, CubicBezier curve ) : void
first int
last int
curve CubicBezier
return void

Property Details

_arclen protected_oe property

length of curve before each point (so, arclen[0] = 0, arclen[1] = distance(pts[0], pts[1]), arclen[2] = arclen[1] + distance(pts[1], pts[2]) ... arclen[n -1] = length of the entire curve, etc).
protected List _arclen
return List

_pts protected_oe property

Points in the whole line being used for fitting.
protected List _pts
return List

_squaredError protected_oe property

maximum squared error before we split the curve
protected Double,System _squaredError
return System.Double

_u protected_oe property

current parametrization of the curve. When fitting, u[i] is the parametrization for the point in pts[first + i]. This is an optimization for CurveBuilder, since it might not need to allocate as big of a _u as is necessary to hold the whole curve.
protected List _u
return List