Developer Documentation

BSplineSurfaceT.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42
43
44
45 //=============================================================================
46 //
47 // CLASS BSplineSurfaceT
48 // Author: Ellen Dekkers <dekkers@cs.rwth-aachen.de>
49 //
50 //=============================================================================
51
52
53 #ifndef BSPLINESURFACET_HH
54 #define BSPLINESURFACET_HH
55
56
57 //== INCLUDES =================================================================
58 #include <vector>
59 #include <iostream>
60
61 #include <ACG/Math/VectorT.hh>
62
63 #include <ObjectTypes/Knotvector/KnotvectorT.hh>
64
65 //== FORWARDDECLARATIONS ======================================================
66
67 //== NAMESPACES ===============================================================
68
69 namespace ACG {
70
71 //== CLASS DEFINITION =========================================================
72
73
81 template <class PointT>
82 class BSplineSurfaceT
83 {
84 public:
85
86 // internal relevant Types
87 typedef PointT Point;
88 typedef typename Point::value_type Scalar;
89 typedef typename std::vector< std::vector< Point > > ControlNet;
90 typedef typename std::vector< std::vector< unsigned char > > PropertyNet;
91
97 explicit BSplineSurfaceT(unsigned int _degm = 3, unsigned int _degn = 3);
98
105 void resize(unsigned int _m, unsigned int _n);
106
108 std::vector< Scalar >& get_knots_m() {return knotvector_m_.getKnotvector();};
110 std::vector< Scalar >& get_knots_n() {return knotvector_n_.getKnotvector();};
111
113 Knotvector get_knotvector_m(){return knotvector_m_;};
115 Knotvector get_knotvector_n(){return knotvector_n_;};
116
118 Knotvector * get_knotvector_m_ref(){return &knotvector_m_;};
120 Knotvector * get_knotvector_n_ref(){return &knotvector_n_;};
121
127 Scalar get_knot_m(int _i) {return knotvector_m_(_i);};
128
134 Scalar get_knot_n(int _i) {return knotvector_n_(_i);};
135
140 void set_knots_m(std::vector< Scalar > _knots);
141
146 void set_knots_n(std::vector< Scalar > _knots);
147
152 void insert_knot_m(double _t);
153
158 void insert_knot_n(double _t);
159
161 void createKnots();
162
168 void set_degree(unsigned int _degm, unsigned int _degn);
169
170
172 int degree_m() const {return degree_m_;}
174 int degree_n() const {return degree_n_;}
175
177 unsigned int n_control_points_m() const {return dimm_;}
179 unsigned int n_control_points_n() const {return dimn_;}
180
182 unsigned int n_knots_m(){return knotvector_m_.size();};
184 unsigned int n_knots_n(){return knotvector_n_.size();};
185
186
188 void reset_control_net();
189
193 Point& get_control_point(unsigned int _m, unsigned int _n)
194 {
195 assert (_m < dimm_ && _n < dimn_);
196 return control_net_[_m][_n];
197 }
198
203 inline Point& operator()(unsigned int _m, unsigned int _n)
204 {
205 assert (_m < dimm_ && _n < dimn_);
206 return control_net_[_m][_n];
207 }
208
213 inline const Point& operator()(unsigned int _m, unsigned int _n) const
214 {
215 assert (_m < dimm_ && _n < dimn_);
216 return control_net_[_m][_n];
217 }
218
223 inline Point& operator()(Vec2i _param)
224 {
225 assert ( (0 <= _param[0]) && (_param[0] < dimm_) && (0 <= _param[1]) &&( _param[1] < dimn_ ) );
226 return control_net_[_param[0]][_param[1]];
227 }
228
233 inline const Point& operator()(Vec2i _param) const
234 {
235 assert ( (0 <= _param[0]) && (_param[0] < dimm_) && (0 <= _param[1]) &&( _param[1] < dimn_ ) );
236 return control_net_[_param[0]][_param[1]];
237 }
238
239
245 void get_vector_m(std::vector< Point> & _control_polygon, unsigned int _m);
246
252 void get_vector_n(std::vector< Point> & _control_polygon, unsigned int _n);
253
254
259 void add_vector_m(const std::vector< Point> & _control_polygon);
260
265 void add_vector_n(const std::vector< Point> & _control_polygon);
266
267
273 void insert_vector_m(const std::vector< Point> & _control_polygon, unsigned int _m);
274
279 void insert_vector_n(const std::vector< Point> & _control_polygon, unsigned int _n);
280
285 void delete_vector_m(unsigned int _m);
286
291 void delete_vector_n(unsigned int _n);
292
293
300 Point surfacePoint(double _u, double _v);
301
312 void surfacePointNormal(Point& _pt, Point& _normal, double _u, double _v);
313
322 Point surfacePoint_rec(double _u, double _v);
323
332 Point derivativeSurfacePoint(double _u, double _v, int _derm, int _dern);
333
340 Point normalSurfacePoint(double _u, double _v);
341 public:
342
351 Scalar basisFunction(Knotvector & _knotvector, int _i, int _n, double _t);
352
361 Scalar derivativeBasisFunction(Knotvector & _knotvector, int _i, int _n, double _t, int _der);
362
367 ACG::Vec2i spanm(double _t);
368
373 ACG::Vec2i spann(double _t);
374
379 ACG::Vec2i interval_m(double _t);
380
385 ACG::Vec2i interval_n(double _t);
386
387
388 public:
389
391 Scalar loweru();
393 Scalar upperu();
394
396 Scalar lowerv();
398 Scalar upperv();
399
400
401 public :
402
404 void request_controlpoint_selections() { request_prop( ref_count_cpselections_, cpselections_);}
406 void request_edge_selections() { request_prop( ref_count_eselections_, eselections_);}
407
409 void release_controlpoint_selections() { release_prop( ref_count_cpselections_, cpselections_);}
411 void release_edge_selections() { release_prop( ref_count_eselections_, eselections_);}
412
414 bool controlpoint_selections_available() const {return bool(ref_count_cpselections_);}
416 bool edge_selections_available() const {return bool(ref_count_eselections_);}
417
418
419 // property access ( no range or availability check! )
420 unsigned char& controlpoint_selection(unsigned int _i, unsigned int _j) {return cpselections_[_i][_j];}
421 const unsigned char& controlpoint_selection(unsigned int _i, unsigned int _j) const {return cpselections_[_i][_j];}
422
423 // unsigned char& controlpoint_selection(unsigned int _idx) {return cpselections_[_idx];}
424 // const unsigned char& controlpoint_selection(unsigned int _idx) const {return cpselections_[_idx];}
425
426 unsigned char& edge_selection(unsigned int _i, unsigned int _j) {return eselections_[_i][_j];}
427 const unsigned char& edge_selection(unsigned int _i, unsigned int _j) const {return eselections_[_i][_j];}
428
429 // /// acces with row / col indices
430 // unsigned char& controlpoint_selection(unsigned int _i, unsigned int _j) {int idx = _i * dimn_ + _j; return cpselections_[idx];}
431 // const unsigned char& controlpoint_selection(unsigned int _i, unsigned int _j) const {int idx = _i * dimn_ + _j; return cpselections_[idx];}
432
433 // /// access with global idx
434 // unsigned char& controlpoint_selection(unsigned int _idx) {return cpselections_[_idx];}
435 // const unsigned char& controlpoint_selection(unsigned int _idx) const {return cpselections_[_idx];}
436
437 // unsigned char& edge_selection(unsigned int _i, unsigned int _j) {int idx = _i * dimn_ + _j; return eselections_[idx];}
438 // const unsigned char& edge_selection(unsigned int _i, unsigned int _j) const {int idx = _i * dimn_ + _j; return eselections_[idx];}
439
440 // Wrapper for selection functions
441 void select_controlpoint(unsigned int _iIdx, unsigned int _jIdx) { controlpoint_selection(_iIdx, _jIdx) = 1; };
442 void deselect_controlpoint(unsigned int _iIdx, unsigned int _jIdx) { controlpoint_selection(_iIdx, _jIdx) = 0; };
443
444 bool controlpoint_selected(unsigned int _iIdx, unsigned int _jIdx) const { return (controlpoint_selection(_iIdx, _jIdx) == 1); };
445
446
447 private:
448
449 template <class PropT>
450 void request_prop( unsigned int& _ref_count, PropT& _prop);
451
452 template <class PropT>
453 void release_prop( unsigned int& _ref_count, PropT& _prop);
454
455 private:
456
457 unsigned int dimm_;
458 unsigned int dimn_;
459 unsigned int degree_m_;
460 unsigned int degree_n_;
461
462 Knotvector knotvector_m_;
463 Knotvector knotvector_n_;
464
465 ControlNet control_net_;
466
467 private: // private properties
468
469 // ############################### Standard Property Handling #############################
470
471 // // list of vertex properties
472 // std::vector< std::vector<unsigned char> > vselections_;
473 // // list of edge properties
474 // std::vector< std::vector<unsigned char> > eselections_;
475
477 // std::vector<unsigned char> cpselections_;
478 PropertyNet cpselections_;
479
481 // std::vector<unsigned char> eselections_;
482 PropertyNet eselections_;
483
484 // property reference counter
485 unsigned int ref_count_cpselections_;
486 unsigned int ref_count_eselections_;
487
488 };
489
490
491 //=============================================================================
492 } // namespace ACG
493 //=============================================================================
494 #if defined(INCLUDE_TEMPLATES) && !defined(BSPLINESURFACE_BSPLINESURFACET_C)
495 #define BSPLINESURFACE_BSPLINESURFACET_TEMPLATES
496 #include "BSplineSurfaceT_impl.hh"
497 #endif
498 //=============================================================================
499 #endif // ACG_BSPLINESURFACET_HH defined
500 //=============================================================================
501
ACG::BSplineSurfaceT::insert_knot_n
void insert_knot_n(double _t)
Insert a knot i in n direction without changing the surface.
Definition: BSplineSurfaceT_impl.hh:424
ACG::BSplineSurfaceT::controlpoint_selections_available
bool controlpoint_selections_available() const
Check if control point selection property is available.
Definition: BSplineSurfaceT.hh:414
ACG::BSplineSurfaceT::operator()
Point & operator()(Vec2i _param)
Returns a reference to the control point (m, n)
Definition: BSplineSurfaceT.hh:223
ACG::BSplineSurfaceT::request_edge_selections
void request_edge_selections()
request edge selection property
Definition: BSplineSurfaceT.hh:406
ACG::BSplineSurfaceT::add_vector_m
void add_vector_m(const std::vector< Point > &_control_polygon)
Adds a control point n-vector.
Definition: BSplineSurfaceT_impl.hh:187
ACG::BSplineSurfaceT::degree_m_
unsigned int degree_m_
Spline degree in m direction.
Definition: BSplineSurfaceT.hh:459
ACG::BSplineSurfaceT::dimm_
unsigned int dimm_
number of control points in m direction
Definition: BSplineSurfaceT.hh:457
ACG
Namespace providing different geometric functions concerning angles.
Definition: BaseObjectData.hh:68
ACG::BSplineSurfaceT::get_knotvector_n_ref
Knotvector * get_knotvector_n_ref()
Get a reference to the knotvector in n direction.
Definition: BSplineSurfaceT.hh:120
ACG::BSplineSurfaceT::upperu
Scalar upperu()
Returns the upper u parameter.
Definition: BSplineSurfaceT_impl.hh:729
ACG::BSplineSurfaceT::release_controlpoint_selections
void release_controlpoint_selections()
release control point selection property
Definition: BSplineSurfaceT.hh:409
ACG::BSplineSurfaceT::interval_n
ACG::Vec2i interval_n(double _t)
Returns the index of the knots v and v+1 such that t in [v, v+1)
Definition: BSplineSurfaceT_impl.hh:797
ACG::BSplineSurfaceT::get_control_point
Point & get_control_point(unsigned int _m, unsigned int _n)
Returns a reference to the control point (m, n)
Definition: BSplineSurfaceT.hh:193
ACG::BSplineSurfaceT::degree_n
int degree_n() const
Returns the spline degree in n direction.
Definition: BSplineSurfaceT.hh:174
ACG::BSplineSurfaceT::cpselections_
PropertyNet cpselections_
list of control point properties
Definition: BSplineSurfaceT.hh:478
ACG::BSplineSurfaceT::set_knots_m
void set_knots_m(std::vector< Scalar > _knots)
Set the knotvector of the bspline surface in m direction.
Definition: BSplineSurfaceT_impl.hh:358
ACG::BSplineSurfaceT::eselections_
PropertyNet eselections_
list of edge properties
Definition: BSplineSurfaceT.hh:482
ACG::BSplineSurfaceT::createKnots
void createKnots()
Creates interpolating knotvectors 0...0, 1, 2, ..., n...n.
Definition: BSplineSurfaceT_impl.hh:165
ACG::BSplineSurfaceT::delete_vector_m
void delete_vector_m(unsigned int _m)
Deletes an n control point vector.
Definition: BSplineSurfaceT_impl.hh:275
ACG::BSplineSurfaceT::insert_vector_n
void insert_vector_n(const std::vector< Point > &_control_polygon, unsigned int _n)
Inserts an m control point vector.
Definition: BSplineSurfaceT_impl.hh:240
ACG::BSplineSurfaceT::n_knots_n
unsigned int n_knots_n()
Returns the number of knots in n direction.
Definition: BSplineSurfaceT.hh:184
ACG::BSplineSurfaceT::operator()
const Point & operator()(unsigned int _m, unsigned int _n) const
Returns a const reference to the control point (m, n)
Definition: BSplineSurfaceT.hh:213
ACG::BSplineSurfaceT::knotvector_n_
Knotvector knotvector_n_
Knotvector in n direction.
Definition: BSplineSurfaceT.hh:463
ACG::BSplineSurfaceT::get_vector_m
void get_vector_m(std::vector< Point > &_control_polygon, unsigned int _m)
Returns an n control point vector.
Definition: BSplineSurfaceT_impl.hh:333
ACG::BSplineSurfaceT::spann
ACG::Vec2i spann(double _t)
Returns the basis functions which are unequal to zero at parameter v.
Definition: BSplineSurfaceT_impl.hh:767
ACG::BSplineSurfaceT::get_knots_m
std::vector< Scalar > & get_knots_m()
get the knotvector in m direction of the bspline surface
Definition: BSplineSurfaceT.hh:108
ACG::BSplineSurfaceT::get_knots_n
std::vector< Scalar > & get_knots_n()
get the knotvector in m direction of the bspline surface
Definition: BSplineSurfaceT.hh:110
ACG::BSplineSurfaceT::get_knot_n
Scalar get_knot_n(int _i)
Get knot i in n direction.
Definition: BSplineSurfaceT.hh:134
ACG::BSplineSurfaceT::insert_vector_m
void insert_vector_m(const std::vector< Point > &_control_polygon, unsigned int _m)
Inserts an n control point vector.
Definition: BSplineSurfaceT_impl.hh:207
ACG::BSplineSurfaceT::get_knotvector_m_ref
Knotvector * get_knotvector_m_ref()
Get a reference to the knotvector in m direction.
Definition: BSplineSurfaceT.hh:118
ACG::BSplineSurfaceT::upperv
Scalar upperv()
Returns the upper v parameter.
Definition: BSplineSurfaceT_impl.hh:748
ACG::BSplineSurfaceT::interval_m
ACG::Vec2i interval_m(double _t)
Returns the index of the knots u and u+1 such that t in [u, u+1)
Definition: BSplineSurfaceT_impl.hh:777
ACG::BSplineSurfaceT::surfacePoint
Point surfacePoint(double _u, double _v)
Evaluates a spline surface at parameters _u and _v.
Definition: BSplineSurfaceT_impl.hh:470
ACG::BSplineSurfaceT::insert_knot_m
void insert_knot_m(double _t)
Insert a knot i in m direction without changing the surface.
Definition: BSplineSurfaceT_impl.hh:380
ACG::BSplineSurfaceT::lowerv
Scalar lowerv()
Returns the lower v parameter.
Definition: BSplineSurfaceT_impl.hh:738
ACG::BSplineSurfaceT::BSplineSurfaceT
BSplineSurfaceT(unsigned int _degm=3, unsigned int _degn=3)
Constructor.
Definition: BSplineSurfaceT_impl.hh:75
ACG::BSplineSurfaceT::reset_control_net
void reset_control_net()
Clears the control net.
Definition: BSplineSurfaceT_impl.hh:151
ACG::BSplineSurfaceT
Definition: BSplineSurfaceT.hh:82
ACG::BSplineSurfaceT::spanm
ACG::Vec2i spanm(double _t)
Returns the basis functions which are unequal to zero at parameter u.
Definition: BSplineSurfaceT_impl.hh:757
ACG::BSplineSurfaceT::surfacePoint_rec
Point surfacePoint_rec(double _u, double _v)
Evaluates a spline surface at parameters _u and _v.
Definition: BSplineSurfaceT_impl.hh:571
ACG::BSplineSurfaceT::resize
void resize(unsigned int _m, unsigned int _n)
Resizes the spline struct.
Definition: BSplineSurfaceT_impl.hh:125
ACG::BSplineSurfaceT::get_knot_m
Scalar get_knot_m(int _i)
Get knot i in m direction.
Definition: BSplineSurfaceT.hh:127
ACG::BSplineSurfaceT::normalSurfacePoint
Point normalSurfacePoint(double _u, double _v)
Returns the normal of a spline surface.
Definition: BSplineSurfaceT_impl.hh:674
ACG::BSplineSurfaceT::n_control_points_n
unsigned int n_control_points_n() const
Returns the number of controlpoints in n direction.
Definition: BSplineSurfaceT.hh:179
ACG::BSplineSurfaceT::get_vector_n
void get_vector_n(std::vector< Point > &_control_polygon, unsigned int _n)
Returns an m ctrPointVector.
Definition: BSplineSurfaceT_impl.hh:344
ACG::BSplineSurfaceT::n_control_points_m
unsigned int n_control_points_m() const
Returns the number of controlpoints in m direction.
Definition: BSplineSurfaceT.hh:177
ACG::BSplineSurfaceT::set_degree
void set_degree(unsigned int _degm, unsigned int _degn)
Sets the degree of the spline surface.
Definition: BSplineSurfaceT_impl.hh:176
ACG::BSplineSurfaceT::loweru
Scalar loweru()
Returns the lower u parameter.
Definition: BSplineSurfaceT_impl.hh:719
ACG::BSplineSurfaceT::operator()
const Point & operator()(Vec2i _param) const
Returns a const reference to the control point (m, n)
Definition: BSplineSurfaceT.hh:233
ACG::BSplineSurfaceT::n_knots_m
unsigned int n_knots_m()
Returns the number of knots in m direction.
Definition: BSplineSurfaceT.hh:182
ACG::BSplineSurfaceT::set_knots_n
void set_knots_n(std::vector< Scalar > _knots)
Set the knotvector of the bspline surface in n direction.
Definition: BSplineSurfaceT_impl.hh:369
ACG::BSplineSurfaceT::add_vector_n
void add_vector_n(const std::vector< Point > &_control_polygon)
Adds a control point m-vector.
Definition: BSplineSurfaceT_impl.hh:197
ACG::BSplineSurfaceT::delete_vector_n
void delete_vector_n(unsigned int _n)
Deletes an m control point vector.
Definition: BSplineSurfaceT_impl.hh:302
ACG::BSplineSurfaceT::release_edge_selections
void release_edge_selections()
release edge selection property
Definition: BSplineSurfaceT.hh:411
ACG::BSplineSurfaceT::derivativeBasisFunction
Scalar derivativeBasisFunction(Knotvector &_knotvector, int _i, int _n, double _t, int _der)
Derivative of a Spline Basis Function.
Definition: BSplineSurfaceT_impl.hh:692
OpenMesh::VectorT
Definition: Vector11T.hh:83
ACG::BSplineSurfaceT::surfacePointNormal
void surfacePointNormal(Point &_pt, Point &_normal, double _u, double _v)
Evaluates a spline surface at parameters _u and _v.
Definition: BSplineSurfaceT_impl.hh:513
ACG::BSplineSurfaceT::degree_n_
unsigned int degree_n_
Spline degree in n direction.
Definition: BSplineSurfaceT.hh:460
ACG::BSplineSurfaceT::operator()
Point & operator()(unsigned int _m, unsigned int _n)
Returns a reference to the control point (m, n)
Definition: BSplineSurfaceT.hh:203
ACG::BSplineSurfaceT::dimn_
unsigned int dimn_
number of control points in n direction
Definition: BSplineSurfaceT.hh:458
ACG::BSplineSurfaceT::derivativeSurfacePoint
Point derivativeSurfacePoint(double _u, double _v, int _derm, int _dern)
Returns the _derm&#39;th derivative of a spline surface.
Definition: BSplineSurfaceT_impl.hh:642
ACG::BSplineSurfaceT::get_knotvector_n
Knotvector get_knotvector_n()
Get the knotvector in n direction.
Definition: BSplineSurfaceT.hh:115
ACG::BSplineSurfaceT::get_knotvector_m
Knotvector get_knotvector_m()
Get the knotvector in m direction.
Definition: BSplineSurfaceT.hh:113
ACG::KnotvectorT< double >
ACG::BSplineSurfaceT::basisFunction
Scalar basisFunction(Knotvector &_knotvector, int _i, int _n, double _t)
A Spline Basis Function.
Definition: BSplineSurfaceT_impl.hh:604
ACG::BSplineSurfaceT::degree_m
int degree_m() const
Returns the spline degree in m direction.
Definition: BSplineSurfaceT.hh:172
ACG::BSplineSurfaceT::request_controlpoint_selections
void request_controlpoint_selections()
request control point selection property
Definition: BSplineSurfaceT.hh:404
ACG::BSplineSurfaceT::knotvector_m_
Knotvector knotvector_m_
Knotvector in m direction.
Definition: BSplineSurfaceT.hh:462
ACG::BSplineSurfaceT::edge_selections_available
bool edge_selections_available() const
Check if edge selection property is available.
Definition: BSplineSurfaceT.hh:416