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