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
57  int degree() const
58  {
59  return deg;
60  }
61  const fmatvec::MatVx4 & ctrlPnts() const
62  {
63  return P;
64  }
65  const fmatvec::Vec4 ctrlPnts(int i) const
66  {
67  return trans(P.row(i));
68  }
69  const fmatvec::Vec& knot() const
70  {
71  return U;
72  }
73  double knot(int i) const
74  {
75  return U(i);
76  }
77 
78  const fmatvec::Vec getuVec() const {
79  return u;
80  }
81 
82  // basic functions
83 
84 // virtual void reset(const Vector<fmatvec::HPoint<3> >& P1, const std::vector<double> &U1, int deg);
85 // virtual NurbsCurve& operator=(const NurbsCurve<T, N>&);
86 //
87 // // Evaluattion functions
88  virtual fmatvec::HPoint<3> operator()(double u) const;
89  fmatvec::HPoint<3> hpointAt(double u) const
90  {
91  return operator()(u);
92  }
93  fmatvec::HPoint<3> hpointAt(double u, int span) const;
94  fmatvec::Point<3> pointAt(double u) const;
95 // friend fmatvec::HPoint<3> C(double u, const NurbsCurve<T, N>& nurb) {
96 // return nurb(u);
97 // } //!< a function interface to operator()
98 // friend fmatvec::Point<3> Cp(double u, const NurbsCurve<T, N>& nurb) {
99 // return project(nurb(u));
100 // } //!< returns the curvePoint in 3D
101 
102  // derivative functions
103  void deriveAtH(double u, int d, fmatvec::MatVx4 & ders) const;
104 // void deriveAt(double u, int, Vector<fmatvec::Point<3> >&) const;
105 // void deriveAtH(double u, int, int, Vector<fmatvec::HPoint<3> >&) const;
106 // void deriveAt(double u, int, int, Vector<fmatvec::Point<3> >&) const;
107  fmatvec::Point<3> derive3D(double u, int d) const;
108  fmatvec::HPoint<3> derive(double u, int d) const;
109  fmatvec::Point<3> normal(double u, const fmatvec::Point<3> & v) const;
110 
111  fmatvec::HPoint<3> firstD(double u) const;
112  fmatvec::HPoint<3> firstD(double u, int span) const;
113  fmatvec::Point<3> firstDn(double u) const;
114  fmatvec::Point<3> firstDn(double u, int span) const;
115 
116 // // Basis functions
117 // T basisFun(T u, int i, int p = -1) const;
118 
119 // void dersBasisFuns(int n, T u, int span, Matrix<T>& M) const;
120 //
121 // // Knot functions
122 // T minKnot() const //! the minimal value for the knot vector
123 // {
124 // return U[0];
125 // }
126 // T maxKnot() const //!< the maximal value for the knot vector
127 // {
128 // return U[U.n() - 1];
129 // }
130 // void findMultSpan(T u, int& r, int& s) const;
131 // int findMult(int r) const;
132 // int findKnot(T u) const;
133 // T getRemovalBnd(int r, int s) const;
134 //
135 // void removeKnot(int r, int s, int num);
136 // void removeKnotsBound(const std::vector<double>& ub, std::vector<double>& ek, T E);
137 // int knotInsertion(T u, int r, NurbsCurve<T, N>& nc);
138 // void refineKnotVector(const std::vector<double>& X);
139 // void refineKnotVectorClosed(const std::vector<double>& X);
140 // void mergeKnotVector(const std::vector<double> &Um);
141 //
142 // void clamp();
143 // void unclamp();
144 //
145 // // Curve fitting functions
146 // int leastSquares(const Vector<fmatvec::Point<3> >& Q, int degC, int n);
147 // int leastSquares(const Vector<fmatvec::Point<3> >& Q, int degC, int n, const std::vector<double>& ub);
148 // int leastSquaresH(const Vector<fmatvec::HPoint<3> >& Q, int degC, int n, const std::vector<double>& ub);
149 // int leastSquares(const Vector<fmatvec::Point<3> >& Q, int degC, int n, const std::vector<double>& ub, const std::vector<double>& knot);
150 // int leastSquaresH(const Vector<fmatvec::HPoint<3> >& Q, int degC, int n, const std::vector<double>& ub, const std::vector<double>& knot);
151 //
152 // int leastSquaresClosed(const Vector<fmatvec::Point<3> >& Q, int degC, int n);
153 // int leastSquaresClosed(const Vector<fmatvec::Point<3> >& Q, int degC, int n, const std::vector<double>& ub);
154 // int leastSquaresClosedH(const Vector<fmatvec::HPoint<3> >& Q, int degC, int n, const std::vector<double>& ub);
155 // int leastSquaresClosed(const Vector<fmatvec::Point<3> >& Q, int degC, int n, const std::vector<double>& ub, const std::vector<double>& knot);
156 // int leastSquaresClosedH(const Vector<fmatvec::HPoint<3> >& Q, int degC, int n, const std::vector<double>& ub, const std::vector<double>& knot);
157 //
158 // void globalApproxErrBnd(Vector<fmatvec::Point<3> >& Q, int deg, T E);
159 // void globalApproxErrBnd(Vector<fmatvec::Point<3> >& Q, std::vector<double>& ub, int deg, T E);
160 // void globalApproxErrBnd2(Vector<fmatvec::Point<3> >& Q, int degC, T E);
161 // void globalApproxErrBnd3(Vector<fmatvec::Point<3> >& Q, int degC, T E);
162 // void globalApproxErrBnd3(Vector<fmatvec::Point<3> >& Q, const std::vector<double> &ub, int degC, T E);
163 //
164 // void globalInterp(const Vector<fmatvec::Point<3> >& Q, int d);
168  void globalInterp(const std::vector<fmatvec::Point<3> >& Q, const std::vector<double>& uk, int d, bool updateLater = false);
169  void globalInterp(const std::vector<fmatvec::Point<3> >& Q, double uMin, double uMax, int d, bool updateLater = false);
170  void globalInterp(const fmatvec::MatVx3& Q, double uMin, double uMax, int d, bool updateLater = false);
171 
172 // void globalInterpH(const Vector<fmatvec::HPoint<3> >& Q, int d);
173 // void globalInterpH(const Vector<fmatvec::HPoint<3> >& Q, const std::vector<double>& U, int d);
174  void globalInterpH(const MatVx4& Q, const Vec& ub, const Vec& Uc, int d, bool updateLater = false);
175 // void globalInterpClosed(const Vector<fmatvec::Point<3> >& Qw, int d);
179  void globalInterpClosed(const fmatvec::MatVx3 & Q, double uMin, double uMax, int d, bool updateLater = false);
180 
184  void update(const fmatvec::MatVx3& Q);
185  void update(const fmatvec::MatVx4& Q);
186 
187 // void globalInterpClosedH(const Vector<fmatvec::HPoint<3> >& Qw, int d);
188 // void globalInterpClosedH(const Vector<fmatvec::HPoint<3> >& Qw, const std::vector<double>& U, int d);
189  void globalInterpClosedH(const MatVx4& Qw, const Vec& ub, const Vec& Uc, int d, bool updateLater = false);
190 // void globalInterpClosed(const Vector<fmatvec::Point<3> >& Qw, const std::vector<double>& ub, const std::vector<double>& Uc, int d);
191 //
192 // void globalInterpD(const Vector<fmatvec::Point<3> >& Q, const Vector<fmatvec::Point<3> >& D, int d, int unitD, T a = 1.0);
193 //
194 // Matrix<T> computeInverse(const std::vector<double> &v, const std::vector<double> &V, const int p);
195 // Matrix<T> computeInverseClosed(const std::vector<double> &v, const std::vector<double> &V, const int p);
196 //
197 // 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;
198 //
199 // T length(T eps = 0.001, int n = 100) const;
200 // T lengthIn(T us, T ue, T eps = 0.001, int n = 100) const;
201 // T lengthF(T) const;
202 // T lengthF(T, int) const;
203 //
204 // // Generate type of curve
205 // void makeCircle(const fmatvec::Point<3> & O, const fmatvec::Point<3> & X, const fmatvec::Point<3> & Y, T r, double as, double ae);
206 // void makeCircle(const fmatvec::Point<3> & O, T r, double as, double ae);
207 // void makeCircle(const fmatvec::Point<3> & O, T r);
208 // void makeLine(const fmatvec::Point<3> & P0, const fmatvec::Point<3> & P1, int d);
209 // virtual void degreeElevate(int t);
210 //
211 // #ifndef HAVE_ISO_FRIEND_DECL
212 // friend void generateCompatibleCurves(NurbsCurveArray<T, N> &ca);
213 // #else
214 // friend void generateCompatibleCurves <>(NurbsCurveArray<T,N> &ca);
215 // #endif
216 //
217 // void decompose(NurbsCurveArray<T, N>& c) const;
218 // void decomposeClosed(NurbsCurveArray<T, N>& c) const;
219 //
220 // int splitAt(T u, NurbsCurve<T, N>& cl, NurbsCurve<T, N>& cu) const;
221 // int mergeOf(const NurbsCurve<T, N>& cl, const NurbsCurve<T, N> &cu);
222 //
223 // // Modifies the NURBS curve
224 // void transform(const MatrixRT<T>& A);
225  void modCP(int i, const fmatvec::HPoint<3> & a) {
226  P.set(i, a.T());
227  } // To manipulate the value of the control point $P[i]$
228 // void modCPby(int i, const fmatvec::HPoint<3> & a) {
229 // P[i] += a;
230 // } // To manipulate the value of the control point $P[i]$
231 // virtual void modKnot(const std::vector<double>& knotU) {
232 // if (knotU.n() - deg_ - 1 == P.n())
233 // U = knotU;
234 // } // to change the values of the knot vector only if the size is compatible with P.n
235 
236 // int movePoint(T u, const fmatvec::Point<3> & delta);
237 // int movePoint(T u, const BasicArray<fmatvec::Point<3> >& delta);
238 // int movePoint(const BasicArray<T>& ur, const BasicArray<fmatvec::Point<3> >& D);
239 // int movePoint(const BasicArray<T>& ur, const BasicArray<fmatvec::Point<3> >& D, const BasicArray_INT& Dr, const BasicArray_INT& Dk);
240 // int movePoint(const BasicArray<T>& ur, const BasicArray<fmatvec::Point<3> >& D, const BasicArray_INT& Dr, const BasicArray_INT& Dk, const BasicArray_INT& fixCP);
241 //
242 // void setTangent(T u, const fmatvec::Point<3> & T0);
243 // void setTangentAtEnd(const fmatvec::Point<3> & T0, const fmatvec::Point<3> & T1);
244 //
245 // // I/O functions
246 // int read(const char*);
247 // int write(const char*) const;
248 // virtual int read(ifstream &fin);
249 // int write(ofstream &fout) const;
250 // int writePS(const char*, int cp = 0, T magFact = T(-1), T dash = T(5), bool bOpen = true) const;
251 // 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;
252 //
253 // int writeVRML(ostream &fout, T radius, int K, const Color& color, int Nu, int Nv, T u_s, T u_e) const;
254 // int writeVRML(const char* filename, T radius, int K, const Color& color, int Nu, int Nv, T u_s, T u_e) const;
255 // int writeVRML(const char* filename, T radius = 1, int K = 5, const Color& color = whiteColor, int Nu = 20, int Nv = 20) const {
256 // return writeVRML(filename, radius, K, color, Nu, Nv, U[0], U[U.n() - 1]);
257 // } // writes the curve to a VRML file
258 // int writeVRML(ostream& fout, T radius = 1, int K = 5, const Color& color = whiteColor, int Nu = 20, int Nv = 20) const {
259 // return writeVRML(fout, radius, K, color, Nu, Nv, U[0], U[U.n() - 1]);
260 // } // writes the curve to a VRML file
261 //
262 // int writeVRML97(const char* filename, T radius, int K, const Color& color, int Nu, int Nv, T u_s, T u_e) const;
263 // int writeVRML97(ostream &fout, T radius, int K, const Color& color, int Nu, int Nv, T u_s, T u_e) const;
264 // int writeVRML97(const char* filename, T radius = 1, int K = 5, const Color& color = whiteColor, int Nu = 20, int Nv = 20) const {
265 // return writeVRML97(filename, radius, K, color, Nu, Nv, U[0], U[U.n() - 1]);
266 // } // writes the curve to a VRML file
267 // int writeVRML97(ostream& fout, T radius = 1, int K = 5, const Color& color = whiteColor, int Nu = 20, int Nv = 20) const {
268 // return writeVRML97(fout, radius, K, color, Nu, Nv, U[0], U[U.n() - 1]);
269 // } // writes the curve to a VRML file
270 //
271 // int writeDisplayLINE(const char* filename, int iNu, const Color& color = blueColor, T fA = 1) const;
272 // int writeDisplayLINE(const char* filename, const Color& color, int iNu, T u_s, T u_e) const;
273 // void drawImg(Image_UBYTE& Img, unsigned char color = 255, T step = 0.01);
274 // void drawImg(Image_Color& Img, const Color& color, T step = 0.01);
275 // void drawAaImg(Image_Color& Img, const Color& color, int precision = 3, int alpha = 1);
276 // void drawAaImg(Image_Color& Img, const Color& color, const NurbsCurve<T, 3>& profile, int precision = 3, int alpha = 1);
277 // 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);
278 //
279 // BasicList<fmatvec::Point<3> > tesselate(T tolerance, BasicList<T> *uk) const;
280 
281  int findSpan(double u) const;
282 
283  protected:
284  fmatvec::MatVx4 P; // the vector of control points
285  fmatvec::SqrMat inverse; //Inverse of Ansatz-functions in case of only update later (different points, same knot-Vecs and same degree)
286  fmatvec::Vec u; // the knot vector
287  fmatvec::Vec U; // the knot vector
288  int deg; // the degree of the NURBS curve
289 
290  void resize(int n, int Deg);
291 
292  void knotAveraging(const std::vector<double>& uk, int deg);
293  double chordLengthParam(const MatVx3& Q, Vec& ub);
294  void updateUVecs(double uMin, double uMax);
295 
296  void knotAveragingClosed(const std::vector<double>& uk, int deg);
297  void updateUVecsClosed(double uMin, double uMax);
298 
299 // Matrix<T> Inverse; //changed
300 // int Inverse_setted; //changed
301  };
302 
303  //TODO: put those functions into mother nurbs class (maybe) to make them "func(...) const"
304  void knotAveraging(const Vec& uk, int deg, Vec& U);
305  void knotAveragingClosed(const Vec& uk, int deg, Vec& U);
306  void basisFuns(double u, int span, int deg, const fmatvec::Vec & U, fmatvec::Vec& funs);
307  void dersBasisFuns(int n, double u, int span, int deg, const fmatvec::Vec & U, fmatvec::Mat& ders);
308  void binomialCoef(Mat& Bin);
309 
310 }
311 #endif
double knot(int i) const
&lt; the i-th knot
Definition: nurbs_curve.h:73
const fmatvec::MatVx4 & ctrlPnts() const
&lt; a reference to the vector of control points
Definition: nurbs_curve.h:61
fmatvec::HPoint< 3 > hpointAt(double u) const
&lt; calls operator()
Definition: nurbs_curve.h:89
wrapper class for nurbs type HPoint
Definition: nurbs_defs.h:43
const fmatvec::Vec & knot() const
&lt; a reference to the vector of knots
Definition: nurbs_curve.h:69
const fmatvec::Vec4 ctrlPnts(int i) const
&lt; a reference to one of the control points
Definition: nurbs_curve.h:65
int degree() const
&lt; a reference to the degree of the curve
Definition: nurbs_curve.h:57
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:597
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:764

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML