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