Developer Documentation
KnotvectorT_impl.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 KnotvectorT - IMPLEMENTATION
48 // Author: Ellen Dekkers <dekkers@cs.rwth-aachen.de>
49 //
50 //=============================================================================
51 
52 
53 #define ACG_KNOTVECTORT_C
54 
55 #include "KnotvectorT.hh"
56 
57 namespace ACG {
58 
59 template < typename Scalar >
62  : ref_count_selections_(0), knotvectorType_(UNIFORM_INTERPOL),num_control_points_(0),spline_degree_(0)
63 {
64 }
65 
66 //-----------------------------------------------------------------------------
67 
68 template < typename Scalar >
70 KnotvectorT( const KnotvectorT& _knotvec )
71  : selections_(_knotvec.selections_),
72  ref_count_selections_( _knotvec.ref_count_selections_),
73  knots_(_knotvec.knots_),
74  knotvectorType_(_knotvec.knotvectorType_),
75  num_control_points_(_knotvec.num_control_points_),
76  spline_degree_(_knotvec.spline_degree_)
77 {
78 
79 }
80 
81 //-----------------------------------------------------------------------------
82 
83 template< typename Scalar >
86 {
87 }
88 
89 //-----------------------------------------------------------------------------
90 
91 template <typename Scalar >
92 void
94 setType(KnotvectorType _type)
95 {
96  knotvectorType_ = _type;
97 
98  if ( (spline_degree_ != 0) && (num_control_points_ != 0))
99  createKnots(spline_degree_, num_control_points_);
100 }
101 
102 //-----------------------------------------------------------------------------
103 
104 template <typename Scalar >
105 void
107 createKnots(unsigned int _splineDeg, unsigned int _dim)
108 {
109  num_control_points_ = _dim;
110  spline_degree_ = _splineDeg;
111 
112  if (knotvectorType_ == UNIFORM)
113  createUniformKnots(_splineDeg, _dim);
114  else if (knotvectorType_ == UNIFORM_INTERPOL)
115  createUniformInterpolatingKnots(_splineDeg, _dim);
116 };
117 
118 //-----------------------------------------------------------------------------
119 
120 template <typename Scalar >
121 void
123 addKnot(Scalar _knot)
124 {
125  knots_.push_back(_knot);
126 
127  // add available property
128  if( selections_available())
129  selections_.push_back( false);
130 }
131 
132 //-----------------------------------------------------------------------------
133 
134 template <typename Scalar >
135 void
137 insertKnot(unsigned int _index, const Scalar _knot)
138 {
139  assert(_index < knots_.size());
140  knots_.insert(knots_.begin()+_index, _knot);
141 
142  // add available property
143  if( selections_available())
144  selections_.insert(selections_.begin()+_index, false);
145 }
146 
147 //-----------------------------------------------------------------------------
148 
149 template< typename Scalar >
150 void
152 deleteKnot(unsigned int _index)
153 {
154  assert(_index < knots_.size());
155  knots_.erase(knots_.begin()+_index);
156 
157  if( selections_available())
158  selections_.erase(selections_.begin()+_index);
159 }
160 
161 //-----------------------------------------------------------------------------
162 
163 template< typename Scalar >
164 void
166 setKnotvector(const std::vector< Scalar >& _knots)
167 {
168  knots_ = _knots;
169 
170  selections_.clear();
171  if( selections_available())
172  selections_.resize(knots_.size(), false);
173 }
174 
175 
176 //-----------------------------------------------------------------------------
177 
178 
179 template< typename Scalar >
180 void
182 createUniformInterpolatingKnots(unsigned int _splineDeg, unsigned int _dim)
183 {
184  knots_.clear();
185 
186  float last=0.0;
187 
188  for (unsigned int i = 0; i < _splineDeg; i++)
189  knots_.push_back(0); // p+1
190 
191  for (int i = 0; i < (int)_dim - (int)_splineDeg + 1; i++) {
192  knots_.push_back(i);
193  last=i;
194  }
195 
196  for (unsigned int i = 0; i < _splineDeg; i++)
197  knots_.push_back(last); // p+1
198 
199  selections_.clear();
200  if( selections_available())
201  selections_.resize(knots_.size(), false);
202 
203 // std::cout << "Added " << knots_.size() << " interpolating knots (deg = " << p << ", dim = " << n+1 << ")" << std::endl;
204 // for (unsigned int i = 0; i < knots_.size(); ++i)
205 // std::cout << knots_[i] << ", " << std::flush;
206 // std::cout << std::endl;
207 }
208 
209 //-----------------------------------------------------------------------------
210 
211 template< typename Scalar >
212 void
214 createUniformKnots(unsigned int _splineDeg, unsigned int _dim)
215 {
216  knots_.clear();
217 
218  // number of required knots
219  int k = _dim + _splineDeg + 1;
220 
221  for ( int i = 0; i < k; ++i )
222  knots_.push_back(i);
223 
224  selections_.clear();
225  if( selections_available())
226  selections_.resize(knots_.size(), false);
227 
228 // std::cout << "Added " << knots_.size() << " uniform knots (deg = " << _splineDeg << ", dim = " << _dim << ")" << std::endl;
229 // for (unsigned int i = 0; i < knots_.size(); ++i)
230 // std::cout << knots_[i] << ", " << std::flush;
231 // std::cout << std::endl;
232 }
233 
234 
235 //-----------------------------------------------------------------------------
236 
237 
238 template< typename Scalar >
239 template <class PropT>
240 void
242 request_prop( unsigned int& _ref_count, PropT& _prop)
243 {
244  if(_ref_count == 0)
245  {
246  _ref_count = 1;
247  _prop.resize(size());
248  }
249  else ++_ref_count;
250 }
251 
252 
253 //-----------------------------------------------------------------------------
254 
255 template< typename Scalar >
256 template <class PropT>
257 void
259 release_prop( unsigned int& _ref_count, PropT& _prop)
260 {
261  if( _ref_count <= 1)
262  {
263  _ref_count = 0;
264  _prop.clear();
265  }
266  else --_ref_count;
267 }
268 
269 
270 }
Namespace providing different geometric functions concerning angles.
KnotvectorT()
Constructor.