Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
BSplineCurveT.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
5 * www.openflipper.org *
6 * *
7 *--------------------------------------------------------------------------- *
8 * This file is part of OpenFlipper. *
9 * *
10 * OpenFlipper is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU Lesser General Public License as *
12 * published by the Free Software Foundation, either version 3 of *
13 * the License, or (at your option) any later version with the *
14 * following exceptions: *
15 * *
16 * If other files instantiate templates or use macros *
17 * or inline functions from this file, or you compile this file and *
18 * link it with other files to produce an executable, this file does *
19 * not by itself cause the resulting executable to be covered by the *
20 * GNU Lesser General Public License. This exception does not however *
21 * invalidate any other reasons why the executable file might be *
22 * covered by the GNU Lesser General Public License. *
23 * *
24 * OpenFlipper is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU Lesser General Public License for more details. *
28 * *
29 * You should have received a copy of the GNU LesserGeneral Public *
30 * License along with OpenFlipper. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36 * *
37 * $Revision: 14193 $ *
38 * $LastChangedBy: moebius $ *
39 * $Date: 2012-03-21 10:12:35 +0100 (Mi, 21 Mär 2012) $ *
40 * *
41 \*===========================================================================*/
42 
43 
44 //=============================================================================
45 //
46 // CLASS BSplineCurveT
47 // Author: Ellen Dekkers <dekkers@cs.rwth-aachen.de>
48 //
49 //=============================================================================
50 
51 
52 #ifndef BSPLINECURVET_HH
53 #define BSPLINECURVET_HH
54 
55 
56 //== INCLUDES =================================================================
57 #include <vector>
58 #include <iostream>
59 
60 #include <ACG/Math/VectorT.hh>
61 
62 #include <ObjectTypes/Knotvector/KnotvectorT.hh>
63 
64 //== FORWARDDECLARATIONS ======================================================
65 
66 //== NAMESPACES ===============================================================
67 
68 namespace ACG {
69 
70 //== CLASS DEFINITION =========================================================
71 
72 
80 template <class PointT>
82 {
83 public:
84 
85  // internal relevant Types
86  typedef PointT Point;
87  typedef typename Point::value_type Scalar;
88 
90  BSplineCurveT(unsigned int _degree = 3);
91 
93  BSplineCurveT(const BSplineCurveT& _curve);
94 
97 
99  std::vector< Scalar >& get_knots() {return knotvector_.getKnotvector();};
100 
102  void set_knots(std::vector< Scalar > _knots);
103 
105  Knotvector * get_knotvector_ref(){return &knotvector_;};
106 
108  void set_knotvector_type(Knotvector::KnotvectorType _type) {knotvector_.setType(_type);};
109 
111  Scalar get_knot(int _i) {return knotvector_(_i);};
112 
114  Point& get_control_point(int _i) {return control_polygon_[_i];};
115 
117  void add_control_point(const Point& _cp);
118 
120  void insert_control_point(int _idx, const Point& _cp);
121 
123  void delete_control_point(int _idx);
124 
126  void set_control_point(int _idx, Point& _cp);
127 
129  void set_control_polygon(std::vector< Point> & _control_polygon);
130 
132  void reset_control_polygon();
133 
135  void print() const;
136 
142  Point curvePoint( double _u );
143 
150  Point derivativeCurvePoint(double _u, unsigned int _der);
151 
157  std::vector<Point> deBoorAlgorithm(double _u);
158 
160  void insertKnot(double _u);
161 
163  unsigned int n_control_points() const {return control_polygon_.size();};
164 
166  unsigned int n_knots() { return knotvector_.size(); };
167 
169  unsigned int degree() {return degree_;};
170 
172  void set_degree(unsigned int _degree) {degree_ = _degree;};
173 
178  ACG::Vec2i span(double _t);
179 
184  ACG::Vec2i interval(double _t);
185 
186  void autocompute_knotvector(bool _auto) {autocompute_knotvector_ = _auto;};
187 
188  void fixNumberOfControlPoints(bool _fix) {fix_number_control_points_ = _fix;};
189 
194  bool projected() {return fix_number_control_points_;};
195 
197  void reverse();
198 
199 
200 public:
201 
209  Scalar basisFunction(int _i, int _n, double _t);
210 
218  Scalar derivativeBasisFunction(int _i, int _n, double _t, int _der);
219 
220 
221 private: // private functions
222 
224  Scalar lower();
225 
227  Scalar upper();
228 
229 
230 public :
231 
232  // request properties
233  void request_controlpoint_selections() { request_prop( ref_count_cpselections_, cpselections_);}
234  void request_edge_selections() { request_prop( ref_count_eselections_, eselections_);}
235 
236  // release properties
237  void release_controlpoint_selections() { release_prop( ref_count_cpselections_, cpselections_);}
238  void release_edge_selections() { release_prop( ref_count_eselections_, eselections_);}
239 
240  // property availability
241  bool controlpoint_selections_available() const {return bool(ref_count_cpselections_);}
242  bool edge_selections_available() const {return bool(ref_count_eselections_);}
243 
244 
245  // property access ( no range or availability check! )
246  unsigned char& controlpoint_selection(unsigned int _i){
247  assert(_i < n_control_points());
248  assert(controlpoint_selections_available());
249  return cpselections_[_i];
250  }
251  const unsigned char& controlpoint_selection(unsigned int _i) const {
252  assert(_i < n_control_points());
253  assert(controlpoint_selections_available());
254  return cpselections_[_i];
255  }
256 
257  unsigned char& edge_selection(unsigned int _i) {
258  assert(edge_selections_available());
259  return eselections_[_i];
260  }
261  const unsigned char& edge_selection(unsigned int _i) const {
262  assert(edge_selections_available());
263  return eselections_[_i];
264  }
265 
266  // Wrapper for selection functions
267  void select_controlpoint(unsigned int _pIdx) { controlpoint_selection(_pIdx) = 1; };
268  void deselect_controlpoint(unsigned int _pIdx) { controlpoint_selection(_pIdx) = 0; };
269 
270  bool controlpoint_selected(unsigned int _pIdx) const { return (controlpoint_selection(_pIdx) == 1); };
271 
272  void select_edge(unsigned int _pIdx) { edge_selection(_pIdx) = 1; };
273  void deselect_edge(unsigned int _pIdx) { edge_selection(_pIdx) = 0; };
274 
275  bool edge_selected(unsigned int _pIdx) const { return (edge_selection(_pIdx) == 1); };
276 
277 private:
278 
279  template <class PropT>
280  void request_prop( unsigned int& _ref_count, PropT& _prop);
281 
282  template <class PropT>
283  void release_prop( unsigned int& _ref_count, PropT& _prop);
284 
285 
286 private: // private objects
287 
288  std::vector<Point> control_polygon_;
289 
290  Knotvector knotvector_;
291 
292  unsigned int degree_;
293 
294  bool autocompute_knotvector_;
295 
296  bool fix_number_control_points_;
297 
298 private: // private properties
299 
300  // ############################### Standard Property Handling #############################
301 
302  // list of vertex properties
303  std::vector<unsigned char> cpselections_;
304 
305  // list of edge properties
306  std::vector<unsigned char> eselections_;
307 
308  // property reference counter
309  unsigned int ref_count_cpselections_;
310  unsigned int ref_count_eselections_;
311 
312 };
313 
314 
315 //=============================================================================
316 } // namespace ACG
317 //=============================================================================
318 #if defined(INCLUDE_TEMPLATES) && !defined(BSPLINECURVE_BSPLINECURVET_C)
319 #define BSPLINECURVE_BSPLINECURVET_TEMPLATES
320 #include "BSplineCurveT.cc"
321 #endif
322 //=============================================================================
323 #endif // ACG_BSPLINECURVET_HH defined
324 //=============================================================================
325