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 * $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>
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 
122 
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 
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 
unsigned int n_knots_m()
Returns the number of knots in m direction.
std::vector< Scalar > & get_knots_m()
get the knotvector in m direction of the bspline surface
unsigned int degree_m_
Spline degree in m direction.
std::vector< Scalar > & get_knots_n()
get the knotvector in m direction of the bspline surface
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.
void request_controlpoint_selections()
request control point selection property
Scalar basisFunction(Knotvector &_knotvector, int _i, int _n, double _t)
A Spline Basis Function.
Point & operator()(unsigned int _m, unsigned int _n)
Returns a reference to the control point (m, n)
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
void release_edge_selections()
release edge selection property
BSplineSurfaceT(unsigned int _degm=3, unsigned int _degn=3)
Constructor.
const Point & operator()(unsigned int _m, unsigned int _n) const
Returns a const reference to the control point (m, n)
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 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.
Scalar get_knot_n(int _i)
Get knot i in n direction.
void delete_vector_m(unsigned int _m)
Deletes an n control point vector.
void reset_control_net()
Clears the control net.
bool edge_selections_available() const
Check if edge selection property is available.
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.
Knotvector * get_knotvector_n_ref()
Get a reference to the knotvector in n direction.
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.
Scalar get_knot_m(int _i)
Get knot i in m direction.
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
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.
int degree_m() const
Returns the spline degree in m direction.
Point & get_control_point(unsigned int _m, unsigned int _n)
Returns a reference to the control point (m, n)
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.
const Point & operator()(Vec2i _param) const
Returns a const reference to the control point (m, n)
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.
bool controlpoint_selections_available() const
Check if control point selection property is available.
Knotvector * get_knotvector_m_ref()
Get a reference to the knotvector in m direction.
Scalar upperv()
Returns the upper v parameter.
Point & operator()(Vec2i _param)
Returns a reference to the control point (m, n)
void release_controlpoint_selections()
release control point selection property
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&#39;th derivative of a spline surface.
void add_vector_n(const std::vector< Point > &_control_polygon)
Adds a control point m-vector.
unsigned int n_knots_n()
Returns the number of knots in n direction.
void request_edge_selections()
request edge selection property