23 #include "core/normgrid.h"
26 using namespace mondschein;
29 void NURBSpatch::uniform_knots()
34 if (curves.size()<=degree)
return;
35 knots.assign(curves.size()+degree+1,0.0);
36 float64 k=knots.size()-degree-1;
39 for (
uint32 i=degree; i<k; ++i)
41 knots.at(i)=(i-degree)/(k-degree);
43 for (
uint32 i=k; i<knots.size(); ++i)
49 catch (std::exception &e)
51 std::string err(
"Mondschein Engine ERROR: ");
53 err+=
", exception raised in function\n\t";
54 err+=
"void mondschein::math::NURBSpatch::uniform_knots()";
59 void NURBSpatch::chord_knots()
64 if (curves.size()<=degree)
return;
65 knots.assign(curves.size()+degree+1,0.0);
66 float64 k=knots.size()-degree-1;
69 std::vector<Eigen::Vector4d> p;
70 for (
uint32 i=0; i<curves.size(); ++i)
72 p.push_back(Eigen::Vector4d(0,0,0,0));
73 uint32 size=curves.at(i)->get_points().size();
74 for (
uint32 j=0; j<size; ++j)
76 p.back()+=curves.at(i)->get_points().at(j);
78 p.back()/=p.back().norm();
82 std::vector<float64> distances(1,0.0);
83 for (
uint32 i=1; i<p.size(); ++i)
85 distances.push_back(distances.at(i-1)+(p.at(i)-p.at(i-1)).norm());
89 for (
uint32 i=degree; i<k; ++i)
91 knots.at(i)=distances.at(i-degree)/distances.back();
93 for (
uint32 i=k; i<knots.size(); ++i)
99 catch (std::exception &e)
101 std::string err(
"Mondschein Engine ERROR: ");
103 err+=
", exception raised in function\n\t";
104 err+=
"void mondschein::math::NURBSpatch::chord_knots()";
109 NURBSpatch::NURBSpatch() : degree(1), curves(), knots()
114 NURBSpatch::NURBSpatch(
uint32 _d,
const std::vector<NURBScurve_p> &_c) : degree(_d), curves(_c), knots()
119 NURBSpatch::NURBSpatch(NURBSpatch_c _p) : degree(_p->degree), curves(_p->curves), knots(_p->knots)
124 NURBSpatch::~NURBSpatch()
129 NURBSpatch &NURBSpatch::operator=(NURBSpatch_c _p)
145 std::string err(*boost::get_error_info<exception_error>(e));
146 err+=
", called in function\n\t";
147 err+=
"Eigen::Vector4d mondschein::math::NURBSpatch::operator()(float64 _t,float64 _u) const";
179 if (_cl) chord_knots();
180 else uniform_knots();
185 std::string err(*boost::get_error_info<exception_error>(e));
186 err+=
", called in function\n\t";
187 err+=
"void mondschein::math::NURBSpatch::calc_knots(bool _cl) const";
196 std::string err(
"Mondschein Engine ERROR: Knot vector is empty, but must be initialized. ");
197 err+=
"Exception raised in function\n\t";
198 err+=
"Eigen::Vector3d mondschein::math::NURBSpatch::get_point(mondschein::float64 _t,mondschein::float64 _u) const";
204 if (_u<=0)
return curves.front()->get_point(_t);
205 else if (_u>=1.0)
return curves.back()->get_point(_t);
208 uint32 i = distance(knots.begin(),upper_bound(knots.begin(),knots.end(),_u))-1;
211 std::vector<Eigen::Vector3d> v(degree+1,Eigen::Vector3d(0,0,0));
212 for (
uint32 j=i-degree; j<=i; ++j) v.at(j-(i-degree))=curves.at(j)->get_point(_t);
215 for (
uint32 r=1; r<=degree; ++r)
217 for (
uint32 j=i; j>=i-(degree-r); --j)
220 float64 c=(_u-knots.at(j)/(knots.at(j+degree-r+1) - knots.at(j)));
221 v.at(m)=(1-c)*v.at(m-1)+c*v.at(m);
228 std::string err(*boost::get_error_info<exception_error>(e));
229 err+=
", called in function\n\t";
230 err+=
"Eigen::Vector4d mondschein::math::NURBSpatch::operator()(float64 _t,float64 _u) const";
233 catch (std::exception &e)
235 std::string err(
"Mondschein Engine ERROR: ");
237 err+=
", exception raised in function\n\t";
238 err+=
"void mondschein::math::NURBSpatch::chord_knots()";
249 std::vector<std::vector<Eigen::Vector3d> > grid;
252 std::vector<Eigen::Vector3d> _grid;
257 grid.push_back(_grid);
260 std::vector<Eigen::Vector3d> normals;
264 normals=ng->flat(grid);
268 normals=ng->flat_inv(grid);
272 normals=ng->intermediate(grid);
275 case INTERMEDIATE_INV:
276 normals=ng->intermediate_inv(grid);
280 std::string err(
"Mondschein Engine ERROR: Normal calculation type not supported. ");
281 err+=
"Exception raised in function\n\t";
282 err+=
"mondschein::scene::Mesh_p mondschein::math::Bezierpatch::generate_mesh(float64 _n,";
283 err+=
"float64 _m, mondschein::normal_calculation_e _normals) const";
287 std::vector<Eigen::Vector4d> v;
288 std::vector<Eigen::Vector3d> vn;
289 std::vector<Eigen::Vector4d> vt;
290 std::vector<Eigen::Vector4d> vc;
292 for (
uint32 i=0; i<grid.size()-1; ++i)
294 for (
uint32 j=0; j<grid.at(i).size()-1; ++j)
296 tmp << grid.at(i).at(j),1.0;
298 tmp << grid.at(i+1).at(j),1.0;
300 tmp << grid.at(i).at(j+1),1.0;
302 if (_normals < INTERMEDIATE)
304 vn.push_back(normals.at(grid.at(i).size()*i+j*2));
305 vn.push_back(normals.at(grid.at(i).size()*i+j*2));
306 vn.push_back(normals.at(grid.at(i).size()*i+j*2));
310 vn.push_back(normals.at(grid.at(i).size()*(i)+j));
311 vn.push_back(normals.at(grid.at(i+1).size()*(i+1)+j));
312 vn.push_back(normals.at(grid.at(i).size()*(i)+j+1));
314 vt.push_back(Eigen::Vector4d(static_cast<float64>(i)/grid.size(),
static_cast<float64>(j)/grid.at(i).size(),
316 vt.push_back(Eigen::Vector4d(static_cast<float64>(i+1)/grid.size(),
static_cast<float64>(j)/grid.at(i).size(),
318 vt.push_back(Eigen::Vector4d(static_cast<float64>(i)/grid.size(),
static_cast<float64>(j+1)/grid.at(i).size(),
320 vc.push_back(Eigen::Vector4d(1.0,1.0,1.0,1.0));
321 vc.push_back(Eigen::Vector4d(1.0,1.0,1.0,1.0));
322 vc.push_back(Eigen::Vector4d(1.0,1.0,1.0,1.0));
324 tmp << grid.at(i).at(j+1),1.0;
326 tmp << grid.at(i+1).at(j),1.0;
328 tmp << grid.at(i+1).at(j+1),1.0;
330 if (_normals < INTERMEDIATE)
332 vn.push_back(normals.at(grid.at(i).size()*i+j*2+1));
333 vn.push_back(normals.at(grid.at(i).size()*i+j*2+1));
334 vn.push_back(normals.at(grid.at(i).size()*i+j*2+1));
338 vn.push_back(normals.at(grid.at(i).size()*(i)+j+1));
339 vn.push_back(normals.at(grid.at(i+1).size()*(i+1)+j));
340 vn.push_back(normals.at(grid.at(i+1).size()*(i+1)+j+1));
342 vt.push_back(Eigen::Vector4d(static_cast<float64>(i)/grid.size(),
static_cast<float64>(j+1)/grid.at(i).size(),
344 vt.push_back(Eigen::Vector4d(static_cast<float64>(i+1)/grid.size(),
static_cast<float64>(j)/grid.at(i).size(),
346 vt.push_back(Eigen::Vector4d(static_cast<float64>(i+1)/grid.size(),
static_cast<float64>(j+1)/grid.at(i).size(),
348 vc.push_back(Eigen::Vector4d(1.0,1.0,1.0,1.0));
349 vc.push_back(Eigen::Vector4d(1.0,1.0,1.0,1.0));
350 vc.push_back(Eigen::Vector4d(1.0,1.0,1.0,1.0));
357 std::string err(*boost::get_error_info<exception_error>(e));
358 err+=
", called in function\n\t";
359 err+=
"mondschein::scene::Mesh_p mondschein::math::NURBSpatch::generate_mesh(float64 _t,float64 _u,";
360 err+=
"normal_calculation_e _normals) const";