58 #define BSPLINESURFACE_BSPLINESURFACET_C 62 #include <OpenMesh/Core/Geometry/VectorT.hh> 67 #include "BSplineSurfaceT.hh" 70 #include <ACG/Geometry/Algorithms.hh> 71 #include <ACG/Math/BSplineBasis.hh> 79 template <
class Po
intT>
84 ref_count_cpselections_(0),
85 ref_count_eselections_(0)
92 template <
class Po
intT>
93 template <
class PropT>
104 for (
unsigned int i = 0; i < _prop.size(); ++i)
112 template <
class Po
intT>
113 template <
class PropT>
128 template <
class Po
intT>
133 control_net_.resize(_m);
135 for (
unsigned int i = 0; i < control_net_.size(); ++i)
136 control_net_[i].
resize(_n);
154 template <
class Po
intT>
159 control_net_.clear();
168 template <
class Po
intT>
179 template <
class Po
intT>
190 template <
class Po
intT>
200 template <
class Po
intT>
210 template <
class Po
intT>
215 std::cout <<
"insert_vector_m of size " << _control_polygon.size() <<
" at m = " << _m << std::endl;
219 dimn_ =_control_polygon.size();
221 assert(_control_polygon.size() ==
dimn_);
225 control_net_.insert(control_net_.begin() + _m, _control_polygon);
226 control_net_.pop_back();
227 std::cout <<
"control_net_: " << control_net_.size() <<
" x " << control_net_[control_net_.size()-1].size() << std::endl;
230 std::vector<unsigned char> dummy(_control_polygon.size(), 0);
243 template <
class Po
intT>
250 dimm_ = _control_polygon.size();
252 assert(_control_polygon.size() ==
dimm_);
256 for (
unsigned int i = 0; i <
dimm_; ++i)
258 control_net_[i].insert(control_net_[i].begin() + _n, _control_polygon[i]);
259 control_net_[i].pop_back();
263 for (
unsigned int i = 0; i <
dimm_; ++i)
269 for (
unsigned int i = 0; i <
dimm_; ++i)
278 template <
class Po
intT>
287 if(control_net_.begin() + _m < control_net_.end())
288 control_net_.erase(control_net_.begin() + _m);
305 template <
class Po
intT>
314 for (
unsigned int i = 0; i < control_net_.size(); ++i) {
315 if(control_net_[i].begin() + _n < control_net_[i].end())
316 control_net_[i].erase(control_net_[i].begin() + _n);
336 template <
class Po
intT>
342 _control_polygon = control_net_[_m];
347 template <
class Po
intT>
353 _control_polygon.resize(
dimm_);
355 for (
unsigned int i = 0; i <
dimm_; ++i)
356 _control_polygon[i] = control_net_[i][_n];
361 template <
class Po
intT>
372 template <
class Po
intT>
383 template <
class Po
intT>
394 newknotvecu.insertKnot(interval[1], _u);
397 std::vector<double> alpha;
398 for(
int i = span[0]; i < span[1]; ++i)
402 alpha.push_back((_u-a)/(b-a));
407 ControlNet oldcpts(control_net_);
414 control_net_[i] = oldcpts[i];
415 else if( i <= span[1])
418 control_net_[i][j] = oldcpts[i-1][j]*(1.0-alpha[i-span[0]-1])+oldcpts[i][j]*alpha[i-span[0]-1];
421 control_net_[i] = oldcpts[i-1];
427 template <
class Po
intT>
438 newknotvecv.insertKnot(interval[1], _v);
441 std::vector<double> alpha;
442 for(
int i = span[0]; i < span[1]; ++i)
446 alpha.push_back((_v-a)/(b-a));
451 ControlNet oldcpts(control_net_);
459 control_net_[j][i] = oldcpts[j][i];
460 else if( i <= span[1])
463 control_net_[j][i] = oldcpts[j][i-1]*(1.0-alpha[i-span[0]-1])+oldcpts[j][i]*alpha[i-span[0]-1];
467 control_net_[j][i] = oldcpts[j][i-1];
473 template <
class Po
intT>
478 double epsilon = 0.0000001;
492 Point point = Point(0.0, 0.0, 0.0);
498 std::vector<Scalar> basisFuns_m(pm+1);
499 std::vector<Scalar> basisFuns_n(pn+1);
507 for (
int i = span_m[0]; i <= span_m[1]; ++i)
508 for (
int j = span_n[0]; j <= span_n[1]; ++j)
509 point += control_net_[i][j] * basisFuns_m[i-span_m[0]] * basisFuns_n[j - span_n[0]];
516 template <
class Po
intT>
521 double epsilon = 0.0000001;
535 _pt = Point(0.0, 0.0, 0.0);
541 std::vector<Scalar> basisFuns_m(pm+1);
542 std::vector<Scalar> ders_m(pm+1);
543 std::vector<Scalar> basisFuns_n(pn+1);
544 std::vector<Scalar> ders_n(pn+1);
553 Point dpdu = Point(0,0,0);
554 Point dpdv = Point(0,0,0);
556 for (
int i = 0; i <= pm; ++i)
558 for (
int j = 0; j <= pn; ++j)
560 Point cp = control_net_[i + span_m[0]][j + span_n[0]];
562 _pt += cp * (basisFuns_m[i] * basisFuns_n[j]);
564 dpdu += cp * (ders_m[i] * basisFuns_n[j]);
565 dpdv += cp * (basisFuns_m[i] * ders_n[j]);
569 _normal = (dpdu % dpdv).normalize();
574 template <
class Po
intT>
579 double epsilon = 0.0000001;
593 Point point = Point(0.0, 0.0, 0.0);
598 for (
int i = span_m[0]; i <= span_m[1]; ++i)
599 for (
int j = span_n[0]; j <= span_n[1]; ++j)
607 template <
class Po
intT>
608 typename BSplineSurfaceT<PointT>::Scalar
612 int m = _knotvector.size() - 1;
615 if ((_i==0 && _t== _knotvector(0)) || (_i==m-_n-1 && _t==_knotvector(m)))
619 if (_t >= _knotvector(_i) && _t < _knotvector(_i+1))
630 if ((_knotvector(_i+_n) - _knotvector(_i)) != 0)
631 fac1 = (_t - _knotvector(_i)) / (_knotvector(_i+_n) - _knotvector(_i)) ;
635 if ( (_knotvector(_i+1+_n) - _knotvector(_i+1)) != 0 )
636 fac2 = (_knotvector(_i+1+_n) - _t) / (_knotvector(_i+1+_n) - _knotvector(_i+1));
640 return (fac1*Nin1 + fac2*Nin2);
645 template <
class Po
intT>
661 std::vector<Scalar> ders_m(pm+1);
662 std::vector<Scalar> ders_n(pn+1);
664 ACG::bsplineBasisDerivatives<Scalar>(ders_m, span_m, _u, _derm,
knotvector_m_.getKnotvector(), 0);
665 ACG::bsplineBasisDerivatives<Scalar>(ders_n, span_n, _v, _dern,
knotvector_n_.getKnotvector(), 0);
667 for (
int i = span_m[0]; i <= span_m[1]; i++)
668 for (
int j = span_n[0]; j <= span_n[1]; j++)
669 point += control_net_[i][j] * ders_m[i - span_m[0]] * ders_n[j - span_n[0]];
677 template <
class Po
intT>
688 Point normal( (derivu%derivv).normalize());
695 template <
class Po
intT>
696 typename BSplineSurfaceT<PointT>::Scalar
710 if ( fabs(_knotvector(_i+_n)-_knotvector(_i)) > 1e-6 )
711 fac1 = Scalar(_n) / (_knotvector(_i+_n)-_knotvector(_i));
714 if ( fabs(_knotvector(_i+_n+1)-_knotvector(_i+1)) > 1e-6 )
715 fac2 = Scalar(_n) / (_knotvector(_i+_n+1)-_knotvector(_i+1));
717 return (fac1*Nin1 - fac2*Nin2);
722 template <
class Po
intT>
723 typename BSplineSurfaceT<PointT>::Scalar
732 template <
class Po
intT>
733 typename BSplineSurfaceT<PointT>::Scalar
741 template <
class Po
intT>
742 typename BSplineSurfaceT<PointT>::Scalar
751 template <
class Po
intT>
752 typename BSplineSurfaceT<PointT>::Scalar
760 template <
class Po
intT>
770 template <
class Po
intT>
780 template <
class Po
intT>
795 return Vec2i(i, i+1);
800 template <
class Po
intT>
815 return Vec2i(i, i+1);
unsigned int degree_m_
Spline degree in m direction.
void createKnots()
Creates interpolating knotvectors 0...0, 1, 2, ..., n...n.
Knotvector knotvector_n_
Knotvector in n direction.
void set_knots_n(std::vector< Scalar > _knots)
Set the knotvector of the bspline surface in n direction.
PropertyNet cpselections_
list of control point properties
int degree_n() const
Returns the spline degree in n direction.
Scalar basisFunction(Knotvector &_knotvector, int _i, int _n, double _t)
A Spline Basis Function.
Scalar loweru()
Returns the lower u parameter.
ACG::Vec2i spanm(double _t)
Returns the basis functions which are unequal to zero at parameter u.
Point surfacePoint(double _u, double _v)
Evaluates a spline surface at parameters _u and _v.
Scalar upperu()
Returns the upper u parameter.
unsigned int dimm_
number of control points in m direction
BSplineSurfaceT(unsigned int _degm=3, unsigned int _degn=3)
Constructor.
void get_vector_m(std::vector< Point > &_control_polygon, unsigned int _m)
Returns an n control point vector.
Knotvector get_knotvector_n()
Get the knotvector in n direction.
ACG::Vec2i interval_n(double _t)
Returns the index of the knots v and v+1 such that t in [v, v+1)
Knotvector knotvector_m_
Knotvector in m direction.
unsigned int n_control_points_m() const
Returns the number of controlpoints in m direction.
void resize(unsigned int _m, unsigned int _n)
Resizes the spline struct.
void bsplineBasisFunctions(std::vector< Scalar > &_N, const Vec2i &_span, Scalar _t, const std::vector< Scalar > &_knots)
Evaluate basis functions in a span.
void add_vector_m(const std::vector< Point > &_control_polygon)
Adds a control point n-vector.
void insert_knot_n(double _t)
Insert a knot i in n direction without changing the surface.
void delete_vector_m(unsigned int _m)
Deletes an n control point vector.
void reset_control_net()
Clears the control net.
Knotvector get_knotvector_m()
Get the knotvector in m direction.
ACG::Vec2i interval_m(double _t)
Returns the index of the knots u and u+1 such that t in [u, u+1)
PropertyNet eselections_
list of edge properties
void delete_vector_n(unsigned int _n)
Deletes an m control point vector.
Scalar derivativeBasisFunction(Knotvector &_knotvector, int _i, int _n, double _t, int _der)
Derivative of a Spline Basis Function.
VectorT< signed int, 2 > Vec2i
void insert_vector_m(const std::vector< Point > &_control_polygon, unsigned int _m)
Inserts an n control point vector.
Vec2i bsplineSpan(Scalar _t, int _degree, const std::vector< Scalar > &_knots)
Find the span of a parameter value.
void surfacePointNormal(Point &_pt, Point &_normal, double _u, double _v)
Evaluates a spline surface at parameters _u and _v.
Namespace providing different geometric functions concerning angles.
void insert_vector_n(const std::vector< Point > &_control_polygon, unsigned int _n)
Inserts an m control point vector.
void get_vector_n(std::vector< Point > &_control_polygon, unsigned int _n)
Returns an m ctrPointVector.
void bsplineBasisDerivatives(std::vector< Scalar > &_ders, const Vec2i &_span, Scalar _t, int _der, const std::vector< Scalar > &_knots, std::vector< Scalar > *_functionVals)
Compute derivatives of basis functions in a span.
int degree_m() const
Returns the spline degree in m direction.
void insert_knot_m(double _t)
Insert a knot i in m direction without changing the surface.
unsigned int n_control_points_n() const
Returns the number of controlpoints in n direction.
ACG::Vec2i spann(double _t)
Returns the basis functions which are unequal to zero at parameter v.
Scalar lowerv()
Returns the lower v parameter.
Point normalSurfacePoint(double _u, double _v)
Returns the normal of a spline surface.
Scalar upperv()
Returns the upper v parameter.
void set_knots_m(std::vector< Scalar > _knots)
Set the knotvector of the bspline surface in m direction.
unsigned int dimn_
number of control points in n direction
unsigned int degree_n_
Spline degree in n direction.
void set_degree(unsigned int _degm, unsigned int _degn)
Sets the degree of the spline surface.
Point surfacePoint_rec(double _u, double _v)
Evaluates a spline surface at parameters _u and _v.
Point derivativeSurfacePoint(double _u, double _v, int _derm, int _dern)
Returns the _derm'th derivative of a spline surface.
void add_vector_n(const std::vector< Point > &_control_polygon)
Adds a control point m-vector.