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>
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 
116 
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 
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 
void delete_vector_n(unsigned int _n)
Deletes an m control point vector.
void resize(unsigned int _m, unsigned int _n)
Resizes the spline struct.
Point normalSurfacePoint(double _u, double _v)
Returns the normal of a spline surface.
Point surfacePoint_rec(double _u, double _v)
Evaluates a spline surface at parameters _u and _v.
void release_controlpoint_selections()
release control point selection property
int degree_m() const
Returns the spline degree in m direction.
unsigned int dimm_
number of control points in m direction
std::vector< Scalar > & get_knots_n()
get the knotvector in m direction of the bspline surface
ACG::Vec2i spanm(double _t)
Returns the basis functions which are unequal to zero at parameter u.
Scalar loweru()
Returns the lower u parameter.
void request_edge_selections()
request edge selection property
Namespace providing different geometric functions concerning angles.
Knotvector * get_knotvector_m_ref()
Get a reference to the knotvector in m direction.
Scalar upperv()
Returns the upper v parameter.
unsigned int n_control_points_n() const
Returns the number of controlpoints in n direction.
void add_vector_n(const std::vector< Point > &_control_polygon)
Adds a control point m-vector.
Knotvector knotvector_m_
Knotvector in m direction.
void set_degree(unsigned int _degm, unsigned int _degn)
Sets the degree of the spline surface.
ACG::Vec2i spann(double _t)
Returns the basis functions which are unequal to zero at parameter v.
void request_controlpoint_selections()
request control point selection property
ACG::Vec2i interval_n(double _t)
Returns the index of the knots v and v+1 such that t in [v, v+1)
unsigned int n_control_points_m() const
Returns the number of controlpoints in m direction.
void createKnots()
Creates interpolating knotvectors 0...0, 1, 2, ..., n...n.
ACG::Vec2i interval_m(double _t)
Returns the index of the knots u and u+1 such that t in [u, u+1)
Point surfacePoint(double _u, double _v)
Evaluates a spline surface at parameters _u and _v.
BSplineSurfaceT(unsigned int _degm=3, unsigned int _degn=3)
Constructor.
bool edge_selections_available() const
Check if edge selection property is available.
void add_vector_m(const std::vector< Point > &_control_polygon)
Adds a control point n-vector.
const Point & operator()(unsigned int _m, unsigned int _n) const
Returns a const reference to the control point (m, n)
Knotvector * get_knotvector_n_ref()
Get a reference to the knotvector in n direction.
void release_edge_selections()
release edge selection property
void set_knots_m(std::vector< Scalar > _knots)
Set the knotvector of the bspline surface in m direction.
void insert_vector_n(const std::vector< Point > &_control_polygon, unsigned int _n)
Inserts an m control point vector.
void set_knots_n(std::vector< Scalar > _knots)
Set the knotvector of the bspline surface in n direction.
Knotvector get_knotvector_m()
Get the knotvector in m direction.
unsigned int n_knots_n()
Returns the number of knots in n direction.
std::vector< Scalar > & get_knots_m()
get the knotvector in m direction of the bspline surface
PropertyNet cpselections_
list of control point properties
unsigned int degree_n_
Spline degree in n direction.
bool controlpoint_selections_available() const
Check if control point selection property is available.
void get_vector_m(std::vector< Point > &_control_polygon, unsigned int _m)
Returns an n control point vector.
unsigned int n_knots_m()
Returns the number of knots in m direction.
void reset_control_net()
Clears the control net.
Scalar lowerv()
Returns the lower v parameter.
Point & operator()(Vec2i _param)
Returns a reference to the control point (m, n)
void delete_vector_m(unsigned int _m)
Deletes an n control point vector.
Point & operator()(unsigned int _m, unsigned int _n)
Returns a reference to the control point (m, n)
unsigned int dimn_
number of control points in n direction
Scalar upperu()
Returns the upper u parameter.
void insert_knot_m(double _t)
Insert a knot i in m direction without changing the surface.
Knotvector knotvector_n_
Knotvector in n direction.
Scalar get_knot_m(int _i)
Get knot i in m direction.
PropertyNet eselections_
list of edge properties
void insert_vector_m(const std::vector< Point > &_control_polygon, unsigned int _m)
Inserts an n control point vector.
void surfacePointNormal(Point &_pt, Point &_normal, double _u, double _v)
Evaluates a spline surface at parameters _u and _v.
void get_vector_n(std::vector< Point > &_control_polygon, unsigned int _n)
Returns an m ctrPointVector.
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.
void insert_knot_n(double _t)
Insert a knot i in n direction without changing the surface.
Knotvector get_knotvector_n()
Get the knotvector in n direction.
Point derivativeSurfacePoint(double _u, double _v, int _derm, int _dern)
Returns the _derm&#39;th derivative of a spline surface.
Point & get_control_point(unsigned int _m, unsigned int _n)
Returns a reference to the control point (m, n)
Scalar get_knot_n(int _i)
Get knot i in n direction.
unsigned int degree_m_
Spline degree in m direction.
const Point & operator()(Vec2i _param) const
Returns a const reference to the control point (m, n)
Scalar derivativeBasisFunction(Knotvector &_knotvector, int _i, int _n, double _t, int _der)
Derivative of a Spline Basis Function.