Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49
50
51 //=============================================================================
52 //
53 // CLASS BSplineSurfaceT
54 // Author: Ellen Dekkers <dekkers@cs.rwth-aachen.de>
55 //
56 //=============================================================================
57
58
59 #ifndef BSPLINESURFACET_HH
60 #define BSPLINESURFACET_HH
61
62
63 //== INCLUDES =================================================================
64 #include <vector>
65 #include <iostream>
66
67 #include <ACG/Math/VectorT.hh>
68
69 #include <ObjectTypes/Knotvector/KnotvectorT.hh>
70
71 //== FORWARDDECLARATIONS ======================================================
72
73 //== NAMESPACES ===============================================================
74
75 namespace ACG {
76
77 //== CLASS DEFINITION =========================================================
78
79
87 template <class PointT>
88 class BSplineSurfaceT
89 {
90 public:
91
92 // internal relevant Types
93 typedef PointT Point;
94 typedef typename Point::value_type Scalar;
95 typedef typename std::vector< std::vector< Point > > ControlNet;
96 typedef typename std::vector< std::vector< unsigned char > > PropertyNet;
97
103 explicit BSplineSurfaceT(unsigned int _degm = 3, unsigned int _degn = 3);
104
111 void resize(unsigned int _m, unsigned int _n);
112
114 std::vector< Scalar >& get_knots_m() {return knotvector_m_.getKnotvector();};
116 std::vector< Scalar >& get_knots_n() {return knotvector_n_.getKnotvector();};
117
119 Knotvector get_knotvector_m(){return knotvector_m_;};
121 Knotvector get_knotvector_n(){return knotvector_n_;};
122
124 Knotvector * get_knotvector_m_ref(){return &knotvector_m_;};
126 Knotvector * get_knotvector_n_ref(){return &knotvector_n_;};
127
133 Scalar get_knot_m(int _i) {return knotvector_m_(_i);};
134
140 Scalar get_knot_n(int _i) {return knotvector_n_(_i);};
141
146 void set_knots_m(std::vector< Scalar > _knots);
147
152 void set_knots_n(std::vector< Scalar > _knots);
153
158 void insert_knot_m(double _t);
159
164 void insert_knot_n(double _t);
165
167 void createKnots();
168
174 void set_degree(unsigned int _degm, unsigned int _degn);
175
176
178 int degree_m() const {return degree_m_;}
180 int degree_n() const {return degree_n_;}
181
183 unsigned int n_control_points_m() const {return dimm_;}
185 unsigned int n_control_points_n() const {return dimn_;}
186
188 unsigned int n_knots_m(){return knotvector_m_.size();};
190 unsigned int n_knots_n(){return knotvector_n_.size();};
191
192
194 void reset_control_net();
195
199 Point& get_control_point(unsigned int _m, unsigned int _n)
200 {
201 assert (_m < dimm_ && _n < dimn_);
202 return control_net_[_m][_n];
203 }
204
209 inline Point& operator()(unsigned int _m, unsigned int _n)
210 {
211 assert (_m < dimm_ && _n < dimn_);
212 return control_net_[_m][_n];
213 }
214
219 inline const Point& operator()(unsigned int _m, unsigned int _n) const
220 {
221 assert (_m < dimm_ && _n < dimn_);
222 return control_net_[_m][_n];
223 }
224
229 inline Point& operator()(Vec2i _param)
230 {
231 assert ( (0 <= _param[0]) && (_param[0] < dimm_) && (0 <= _param[1]) &&( _param[1] < dimn_ ) );
232 return control_net_[_param[0]][_param[1]];
233 }
234
239 inline const Point& operator()(Vec2i _param) const
240 {
241 assert ( (0 <= _param[0]) && (_param[0] < dimm_) && (0 <= _param[1]) &&( _param[1] < dimn_ ) );
242 return control_net_[_param[0]][_param[1]];
243 }
244
245
251 void get_vector_m(std::vector< Point> & _control_polygon, unsigned int _m);
252
258 void get_vector_n(std::vector< Point> & _control_polygon, unsigned int _n);
259
260
265 void add_vector_m(const std::vector< Point> & _control_polygon);
266
271 void add_vector_n(const std::vector< Point> & _control_polygon);
272
273
279 void insert_vector_m(const std::vector< Point> & _control_polygon, unsigned int _m);
280
285 void insert_vector_n(const std::vector< Point> & _control_polygon, unsigned int _n);
286
291 void delete_vector_m(unsigned int _m);
292
297 void delete_vector_n(unsigned int _n);
298
299
306 Point surfacePoint(double _u, double _v);
307
318 void surfacePointNormal(Point& _pt, Point& _normal, double _u, double _v);
319
328 Point surfacePoint_rec(double _u, double _v);
329
338 Point derivativeSurfacePoint(double _u, double _v, int _derm, int _dern);
339
346 Point normalSurfacePoint(double _u, double _v);
347 public:
348
357 Scalar basisFunction(Knotvector & _knotvector, int _i, int _n, double _t);
358
367 Scalar derivativeBasisFunction(Knotvector & _knotvector, int _i, int _n, double _t, int _der);
368
373 ACG::Vec2i spanm(double _t);
374
379 ACG::Vec2i spann(double _t);
380
385 ACG::Vec2i interval_m(double _t);
386
391 ACG::Vec2i interval_n(double _t);
392
393
394 public:
395
397 Scalar loweru();
399 Scalar upperu();
400
402 Scalar lowerv();
404 Scalar upperv();
405
406
407 public :
408
410 void request_controlpoint_selections() { request_prop( ref_count_cpselections_, cpselections_);}
412 void request_edge_selections() { request_prop( ref_count_eselections_, eselections_);}
413
415 void release_controlpoint_selections() { release_prop( ref_count_cpselections_, cpselections_);}
417 void release_edge_selections() { release_prop( ref_count_eselections_, eselections_);}
418
420 bool controlpoint_selections_available() const {return bool(ref_count_cpselections_);}
422 bool edge_selections_available() const {return bool(ref_count_eselections_);}
423
424
425 // property access ( no range or availability check! )
426 unsigned char& controlpoint_selection(unsigned int _i, unsigned int _j) {return cpselections_[_i][_j];}
427 const unsigned char& controlpoint_selection(unsigned int _i, unsigned int _j) const {return cpselections_[_i][_j];}
428
429 // unsigned char& controlpoint_selection(unsigned int _idx) {return cpselections_[_idx];}
430 // const unsigned char& controlpoint_selection(unsigned int _idx) const {return cpselections_[_idx];}
431
432 unsigned char& edge_selection(unsigned int _i, unsigned int _j) {return eselections_[_i][_j];}
433 const unsigned char& edge_selection(unsigned int _i, unsigned int _j) const {return eselections_[_i][_j];}
434
435 // /// acces with row / col indices
436 // unsigned char& controlpoint_selection(unsigned int _i, unsigned int _j) {int idx = _i * dimn_ + _j; return cpselections_[idx];}
437 // const unsigned char& controlpoint_selection(unsigned int _i, unsigned int _j) const {int idx = _i * dimn_ + _j; return cpselections_[idx];}
438
439 // /// access with global idx
440 // unsigned char& controlpoint_selection(unsigned int _idx) {return cpselections_[_idx];}
441 // const unsigned char& controlpoint_selection(unsigned int _idx) const {return cpselections_[_idx];}
442
443 // unsigned char& edge_selection(unsigned int _i, unsigned int _j) {int idx = _i * dimn_ + _j; return eselections_[idx];}
444 // const unsigned char& edge_selection(unsigned int _i, unsigned int _j) const {int idx = _i * dimn_ + _j; return eselections_[idx];}
445
446 // Wrapper for selection functions
447 void select_controlpoint(unsigned int _iIdx, unsigned int _jIdx) { controlpoint_selection(_iIdx, _jIdx) = 1; };
448 void deselect_controlpoint(unsigned int _iIdx, unsigned int _jIdx) { controlpoint_selection(_iIdx, _jIdx) = 0; };
449
450 bool controlpoint_selected(unsigned int _iIdx, unsigned int _jIdx) const { return (controlpoint_selection(_iIdx, _jIdx) == 1); };
451
452
453 private:
454
455 template <class PropT>
456 void request_prop( unsigned int& _ref_count, PropT& _prop);
457
458 template <class PropT>
459 void release_prop( unsigned int& _ref_count, PropT& _prop);
460
461 private:
462
463 unsigned int dimm_;
464 unsigned int dimn_;
465 unsigned int degree_m_;
466 unsigned int degree_n_;
467
468 Knotvector knotvector_m_;
469 Knotvector knotvector_n_;
470
471 ControlNet control_net_;
472
473 private: // private properties
474
475 // ############################### Standard Property Handling #############################
476
477 // // list of vertex properties
478 // std::vector< std::vector<unsigned char> > vselections_;
479 // // list of edge properties
480 // std::vector< std::vector<unsigned char> > eselections_;
481
483 // std::vector<unsigned char> cpselections_;
484 PropertyNet cpselections_;
485
487 // std::vector<unsigned char> eselections_;
488 PropertyNet eselections_;
489
490 // property reference counter
491 unsigned int ref_count_cpselections_;
492 unsigned int ref_count_eselections_;
493
494 };
495
496
497 //=============================================================================
498 } // namespace ACG
499 //=============================================================================
500 #if defined(INCLUDE_TEMPLATES) && !defined(BSPLINESURFACE_BSPLINESURFACET_C)
501 #define BSPLINESURFACE_BSPLINESURFACET_TEMPLATES
502 #include "BSplineSurfaceT.cc"
503 #endif
504 //=============================================================================
505 #endif // ACG_BSPLINESURFACET_HH defined
506 //=============================================================================
507
ACG::BSplineSurfaceT::degree_n
int degree_n() const
Returns the spline degree in n direction.
Definition: BSplineSurfaceT.hh:180
ACG::BSplineSurfaceT::get_vector_n
void get_vector_n(std::vector< Point > &_control_polygon, unsigned int _n)
Returns an m ctrPointVector.
Definition: BSplineSurfaceT.cc:350
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.cc:339
ACG::BSplineSurfaceT::get_knots_n
std::vector< Scalar > & get_knots_n()
get the knotvector in m direction of the bspline surface
Definition: BSplineSurfaceT.hh:116
ACG::BSplineSurfaceT::get_knotvector_n_ref
Knotvector * get_knotvector_n_ref()
Get a reference to the knotvector in n direction.
Definition: BSplineSurfaceT.hh:126
ACG::BSplineSurfaceT::release_edge_selections
void release_edge_selections()
release edge selection property
Definition: BSplineSurfaceT.hh:417
ACG::BSplineSurfaceT::surfacePoint
Point surfacePoint(double _u, double _v)
Evaluates a spline surface at parameters _u and _v.
Definition: BSplineSurfaceT.cc:476
ACG
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
ACG::BSplineSurfaceT::request_edge_selections
void request_edge_selections()
request edge selection property
Definition: BSplineSurfaceT.hh:412
ACG::BSplineSurfaceT::cpselections_
PropertyNet cpselections_
list of control point properties
Definition: BSplineSurfaceT.hh:484
ACG::BSplineSurfaceT::dimm_
unsigned int dimm_
number of control points in m direction
Definition: BSplineSurfaceT.hh:463
ACG::BSplineSurfaceT::upperv
Scalar upperv()
Returns the upper v parameter.
Definition: BSplineSurfaceT.cc:754
ACG::BSplineSurfaceT::request_controlpoint_selections
void request_controlpoint_selections()
request control point selection property
Definition: BSplineSurfaceT.hh:410
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:219
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.cc:364
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.cc:803
ACG::BSplineSurfaceT::n_knots_n
unsigned int n_knots_n()
Returns the number of knots in n direction.
Definition: BSplineSurfaceT.hh:190
ACG::KnotvectorT< double >
ACG::BSplineSurfaceT::add_vector_m
void add_vector_m(const std::vector< Point > &_control_polygon)
Adds a control point n-vector.
Definition: BSplineSurfaceT.cc:193
ACG::BSplineSurfaceT::delete_vector_m
void delete_vector_m(unsigned int _m)
Deletes an n control point vector.
Definition: BSplineSurfaceT.cc:281
ACG::BSplineSurfaceT::degree_m
int degree_m() const
Returns the spline degree in m direction.
Definition: BSplineSurfaceT.hh:178
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.cc:783
ACG::BSplineSurfaceT::get_knot_n
Scalar get_knot_n(int _i)
Get knot i in n direction.
Definition: BSplineSurfaceT.hh:140
ACG::BSplineSurfaceT::operator()
const Point & operator()(Vec2i _param) const
Returns a const reference to the control point (m, n)
Definition: BSplineSurfaceT.hh:239
ACG::BSplineSurfaceT::createKnots
void createKnots()
Creates interpolating knotvectors 0...0, 1, 2, ..., n...n.
Definition: BSplineSurfaceT.cc:171
ACG::BSplineSurfaceT::n_control_points_n
unsigned int n_control_points_n() const
Returns the number of controlpoints in n direction.
Definition: BSplineSurfaceT.hh:185
ACG::BSplineSurfaceT::insert_knot_n
void insert_knot_n(double _t)
Insert a knot i in n direction without changing the surface.
Definition: BSplineSurfaceT.cc:430
ACG::BSplineSurfaceT::operator()
Point & operator()(Vec2i _param)
Returns a reference to the control point (m, n)
Definition: BSplineSurfaceT.hh:229
ACG::BSplineSurfaceT::derivativeSurfacePoint
Point derivativeSurfacePoint(double _u, double _v, int _derm, int _dern)
Returns the _derm'th derivative of a spline surface.
Definition: BSplineSurfaceT.cc:648
ACG::BSplineSurfaceT::release_controlpoint_selections
void release_controlpoint_selections()
release control point selection property
Definition: BSplineSurfaceT.hh:415
ACG::BSplineSurfaceT::basisFunction
Scalar basisFunction(Knotvector &_knotvector, int _i, int _n, double _t)
A Spline Basis Function.
Definition: BSplineSurfaceT.cc:610
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:199
ACG::BSplineSurfaceT::lowerv
Scalar lowerv()
Returns the lower v parameter.
Definition: BSplineSurfaceT.cc:744
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.cc:246
ACG::BSplineSurfaceT::knotvector_m_
Knotvector knotvector_m_
Knotvector in m direction.
Definition: BSplineSurfaceT.hh:468
ACG::BSplineSurfaceT::knotvector_n_
Knotvector knotvector_n_
Knotvector in n direction.
Definition: BSplineSurfaceT.hh:469
ACG::BSplineSurfaceT::get_knot_m
Scalar get_knot_m(int _i)
Get knot i in m direction.
Definition: BSplineSurfaceT.hh:133
ACG::BSplineSurfaceT::delete_vector_n
void delete_vector_n(unsigned int _n)
Deletes an m control point vector.
Definition: BSplineSurfaceT.cc:308
ACG::BSplineSurfaceT
Definition: BSplineSurfaceT.hh:88
ACG::BSplineSurfaceT::get_knotvector_m_ref
Knotvector * get_knotvector_m_ref()
Get a reference to the knotvector in m direction.
Definition: BSplineSurfaceT.hh:124
OpenMesh::VectorT
Definition: Vector11T.hh:83
ACG::BSplineSurfaceT::controlpoint_selections_available
bool controlpoint_selections_available() const
Check if control point selection property is available.
Definition: BSplineSurfaceT.hh:420
ACG::BSplineSurfaceT::reset_control_net
void reset_control_net()
Clears the control net.
Definition: BSplineSurfaceT.cc:157
ACG::BSplineSurfaceT::BSplineSurfaceT
BSplineSurfaceT(unsigned int _degm=3, unsigned int _degn=3)
Constructor.
Definition: BSplineSurfaceT.cc:81
ACG::BSplineSurfaceT::derivativeBasisFunction
Scalar derivativeBasisFunction(Knotvector &_knotvector, int _i, int _n, double _t, int _der)
Derivative of a Spline Basis Function.
Definition: BSplineSurfaceT.cc:698
ACG::BSplineSurfaceT::spann
ACG::Vec2i spann(double _t)
Returns the basis functions which are unequal to zero at parameter v.
Definition: BSplineSurfaceT.cc:773
ACG::BSplineSurfaceT::dimn_
unsigned int dimn_
number of control points in n direction
Definition: BSplineSurfaceT.hh:464
ACG::BSplineSurfaceT::eselections_
PropertyNet eselections_
list of edge properties
Definition: BSplineSurfaceT.hh:488
ACG::BSplineSurfaceT::add_vector_n
void add_vector_n(const std::vector< Point > &_control_polygon)
Adds a control point m-vector.
Definition: BSplineSurfaceT.cc:203
ACG::BSplineSurfaceT::operator()
Point & operator()(unsigned int _m, unsigned int _n)
Returns a reference to the control point (m, n)
Definition: BSplineSurfaceT.hh:209
ACG::BSplineSurfaceT::get_knots_m
std::vector< Scalar > & get_knots_m()
get the knotvector in m direction of the bspline surface
Definition: BSplineSurfaceT.hh:114
ACG::BSplineSurfaceT::get_knotvector_n
Knotvector get_knotvector_n()
Get the knotvector in n direction.
Definition: BSplineSurfaceT.hh:121
ACG::BSplineSurfaceT::spanm
ACG::Vec2i spanm(double _t)
Returns the basis functions which are unequal to zero at parameter u.
Definition: BSplineSurfaceT.cc:763
ACG::BSplineSurfaceT::surfacePointNormal
void surfacePointNormal(Point &_pt, Point &_normal, double _u, double _v)
Evaluates a spline surface at parameters _u and _v.
Definition: BSplineSurfaceT.cc:519
ACG::BSplineSurfaceT::resize
void resize(unsigned int _m, unsigned int _n)
Resizes the spline struct.
Definition: BSplineSurfaceT.cc:131
ACG::BSplineSurfaceT::degree_n_
unsigned int degree_n_
Spline degree in n direction.
Definition: BSplineSurfaceT.hh:466
ACG::BSplineSurfaceT::get_knotvector_m
Knotvector get_knotvector_m()
Get the knotvector in m direction.
Definition: BSplineSurfaceT.hh:119
ACG::BSplineSurfaceT::insert_knot_m
void insert_knot_m(double _t)
Insert a knot i in m direction without changing the surface.
Definition: BSplineSurfaceT.cc:386
ACG::BSplineSurfaceT::n_control_points_m
unsigned int n_control_points_m() const
Returns the number of controlpoints in m direction.
Definition: BSplineSurfaceT.hh:183
ACG::BSplineSurfaceT::degree_m_
unsigned int degree_m_
Spline degree in m direction.
Definition: BSplineSurfaceT.hh:465
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.cc:213
ACG::BSplineSurfaceT::set_degree
void set_degree(unsigned int _degm, unsigned int _degn)
Sets the degree of the spline surface.
Definition: BSplineSurfaceT.cc:182
ACG::BSplineSurfaceT::upperu
Scalar upperu()
Returns the upper u parameter.
Definition: BSplineSurfaceT.cc:735
ACG::BSplineSurfaceT::edge_selections_available
bool edge_selections_available() const
Check if edge selection property is available.
Definition: BSplineSurfaceT.hh:422
ACG::BSplineSurfaceT::surfacePoint_rec
Point surfacePoint_rec(double _u, double _v)
Evaluates a spline surface at parameters _u and _v.
Definition: BSplineSurfaceT.cc:577
ACG::BSplineSurfaceT::normalSurfacePoint
Point normalSurfacePoint(double _u, double _v)
Returns the normal of a spline surface.
Definition: BSplineSurfaceT.cc:680
ACG::BSplineSurfaceT::loweru
Scalar loweru()
Returns the lower u parameter.
Definition: BSplineSurfaceT.cc:725
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.cc:375
ACG::BSplineSurfaceT::n_knots_m
unsigned int n_knots_m()
Returns the number of knots in m direction.
Definition: BSplineSurfaceT.hh:188