-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBSpline.h
More file actions
89 lines (79 loc) · 2.98 KB
/
BSpline.h
File metadata and controls
89 lines (79 loc) · 2.98 KB
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
/******************************************************************************
(c) 2005-2016 Scientific Computation Research Center,
Rensselaer Polytechnic Institute. All rights reserved.
This work is open source software, licensed under the terms of the
BSD license as described in the LICENSE file in the top-level directory.
*******************************************************************************/
#ifndef BSPLINE_H
#define BSPLINE_H
#include <vector>
namespace Spline {
/**
Base class of 2D parametric curve
given parametric coordinate x, it evaluates
a. physical coordinate
b. first deriviative and normal vector
c. second deriviative and curvatur
*/
class Expression {
public:
virtual double eval(double x, bool debug=false) const = 0;
virtual double evalFirstDeriv(double x) const = 0;
virtual double evalSecondDeriv(double x) const = 0;
};
void dummyAnalyticExpression(double phi, double dummy, double *xyz,
void *userdata);
void evalCoord(double para, double *xyz, void *userdata);
void evalNormalVector(Expression *xp, Expression *yp, double para,
double *normalvec);
void evalCurvature(Expression *xp, Expression *yp, double para, double *curv);
int calcuBinomial(int j, int i);
/** Implementation of monomic polynomial*/
class PolyNomial : public Expression {
public:
explicit PolyNomial(int degree_p, std::vector<double> &coffs_p);
~PolyNomial(){};
void getcoeffs(std::vector<double> &coffs_p) const;
virtual double eval(double x, bool debug=false) const;
virtual double evalFirstDeriv(double x) const;
virtual double evalSecondDeriv(double x) const;
void print();
private:
int degree;
std::vector<double> coffs;
std::vector<double> firstDerivCoffs;
std::vector<double> secondDerivCoffs;
};
// for clamped b-spline, the same as sim geo advanced
/** BSpline implementation
It also includes conversions between BSpline and monic polynomial
*/
class BSpline : public Expression {
public:
BSpline(int order_p, std::vector<double> &ctrlPts_p,
std::vector<double> &knots_p, std::vector<double> &weight_p);
BSpline() : order(-1) {}
~BSpline(){};
int getOrder() const { return order; }
int getNumCtrlPts() const { return ctrlPts.size(); }
int getNumKnots() const { return knots.size(); }
double getCtrlPt(std::size_t i) const { return ctrlPts.at(i); }
double getKnot(std::size_t i) const { return knots.at(i); }
virtual double eval(double x, bool debug=false) const;
virtual double evalFirstDeriv(double x) const;
virtual double evalSecondDeriv(double x) const;
void print();
void getpara(int &order_p, std::vector<double> &ctrlPts_p,
std::vector<double> &knots_p, std::vector<double> &weight_p);
BSpline &operator=(const PolyNomial &pn);
private:
void calcuDerivCoeff();
int order;
std::vector<double> ctrlPts;
std::vector<double> knots;
std::vector<double> weight;
std::vector<double> ctrlPts_1st;
std::vector<double> ctrlPts_2nd;
};
}; // namespace Spline
#endif