LibreCAD
|
#include <stddef.h>
Go to the source code of this file.
Classes | |
struct | tsDeBoorNet |
struct | tsBSpline |
Typedefs | |
typedef float | tsRational |
Enumerations | |
enum | tsError { TS_SUCCESS = 0, TS_MALLOC = -1, TS_DIM_ZERO = -2, TS_DEG_GE_NCTRLP = -3, TS_U_UNDEFINED = -4, TS_MULTIPLICITY = -5, TS_KNOTS_DECR = -6, TS_NUM_KNOTS = -7, TS_UNDERIVABLE = -8 } |
enum | tsBSplineType { TS_OPENED = 0, TS_CLAMPED = 1, TS_BEZIERS = 2, TS_NONE = 3 } |
typedef float tsRational |
Definition at line 19 of file tinyspline.h.
enum tsBSplineType |
This enum describes how to fill the knot vector of a spline.
If you don't know what an opened or clamped spline is, take a look at: www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/B-spline/bspline-curve.html
Enumerator | |
---|---|
TS_OPENED | |
TS_CLAMPED | |
TS_BEZIERS | |
TS_NONE |
Definition at line 61 of file tinyspline.h.
enum tsError |
This enum contains all error codes used by TinySpline.
The following snippet shows how to handle errors: TsError err = ... // any function call here if (err < 0) { // or use err != TS_SUCCESS printf("we got an error!");
// you may want to reuse error codes // over several functions return err; }
Enumerator | |
---|---|
TS_SUCCESS | |
TS_MALLOC | |
TS_DIM_ZERO | |
TS_DEG_GE_NCTRLP | |
TS_U_UNDEFINED | |
TS_MULTIPLICITY | |
TS_KNOTS_DECR | |
TS_NUM_KNOTS | |
TS_UNDERIVABLE |
Definition at line 41 of file tinyspline.h.
tsError ts_bspline_buckle | ( | const tsBSpline * | original, |
const tsRational | b, | ||
tsBSpline * | buckled | ||
) |
Buckles by and stores the result in .
This function is based on: Holten, Danny. "Hierarchical edge bundles: Visualization of adjacency relations in hierarchical data." Visualization and Computer Graphics, IEEE Transactions on 12.5 (2006): 741-748. Holten calls it "straightening" (page 744, equation 1).
Usually the range of is: 0 <= <= 1, where 0 results in a line between the first and the last control point (no buckle) and 1 keeps the original shape (maximum buckle). If < 0 or > 1 the behaviour is undefined, though it will not result in an error.
This function creates a deep copy of , if != and will never fail if == (always returns TS_SUCCESS).
On error all values of are 0/NULL.
The copy constructor of tsBSpline.
Creates a deep copy of and stores the result in . This function does not free already allocated memory in . If you want to reuse an instance of tsBSpline by using it in multiple calls of this function, make sure to call ts_bspline_free beforehand.
On error all values of are 0/NULL. The function does nothing if ==
void ts_bspline_default | ( | tsBSpline * | bspline | ) |
The default constructor of tsBSpline.
All values of are set to 0/NULL.
Computes the derivative of . http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/B-spline/bspline-derv.html
The derivative of a spline of degree ->deg with ->n_ctrlp control points and ->n_knots knots is another spline of degree ->deg-1 with ->n_ctrl-1 control points and ->n_knots-2 knots, defined over as C'(u) = Sum_{i=0}^{n-1} N_{i+1,p-1}(u) * (P_{i+1} - P_{i}) * p / (u_{i+p+1}-u_{i+1}) = Sum_{i=1}^{n} N_{i,p-1}(u) * (P_{i} - P_{i-1}) * p / (u_{i+p}-u_{i}) If is clamped, it can be shown that C'(u) = Sum_{i=0}^{n-1} N_{i,p-1}(u) * (P_{i+1} - P_{i}) * p / (u_{i+p+1}-u_{i+1}) where the multiplicity of the first and the last u is p rather than p+1.
This function does not free already allocated memory in . If you want to reuse an instance of tsBSpline by using it in multiple calls of this function, make sure to call ts_deboornet_free beforehand.
On error (and if != ) all values of are 0/NULL.
tsError ts_bspline_evaluate | ( | const tsBSpline * | bspline, |
const tsRational | u, | ||
tsDeBoorNet * | deBoorNet | ||
) |
Evaluates at knot value and stores result in .
This function does not free already allocated memory in . If you want to reuse an instance of tsDeBoorNet by using it in multiple calls of this function, make sure to call ts_deboornet_free beforehand.
On error all values of are 0/NULL.
void ts_bspline_free | ( | tsBSpline * | bspline | ) |
The destructor of tsBSpline.
Frees all dynamically allocated memory and calls ts_deboornet_free afterwards.
tsError ts_bspline_insert_knot | ( | const tsBSpline * | bspline, |
const tsRational | u, | ||
const size_t | n, | ||
tsBSpline * | result, | ||
size_t * | k | ||
) |
tsError ts_bspline_interpolate | ( | const tsRational * | points, |
const size_t | n, | ||
const size_t | dim, | ||
tsBSpline * | bspline | ||
) |
Performs a cubic spline interpolation using thomas algorithm. https://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm http://www.math.ucla.edu/~baker/149.1.02w/handouts/dd_splines.pdf http://www.bakoma-tex.com/doc/generic/pst-bspline/pst-bspline-doc.pdf
The resulting spline is a sequence of bezier curves connecting each point in . Each bezier curve is of degree 3 with dimension . The total number of control points is (n-1)*4.
This function does not free already allocated memory in . If you want to reuse an instance of tsBSpline by using it in multiple calls of this function, make sure to call ts_deboornet_free beforehand.
On error all values of are 0/NULL.
Note:
is the number of points in and not the length of .
The move constructor of tsBSpline.
Moves all values from to and calls ts_bspline_default on afterwards.
tsError ts_bspline_new | ( | const size_t | deg, |
const size_t | dim, | ||
const size_t | n_ctrlp, | ||
const tsBSplineType | type, | ||
tsBSpline * | bspline | ||
) |
A convenient constructor for tsBSpline.
Create a new spline of degree with dimension and many control points. This function automatically calculates the necessary number of knots and fills the knot vector according to .
On error all values of are 0/NULL.
tsError ts_bspline_resize | ( | const tsBSpline * | bspline, |
const int | n, | ||
const int | back, | ||
tsBSpline * | resized | ||
) |
Resizes by
(number of control points) and stores the result in . If != 0 the resulting splines is resized at the end. If == 0 the resulting spline is resized at the front.
Resizing a spline at the end is usually faster, because the current values don't need to be copied.
This function creates a deep copy of , if != .
On error (and if != ) all values of are 0/NULL.
if != :
tsError ts_bspline_set_ctrlp | ( | const tsBSpline * | bspline, |
const tsRational * | ctrlp, | ||
tsBSpline * | result | ||
) |
Creates a deep copy of (only if !=
On error (and if !=
tsError ts_bspline_set_knots | ( | const tsBSpline * | bspline, |
const tsRational * | knots, | ||
tsBSpline * | result | ||
) |
Creates a deep copy of (only if !=
On error (and if !=
tsError ts_bspline_setup_knots | ( | const tsBSpline * | original, |
const tsBSplineType | type, | ||
const tsRational | min, | ||
const tsRational | max, | ||
tsBSpline * | result | ||
) |
Fills the knot vector of according to with minimum knot value to maximum knot value and stores the result in
This function creates a deep copy of , if !=
On error all values of
tsError ts_bspline_split | ( | const tsBSpline * | bspline, |
const tsRational | u, | ||
tsBSpline * | split, | ||
size_t * | k | ||
) |
tsError ts_deboornet_copy | ( | const tsDeBoorNet * | original, |
tsDeBoorNet * | copy | ||
) |
The copy constructor of tsDeBoorNet.
Creates a deep copy of and stores the result in . This function does not free already allocated memory in . If you want to reuse an instance of tsDeBoorNet by using it in multiple calls of this function, make sure to call ts_deboornet_free beforehand.
On error all values of are 0/NULL. The function does nothing if ==
void ts_deboornet_default | ( | tsDeBoorNet * | deBoorNet | ) |
The default constructor of tsDeBoorNet.
All values of are set to 0/NULL.
void ts_deboornet_free | ( | tsDeBoorNet * | deBoorNet | ) |
The destructor of tsDeBoorNet.
Frees all dynamically allocated memory and calls ts_deboornet_default afterwards.
char* ts_enum_str | ( | const tsError | err | ) |
Returns the error message associated to . Returns "unknown error" if is not associated (indicating a bug) or is TS_SUCCESS (which is not an actual error).
int ts_fequals | ( | const tsRational | x, |
const tsRational | y | ||
) |
Compares the tsRational values and by using absolute and relative epsilon.
void ts_ffill | ( | tsRational * | arr, |
const size_t | num, | ||
const tsRational | val | ||
) |
Fills the given array with from +0 to + (exclusive).
tsError ts_str_enum | ( | const char * | str | ) |
Returns the error code associated to or TS_SUCCESS if is not associated. Keep in mind that by concept "unknown error" is not associated, though, TS_SUCCESS is returned.