TinySpline
Spline Library for a Multitude of Programming Languages
v0.3.0
tinysplinecpp.h
1 #pragma once
2 
3 #include "tinyspline.h"
4 #include <vector>
5 #include <string>
6 
7 #ifdef SWIG
8 #define std_real_vector_in std::vector<tinyspline::real> *
9 #define std_real_vector_out std::vector<tinyspline::real> *
10 #else
11 #define std_real_vector_in std::vector<tinyspline::real> &
12 #define std_real_vector_out std::vector<tinyspline::real>
13 #endif
14 
15 namespace tinyspline {
16 
17 typedef tsReal real;
18 class BSpline;
19 
20 class DeBoorNet {
21 public:
22  /* Constructors & Destructors */
23  DeBoorNet(const DeBoorNet &other);
24  ~DeBoorNet();
25 
26  /* Operators */
27  DeBoorNet & operator=(const DeBoorNet &other);
28 
29  /* Accessors */
30  real knot() const;
31  size_t index() const;
32  size_t multiplicity() const;
33  size_t numInsertions() const;
34  size_t dimension() const;
35  std::vector<real> points() const;
36  std::vector<real> result() const;
37  tsDeBoorNet * data();
38 
39 private:
40  tsDeBoorNet net;
41 
42  /* Constructors & Destructors */
43  DeBoorNet();
44 
45  friend class BSpline;
46 };
47 
48 class Domain {
49 public:
50  /* Constructors & Destructors */
51  Domain(tsReal min, tsReal max);
52  Domain(const Domain &other);
53 
54  /* Operators */
55  Domain &operator=(const Domain &other);
56 
57  /* Getter */
58  real min() const;
59  real max() const;
60 private:
61  real _min;
62  real _max;
63 };
64 
65 class BSpline {
66 public:
67  typedef tsBSplineType type;
68 
69  /* Constructors & Destructors */
70  BSpline();
71  BSpline(const BSpline &other);
72  explicit BSpline(size_t nCtrlp, size_t dim = 2, size_t deg = 3,
73  tinyspline::BSpline::type type = TS_CLAMPED);
74  ~BSpline();
75 
76  /* Operators */
77  BSpline & operator=(const BSpline &other);
78  DeBoorNet operator()(real u) const;
79 
80  /* Accessors */
81  size_t degree() const;
82  size_t order() const;
83  size_t dimension() const;
84  std::vector<real> controlPoints() const;
85  std_real_vector_out controlPointAt(size_t index) const;
86  std::vector<real> knots() const;
87  tsBSpline * data();
88 
89  /* Query */
90  size_t numDistinctKnots() const;
91  DeBoorNet eval(real u) const;
92  std_real_vector_out evalAll(const std_real_vector_in us) const;
93  std_real_vector_out sample(size_t num = 0) const;
94  DeBoorNet bisect(real value, real epsilon = 0.01,
95  bool persnickety = false, size_t index = 0,
96  bool ascending = true, size_t maxIter = 30) const;
97  Domain domain() const;
98  bool isClosed(real epsilon = 0.00001) const;
99 
100  /* Serialization */
101  std::string toJSON();
102  void fromJSON(std::string json);
103  void save(std::string path);
104  void load(std::string path);
105 
106  /* Modifications */
107  void setControlPoints(const std::vector<real> &ctrlp);
108  void setControlPointAt(size_t index, const std_real_vector_in ctrlp);
109  void setKnots(const std::vector<real> &knots);
110 
111  /* Transformations */
112  BSpline insertKnot(real u, size_t n) const;
113  BSpline split(real u) const;
114  BSpline tension(real tension) const;
115  BSpline toBeziers() const;
116  BSpline derive(size_t n = 1) const;
117 
118 private:
119  tsBSpline spline;
120 };
121 
122 class Utils {
123 public:
124  static BSpline interpolateCubic(
125  const std::vector<real> *points, size_t dim);
126  static bool knotsEqual(real x, real y);
127 
128 private:
129  Utils() {}
130 };
131 
132 }
Definition: tinysplinecpp.h:122
Definition: tinyspline.h:296
Definition: tinysplinecpp.h:20
Definition: tinysplinecpp.h:15
Definition: tinysplinecpp.h:48
Definition: tinyspline.h:383
Definition: tinysplinecpp.h:65
tsBSplineType
Definition: tinyspline.h:258