Developer Documentation
Loading...
Searching...
No Matches
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
69namespace ACG {
70
71//== CLASS DEFINITION =========================================================
72
73
77template< typename Scalar >
79
80public:
81
82 enum KnotvectorType {
83 UNIFORM_INTERPOL = 0,
84 UNIFORM = 1,
85 };
86
89
91 KnotvectorT(const KnotvectorT& _knotvec);
92
94 KnotvectorT& operator= ( const KnotvectorT & ) = default;
95
98
99 void setType(KnotvectorType _type);
100
101 void createKnots(unsigned int _splineDeg, unsigned int _dim);
102
103 inline std::vector< Scalar >& getKnotvector() {return knots_;}
104 inline const std::vector< Scalar >& getKnotvector() const { return knots_; }
105
106 inline unsigned int size() const {return knots_.size();}
107
108 inline Scalar getKnot(unsigned int _index) const {
109 assert(_index < knots_.size());
110 return knots_.at(_index);
111 }
112
113 void setKnotvector(const std::vector< Scalar >& _knots);
114
115 void resize(unsigned int _size) {knots_.resize(_size);}
116
117 void insertKnot(unsigned int _index, const Scalar _knot);
118
119 void addKnot(Scalar _knot);
120
121 inline void setKnot(unsigned int _index, Scalar _knot) {
122 assert(_index < knots_.size());
123 knots_.at(_index) = _knot;
124 }
125
126 void deleteKnot(unsigned int _index);
127
128
133 inline Scalar & operator()(unsigned int _index) {
134 assert (_index < knots_.size());
135 return knots_[_index];
136 }
137
142 inline const Scalar & operator()(unsigned int _index) const {
143 assert (_index < knots_.size());
144 return knots_[_index];
145 }
146
147 void clear() {knots_.clear();};
148
149
150
151public : // selection handling
152
153 // request properties
154 void request_selections() { request_prop( ref_count_selections_, selections_);}
155
156 // release properties
157 void release_selections() { release_prop( ref_count_selections_, selections_);}
158
159 // property availability
160 bool selections_available() const {return bool(ref_count_selections_);}
161
162 // property access ( no range or availability check! )
163 unsigned char& selection(unsigned int _i) {
164 assert(_i < selections_.size());
165 assert(selections_available());
166 return selections_[_i];
167 }
168 const unsigned char& selection(unsigned int _i) const {
169 assert(_i < selections_.size());
170 assert(selections_available());
171 return selections_[_i];
172 }
173
174 // Wrapper for selection functions
175 void select(unsigned int _pIdx) { selection(_pIdx) = 1; };
176 void deselect(unsigned int _pIdx) { selection(_pIdx) = 0; };
177
178 bool selected(unsigned int _pIdx) const { return (selection(_pIdx) == 1); };
179
180
181private:
182
183 template <class PropT>
184 void request_prop( unsigned int& _ref_count, PropT& _prop);
185
186 template <class PropT>
187 void release_prop( unsigned int& _ref_count, PropT& _prop);
188
189 // ############################### Standard Property Handling #############################
190
191 // properties
192 std::vector<unsigned char> selections_;
193
194 // property reference counter
195 unsigned int ref_count_selections_;
196
197private:
198
199 std::vector<Scalar> knots_;
200
201 KnotvectorType knotvectorType_;
202
203 void createUniformInterpolatingKnots(unsigned int _splineDeg, unsigned int _dim);
204
205 void createUniformKnots(unsigned int _splineDeg, unsigned int _dim);
206
207 unsigned int num_control_points_;
208 unsigned int spline_degree_;
209
210};
211
213
214
215template< typename Scalar >
216inline std::ostream& operator<<(std::ostream& _stream, const KnotvectorT< Scalar >& _knotvector) {
217
218 KnotvectorT< Scalar > knotvector = _knotvector;
219 for (unsigned int i = 0; i < knotvector.size(); i++)
220 _stream << knotvector(i) << " ";
221
222 return _stream;
223}
224
225
226template< typename Scalar >
227inline std::istream& operator>>(std::istream& _is, KnotvectorT< Scalar >& _knotvector) {
228
229 unsigned int size(0);
230 _is >> size;
231 _knotvector.resize(size);
232 for (unsigned int i = 0; i < size; i++)
233 _is >> _knotvector(i);
234
235 return _is;
236}
237
238
239}
240
241//=============================================================================
242#if defined(INCLUDE_TEMPLATES) && !defined(ACG_KNOTVECTORT_C)
243#define ACG_KNOTVECTORT_TEMPLATES
244#include "KnotvectorT_impl.hh"
245#endif
246//=============================================================================
247#endif // ACG_KNOTVECTORT_HH defined
248//=============================================================================
const Scalar & operator()(unsigned int _index) const
returns a const reference to the _index'th knot
KnotvectorT()
Constructor.
KnotvectorT & operator=(const KnotvectorT &)=default
Use the default = operator.
~KnotvectorT()
Destructor.
Scalar & operator()(unsigned int _index)
returns a reference to the _index'th knot
Namespace providing different geometric functions concerning angles.
std::ostream & operator<<(std::ostream &os, const Matrix4x4T< Scalar > &m)
output matrix to ostream os
std::istream & operator>>(std::istream &is, Matrix4x4T< Scalar > &m)
read the space-separated components of a vector from a stream *‍/