-
Notifications
You must be signed in to change notification settings - Fork 0
/
CubicBspline.h
91 lines (68 loc) · 3.03 KB
/
CubicBspline.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* CubicBspline.h: Header file for a uniform cubic B-spline class.
*
* (c) 2001-2002 Stephen Chenney, University of Wisconsin at Madison
*/
#ifndef _CUBICBSPLINE_H_
#define _CUBICBSPLINE_H_
#include <stdio.h>
class CubicBspline {
private:
unsigned short d; /* The dimension of each point on the curve. */
unsigned short n; /* The number of control points. */
float **c_pts; /* The control points. */
bool loop; /* Whether the curve loops or not. */
public:
float z; /* base elevation of the spline */
public:
/* Initializes with the given dimension and no control points. */
CubicBspline(const unsigned short dim = 3, const bool l = true)
{ d = dim; n = 0; c_pts = NULL; loop = l; z = 0; };
/* Initializes with the given dimension and control points. */
CubicBspline(const unsigned short, const unsigned short, float**,
const bool, const float elev);
/* Destructor. */
~CubicBspline(void);
/* Copy operator. */
CubicBspline& operator=(const CubicBspline&);
/* Query the dimension. */
unsigned short D(void) { return d; };
/* Query the number of control points. */
unsigned short N(void) { return n; };
/* Query a control point, putting the value into the given array.
** Throws an exception if the index is out of range. */
void C(unsigned short, float*);
/* Query whether the curve is a loop. */
bool Loop(void) { return loop; }
/* Change a control point at the given position.
** Will throw an exception if the position is out of range. */
void Set_Control(const float*, const unsigned short);
/* Add a control point at the end. */
void Append_Control(const float*);
/* Add a control point at the given position. */
/* Will throw an exception if the position is beyond the end of
** the existing set of control points. */
void Insert_Control(const float*, const unsigned short);
/* Remove a control point at the given position. */
/* Will throw an exception the position is out of range. */
void Delete_Control(const unsigned short);
/* Evaluate the curve at a parameter value and copy the result into
** the given array. Throws an exception if the parameter is out of
** range, unless told to wrap. */
void Evaluate_Point(const float, float*);
void Get_Point(const float, float*);
/* Evaluate the derivative at a parameter value and copy the result into
** the given array. Throws an exception if the parameter is out of
** range, unless told to wrap. */
void Evaluate_Derivative(const float, float*);
/* Refine the curve one level, putting the result into the given curve. This
** will correctly account for cyclic curves. There is also a tolerance
** version that stops when each sub-section is locally flat enough. */
void Refine(CubicBspline&);
void Refine_Tolerance(CubicBspline&, const float);
private:
void Copy_Controls(float**);
void Delete_Controls(void);
bool Within_Tolerance(const float);
};
#endif