MBSim |
Project Page |
00001 #ifndef NURBS_SURFACE_FMATVEC_H_ 00002 #define NURBS_SURFACE_FMATVEC_H_ 00003 00004 #include <mbsim/numerics/nurbs/nurbs_defs.h> 00005 #include "nurbs_curve.h" 00006 00007 namespace fmatvec { 00008 typedef Matrix<General, Fixed<4>, Var, double> Mat4xV; 00009 00010 typedef Matrix<General, Var, Fixed<4>, double> MatVx4; 00011 } 00012 00013 namespace MBSim { 00014 00015 // enum Direction { u_direction=1, v_direction=2, both_direction=3} ; 00016 // 00017 // template <class T, int N> class NurbsSurfaceArray ; 00018 // 00019 // template <class T, int N> void gordonSurface(NurbsCurveArray<T,N>& , NurbsCurveArray<T,N>& , const Matrix< Point_nD<T,N> >& , NurbsSurface<T,N>& ); 00020 int surfMeshParams(const GeneralMatrix<fmatvec::Vec3>& Q, Vec& uk, Vec& vl); 00021 // template <class T, int N> int surfMeshParamsH(const Matrix< HPoint_nD<T,N> >& , Vector<T>& , Vector<T>& ); 00022 // template <class T, int N> int surfMeshParamsClosedU(const Matrix< Point_nD<T,N> >& Qw, Vector<T>& uk, Vector<T>& vl, int degU ); 00023 int surfMeshParamsClosedU(const GeneralMatrix<fmatvec::Vec3>& Q, Vec& uk, Vec& vl, int degU); 00024 // template <class T, int N> int surfMeshParamsClosedUH(const Matrix< HPoint_nD<T,N> >& Qw, Vector<T>& uk, Vector<T>& vl, int degU ); 00025 // 00026 // template <class T, int N> void globalSurfInterpXY(const Matrix< Point_nD<T,N> >& , int , int , NurbsSurface<T,N>& ); 00027 // template <class T, int N> void globalSurfInterpXY(const Matrix< Point_nD<T,N> >& , int , int , NurbsSurface<T,N>& , const Vector<T>& , const Vector<T>& ); 00028 // template <class T, int N> void globalSurfApprox(const Matrix< Point_nD<T,N> >& , int , int , NurbsSurface<T,N>& , double=0); 00029 // template <class T, int N> void wrapPointMatrix(const Matrix< Point_nD<T,N> >& Q, int , int, Matrix< Point_nD<T,N> >& Qw); 00030 00038 //template <class T, int N> 00039 class NurbsSurface { 00040 public: 00041 NurbsSurface(); 00042 NurbsSurface(const NurbsSurface& nS); 00043 // NurbsSurface(int DegU, int DegV, const Vector<T>& Uk, const Vector<T>& Vk, const Matrix< HPoint_nD<T,N> >& Cp) ; 00044 // NurbsSurface(int DegU, int DegV, Vector<T>& Uk, Vector<T>& Vk, Matrix< Point_nD<T,N> >& Cp, Matrix<T>& W) ; 00045 virtual ~NurbsSurface() 00046 { 00047 ; 00048 } 00049 00050 public: 00051 // Reference to internal data 00052 const Vec& knotU() const 00053 { 00054 return U; 00055 } 00056 const Vec& knotV() const 00057 { 00058 return V; 00059 } 00060 double knotU(int i) const 00061 { 00062 return U(i); 00063 } 00064 double knotV(int i) const 00065 { 00066 return V(i); 00067 } 00068 const GeneralMatrix<Vec4>& ctrlPnts() const 00069 { 00070 return P; 00071 } 00072 const fmatvec::Vec4 ctrlPnts(int i, int j) const 00073 { 00074 return P(i, j); 00075 } 00076 int degreeU() const 00077 { 00078 return degU; 00079 } 00080 int degreeV() const 00081 { 00082 return degV; 00083 } 00084 00085 // Basic operators 00086 virtual NurbsSurface& operator=(const NurbsSurface&); 00087 void resize(int Pu, int Pv, int DegU, int DegV); 00088 // virtual void resizeKeep(int Pu, int Pv, int DegU, int DegV) ; 00089 // int ok(); 00090 00091 // Basis functions 00092 fmatvec::HPoint<3> operator()(double u, double v) const; 00093 fmatvec::Point<3> pointAt(double u, double v) const; 00094 // void basisFuns(T u, T v, int spanU, int spanV, Vector<T>& Nu, Vector<T>& Nv) const ; 00095 // void basisFunsU(T u, int span, Vector<T>& M) const ; 00096 // void basisFunsV(T u, int span, Vector<T>& M) const ; 00097 // void dersBasisFuns(T u, T v, int dU, int dV,int uspan, int vspan,Matrix<T> & Niku, Matrix<T>& Njkv ) const ; 00098 00099 // Derivative functions 00100 void deriveAt(double u, double v, int d, GeneralMatrix<Vec3> &skl) const; 00101 void deriveAtH(double u, double v, int d, GeneralMatrix<Vec4> &skl) const; 00102 Vec3 normal(double u, double v) const; 00103 00104 // Surface fitting functions 00105 00106 void globalInterp(const GeneralMatrix<fmatvec::Vec3>& Q, int DegU, int DegV); 00107 void globalInterp(const GeneralMatrix<fmatvec::Vec3>& Q, const Vec& uk, const Vec& vk, int DegU, int DegV); 00108 void globalInterpClosedU(const GeneralMatrix<fmatvec::Vec3>& Q, int DegU, int DegV); 00109 void globalInterpClosedU(const GeneralMatrix<fmatvec::Vec3>& Q, const Vec& uk, const Vec& vk, int DegU, int DegV); 00110 // void globalInterpClosedU(const Matrix< Point_nD<T,N> >& Q,const Vector<T> &Uk, const Vector<T> &Vk, const Vector<T> &uk, const Vector<T> &vk, int pU, int pV);//testing 00111 // void globalInterpClosedUH(const Matrix< HPoint_nD<T,N> >& Q, int pU, int pV); 00112 // void globalInterpClosedUH(const Matrix< HPoint_nD<T,N> >& Q,const Vector<T> &Uk, const Vector<T> &Vk, const Vector<T> &uk, const Vector<T> &vk, int pU, int pV);//testing 00113 // void leastSquares(const Matrix< Point_nD<T,N> >& Q, int pU, int pV, int nU, int nV) ; 00114 // void leastSquaresClosedU(const Matrix< Point_nD<T,N> >& Q, int pU, int pV, int nU, int nV) ; 00115 // 00116 //#ifndef HAVE_ISO_FRIEND_DECL 00117 // friend void gordonSurface (NurbsCurveArray<T,N>& lU, NurbsCurveArray<T,N>& lV, const Matrix< Point_nD<T,N> >& intersections, NurbsSurface<T,N>& gS); 00118 // friend void globalSurfInterpXY (const Matrix< Point_nD<T,N> >& Q, int pU, int pV, NurbsSurface<T,N>& S); 00119 // friend void globalSurfInterpXY (const Matrix< Point_nD<T,N> >& Q, int pU, int pV, NurbsSurface<T,N>& S, const Vector<T>& uk, const Vector<T>& vk); 00120 // friend void globalSurfApprox (const Matrix< Point_nD<T,N> >& Q, int pU, int pV, NurbsSurface<T,N>& S, double error); 00121 //#else 00122 // friend void gordonSurface <> (NurbsCurveArray<T,N>& lU, NurbsCurveArray<T,N>& lV, const Matrix< Point_nD<T,N> >& intersections, NurbsSurface<T,N>& gS); 00123 // friend void globalSurfInterpXY <> (const Matrix< Point_nD<T,N> >& Q, int pU, int pV, NurbsSurface<T,N>& S); 00124 // friend void globalSurfInterpXY <> (const Matrix< Point_nD<T,N> >& Q, int pU, int pV, NurbsSurface<T,N>& S, const Vector<T>& uk, const Vector<T>& vk); 00125 // friend void globalSurfApprox <> (const Matrix< Point_nD<T,N> >& Q, int pU, int pV, NurbsSurface<T,N>& S, double error); 00126 //#endif 00127 // 00128 // // Surface generation function 00129 // int skinV(NurbsCurveArray<T,N>& ca, int degV); 00130 // int skinU(NurbsCurveArray<T,N>& ca, int degU); 00131 // void sweep(const NurbsCurve<T,N>& t, const NurbsCurve<T,N>& C, const NurbsCurve<T,N>& Sv, int K,int useAy=0, int invAz=0) ; 00132 // void sweep(const NurbsCurve<T,N>& t, const NurbsCurve<T,N>& C, int K,int useAy=0, int invAz=0) ; 00133 // void makeFromRevolution(const NurbsCurve<T,N>& profile, const Point_nD<T,N>& S, const Point_nD<T,N>& Z, double theta) ; 00134 // void makeFromRevolution(const NurbsCurve<T,N>& profile, const Point_nD<T,N>& S, const Point_nD<T,N>& Z) ; 00135 // void makeFromRevolution(const NurbsCurve<T,N>& profile) ; 00136 // 00137 // void makeSphere(const Point_nD<T,N>& O, T r) ; 00138 // void makeTorus(const Point_nD<T,N>& O, T R, T r); 00139 // 00140 // 00141 // void degreeElevate(int tU, int tV) ; 00142 // virtual void degreeElevateU(int tU) ; 00143 // virtual void degreeElevateV(int tV) ; 00144 // 00145 // 00146 // int decompose(NurbsSurfaceArray<T,N>& Sa) const ; 00147 // 00148 // 00149 // 00150 // virtual void refineKnots(const Vector<T>& nU, const Vector<T>& nV) ; 00151 // virtual void refineKnotU(const Vector<T>& X); 00152 // virtual void refineKnotV(const Vector<T>& X); 00153 // 00154 // virtual void mergeKnots(const Vector<T>& nU, const Vector<T>& nV) ; 00155 // virtual void mergeKnotU(const Vector<T>& X); 00156 // virtual void mergeKnotV(const Vector<T>& X); 00157 // 00158 // // Measuring functions 00159 // T area(T eps=0.001,int n=100) const ; 00160 // T areaIn(T us, T ue, T vs, T ve, T eps, int n) const ; 00161 // T areaF(T u, T v) const ; 00162 // 00163 // // special functions 00164 // void isoCurveU(T u, NurbsCurve<T,N>& c) const ; 00165 // void isoCurveV(T v, NurbsCurve<T,N>& c) const ; 00166 // 00167 // // I/O functions 00168 // int read(const char* filename); 00169 // int write(const char* filename) const; 00170 // virtual int read(ifstream &fin) ; 00171 // int write(ofstream &fout) const ; 00172 // int writeVRML(const char* filename,const Color& color,int Nu,int Nv, T u_s, T u_e, T v_s, T v_e) const { return ParaSurface<T,N>::writeVRML(filename,color,Nu,Nv,u_s,u_e,v_s,v_e);} 00173 // int writeVRML(ostream &fout,const Color& color,int Nu,int Nv, T u_s, T u_e, T v_s, T v_e) const { return ParaSurface<T,N>::writeVRML(fout,color,Nu,Nv,u_s,u_e,v_s,v_e);} 00174 // int writeVRML97(const char* filename,const Color& color,int Nu,int Nv, T u_s, T u_e, T v_s, T v_e) const { return ParaSurface<T,N>::writeVRML97(filename,color,Nu,Nv,u_s,u_e,v_s,v_e);} 00175 // int writeVRML97(ostream &fout,const Color& color,int Nu,int Nv, T u_s, T u_e, T v_s, T v_e) const { return ParaSurface<T,N>::writeVRML97(fout,color,Nu,Nv,u_s,u_e,v_s,v_e);} 00176 // ostream& print(ostream& os) const ; 00177 // 00178 // int writeVRML(const char* filename,const Color& color=whiteColor,int Nu=20,int Nv=20) const //!< Calls the ParaSurface routine with proper values 00179 // { return ParaSurface<T,N>::writeVRML(filename,color,Nu,Nv,U[0],U[U.n()-1],V[0],V[V.n()-1]); } 00180 // int writeVRML(ostream& fout,const Color& color=whiteColor,int Nu=20,int Nv=20) const //!< Calls the ParaSurface routine with proper values 00181 // { return ParaSurface<T,N>::writeVRML(fout,color,Nu,Nv,U[0],U[U.n()-1],V[0],V[V.n()-1]); } 00182 // 00183 // int writeVRML97(const char* filename,const Color& color=whiteColor,int Nu=20,int Nv=20) const //!< Calls the ParaSurface routine with proper values 00184 // { return ParaSurface<T,N>::writeVRML97(filename,color,Nu,Nv,U[0],U[U.n()-1],V[0],V[V.n()-1]); } 00185 // int writeVRML97(ostream& fout,const Color& color=whiteColor,int Nu=20,int Nv=20) const //!< Calls the ParaSurface routine with proper values 00186 // { return ParaSurface<T,N>::writeVRML97(fout,color,Nu,Nv,U[0],U[U.n()-1],V[0],V[V.n()-1]); } 00187 // 00188 // int writePOVRAY(ostream& povray, int patch_type=1, double flatness=0.01, int num_u_steps=8, int num_v_steps=8) const ; 00189 // int writePOVRAY(T, ostream& povray, const Color& color=Color(250,250,250),int smooth=0 , T ambient=0.2, T diffuse=0.6) const ; 00190 // int writePOVRAY(const char *filename, const Color& color, const Point_nD<T,N>& view, const Point_nD<T,N>& up, int patch_type=1, double flatness=0.01, int num_u_steps=8, int num_v_steps=8) const ; 00191 // int writePOVRAY(T tolerance, const char *filename, const Color& color, const Point_nD<T,N>& view, const Point_nD<T,N>& up, int smooth=0, T ambient=0.2, T diffuse=0.6) const ; 00192 // 00193 // int writeRIB(ostream& rib) const ; 00194 // int writeRIB(char* filename, const Color& color, const Point_nD<T,N>& view) const ; 00195 // 00196 // // tesselate is deprecated... 00197 // void tesselate(T tolerance, BasicList<Point_nD<T,N> > &points, BasicList<int> &connect, BasicList<Point_nD<T,N> > *normal=0) const ; 00198 // 00199 // int writePS(const char*, int nu, int nv, const Point_nD<T,N>& camera, const Point_nD<T,N>& lookAt, int cp=0,T magFact=T(-1),T dash=T(5)) const ; 00200 // int writePSp(const char*, int nu, int nv, const Point_nD<T,N>& camera, const Point_nD<T,N>& lookAt, const Vector< Point_nD<T,N> >&,const Vector< Point_nD<T,N> >&, int cp=0,T magFact=0.0,T dash=5.0) const ; 00201 // int writeOOGL(const char* filename, T fDu, T fDv,T fBu=0.0, T fBv=0.0, T fEu=1.0, T fEv=1.0, bool bDRawCP=false) const ; 00202 // int writeOOGL(const char* filename) const ; 00203 // 00204 // int writeDisplayQUADMESH(const char* filename, int iNu=100,int iNv=100,const Color& color=blueColor,T fA=.25, T fO=0.2) const; 00205 // 00206 // 00207 // // Modifies the shape of the surface 00208 // void transform(const MatrixRT<T>& A) ; 00209 // void modCP(int i, int j, const HPoint_nD<T,N>& p) //!< Modifies a control point 00210 // { P(i,j) = p ; } 00211 // void modCPby(int i, int j, const HPoint_nD<T,N>& p) //!< Modifies a control point 00212 // { P(i,j) += p ; } 00213 // 00214 // T& modU(int i) { return U[i] ; } 00215 // T modU(int i) const { return U[i]; } //!< modifies a knot 00216 // T& modV(int i) { return V[i] ; } //!< modifies a knot 00217 // T modV(int i) const { return V[i]; } //!< modifies a knot 00218 // 00219 // void modKnotU(const Vector<T>& uKnot) { if(P.rows()+degU+1==uKnot.n()) U=uKnot ; } //!< modifies the U knot vector if uKnot is of a proper size 00220 // void modKnotV(const Vector<T>& vKnot) { if(P.cols()+degV+1==vKnot.n()) V=vKnot ; } //!< modifies the U knot vector if uKnot is of a proper size 00221 // 00222 // int movePoint(T u, T v, const Point_nD<T,N>& delta); 00223 // int movePoint(const Vector<T>& ur, const Vector<T>& vr, const Vector< Point_nD<T,N> >& D, const Vector_INT& Du, const Vector_INT& Dv) ; 00224 // int movePoint(const Vector<T>& ur, const Vector<T>& vr, const Vector< Point_nD<T,N> >& D, const Vector_INT& Du, const Vector_INT& Dv, const Vector_INT& Dk, const Vector_INT& Dl) ; 00225 // int movePoint(const Vector<T>& ur, const Vector<T>& vr, const Vector< Point_nD<T,N> >& D, const Vector_INT& Du, const Vector_INT& Dv, const Vector_INT& Dk, const Vector_INT& Dl, const BasicArray<Coordinate>& fixCP) ; 00226 // 00227 // NurbsSurface<T,N>& transpose(void) ; 00228 00229 protected: 00230 fmatvec::Vec U; 00231 fmatvec::Vec V; 00232 GeneralMatrix<fmatvec::Vec4> P; 00233 int degU; 00234 int degV; 00235 00236 //changed 00237 Mat InverseU; 00238 Mat InverseV; 00239 00240 // Knot functions 00241 void findSpan(double u, double v, int spanU, int spanV) const; 00242 int findSpanU(double u) const; 00243 int findSpanV(double v) const; 00244 00245 int findMultU(int r) const; 00246 int findMultV(int r) const; 00247 00248 }; 00249 00250 } // end namespace 00251 00253 // */ 00254 //namespace PLib { 00255 // 00257 // \class NurbsSurfaceArray nurbsS.h 00258 // \brief An array of NurbsSurface 00259 // 00260 // This class represents an array of NurbsSurface. 00261 // 00262 // \author Philippe Lavoie 00263 // \date 4 Oct. 1996 00264 //*/ 00265 //template <class T, int N> 00266 //class NurbsSurfaceArray { 00267 //public: 00268 // int n() const //!< a reference to the size of the array 00269 // { return sze ; } 00270 // NurbsSurfaceArray(NurbsSurface<T,N>* Sa, int size) ; 00271 // NurbsSurfaceArray() { S = 0 ; sze = 0 ; rsize = 0 ;} //<! Default constructor 00272 // virtual ~NurbsSurfaceArray(){ if(S){ for(int i=0;i<rsize;i++) delete S[i]; delete []S ; }} 00273 // 00274 // virtual NurbsSurface<T,N>& operator[](int i) 00275 // { return *(S[i]) ; } //!< the ith surface 00276 // virtual NurbsSurface<T,N> operator[](int i) const 00277 // { return *(S[i]) ; } //!< the ith surface 00278 // 00279 // virtual void resize(int s) ; 00280 // void init(NurbsSurface<T,N>* Sa, int size) ; 00281 // 00282 // NurbsSurfaceArray<T,N>& operator=(const NurbsSurfaceArray<T,N>& Sa) ; 00283 // 00284 //protected: 00285 // int sze ; //!< the number of NURBS curves in the array 00286 // int rsize ; //!< the number of space allocated for the array 00287 // NurbsSurface<T,N>** S ; //!< An array of pointers to NURBS curves 00288 //}; 00289 // 00290 //}//end namespace 00291 // 00293 //template <class T, int N> 00294 //inline void degreeElevate(const PLib::NurbsSurface<T,N>& S, int tU, int tV, PLib::NurbsSurface<T,N>& nS) { nS = S ; nS.degreeElevate(tU,tV) ; } 00295 //template <class T, int N> 00296 //inline void degreeElevateU(const PLib::NurbsSurface<T,N>& S, int tU, PLib::NurbsSurface<T,N>& nS) { nS = S ; nS.degreeElevateU(tU) ; } 00297 //template <class T, int N> 00298 //inline void degreeElevateV(const PLib::NurbsSurface<T,N>& S, int tV, PLib::NurbsSurface<T,N>& nS) { nS = S ; nS.degreeElevateV(tV) ; } 00299 // 00300 // 00301 //#ifdef INCLUDE_TEMPLATE_SOURCE 00302 //#include "nurbsS.cpp" 00303 //#endif 00304 00305 #endif
1.8.0