24 using namespace mondschein;
27 void NURBScurve::uniform_knots()
32 if (points.size()<=degree)
return;
33 knots.assign(points.size()+degree+1,0.0);
34 float64 k=knots.size()-degree-1;
37 for (
uint32 i=degree; i<k; ++i)
39 knots.at(i)=(i-degree)/(k-degree);
41 for (
uint32 i=k; i<knots.size(); ++i)
47 catch (std::exception &e)
49 std::string err(
"Mondschein Engine ERROR: ");
51 err+=
", exception raised in function\n\t";
52 err+=
"void mondschein::math::NURBScurve::uniform_knots()";
57 void NURBScurve::chord_knots()
62 if (points.size()<=degree)
return;
63 knots.assign(points.size()+degree+1,0.0);
64 float64 k=knots.size()-degree-1;
67 std::vector<float64> distances(1,0.0);
68 for (
uint32 i=1; i<points.size(); ++i)
70 distances.push_back(distances.at(i-1)+(points.at(i)-points.at(i-1)).norm());
74 for (
uint32 i=degree; i<k; ++i)
76 knots.at(i)=distances.at(i-degree)/distances.back();
78 for (
uint32 i=k; i<knots.size(); ++i)
84 catch (std::exception &e)
86 std::string err(
"Mondschein Engine ERROR: ");
88 err+=
", exception raised in function\n\t";
89 err+=
"void mondschein::math::NURBScurve::chord_knots()";
94 NURBScurve::NURBScurve() : degree(1), points(), knots()
99 NURBScurve::NURBScurve(
uint32 _d,
const std::vector<Eigen::Vector4d> &_p) : degree(_d), points(_p), knots()
104 NURBScurve::NURBScurve(NURBScurve_c _c) : degree(_c->degree), points(_c->points), knots(_c->knots)
109 NURBScurve::~NURBScurve()
114 NURBScurve &NURBScurve::operator=(NURBScurve_c _c)
130 std::string err(*boost::get_error_info<exception_error>(e));
131 err+=
", called in function\n\t";
132 err+=
"Eigen::Vector4d mondschein::math::NURBScurve::operator()(float64 _t) const";
164 if (_cl) chord_knots();
165 else uniform_knots();
170 std::string err(*boost::get_error_info<exception_error>(e));
171 err+=
", called in function\n\t";
172 err+=
"void mondschein::math::NURBScurve::calc_knots(bool _cl) const";
181 std::string err(
"Mondschein Engine ERROR: Knot vector must not be empty. ");
182 err+=
"Exception raised in function\n\t";
183 err+=
"Eigen::Vector3d mondschein::math::NURBScurve::get_point(mondschein::float64 _t) const";
189 if (_t<=0)
return Eigen::Vector3d(points.front()(0),points.front()(1),points.front()(2));
190 else if (_t>=1.0)
return Eigen::Vector3d(points.back()(0),points.back()(1),points.back()(2));
193 uint32 i = distance(knots.begin(),upper_bound(knots.begin(),knots.end(),_t))-1;
196 std::vector<Eigen::Vector3d> v(degree+1,Eigen::Vector3d(0,0,0));
198 for (
uint32 j=i-degree; j<=i; ++j)
201 v.at(j-(i-degree)) << tmp(0),tmp(1),tmp(2);
202 v.at(j-(i-degree))*=tmp(3);
206 for (
uint32 r=1; r<=degree; ++r)
208 for (
uint32 j=i; j>=i-(degree-r); --j)
211 float64 c=(_t-knots.at(j)/(knots.at(j+degree-r+1) - knots.at(j)));
212 v.at(m)=(1-c)*v.at(m-1)+c*v.at(m);
217 catch (std::exception &e)
219 std::string err(
"Mondschein Engine ERROR: ");
221 err+=
", exception raised in function\n\t";
222 err+=
"void mondschein::math::NURBScurve::get_curve_point(float64 _t)";