Developer Documentation
Loading...
Searching...
No Matches
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
69namespace ACG {
70
71//== CLASS DEFINITION =========================================================
72
73
81template <class PointT>
83{
84public:
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
97 BSplineCurveT& operator= ( const BSplineCurveT & ) = default;
98
101
103 std::vector< Scalar >& get_knots() {return knotvector_.getKnotvector();};
104
106 void set_knots(std::vector< Scalar > _knots);
107
109 Knotvector * get_knotvector_ref(){return &knotvector_;};
110
112 void set_knotvector_type(Knotvector::KnotvectorType _type) {knotvector_.setType(_type);};
113
115 Scalar get_knot(int _i) {return knotvector_(_i);};
116
118 Point& get_control_point(int _i) {return control_polygon_[_i];};
119
121 void add_control_point(const Point& _cp);
122
124 void insert_control_point(int _idx, const Point& _cp);
125
127 void delete_control_point(int _idx);
128
130 void set_control_point(int _idx, const Point& _cp);
131
133 void set_control_polygon(std::vector< Point> & _control_polygon);
134
137
139 void print() const;
140
146 Point curvePoint( Scalar _u );
147
154 Point derivativeCurvePoint(Scalar _u, unsigned int _der);
155
161 std::vector<Point> deBoorAlgorithm(double _u);
162
164 void insertKnot(double _u);
165
167 unsigned int n_control_points() const {return control_polygon_.size();};
168
170 unsigned int n_knots() const { return knotvector_.size(); };
171
173 unsigned int degree() const {return degree_;};
174
176 void set_degree(unsigned int _degree) {degree_ = _degree;};
177
182 ACG::Vec2i span(double _t);
183
188 ACG::Vec2i interval(double _t);
189
190 void autocompute_knotvector(bool _auto) {autocompute_knotvector_ = _auto;};
191
192 void fixNumberOfControlPoints(bool _fix) {fix_number_control_points_ = _fix;};
193
198 bool projected() {return fix_number_control_points_;};
199
201 void reverse();
202
203
204public:
205
213 Scalar basisFunction(int _i, int _n, Scalar _t);
214
222 Scalar derivativeBasisFunction(int _i, int _n, Scalar _t, int _der);
223
224
225public:
226
228 Scalar lower() const;
229
231 Scalar upper() const;
232
233
234 // request properties
235 void request_controlpoint_selections() { request_prop( ref_count_cpselections_, cpselections_);}
236 void request_edge_selections() { request_prop( ref_count_eselections_, eselections_);}
237
238 // release properties
239 void release_controlpoint_selections() { release_prop( ref_count_cpselections_, cpselections_);}
240 void release_edge_selections() { release_prop( ref_count_eselections_, eselections_);}
241
242 // property availability
243 bool controlpoint_selections_available() const {return bool(ref_count_cpselections_);}
244 bool edge_selections_available() const {return bool(ref_count_eselections_);}
245
246
247 // property access ( no range or availability check! )
248 unsigned char& controlpoint_selection(unsigned int _i){
249 assert(_i < n_control_points());
250 assert(controlpoint_selections_available());
251 return cpselections_[_i];
252 }
253 const unsigned char& controlpoint_selection(unsigned int _i) const {
254 assert(_i < n_control_points());
255 assert(controlpoint_selections_available());
256 return cpselections_[_i];
257 }
258
259 unsigned char& edge_selection(unsigned int _i) {
260 assert(edge_selections_available());
261 return eselections_[_i];
262 }
263 const unsigned char& edge_selection(unsigned int _i) const {
264 assert(edge_selections_available());
265 return eselections_[_i];
266 }
267
268 // Wrapper for selection functions
269 void select_controlpoint(unsigned int _pIdx) { controlpoint_selection(_pIdx) = 1; };
270 void deselect_controlpoint(unsigned int _pIdx) { controlpoint_selection(_pIdx) = 0; };
271
272 bool controlpoint_selected(unsigned int _pIdx) const { return (controlpoint_selection(_pIdx) == 1); };
273
274 void select_edge(unsigned int _pIdx) { edge_selection(_pIdx) = 1; };
275 void deselect_edge(unsigned int _pIdx) { edge_selection(_pIdx) = 0; };
276
277 bool edge_selected(unsigned int _pIdx) const { return (edge_selection(_pIdx) == 1); };
278
279private:
280
281 template <class PropT>
282 void request_prop( unsigned int& _ref_count, PropT& _prop);
283
284 template <class PropT>
285 void release_prop( unsigned int& _ref_count, PropT& _prop);
286
287
288private: // private objects
289
290 std::vector<Point> control_polygon_;
291
292 Knotvector knotvector_;
293
294 unsigned int degree_;
295
296 bool autocompute_knotvector_;
297
298 bool fix_number_control_points_;
299
300private: // private properties
301
302 // ############################### Standard Property Handling #############################
303
304 // list of vertex properties
305 std::vector<unsigned char> cpselections_;
306
307 // list of edge properties
308 std::vector<unsigned char> eselections_;
309
310 // property reference counter
311 unsigned int ref_count_cpselections_;
312 unsigned int ref_count_eselections_;
313
314};
315
316
317//=============================================================================
318} // namespace ACG
319//=============================================================================
320#if defined(INCLUDE_TEMPLATES) && !defined(BSPLINECURVE_BSPLINECURVET_C)
321#define BSPLINECURVE_BSPLINECURVET_TEMPLATES
322#include "BSplineCurveT_impl.hh"
323#endif
324//=============================================================================
325#endif // ACG_BSPLINECURVET_HH defined
326//=============================================================================
327
std::vector< Scalar > & get_knots()
get the knotvector of the bspline curve
void set_knotvector_type(Knotvector::KnotvectorType _type)
set type of knotvector
bool projected()
projected
void add_control_point(const Point &_cp)
add a control point
void print() const
print information string
void set_knots(std::vector< Scalar > _knots)
set the knotvector of the bspline curve
Knotvector * get_knotvector_ref()
get a reference to the knotvector
void set_degree(unsigned int _degree)
Sets the spline degree.
unsigned int n_control_points() const
Returns the number of control points.
Scalar derivativeBasisFunction(int _i, int _n, Scalar _t, int _der)
Point & get_control_point(int _i)
get control point i
void delete_control_point(int _idx)
delete control point at given index
ACG::Vec2i interval(double _t)
ACG::Vec2i span(double _t)
~BSplineCurveT()
Destructor.
void reverse()
Reverses the curve.
std::vector< Point > deBoorAlgorithm(double _u)
Scalar get_knot(int _i)
get knot i
Scalar lower() const
Returns the lower parameter.
void insert_control_point(int _idx, const Point &_cp)
insert a control point at given index
void insertKnot(double _u)
Inserts a new knot at parameter u.
Scalar upper() const
Returns the upper parameter.
void set_control_point(int _idx, const Point &_cp)
reset a control point
Point curvePoint(Scalar _u)
void set_control_polygon(std::vector< Point > &_control_polygon)
set whole control polygon
Point derivativeCurvePoint(Scalar _u, unsigned int _der)
BSplineCurveT & operator=(const BSplineCurveT &)=default
Use the default = operator.
unsigned int n_knots() const
Returns the number of knots.
unsigned int degree() const
Returns the spline degree.
Scalar basisFunction(int _i, int _n, Scalar _t)
void reset_control_polygon()
Clears the control polygon.
Namespace providing different geometric functions concerning angles.