All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
nurbs_curve.h
1 /* Copyright (C) 2004-2014 MBSim Development Team
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Contact: martin.o.foerg@googlemail.com
18  */
19 
20 #ifndef NURBS_CURVE_FMATVEC_H_
21 #define NURBS_CURVE_FMATVEC_H_
22 
23 #include <mbsim/numerics/nurbs/nurbs_defs.h>
24 
25 namespace fmatvec {
26  typedef Matrix<General, Fixed<4>, Var, double> Mat4xV;
27 
28  typedef Matrix<General, Var, Fixed<4>, double> MatVx4;
29 }
30 
31 using namespace std;
32 using namespace fmatvec;
33 
34 namespace MBSim {
35 
41  class NurbsCurve {
42  public:
46  NurbsCurve();
47 // NurbsCurve(Matrix<T> inverse) {
48 // Inverse = inverse;
49 // Inverse_setted = 1;
50 // } //changed
51 // NurbsCurve(const NurbsCurve<T, N>& nurb);
52 // NurbsCurve(const Vector<fmatvec::HPoint<3> >& P1, const std::vector<double> &U1, int deg = 3);
53 // NurbsCurve(const Vector<fmatvec::Point<3> >& P1, const std::vector<double> &W, const std::vector<double> &U1, int deg = 3);
54  virtual ~NurbsCurve(); // empty destructor
55 
56  // Reference to internal data
58  int degree() const
59  {
60  return deg;
61  }
63  const fmatvec::MatVx4 & ctrlPnts() const
64  {
65  return P;
66  }
68  const fmatvec::Vec4 ctrlPnts(int i) const
69  {
70  return trans(P.row(i));
71  }
73  const fmatvec::Vec& knot() const
74  {
75  return U;
76  }
78  double knot(int i) const
79  {
80  return U(i);
81  }
82 
83  const fmatvec::Vec getuVec() const {
84  return u;
85  }
86 
87  // basic functions
88 
89 // virtual void reset(const Vector<fmatvec::HPoint<3> >& P1, const std::vector<double> &U1, int deg);
90 // virtual NurbsCurve& operator=(const NurbsCurve<T, N>&);
91 //
92 // // Evaluattion functions
93  virtual fmatvec::HPoint<3> operator()(double u) const;
95  fmatvec::HPoint<3> hpointAt(double u) const
96  {
97  return operator()(u);
98  }
99  fmatvec::HPoint<3> hpointAt(double u, int span) const;
100  fmatvec::Point<3> pointAt(double u) const;
101 // //! a function interface to operator()
102 // friend fmatvec::HPoint<3> C(double u, const NurbsCurve<T, N>& nurb) {
103 // return nurb(u);
104 // }
105 // //! returns the curvePoint in 3D
106 // friend fmatvec::Point<3> Cp(double u, const NurbsCurve<T, N>& nurb) {
107 // return project(nurb(u));
108 // }
109 
110  // derivative functions
111  void deriveAtH(double u, int d, fmatvec::MatVx4 & ders) const;
112 // void deriveAt(double u, int, Vector<fmatvec::Point<3> >&) const;
113 // void deriveAtH(double u, int, int, Vector<fmatvec::HPoint<3> >&) const;
114 // void deriveAt(double u, int, int, Vector<fmatvec::Point<3> >&) const;
115  fmatvec::Point<3> derive3D(double u, int d) const;
116  fmatvec::HPoint<3> derive(double u, int d) const;
117  fmatvec::Point<3> normal(double u, const fmatvec::Point<3> & v) const;
118 
119  fmatvec::HPoint<3> firstD(double u) const;
120  fmatvec::HPoint<3> firstD(double u, int span) const;
121  fmatvec::Point<3> firstDn(double u) const;
122  fmatvec::Point<3> firstDn(double u, int span) const;
123 
124 // // Basis functions
125 // T basisFun(T u, int i, int p = -1) const;
126 
127 // void dersBasisFuns(int n, T u, int span, Matrix<T>& M) const;
128 //
129 // // Knot functions
130 // T minKnot() const //! the minimal value for the knot vector
131 // {
132 // return U[0];
133 // }
134 // //! the maximal value for the knot vector
135 // T maxKnot() const
136 // {
137 // return U[U.n() - 1];
138 // }
139 // void findMultSpan(T u, int& r, int& s) const;
140 // int findMult(int r) const;
141 // int findKnot(T u) const;
142 // T getRemovalBnd(int r, int s) const;
143 //
144 // void removeKnot(int r, int s, int num);
145 // void removeKnotsBound(const std::vector<double>& ub, std::vector<double>& ek, T E);
146 // int knotInsertion(T u, int r, NurbsCurve<T, N>& nc);
147 // void refineKnotVector(const std::vector<double>& X);
148 // void refineKnotVectorClosed(const std::vector<double>& X);
149 // void mergeKnotVector(const std::vector<double> &Um);
150 //
151 // void clamp();
152 // void unclamp();
153 //
154 // // Curve fitting functions
155 // int leastSquares(const Vector<fmatvec::Point<3> >& Q, int degC, int n);
156 // int leastSquares(const Vector<fmatvec::Point<3> >& Q, int degC, int n, const std::vector<double>& ub);
157 // int leastSquaresH(const Vector<fmatvec::HPoint<3> >& Q, int degC, int n, const std::vector<double>& ub);
158 // int leastSquares(const Vector<fmatvec::Point<3> >& Q, int degC, int n, const std::vector<double>& ub, const std::vector<double>& knot);
159 // int leastSquaresH(const Vector<fmatvec::HPoint<3> >& Q, int degC, int n, const std::vector<double>& ub, const std::vector<double>& knot);
160 //
161 // int leastSquaresClosed(const Vector<fmatvec::Point<3> >& Q, int degC, int n);
162 // int leastSquaresClosed(const Vector<fmatvec::Point<3> >& Q, int degC, int n, const std::vector<double>& ub);
163 // int leastSquaresClosedH(const Vector<fmatvec::HPoint<3> >& Q, int degC, int n, const std::vector<double>& ub);
164 // int leastSquaresClosed(const Vector<fmatvec::Point<3> >& Q, int degC, int n, const std::vector<double>& ub, const std::vector<double>& knot);
165 // int leastSquaresClosedH(const Vector<fmatvec::HPoint<3> >& Q, int degC, int n, const std::vector<double>& ub, const std::vector<double>& knot);
166 //
167 // void globalApproxErrBnd(Vector<fmatvec::Point<3> >& Q, int deg, T E);
168 // void globalApproxErrBnd(Vector<fmatvec::Point<3> >& Q, std::vector<double>& ub, int deg, T E);
169 // void globalApproxErrBnd2(Vector<fmatvec::Point<3> >& Q, int degC, T E);
170 // void globalApproxErrBnd3(Vector<fmatvec::Point<3> >& Q, int degC, T E);
171 // void globalApproxErrBnd3(Vector<fmatvec::Point<3> >& Q, const std::vector<double> &ub, int degC, T E);
172 //
173 // void globalInterp(const Vector<fmatvec::Point<3> >& Q, int d);
177  void globalInterp(const std::vector<fmatvec::Point<3> >& Q, const std::vector<double>& uk, int d, bool updateLater = false);
178  void globalInterp(const std::vector<fmatvec::Point<3> >& Q, double uMin, double uMax, int d, bool updateLater = false);
179  void globalInterp(const fmatvec::MatVx3& Q, double uMin, double uMax, int d, bool updateLater = false);
180 
181 // void globalInterpH(const Vector<fmatvec::HPoint<3> >& Q, int d);
182 // void globalInterpH(const Vector<fmatvec::HPoint<3> >& Q, const std::vector<double>& U, int d);
183  void globalInterpH(const MatVx4& Q, const Vec& ub, const Vec& Uc, int d, bool updateLater = false);
184 // void globalInterpClosed(const Vector<fmatvec::Point<3> >& Qw, int d);
188  void globalInterpClosed(const fmatvec::MatVx3 & Q, double uMin, double uMax, int d, bool updateLater = false);
189 
193  void update(const fmatvec::MatVx3& Q);
194  void update(const fmatvec::MatVx4& Q);
195 
196 // void globalInterpClosedH(const Vector<fmatvec::HPoint<3> >& Qw, int d);
197 // void globalInterpClosedH(const Vector<fmatvec::HPoint<3> >& Qw, const std::vector<double>& U, int d);
198  void globalInterpClosedH(const MatVx4& Qw, const Vec& ub, const Vec& Uc, int d, bool updateLater = false);
199 // void globalInterpClosed(const Vector<fmatvec::Point<3> >& Qw, const std::vector<double>& ub, const std::vector<double>& Uc, int d);
200 //
201 // void globalInterpD(const Vector<fmatvec::Point<3> >& Q, const Vector<fmatvec::Point<3> >& D, int d, int unitD, T a = 1.0);
202 //
203 // Matrix<T> computeInverse(const std::vector<double> &v, const std::vector<double> &V, const int p);
204 // Matrix<T> computeInverseClosed(const std::vector<double> &v, const std::vector<double> &V, const int p);
205 //
206 // void projectTo(const fmatvec::Point<3> & p, T guess, T& u, fmatvec::Point<3> & r, T e1 = 0.001, T e2 = 0.001, int maxTry = 100) const;
207 //
208 // T length(T eps = 0.001, int n = 100) const;
209 // T lengthIn(T us, T ue, T eps = 0.001, int n = 100) const;
210 // T lengthF(T) const;
211 // T lengthF(T, int) const;
212 //
213 // // Generate type of curve
214 // void makeCircle(const fmatvec::Point<3> & O, const fmatvec::Point<3> & X, const fmatvec::Point<3> & Y, T r, double as, double ae);
215 // void makeCircle(const fmatvec::Point<3> & O, T r, double as, double ae);
216 // void makeCircle(const fmatvec::Point<3> & O, T r);
217 // void makeLine(const fmatvec::Point<3> & P0, const fmatvec::Point<3> & P1, int d);
218 // virtual void degreeElevate(int t);
219 //
220 // #ifndef HAVE_ISO_FRIEND_DECL
221 // friend void generateCompatibleCurves(NurbsCurveArray<T, N> &ca);
222 // #else
223 // friend void generateCompatibleCurves <>(NurbsCurveArray<T,N> &ca);
224 // #endif
225 //
226 // void decompose(NurbsCurveArray<T, N>& c) const;
227 // void decomposeClosed(NurbsCurveArray<T, N>& c) const;
228 //
229 // int splitAt(T u, NurbsCurve<T, N>& cl, NurbsCurve<T, N>& cu) const;
230 // int mergeOf(const NurbsCurve<T, N>& cl, const NurbsCurve<T, N> &cu);
231 //
232 // // Modifies the NURBS curve
233 // void transform(const MatrixRT<T>& A);
234  void modCP(int i, const fmatvec::HPoint<3> & a) {
235  P.set(i, a.T());
236  } // To manipulate the value of the control point $P[i]$
237 // void modCPby(int i, const fmatvec::HPoint<3> & a) {
238 // P[i] += a;
239 // } // To manipulate the value of the control point $P[i]$
240 // virtual void modKnot(const std::vector<double>& knotU) {
241 // if (knotU.n() - deg_ - 1 == P.n())
242 // U = knotU;
243 // } // to change the values of the knot vector only if the size is compatible with P.n
244 
245 // int movePoint(T u, const fmatvec::Point<3> & delta);
246 // int movePoint(T u, const BasicArray<fmatvec::Point<3> >& delta);
247 // int movePoint(const BasicArray<T>& ur, const BasicArray<fmatvec::Point<3> >& D);
248 // int movePoint(const BasicArray<T>& ur, const BasicArray<fmatvec::Point<3> >& D, const BasicArray_INT& Dr, const BasicArray_INT& Dk);
249 // int movePoint(const BasicArray<T>& ur, const BasicArray<fmatvec::Point<3> >& D, const BasicArray_INT& Dr, const BasicArray_INT& Dk, const BasicArray_INT& fixCP);
250 //
251 // void setTangent(T u, const fmatvec::Point<3> & T0);
252 // void setTangentAtEnd(const fmatvec::Point<3> & T0, const fmatvec::Point<3> & T1);
253 //
254 // // I/O functions
255 // int read(const char*);
256 // int write(const char*) const;
257 // virtual int read(ifstream &fin);
258 // int write(ofstream &fout) const;
259 // int writePS(const char*, int cp = 0, T magFact = T(-1), T dash = T(5), bool bOpen = true) const;
260 // int writePSp(const char*, const Vector<fmatvec::Point<3> >&, const Vector<fmatvec::Point<3> >&, int cp = 0, T magFact = 0.0, T dash = 5.0, bool bOpen = true) const;
261 //
262 // int writeVRML(ostream &fout, T radius, int K, const Color& color, int Nu, int Nv, T u_s, T u_e) const;
263 // int writeVRML(const char* filename, T radius, int K, const Color& color, int Nu, int Nv, T u_s, T u_e) const;
264 // int writeVRML(const char* filename, T radius = 1, int K = 5, const Color& color = whiteColor, int Nu = 20, int Nv = 20) const {
265 // return writeVRML(filename, radius, K, color, Nu, Nv, U[0], U[U.n() - 1]);
266 // } // writes the curve to a VRML file
267 // int writeVRML(ostream& fout, T radius = 1, int K = 5, const Color& color = whiteColor, int Nu = 20, int Nv = 20) const {
268 // return writeVRML(fout, radius, K, color, Nu, Nv, U[0], U[U.n() - 1]);
269 // } // writes the curve to a VRML file
270 //
271 // int writeVRML97(const char* filename, T radius, int K, const Color& color, int Nu, int Nv, T u_s, T u_e) const;
272 // int writeVRML97(ostream &fout, T radius, int K, const Color& color, int Nu, int Nv, T u_s, T u_e) const;
273 // int writeVRML97(const char* filename, T radius = 1, int K = 5, const Color& color = whiteColor, int Nu = 20, int Nv = 20) const {
274 // return writeVRML97(filename, radius, K, color, Nu, Nv, U[0], U[U.n() - 1]);
275 // } // writes the curve to a VRML file
276 // int writeVRML97(ostream& fout, T radius = 1, int K = 5, const Color& color = whiteColor, int Nu = 20, int Nv = 20) const {
277 // return writeVRML97(fout, radius, K, color, Nu, Nv, U[0], U[U.n() - 1]);
278 // } // writes the curve to a VRML file
279 //
280 // int writeDisplayLINE(const char* filename, int iNu, const Color& color = blueColor, T fA = 1) const;
281 // int writeDisplayLINE(const char* filename, const Color& color, int iNu, T u_s, T u_e) const;
282 // void drawImg(Image_UBYTE& Img, unsigned char color = 255, T step = 0.01);
283 // void drawImg(Image_Color& Img, const Color& color, T step = 0.01);
284 // void drawAaImg(Image_Color& Img, const Color& color, int precision = 3, int alpha = 1);
285 // void drawAaImg(Image_Color& Img, const Color& color, const NurbsCurve<T, 3>& profile, int precision = 3, int alpha = 1);
286 // NurbsSurface<T, 3> drawAaImg(Image_Color& Img, const Color& color, const NurbsCurve<T, 3>& profile, const NurbsCurve<T, 3> &scaling, int precision = 3, int alpha = 1);
287 //
288 // BasicList<fmatvec::Point<3> > tesselate(T tolerance, BasicList<T> *uk) const;
289 
290  int findSpan(double u) const;
291 
292  protected:
293  fmatvec::MatVx4 P; // the vector of control points
294  fmatvec::SqrMat inverse; //Inverse of Ansatz-functions in case of only update later (different points, same knot-Vecs and same degree)
295  fmatvec::Vec u; // the knot vector
296  fmatvec::Vec U; // the knot vector
297  int deg; // the degree of the NURBS curve
298 
299  void resize(int n, int Deg);
300 
301  void knotAveraging(const std::vector<double>& uk, int deg);
302  double chordLengthParam(const MatVx3& Q, Vec& ub);
303  void updateUVecs(double uMin, double uMax);
304 
305  void knotAveragingClosed(const std::vector<double>& uk, int deg);
306  void updateUVecsClosed(double uMin, double uMax);
307 
308 // Matrix<T> Inverse; //changed
309 // int Inverse_setted; //changed
310  };
311 
312  //TODO: put those functions into mother nurbs class (maybe) to make them "func(...) const"
313  void knotAveraging(const Vec& uk, int deg, Vec& U);
314  void knotAveragingClosed(const Vec& uk, int deg, Vec& U);
315  void basisFuns(double u, int span, int deg, const fmatvec::Vec & U, fmatvec::Vec& funs);
316  void dersBasisFuns(int n, double u, int span, int deg, const fmatvec::Vec & U, fmatvec::Mat& ders);
317  void binomialCoef(Mat& Bin);
318 
319 }
320 #endif
double knot(int i) const
the i-th knot
Definition: nurbs_curve.h:78
const fmatvec::MatVx4 & ctrlPnts() const
a reference to the vector of control points
Definition: nurbs_curve.h:63
fmatvec::HPoint< 3 > hpointAt(double u) const
calls operator()
Definition: nurbs_curve.h:95
wrapper class for nurbs type HPoint
Definition: nurbs_defs.h:43
const fmatvec::Vec & knot() const
a reference to the vector of knots
Definition: nurbs_curve.h:73
const fmatvec::Vec4 ctrlPnts(int i) const
a reference to one of the control points
Definition: nurbs_curve.h:68
int degree() const
a reference to the degree of the curve
Definition: nurbs_curve.h:58
void knotAveragingClosed(const Vec &uk, int deg, Vec &U)
generates a knot vector using the averaging technique for interpolation with closed curve...
Definition: nurbs_curve.cc:589
wrapper class for nurbs type Point
Definition: nurbs_defs.h:13
RowVector< Ref, AT > trans(const Vector< Ref, AT > &x)
class that copies the nurbs++-library using the fmatvec as a basis-math-library
Definition: nurbs_curve.h:41
void binomialCoef(Mat &Bin)
Setup a matrix containing binomial coefficients.
Definition: nurbs_curve.cc:755

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Home