Developer Documentation
BSplineCurveT.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 BSplineCurveT
54 // Author: Ellen Dekkers <dekkers@cs.rwth-aachen.de>
55 //
56 //=============================================================================
57 
58 
59 #ifndef BSPLINECURVET_HH
60 #define BSPLINECURVET_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 
97  BSplineCurveT(unsigned int _degree = 3);
98 
100  BSplineCurveT(const BSplineCurveT& _curve);
101 
104 
106  std::vector< Scalar >& get_knots() {return knotvector_.getKnotvector();};
107 
109  void set_knots(std::vector< Scalar > _knots);
110 
112  Knotvector * get_knotvector_ref(){return &knotvector_;};
113 
115  void set_knotvector_type(Knotvector::KnotvectorType _type) {knotvector_.setType(_type);};
116 
118  Scalar get_knot(int _i) {return knotvector_(_i);};
119 
121  Point& get_control_point(int _i) {return control_polygon_[_i];};
122 
124  void add_control_point(const Point& _cp);
125 
127  void insert_control_point(int _idx, const Point& _cp);
128 
130  void delete_control_point(int _idx);
131 
133  void set_control_point(int _idx, const Point& _cp);
134 
136  void set_control_polygon(std::vector< Point> & _control_polygon);
137 
139  void reset_control_polygon();
140 
142  void print() const;
143 
149  Point curvePoint( Scalar _u );
150 
157  Point derivativeCurvePoint(Scalar _u, unsigned int _der);
158 
164  std::vector<Point> deBoorAlgorithm(double _u);
165 
167  void insertKnot(double _u);
168 
170  unsigned int n_control_points() const {return control_polygon_.size();};
171 
173  unsigned int n_knots() const { return knotvector_.size(); };
174 
176  unsigned int degree() const {return degree_;};
177 
179  void set_degree(unsigned int _degree) {degree_ = _degree;};
180 
185  ACG::Vec2i span(double _t);
186 
191  ACG::Vec2i interval(double _t);
192 
193  void autocompute_knotvector(bool _auto) {autocompute_knotvector_ = _auto;};
194 
195  void fixNumberOfControlPoints(bool _fix) {fix_number_control_points_ = _fix;};
196 
201  bool projected() {return fix_number_control_points_;};
202 
204  void reverse();
205 
206 
207 public:
208 
216  Scalar basisFunction(int _i, int _n, Scalar _t);
217 
225  Scalar derivativeBasisFunction(int _i, int _n, Scalar _t, int _der);
226 
227 
228 public:
229 
231  Scalar lower() const;
232 
234  Scalar upper() const;
235 
236 
237  // request properties
238  void request_controlpoint_selections() { request_prop( ref_count_cpselections_, cpselections_);}
239  void request_edge_selections() { request_prop( ref_count_eselections_, eselections_);}
240 
241  // release properties
242  void release_controlpoint_selections() { release_prop( ref_count_cpselections_, cpselections_);}
243  void release_edge_selections() { release_prop( ref_count_eselections_, eselections_);}
244 
245  // property availability
246  bool controlpoint_selections_available() const {return bool(ref_count_cpselections_);}
247  bool edge_selections_available() const {return bool(ref_count_eselections_);}
248 
249 
250  // property access ( no range or availability check! )
251  unsigned char& controlpoint_selection(unsigned int _i){
252  assert(_i < n_control_points());
253  assert(controlpoint_selections_available());
254  return cpselections_[_i];
255  }
256  const unsigned char& controlpoint_selection(unsigned int _i) const {
257  assert(_i < n_control_points());
258  assert(controlpoint_selections_available());
259  return cpselections_[_i];
260  }
261 
262  unsigned char& edge_selection(unsigned int _i) {
263  assert(edge_selections_available());
264  return eselections_[_i];
265  }
266  const unsigned char& edge_selection(unsigned int _i) const {
267  assert(edge_selections_available());
268  return eselections_[_i];
269  }
270 
271  // Wrapper for selection functions
272  void select_controlpoint(unsigned int _pIdx) { controlpoint_selection(_pIdx) = 1; };
273  void deselect_controlpoint(unsigned int _pIdx) { controlpoint_selection(_pIdx) = 0; };
274 
275  bool controlpoint_selected(unsigned int _pIdx) const { return (controlpoint_selection(_pIdx) == 1); };
276 
277  void select_edge(unsigned int _pIdx) { edge_selection(_pIdx) = 1; };
278  void deselect_edge(unsigned int _pIdx) { edge_selection(_pIdx) = 0; };
279 
280  bool edge_selected(unsigned int _pIdx) const { return (edge_selection(_pIdx) == 1); };
281 
282 private:
283 
284  template <class PropT>
285  void request_prop( unsigned int& _ref_count, PropT& _prop);
286 
287  template <class PropT>
288  void release_prop( unsigned int& _ref_count, PropT& _prop);
289 
290 
291 private: // private objects
292 
293  std::vector<Point> control_polygon_;
294 
295  Knotvector knotvector_;
296 
297  unsigned int degree_;
298 
299  bool autocompute_knotvector_;
300 
301  bool fix_number_control_points_;
302 
303 private: // private properties
304 
305  // ############################### Standard Property Handling #############################
306 
307  // list of vertex properties
308  std::vector<unsigned char> cpselections_;
309 
310  // list of edge properties
311  std::vector<unsigned char> eselections_;
312 
313  // property reference counter
314  unsigned int ref_count_cpselections_;
315  unsigned int ref_count_eselections_;
316 
317 };
318 
319 
320 //=============================================================================
321 } // namespace ACG
322 //=============================================================================
323 #if defined(INCLUDE_TEMPLATES) && !defined(BSPLINECURVE_BSPLINECURVET_C)
324 #define BSPLINECURVE_BSPLINECURVET_TEMPLATES
325 #include "BSplineCurveT.cc"
326 #endif
327 //=============================================================================
328 #endif // ACG_BSPLINECURVET_HH defined
329 //=============================================================================
330 
void set_control_polygon(std::vector< Point > &_control_polygon)
set whole control polygon
void set_degree(unsigned int _degree)
Sets the spline degree.
BSplineCurveT(unsigned int _degree=3)
Constructor.
ACG::Vec2i interval(double _t)
void delete_control_point(int _idx)
delete control point at given index
Scalar derivativeBasisFunction(int _i, int _n, Scalar _t, int _der)
Scalar get_knot(int _i)
get knot i
void set_knotvector_type(Knotvector::KnotvectorType _type)
set type of knotvector
Scalar upper() const
Returns the upper parameter.
void reset_control_polygon()
Clears the control polygon.
Point & get_control_point(int _i)
get control point i
unsigned int n_control_points() const
Returns the number of control points.
std::vector< Scalar > & get_knots()
get the knotvector of the bspline curve
~BSplineCurveT()
Destructor.
void reverse()
Reverses the curve.
unsigned int n_knots() const
Returns the number of knots.
void set_control_point(int _idx, const Point &_cp)
reset a control point
void insertKnot(double _u)
Inserts a new knot at parameter u.
void print() const
print information string
unsigned int degree() const
Returns the spline degree.
Scalar basisFunction(int _i, int _n, Scalar _t)
Point curvePoint(Scalar _u)
std::vector< Point > deBoorAlgorithm(double _u)
void add_control_point(const Point &_cp)
add a control point
bool projected()
projected
void insert_control_point(int _idx, const Point &_cp)
insert a control point at given index
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
ACG::Vec2i span(double _t)
Knotvector * get_knotvector_ref()
get a reference to the knotvector
void set_knots(std::vector< Scalar > _knots)
set the knotvector of the bspline curve
Scalar lower() const
Returns the lower parameter.
Point derivativeCurvePoint(Scalar _u, unsigned int _der)