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>
82 class BSplineCurveT
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
97 ~BSplineCurveT() {}
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
ACG
Namespace providing different geometric functions concerning angles.
Definition: BaseObjectData.hh:68
ACG::BSplineCurveT::n_control_points
unsigned int n_control_points() const
Returns the number of control points.
Definition: BSplineCurveT.hh:164
ACG::BSplineCurveT::derivativeBasisFunction
Scalar derivativeBasisFunction(int _i, int _n, Scalar _t, int _der)
Definition: BSplineCurveT_impl.hh:374
ACG::BSplineCurveT::set_knotvector_type
void set_knotvector_type(Knotvector::KnotvectorType _type)
set type of knotvector
Definition: BSplineCurveT.hh:109
ACG::BSplineCurveT::basisFunction
Scalar basisFunction(int _i, int _n, Scalar _t)
Definition: BSplineCurveT_impl.hh:335
ACG::BSplineCurveT::projected
bool projected()
projected
Definition: BSplineCurveT.hh:195
ACG::BSplineCurveT::~BSplineCurveT
~BSplineCurveT()
Destructor.
Definition: BSplineCurveT.hh:97
ACG::BSplineCurveT::set_knots
void set_knots(std::vector< Scalar > _knots)
set the knotvector of the bspline curve
Definition: BSplineCurveT_impl.hh:558
ACG::BSplineCurveT::curvePoint
Point curvePoint(Scalar _u)
Definition: BSplineCurveT_impl.hh:280
ACG::BSplineCurveT::degree
unsigned int degree() const
Returns the spline degree.
Definition: BSplineCurveT.hh:170
ACG::BSplineCurveT::reset_control_polygon
void reset_control_polygon()
Clears the control polygon.
Definition: BSplineCurveT_impl.hh:266
ACG::BSplineCurveT::insertKnot
void insertKnot(double _u)
Inserts a new knot at parameter u.
Definition: BSplineCurveT_impl.hh:515
ACG::BSplineCurveT::get_knotvector_ref
Knotvector * get_knotvector_ref()
get a reference to the knotvector
Definition: BSplineCurveT.hh:106
ACG::BSplineCurveT::span
ACG::Vec2i span(double _t)
Definition: BSplineCurveT_impl.hh:468
ACG::BSplineCurveT::add_control_point
void add_control_point(const Point &_cp)
add a control point
Definition: BSplineCurveT_impl.hh:149
ACG::BSplineCurveT::n_knots
unsigned int n_knots() const
Returns the number of knots.
Definition: BSplineCurveT.hh:167
ACG::BSplineCurveT
Definition: BSplineCurveT.hh:82
ACG::BSplineCurveT::insert_control_point
void insert_control_point(int _idx, const Point &_cp)
insert a control point at given index
Definition: BSplineCurveT_impl.hh:174
ACG::BSplineCurveT::derivativeCurvePoint
Point derivativeCurvePoint(Scalar _u, unsigned int _der)
Definition: BSplineCurveT_impl.hh:310
ACG::BSplineCurveT::reverse
void reverse()
Reverses the curve.
Definition: BSplineCurveT_impl.hh:571
ACG::BSplineCurveT::get_control_point
Point & get_control_point(int _i)
get control point i
Definition: BSplineCurveT.hh:115
ACG::BSplineCurveT::print
void print() const
print information string
Definition: BSplineCurveT_impl.hh:501
ACG::BSplineCurveT::set_control_polygon
void set_control_polygon(std::vector< Point > &_control_polygon)
set whole control polygon
Definition: BSplineCurveT_impl.hh:245
ACG::BSplineCurveT::deBoorAlgorithm
std::vector< Point > deBoorAlgorithm(double _u)
Definition: BSplineCurveT_impl.hh:401
OpenMesh::VectorT
Definition: Vector11T.hh:83
ACG::BSplineCurveT::set_degree
void set_degree(unsigned int _degree)
Sets the spline degree.
Definition: BSplineCurveT.hh:173
ACG::BSplineCurveT::set_control_point
void set_control_point(int _idx, const Point &_cp)
reset a control point
Definition: BSplineCurveT_impl.hh:234
ACG::BSplineCurveT::lower
Scalar lower() const
Returns the lower parameter.
Definition: BSplineCurveT_impl.hh:448
ACG::BSplineCurveT::interval
ACG::Vec2i interval(double _t)
Definition: BSplineCurveT_impl.hh:487
ACG::BSplineCurveT::get_knots
std::vector< Scalar > & get_knots()
get the knotvector of the bspline curve
Definition: BSplineCurveT.hh:100
ACG::BSplineCurveT::upper
Scalar upper() const
Returns the upper parameter.
Definition: BSplineCurveT_impl.hh:458
ACG::BSplineCurveT::BSplineCurveT
BSplineCurveT(unsigned int _degree=3)
Constructor.
Definition: BSplineCurveT_impl.hh:76
ACG::BSplineCurveT::delete_control_point
void delete_control_point(int _idx)
delete control point at given index
Definition: BSplineCurveT_impl.hh:205
ACG::KnotvectorT< double >
ACG::BSplineCurveT::get_knot
Scalar get_knot(int _i)
get knot i
Definition: BSplineCurveT.hh:112