MBSim |
Project Page |
00001 #ifndef NURBS_CURVE_FMATVEC_H_ 00002 #define NURBS_CURVE_FMATVEC_H_ 00003 00004 #include <mbsim/numerics/nurbs/nurbs_defs.h> 00005 00006 namespace fmatvec { 00007 typedef Matrix<General, Fixed<4>, Var, double> Mat4xV; 00008 00009 typedef Matrix<General, Var, Fixed<4>, double> MatVx4; 00010 } 00011 00012 namespace MBSim { 00013 00017 class NurbsCurve { 00018 public: 00022 NurbsCurve(); 00023 // NurbsCurve(Matrix<T> inverse) { 00024 // Inverse = inverse; 00025 // Inverse_setted = 1; 00026 // } //changed 00027 // NurbsCurve(const NurbsCurve<T, N>& nurb); 00028 // NurbsCurve(const Vector<fmatvec::HPoint<3> >& P1, const std::vector<double> &U1, int deg = 3); 00029 // NurbsCurve(const Vector<fmatvec::Point<3> >& P1, const std::vector<double> &W, const std::vector<double> &U1, int deg = 3); 00030 virtual ~NurbsCurve(); // empty destructor 00031 00032 // Reference to internal data 00033 int degree() const 00034 { 00035 return deg; 00036 } 00037 const fmatvec::MatVx4 & ctrlPnts() const 00038 { 00039 return P; 00040 } 00041 const fmatvec::MatVx4 ctrlPnts(int i) const 00042 { 00043 return P.row(i); 00044 } 00045 const fmatvec::Vec& knot() const 00046 { 00047 return U; 00048 } 00049 double knot(int i) const 00050 { 00051 return U(i); 00052 } 00053 00054 // basic functions 00055 00056 // virtual void reset(const Vector<fmatvec::HPoint<3> >& P1, const std::vector<double> &U1, int deg); 00057 // virtual NurbsCurve& operator=(const NurbsCurve<T, N>&); 00058 // 00059 // // Evaluattion functions 00060 virtual fmatvec::HPoint<3> operator()(double u) const; 00061 fmatvec::HPoint<3> hpointAt(double u) const 00062 { 00063 return operator()(u); 00064 } 00065 fmatvec::HPoint<3> hpointAt(double u, int span) const; 00066 fmatvec::Point<3> pointAt(double u) const; 00067 // friend fmatvec::HPoint<3> C(double u, const NurbsCurve<T, N>& nurb) { 00068 // return nurb(u); 00069 // } //!< a function interface to operator() 00070 // friend fmatvec::Point<3> Cp(double u, const NurbsCurve<T, N>& nurb) { 00071 // return project(nurb(u)); 00072 // } //!< returns the curvePoint in 3D 00073 00074 // derivative functions 00075 void deriveAtH(double u, int, fmatvec::MatVx4 & ders) const; 00076 // void deriveAt(double u, int, Vector<fmatvec::Point<3> >&) const; 00077 // void deriveAtH(double u, int, int, Vector<fmatvec::HPoint<3> >&) const; 00078 // void deriveAt(double u, int, int, Vector<fmatvec::Point<3> >&) const; 00079 fmatvec::Point<3> derive3D(double u, int d) const; 00080 fmatvec::HPoint<3> derive(double u, int d) const; 00081 fmatvec::Point<3> normal(double u, const fmatvec::Point<3> & v) const; 00082 00083 fmatvec::HPoint<3> firstD(double u) const; 00084 fmatvec::HPoint<3> firstD(double u, int span) const; 00085 fmatvec::Point<3> firstDn(double u) const; 00086 fmatvec::Point<3> firstDn(double u, int span) const; 00087 00088 // // Basis functions 00089 // T basisFun(T u, int i, int p = -1) const; 00090 00091 // void dersBasisFuns(int n, T u, int span, Matrix<T>& M) const; 00092 // 00093 // // Knot functions 00094 // T minKnot() const //! the minimal value for the knot vector 00095 // { 00096 // return U[0]; 00097 // } 00098 // T maxKnot() const //!< the maximal value for the knot vector 00099 // { 00100 // return U[U.n() - 1]; 00101 // } 00102 // void findMultSpan(T u, int& r, int& s) const; 00103 // int findMult(int r) const; 00104 // int findKnot(T u) const; 00105 // T getRemovalBnd(int r, int s) const; 00106 // 00107 // void removeKnot(int r, int s, int num); 00108 // void removeKnotsBound(const std::vector<double>& ub, std::vector<double>& ek, T E); 00109 // int knotInsertion(T u, int r, NurbsCurve<T, N>& nc); 00110 // void refineKnotVector(const std::vector<double>& X); 00111 // void refineKnotVectorClosed(const std::vector<double>& X); 00112 // void mergeKnotVector(const std::vector<double> &Um); 00113 // 00114 // void clamp(); 00115 // void unclamp(); 00116 // 00117 // // Curve fitting functions 00118 // int leastSquares(const Vector<fmatvec::Point<3> >& Q, int degC, int n); 00119 // int leastSquares(const Vector<fmatvec::Point<3> >& Q, int degC, int n, const std::vector<double>& ub); 00120 // int leastSquaresH(const Vector<fmatvec::HPoint<3> >& Q, int degC, int n, const std::vector<double>& ub); 00121 // int leastSquares(const Vector<fmatvec::Point<3> >& Q, int degC, int n, const std::vector<double>& ub, const std::vector<double>& knot); 00122 // int leastSquaresH(const Vector<fmatvec::HPoint<3> >& Q, int degC, int n, const std::vector<double>& ub, const std::vector<double>& knot); 00123 // 00124 // int leastSquaresClosed(const Vector<fmatvec::Point<3> >& Q, int degC, int n); 00125 // int leastSquaresClosed(const Vector<fmatvec::Point<3> >& Q, int degC, int n, const std::vector<double>& ub); 00126 // int leastSquaresClosedH(const Vector<fmatvec::HPoint<3> >& Q, int degC, int n, const std::vector<double>& ub); 00127 // int leastSquaresClosed(const Vector<fmatvec::Point<3> >& Q, int degC, int n, const std::vector<double>& ub, const std::vector<double>& knot); 00128 // int leastSquaresClosedH(const Vector<fmatvec::HPoint<3> >& Q, int degC, int n, const std::vector<double>& ub, const std::vector<double>& knot); 00129 // 00130 // void globalApproxErrBnd(Vector<fmatvec::Point<3> >& Q, int deg, T E); 00131 // void globalApproxErrBnd(Vector<fmatvec::Point<3> >& Q, std::vector<double>& ub, int deg, T E); 00132 // void globalApproxErrBnd2(Vector<fmatvec::Point<3> >& Q, int degC, T E); 00133 // void globalApproxErrBnd3(Vector<fmatvec::Point<3> >& Q, int degC, T E); 00134 // void globalApproxErrBnd3(Vector<fmatvec::Point<3> >& Q, const std::vector<double> &ub, int degC, T E); 00135 // 00136 // void globalInterp(const Vector<fmatvec::Point<3> >& Q, int d); 00140 void globalInterp(const fmatvec::MatVx3& Q, double uMin, double uMax, int d, bool updateLater = false); 00141 // void globalInterpH(const Vector<fmatvec::HPoint<3> >& Q, int d); 00142 // void globalInterpH(const Vector<fmatvec::HPoint<3> >& Q, const std::vector<double>& U, int d); 00143 // void globalInterpH(const Vector<fmatvec::HPoint<3> >& Q, const std::vector<double>& ub, const std::vector<double>& U, int d); 00144 // void globalInterpClosed(const Vector<fmatvec::Point<3> >& Qw, int d); 00148 void globalInterpClosed(const fmatvec::MatVx3 & Q, double uMin, double uMax, int d, bool updateLater = false); 00149 00153 void update(const fmatvec::MatVx3& Q); 00154 00155 // void globalInterpClosedH(const Vector<fmatvec::HPoint<3> >& Qw, int d); 00156 // void globalInterpClosedH(const Vector<fmatvec::HPoint<3> >& Qw, const std::vector<double>& U, int d); 00157 // void globalInterpClosedH(const Vector<fmatvec::HPoint<3> >& Qw, const std::vector<double>& ub, const std::vector<double>& U, int d); 00158 // void globalInterpClosed(const Vector<fmatvec::Point<3> >& Qw, const std::vector<double>& ub, const std::vector<double>& Uc, int d); 00159 // 00160 // void globalInterpD(const Vector<fmatvec::Point<3> >& Q, const Vector<fmatvec::Point<3> >& D, int d, int unitD, T a = 1.0); 00161 // 00162 // Matrix<T> computeInverse(const std::vector<double> &v, const std::vector<double> &V, const int p); 00163 // Matrix<T> computeInverseClosed(const std::vector<double> &v, const std::vector<double> &V, const int p); 00164 // 00165 // 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; 00166 // 00167 // T length(T eps = 0.001, int n = 100) const; 00168 // T lengthIn(T us, T ue, T eps = 0.001, int n = 100) const; 00169 // T lengthF(T) const; 00170 // T lengthF(T, int) const; 00171 // 00172 // // Generate type of curve 00173 // void makeCircle(const fmatvec::Point<3> & O, const fmatvec::Point<3> & X, const fmatvec::Point<3> & Y, T r, double as, double ae); 00174 // void makeCircle(const fmatvec::Point<3> & O, T r, double as, double ae); 00175 // void makeCircle(const fmatvec::Point<3> & O, T r); 00176 // void makeLine(const fmatvec::Point<3> & P0, const fmatvec::Point<3> & P1, int d); 00177 // virtual void degreeElevate(int t); 00178 // 00179 // #ifndef HAVE_ISO_FRIEND_DECL 00180 // friend void generateCompatibleCurves(NurbsCurveArray<T, N> &ca); 00181 // #else 00182 // friend void generateCompatibleCurves <>(NurbsCurveArray<T,N> &ca); 00183 // #endif 00184 // 00185 // void decompose(NurbsCurveArray<T, N>& c) const; 00186 // void decomposeClosed(NurbsCurveArray<T, N>& c) const; 00187 // 00188 // int splitAt(T u, NurbsCurve<T, N>& cl, NurbsCurve<T, N>& cu) const; 00189 // int mergeOf(const NurbsCurve<T, N>& cl, const NurbsCurve<T, N> &cu); 00190 // 00191 // // Modifies the NURBS curve 00192 // void transform(const MatrixRT<T>& A); 00193 // void modCP(int i, const fmatvec::HPoint<3> & a) { 00194 // P[i] = a; 00195 // } // To manipulate the value of the control point $P[i]$ 00196 // void modCPby(int i, const fmatvec::HPoint<3> & a) { 00197 // P[i] += a; 00198 // } // To manipulate the value of the control point $P[i]$ 00199 // virtual void modKnot(const std::vector<double>& knotU) { 00200 // if (knotU.n() - deg_ - 1 == P.n()) 00201 // U = knotU; 00202 // } // to change the values of the knot vector only if the size is compatible with P.n 00203 00204 // int movePoint(T u, const fmatvec::Point<3> & delta); 00205 // int movePoint(T u, const BasicArray<fmatvec::Point<3> >& delta); 00206 // int movePoint(const BasicArray<T>& ur, const BasicArray<fmatvec::Point<3> >& D); 00207 // int movePoint(const BasicArray<T>& ur, const BasicArray<fmatvec::Point<3> >& D, const BasicArray_INT& Dr, const BasicArray_INT& Dk); 00208 // int movePoint(const BasicArray<T>& ur, const BasicArray<fmatvec::Point<3> >& D, const BasicArray_INT& Dr, const BasicArray_INT& Dk, const BasicArray_INT& fixCP); 00209 // 00210 // void setTangent(T u, const fmatvec::Point<3> & T0); 00211 // void setTangentAtEnd(const fmatvec::Point<3> & T0, const fmatvec::Point<3> & T1); 00212 // 00213 // // I/O functions 00214 // int read(const char*); 00215 // int write(const char*) const; 00216 // virtual int read(ifstream &fin); 00217 // int write(ofstream &fout) const; 00218 // int writePS(const char*, int cp = 0, T magFact = T(-1), T dash = T(5), bool bOpen = true) const; 00219 // 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; 00220 // 00221 // int writeVRML(ostream &fout, T radius, int K, const Color& color, int Nu, int Nv, T u_s, T u_e) const; 00222 // int writeVRML(const char* filename, T radius, int K, const Color& color, int Nu, int Nv, T u_s, T u_e) const; 00223 // int writeVRML(const char* filename, T radius = 1, int K = 5, const Color& color = whiteColor, int Nu = 20, int Nv = 20) const { 00224 // return writeVRML(filename, radius, K, color, Nu, Nv, U[0], U[U.n() - 1]); 00225 // } // writes the curve to a VRML file 00226 // int writeVRML(ostream& fout, T radius = 1, int K = 5, const Color& color = whiteColor, int Nu = 20, int Nv = 20) const { 00227 // return writeVRML(fout, radius, K, color, Nu, Nv, U[0], U[U.n() - 1]); 00228 // } // writes the curve to a VRML file 00229 // 00230 // int writeVRML97(const char* filename, T radius, int K, const Color& color, int Nu, int Nv, T u_s, T u_e) const; 00231 // int writeVRML97(ostream &fout, T radius, int K, const Color& color, int Nu, int Nv, T u_s, T u_e) const; 00232 // int writeVRML97(const char* filename, T radius = 1, int K = 5, const Color& color = whiteColor, int Nu = 20, int Nv = 20) const { 00233 // return writeVRML97(filename, radius, K, color, Nu, Nv, U[0], U[U.n() - 1]); 00234 // } // writes the curve to a VRML file 00235 // int writeVRML97(ostream& fout, T radius = 1, int K = 5, const Color& color = whiteColor, int Nu = 20, int Nv = 20) const { 00236 // return writeVRML97(fout, radius, K, color, Nu, Nv, U[0], U[U.n() - 1]); 00237 // } // writes the curve to a VRML file 00238 // 00239 // int writeDisplayLINE(const char* filename, int iNu, const Color& color = blueColor, T fA = 1) const; 00240 // int writeDisplayLINE(const char* filename, const Color& color, int iNu, T u_s, T u_e) const; 00241 // void drawImg(Image_UBYTE& Img, unsigned char color = 255, T step = 0.01); 00242 // void drawImg(Image_Color& Img, const Color& color, T step = 0.01); 00243 // void drawAaImg(Image_Color& Img, const Color& color, int precision = 3, int alpha = 1); 00244 // void drawAaImg(Image_Color& Img, const Color& color, const NurbsCurve<T, 3>& profile, int precision = 3, int alpha = 1); 00245 // 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); 00246 // 00247 // BasicList<fmatvec::Point<3> > tesselate(T tolerance, BasicList<T> *uk) const; 00248 00249 protected: 00250 fmatvec::MatVx4 P; // the vector of control points 00251 fmatvec::SqrMat inverse; //Inverse of Ansatz-functions in case of only update later (different points, same knot-Vecs and same degree) 00252 fmatvec::Vec u; // the knot vector 00253 fmatvec::Vec U; // the knot vector 00254 int deg; // the degree of the NURBS curve 00255 00256 void resize(int n, int Deg); 00257 00258 void knotAveraging(const std::vector<double>& uk, int deg); 00259 void updateUVecs(double uMin, double uMax); 00260 00261 void knotAveragingClosed(const std::vector<double>& uk, int deg); 00262 void updateUVecsClosed(double uMin, double uMax); 00263 00264 int findSpan(double u) const; 00265 00266 // Matrix<T> Inverse; //changed 00267 // int Inverse_setted; //changed 00268 }; 00269 00270 //TODO: put those functions into mother nurbs class (maybe) to make them "func(...) const" 00271 void basisFuns(double u, int span, int deg, const fmatvec::Vec & U, fmatvec::Vec& funs); 00272 void dersBasisFuns(int n, double u, int span, int deg, const fmatvec::Vec & U, fmatvec::Mat& ders); 00273 00274 } 00275 #endif
1.8.0