rev |
line source |
nuclear@0
|
1 #ifndef CURVE_H_
|
nuclear@0
|
2 #define CURVE_H_
|
nuclear@0
|
3
|
nuclear@0
|
4 #include <vector>
|
nuclear@0
|
5 #include <vmath/vmath.h>
|
nuclear@0
|
6
|
nuclear@0
|
7 enum CurveType {
|
nuclear@0
|
8 CURVE_LINEAR,
|
nuclear@0
|
9 CURVE_HERMITE,
|
nuclear@0
|
10 CURVE_BSPLINE
|
nuclear@0
|
11 };
|
nuclear@0
|
12
|
nuclear@0
|
13 class Curve {
|
nuclear@0
|
14 private:
|
nuclear@12
|
15 std::vector<Vector4> cp;
|
nuclear@0
|
16 CurveType type;
|
nuclear@0
|
17
|
nuclear@12
|
18 // bounding box
|
nuclear@12
|
19 mutable Vector3 bbmin, bbmax;
|
nuclear@12
|
20 mutable bool bbvalid;
|
nuclear@12
|
21
|
nuclear@12
|
22 void calc_bounds() const;
|
nuclear@12
|
23 void inval_bounds() const;
|
nuclear@12
|
24
|
nuclear@0
|
25 public:
|
nuclear@0
|
26 Curve(CurveType type = CURVE_HERMITE);
|
nuclear@12
|
27 Curve(const Vector4 *cp, int numcp, CurveType type = CURVE_HERMITE); // homogenous
|
nuclear@12
|
28 Curve(const Vector3 *cp, int numcp, CurveType type = CURVE_HERMITE); // 3D points, w=1
|
nuclear@12
|
29 Curve(const Vector2 *cp, int numcp, CurveType type = CURVE_HERMITE); // 2D points, z=0, w=1
|
nuclear@0
|
30
|
nuclear@0
|
31 void set_type(CurveType type);
|
nuclear@0
|
32 CurveType get_type() const;
|
nuclear@0
|
33
|
nuclear@12
|
34 void add_point(const Vector4 &p);
|
nuclear@12
|
35 void add_point(const Vector3 &p, float weight = 1.0f);
|
nuclear@0
|
36 void add_point(const Vector2 &p, float weight = 1.0f);
|
nuclear@0
|
37 bool remove_point(int idx);
|
nuclear@0
|
38
|
nuclear@12
|
39 void clear(); // remove all control points
|
nuclear@12
|
40 bool empty() const; // true if 0 control points
|
nuclear@12
|
41 int size() const; // returns number of control points
|
nuclear@12
|
42 // access operators for control points
|
nuclear@12
|
43 Vector4 &operator [](int idx);
|
nuclear@12
|
44 const Vector4 &operator [](int idx) const;
|
nuclear@12
|
45 const Vector4 &get_point(int idx) const;
|
nuclear@0
|
46
|
nuclear@12
|
47 Vector3 get_point3(int idx) const;
|
nuclear@12
|
48 Vector2 get_point2(int idx) const;
|
nuclear@0
|
49 float get_weight(int idx) const;
|
nuclear@0
|
50
|
nuclear@12
|
51 bool set_point(int idx, const Vector3 &p, float weight = 1.0f);
|
nuclear@0
|
52 bool set_point(int idx, const Vector2 &p, float weight = 1.0f);
|
nuclear@0
|
53 bool set_weight(int idx, float weight);
|
nuclear@2
|
54 // move point without changing its weight
|
nuclear@12
|
55 bool move_point(int idx, const Vector3 &p);
|
nuclear@2
|
56 bool move_point(int idx, const Vector2 &p);
|
nuclear@12
|
57
|
nuclear@12
|
58 int nearest_point(const Vector3 &p) const;
|
nuclear@12
|
59 // nearest control point on the 2D plane z=0
|
nuclear@12
|
60 int nearest_point(const Vector2 &p) const;
|
nuclear@0
|
61
|
nuclear@12
|
62 /* get_bbox returns the axis-aligned bounding box of the curve's
|
nuclear@12
|
63 * control points.
|
nuclear@12
|
64 * NOTE: hermite curves can go outside of the bounding box of their control points
|
nuclear@12
|
65 * NOTE: lazy calculation of bounds is performed, use calc_bbox in multithreaded programs
|
nuclear@12
|
66 */
|
nuclear@12
|
67 void get_bbox(Vector3 *bbmin, Vector3 *bbmax) const;
|
nuclear@12
|
68 void calc_bbox(Vector3 *bbmin, Vector3 *bbmax) const;
|
nuclear@12
|
69 // normalize the curve's bounds to coincide with the unit cube
|
nuclear@12
|
70 void normalize();
|
nuclear@12
|
71
|
nuclear@12
|
72 // project a point to the curve (nearest point on the curve)
|
nuclear@13
|
73 Vector3 proj_point(const Vector3 &p, float refine_thres = 0.01) const;
|
nuclear@13
|
74 // equivalent to (proj_point(p) - p).length()
|
nuclear@12
|
75 float distance(const Vector3 &p) const;
|
nuclear@13
|
76 // equivalent to fabs((proj_point(p) - p).length_sq())
|
nuclear@13
|
77 float distance_sq(const Vector3 &p) const;
|
nuclear@12
|
78
|
nuclear@12
|
79 Vector3 interpolate_segment(int a, int b, float t) const;
|
nuclear@12
|
80 Vector3 interpolate(float t) const;
|
nuclear@12
|
81 Vector2 interpolate2(float t) const;
|
nuclear@12
|
82 Vector3 operator ()(float t) const;
|
nuclear@0
|
83 };
|
nuclear@0
|
84
|
nuclear@0
|
85 #endif // CURVE_H_
|