Main Page | Class Hierarchy | Class List | File List | Class Members

nurbsS.h

00001 /*============================================================================= 00002 File: nurbsS.h 00003 Purpose: 00004 Revision: $Id: nurbsS.h,v 1.2 2002/05/13 21:07:46 philosophil Exp $ 00005 Created by: Philippe Lavoie (3 Oct, 1996) 00006 Modified by: 00007 00008 Copyright notice: 00009 Copyright (C) 1996-1999 Philippe Lavoie 00010 00011 This library is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU Library General Public 00013 License as published by the Free Software Foundation; either 00014 version 2 of the License, or (at your option) any later version. 00015 00016 This library is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 Library General Public License for more details. 00020 00021 You should have received a copy of the GNU Library General Public 00022 License along with this library; if not, write to the Free 00023 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00024 =============================================================================*/ 00025 00026 #ifndef _nurbs_nurbsS_h_ 00027 #define _nurbs_nurbsS_h_ 00028 00029 #include "nurbs.h" 00030 #include "surface.h" 00031 00034 namespace PLib{ 00035 00036 enum Direction { u_direction=1, v_direction=2, both_direction=3} ; 00037 00038 template <class T, int N> class NurbsSurfaceArray ; 00039 00040 template <class T, int N> void gordonSurface(NurbsCurveArray<T,N>& , NurbsCurveArray<T,N>& , const Matrix< Point_nD<T,N> >& , NurbsSurface<T,N>& ); 00041 template <class T, int N> int surfMeshParams(const Matrix< Point_nD<T,N> >& , Vector<T>& , Vector<T>& ); 00042 template <class T, int N> int surfMeshParamsH(const Matrix< HPoint_nD<T,N> >& , Vector<T>& , Vector<T>& ); 00043 template <class T, int N> int surfMeshParamsClosedU(const Matrix< Point_nD<T,N> >& Qw, Vector<T>& uk, Vector<T>& vl, int degU ); 00044 template <class T, int N> int surfMeshParamsClosedUH(const Matrix< HPoint_nD<T,N> >& Qw, Vector<T>& uk, Vector<T>& vl, int degU ); 00045 00046 template <class T, int N> void globalSurfInterpXY(const Matrix< Point_nD<T,N> >& , int , int , NurbsSurface<T,N>& ); 00047 template <class T, int N> void globalSurfInterpXY(const Matrix< Point_nD<T,N> >& , int , int , NurbsSurface<T,N>& , const Vector<T>& , const Vector<T>& ); 00048 template <class T, int N> void globalSurfApprox(const Matrix< Point_nD<T,N> >& , int , int , NurbsSurface<T,N>& , double=0); 00049 template <class T, int N> void wrapPointMatrix(const Matrix< Point_nD<T,N> >& Q, int , int, Matrix< Point_nD<T,N> >& Qw); 00050 00051 00052 00063 template <class T, int N> 00064 class NurbsSurface : public ParaSurface<T,N> { 00065 public: 00066 NurbsSurface() ; 00067 NurbsSurface(const NurbsSurface<T,N>& nS) ; 00068 NurbsSurface(int DegU, int DegV, const Vector<T>& Uk, const Vector<T>& Vk, const Matrix< HPoint_nD<T,N> >& Cp) ; 00069 NurbsSurface(int DegU, int DegV, Vector<T>& Uk, Vector<T>& Vk, Matrix< Point_nD<T,N> >& Cp, Matrix<T>& W) ; 00070 virtual ~NurbsSurface() 00071 {;} 00072 00073 public: 00074 // Reference to internal data 00075 const Vector<T>& knotU() const 00076 { return U ; } 00077 const Vector<T>& knotV() const 00078 { return V ; } 00079 T knotU(int i) const 00080 { return U[i] ; } 00081 T knotV(int i) const 00082 { return V[i] ; } 00083 const Matrix< HPoint_nD<T,N> >& ctrlPnts() const 00084 { return P; } 00085 const HPoint_nD<T,N> ctrlPnts(int i, int j) const 00086 { return P(i,j); } 00087 int degreeU() const 00088 { return degU ; } 00089 int degreeV() const 00090 { return degV ; } 00091 00092 // Basic operators 00093 virtual NurbsSurface<T,N>& operator=(const NurbsSurface<T,N>&) ; 00094 void resize(int Pu, int Pv, int DegU, int DegV) ; 00095 virtual void resizeKeep(int Pu, int Pv, int DegU, int DegV) ; 00096 int ok(); 00097 00098 // Basis functions 00099 virtual HPoint_nD<T,N> operator()(T u, T v) const ; 00100 00101 void basisFuns(T u, T v, int spanU, int spanV, Vector<T>& Nu, Vector<T>& Nv) const ; 00102 void basisFunsU(T u, int span, Vector<T>& N) const ; 00103 void basisFunsV(T u, int span, Vector<T>& N) const ; 00104 void dersBasisFuns(T u, T v, int dU, int dV,int uspan, int vspan,Matrix<T> & Niku, Matrix<T>& Njkv ) const ; 00105 00106 // Derivative functions 00107 void deriveAt(T u, T v, int d, Matrix< Point_nD<T,N> >& skl) const ; 00108 void deriveAtH(T u, T v, int d, Matrix< HPoint_nD<T,N> >& skl) const; 00109 Point_nD<T,N> normal(T u, T v) const ; 00110 00111 00112 // Surface fitting functions 00113 00114 void globalInterp(const Matrix< Point_nD<T,N> >& Q, int pU, int pV); 00115 void globalInterpH(const Matrix< HPoint_nD<T,N> >& Q, int pU, int pV); 00116 void globalInterpClosedU(const Matrix< Point_nD<T,N> >& Q, int pU, int pV); 00117 void globalInterpClosedUH(const Matrix< HPoint_nD<T,N> >& Q, int pU, int pV); 00118 void leastSquares(const Matrix< Point_nD<T,N> >& Q, int pU, int pV, int nU, int nV) ; 00119 void leastSquaresClosedU(const Matrix< Point_nD<T,N> >& Q, int pU, int pV, int nU, int nV) ; 00120 00121 #ifndef HAVE_ISO_FRIEND_DECL 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 #else 00127 friend void gordonSurface <> (NurbsCurveArray<T,N>& lU, NurbsCurveArray<T,N>& lV, const Matrix< Point_nD<T,N> >& intersections, NurbsSurface<T,N>& gS); 00128 friend void globalSurfInterpXY <> (const Matrix< Point_nD<T,N> >& Q, int pU, int pV, NurbsSurface<T,N>& S); 00129 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); 00130 friend void globalSurfApprox <> (const Matrix< Point_nD<T,N> >& Q, int pU, int pV, NurbsSurface<T,N>& S, double error); 00131 #endif 00132 00133 // Surface generation function 00134 int skinV(NurbsCurveArray<T,N>& ca, int degV); 00135 int skinU(NurbsCurveArray<T,N>& ca, int degU); 00136 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) ; 00137 void sweep(const NurbsCurve<T,N>& t, const NurbsCurve<T,N>& C, int K,int useAy=0, int invAz=0) ; 00138 void makeFromRevolution(const NurbsCurve<T,N>& profile, const Point_nD<T,N>& S, const Point_nD<T,N>& T, double theta) ; 00139 void makeFromRevolution(const NurbsCurve<T,N>& profile, const Point_nD<T,N>& S, const Point_nD<T,N>& T) ; 00140 void makeFromRevolution(const NurbsCurve<T,N>& profile) ; 00141 00142 void makeSphere(const Point_nD<T,N>& O, T r) ; 00143 void makeTorus(const Point_nD<T,N>& O, T R, T r); 00144 00145 00146 void degreeElevate(int tU, int tV) ; 00147 virtual void degreeElevateU(int tU) ; 00148 virtual void degreeElevateV(int tV) ; 00149 00150 00151 int decompose(NurbsSurfaceArray<T,N>& Sa) const ; 00152 00153 // Knot functions 00154 void findSpan(T u, T v, int& spanU, int& spanV) const ; 00155 int findSpanU(T u) const ; 00156 int findSpanV(T v) const ; 00157 00158 int findMultU(int r) const ; 00159 int findMultV(int r) const ; 00160 00161 virtual void refineKnots(const Vector<T>& nU, const Vector<T>& nV) ; 00162 virtual void refineKnotU(const Vector<T>& X); 00163 virtual void refineKnotV(const Vector<T>& X); 00164 00165 virtual void mergeKnots(const Vector<T>& nU, const Vector<T>& nV) ; 00166 virtual void mergeKnotU(const Vector<T>& X); 00167 virtual void mergeKnotV(const Vector<T>& X); 00168 00169 // Measuring functions 00170 T area(T eps=0.001,int n=100) const ; 00171 T areaIn(T us, T ue, T vs, T ve, T eps, int n) const ; 00172 T areaF(T u, T v) const ; 00173 00174 // special functions 00175 void isoCurveU(T u, NurbsCurve<T,N>& c) const ; 00176 void isoCurveV(T v, NurbsCurve<T,N>& c) const ; 00177 00178 // I/O functions 00179 int read(const char* filename); 00180 int write(const char* filename) const; 00181 virtual int read(ifstream &fin) ; 00182 int write(ofstream &fout) const ; 00183 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);} 00184 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);} 00185 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);} 00186 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);} 00187 ostream& print(ostream& os) const ; 00188 00189 int writeVRML(const char* filename,const Color& color=whiteColor,int Nu=20,int Nv=20) const 00190 { return ParaSurface<T,N>::writeVRML(filename,color,Nu,Nv,U[0],U[U.n()-1],V[0],V[V.n()-1]); } 00191 int writeVRML(ostream& fout,const Color& color=whiteColor,int Nu=20,int Nv=20) const 00192 { return ParaSurface<T,N>::writeVRML(fout,color,Nu,Nv,U[0],U[U.n()-1],V[0],V[V.n()-1]); } 00193 00194 int writeVRML97(const char* filename,const Color& color=whiteColor,int Nu=20,int Nv=20) const 00195 { return ParaSurface<T,N>::writeVRML97(filename,color,Nu,Nv,U[0],U[U.n()-1],V[0],V[V.n()-1]); } 00196 int writeVRML97(ostream& fout,const Color& color=whiteColor,int Nu=20,int Nv=20) const 00197 { return ParaSurface<T,N>::writeVRML97(fout,color,Nu,Nv,U[0],U[U.n()-1],V[0],V[V.n()-1]); } 00198 00199 int writePOVRAY(ostream& povray, int patch_type=1, double flatness=0.01, int num_u_steps=8, int num_v_steps=8) const ; 00200 int writePOVRAY(T, ostream& povray, const Color& color=Color(250,250,250),int smooth=0 , T ambient=0.2, T diffuse=0.6) const ; 00201 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 ; 00202 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 ; 00203 00204 int writeRIB(ostream& rib) const ; 00205 int writeRIB(const char* filename, const Color& color, const Point_nD<T,N>& view) const ; 00206 00207 // tesselate is deprecated... 00208 void tesselate(T tolerance, BasicList<Point_nD<T,N> > &points, BasicList<int> &connect, BasicList<Point_nD<T,N> > *normal=0) const ; 00209 00210 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 ; 00211 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 ; 00212 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 ; 00213 int writeOOGL(const char* filename) const ; 00214 00215 int writeDisplayQUADMESH(const char* filename, int iNu=100,int iNv=100,const Color& color=blueColor,T fA=.25, T fO=0.2) const; 00216 00217 00218 // Modifies the shape of the surface 00219 void transform(const MatrixRT<T>& A) ; 00220 void modCP(int i, int j, const HPoint_nD<T,N>& p) 00221 { P(i,j) = p ; } 00222 void modCPby(int i, int j, const HPoint_nD<T,N>& p) 00223 { P(i,j) += p ; } 00224 00225 T& modU(int i) { return U[i] ; } 00226 T modU(int i) const { return U[i]; } 00227 T& modV(int i) { return V[i] ; } 00228 T modV(int i) const { return V[i]; } 00229 00230 void modKnotU(const Vector<T>& uKnot) { if(P.rows()+degU+1==uKnot.n()) U=uKnot ; } 00231 void modKnotV(const Vector<T>& vKnot) { if(P.cols()+degV+1==vKnot.n()) V=vKnot ; } 00232 00233 int movePoint(T u, T v, const Point_nD<T,N>& delta); 00234 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) ; 00235 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) ; 00236 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) ; 00237 00238 NurbsSurface<T,N>& transpose(void) ; 00239 00240 00241 protected: 00242 Vector<T> U ; 00243 Vector<T> V ; 00244 Matrix< HPoint_nD<T,N> > P ; 00245 int degU ; 00246 int degV ; 00247 00248 }; 00249 00250 typedef NurbsSurface<float,3> NurbsSurfacef ; 00251 typedef NurbsSurface<double,3> NurbsSurfaced ; 00252 00253 } // end namespace 00254 00255 typedef PLib::NurbsSurface<float,3> PlNurbsSurfacef ; 00256 typedef PLib::NurbsSurface<double,3> PlNurbsSurfaced ; 00257 00260 namespace PLib { 00261 00271 template <class T, int N> 00272 class NurbsSurfaceArray { 00273 public: 00274 int n() const 00275 { return sze ; } 00276 NurbsSurfaceArray(NurbsSurface<T,N>* Sa, int size) ; 00277 NurbsSurfaceArray() { S = 0 ; sze = 0 ; rsize = 0 ;} //<! Default constructor 00278 virtual ~NurbsSurfaceArray(){ if(S){ for(int i=0;i<rsize;i++) delete S[i]; delete []S ; }} 00279 00280 virtual NurbsSurface<T,N>& operator[](int i) 00281 { return *(S[i]) ; } 00282 virtual NurbsSurface<T,N> operator[](int i) const 00283 { return *(S[i]) ; } 00284 00285 virtual void resize(int s) ; 00286 void init(NurbsSurface<T,N>* Sa, int size) ; 00287 00288 NurbsSurfaceArray<T,N>& operator=(const NurbsSurfaceArray<T,N>& Sa) ; 00289 00290 protected: 00291 int sze ; 00292 int rsize ; 00293 NurbsSurface<T,N>** S ; 00294 }; 00295 00296 }//end namespace 00297 00298 // In case someone wants the old behavior for degree elevation 00299 template <class T, int N> 00300 inline void degreeElevate(const PLib::NurbsSurface<T,N>& S, int tU, int tV, PLib::NurbsSurface<T,N>& nS) { nS = S ; nS.degreeElevate(tU,tV) ; } 00301 template <class T, int N> 00302 inline void degreeElevateU(const PLib::NurbsSurface<T,N>& S, int tU, PLib::NurbsSurface<T,N>& nS) { nS = S ; nS.degreeElevateU(tU) ; } 00303 template <class T, int N> 00304 inline void degreeElevateV(const PLib::NurbsSurface<T,N>& S, int tV, PLib::NurbsSurface<T,N>& nS) { nS = S ; nS.degreeElevateV(tV) ; } 00305 00306 00307 #ifdef INCLUDE_TEMPLATE_SOURCE 00308 #include "nurbsS.cpp" 00309 #endif 00310 00311 00312 #endif

Generated on Fri Aug 13 11:03:45 2004 for NURBS++ by doxygen 1.3.7