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