Developer Documentation
KnotvectorT.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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 
51 //=============================================================================
52 //
53 // CLASS KnotvectorT
54 // Author: Ellen Dekkers <dekkers@cs.rwth-aachen.de>
55 //
56 //=============================================================================
57 
58 
59 #ifndef ACG_KNOTVECTORT_HH
60 #define ACG_KNOTVECTORT_HH
61 
62 //== INCLUDES =================================================================
63 
64 #include <iostream>
65 #include <string>
66 #include <vector>
67 #include <map>
68 #include <cassert>
69 
70 
71 //== FORWARDDECLARATIONS ======================================================
72 
73 //== NAMESPACES ===============================================================
74 
75 namespace ACG {
76 
77 //== CLASS DEFINITION =========================================================
78 
79 
83 template< typename Scalar >
84 class KnotvectorT {
85 
86 public:
87 
88  enum KnotvectorType {
89  UNIFORM_INTERPOL = 0,
90  UNIFORM = 1,
91  };
92 
94  KnotvectorT();
95 
97  KnotvectorT(const KnotvectorT& _knotvec);
98 
100  ~KnotvectorT();
101 
102  void setType(KnotvectorType _type);
103 
104  void createKnots(unsigned int _splineDeg, unsigned int _dim);
105 
106  inline std::vector< Scalar >& getKnotvector() {return knots_;}
107  inline const std::vector< Scalar >& getKnotvector() const { return knots_; }
108 
109  inline unsigned int size() const {return knots_.size();}
110 
111  inline Scalar getKnot(unsigned int _index) const {
112  assert(_index < knots_.size());
113  return knots_.at(_index);
114  }
115 
116  void setKnotvector(const std::vector< Scalar >& _knots);
117 
118  void resize(unsigned int _size) {knots_.resize(_size);}
119 
120  void insertKnot(unsigned int _index, const Scalar _knot);
121 
122  void addKnot(Scalar _knot);
123 
124  inline void setKnot(unsigned int _index, Scalar _knot) {
125  assert(_index < knots_.size());
126  knots_.at(_index) = _knot;
127  }
128 
129  void deleteKnot(unsigned int _index);
130 
131 
136  inline Scalar & operator()(unsigned int _index) {
137  assert (_index < knots_.size());
138  return knots_[_index];
139  }
140 
145  inline const Scalar & operator()(unsigned int _index) const {
146  assert (_index < knots_.size());
147  return knots_[_index];
148  }
149 
150  void clear() {knots_.clear();};
151 
152 
153 
154 public : // selection handling
155 
156  // request properties
157  void request_selections() { request_prop( ref_count_selections_, selections_);}
158 
159  // release properties
160  void release_selections() { release_prop( ref_count_selections_, selections_);}
161 
162  // property availability
163  bool selections_available() const {return bool(ref_count_selections_);}
164 
165  // property access ( no range or availability check! )
166  unsigned char& selection(unsigned int _i) {
167  assert(_i < selections_.size());
168  assert(selections_available());
169  return selections_[_i];
170  }
171  const unsigned char& selection(unsigned int _i) const {
172  assert(_i < selections_.size());
173  assert(selections_available());
174  return selections_[_i];
175  }
176 
177  // Wrapper for selection functions
178  void select(unsigned int _pIdx) { selection(_pIdx) = 1; };
179  void deselect(unsigned int _pIdx) { selection(_pIdx) = 0; };
180 
181  bool selected(unsigned int _pIdx) const { return (selection(_pIdx) == 1); };
182 
183 
184 private:
185 
186  template <class PropT>
187  void request_prop( unsigned int& _ref_count, PropT& _prop);
188 
189  template <class PropT>
190  void release_prop( unsigned int& _ref_count, PropT& _prop);
191 
192  // ############################### Standard Property Handling #############################
193 
194  // properties
195  std::vector<unsigned char> selections_;
196 
197  // property reference counter
198  unsigned int ref_count_selections_;
199 
200 private:
201 
202  std::vector<Scalar> knots_;
203 
204  KnotvectorType knotvectorType_;
205 
206  void createUniformInterpolatingKnots(unsigned int _splineDeg, unsigned int _dim);
207 
208  void createUniformKnots(unsigned int _splineDeg, unsigned int _dim);
209 
210  unsigned int num_control_points_;
211  unsigned int spline_degree_;
212 
213 };
214 
216 
217 
218 template< typename Scalar >
219 inline std::ostream& operator<<(std::ostream& _stream, const KnotvectorT< Scalar >& _knotvector) {
220 
221  KnotvectorT< Scalar > knotvector = _knotvector;
222  for (unsigned int i = 0; i < knotvector.size(); i++)
223  _stream << knotvector(i) << " ";
224 
225  return _stream;
226 }
227 
228 
229 template< typename Scalar >
230 inline std::istream& operator>>(std::istream& _is, KnotvectorT< Scalar >& _knotvector) {
231 
232  unsigned int size(0);
233  _is >> size;
234  _knotvector.resize(size);
235  for (unsigned int i = 0; i < size; i++)
236  _is >> _knotvector(i);
237 
238  return _is;
239 }
240 
241 
242 }
243 
244 //=============================================================================
245 #if defined(INCLUDE_TEMPLATES) && !defined(ACG_KNOTVECTORT_C)
246 #define ACG_KNOTVECTORT_TEMPLATES
247 #include "KnotvectorT.cc"
248 #endif
249 //=============================================================================
250 #endif // ACG_KNOTVECTORT_HH defined
251 //=============================================================================
KnotvectorT()
Constructor.
Definition: KnotvectorT.cc:67
Scalar & operator()(unsigned int _index)
returns a reference to the _index&#39;th knot
Definition: KnotvectorT.hh:136
~KnotvectorT()
Destructor.
Definition: KnotvectorT.cc:97
std::istream & operator>>(std::istream &is, Matrix4x4T< Scalar > &m)
read the space-separated components of a vector from a stream */
Definition: Matrix4x4T.hh:301
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
const Scalar & operator()(unsigned int _index) const
returns a const reference to the _index&#39;th knot
Definition: KnotvectorT.hh:145