Main Page   Class Hierarchy   Compound List   File List   Compound Members  

nurbsS.h

00001 /*=============================================================================
00002         File: nurbsS.h
00003      Purpose:       
00004     Revision: $Id: nurbsS.h,v 1.3 2002/05/27 19:57:45 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   virtual void reset(const Matrix< HPoint_nD<T,N> >& Pts, const Vector<T> &U1, const Vector<T> &V1) ;
00095   void resize(int Pu, int Pv, int DegU, int DegV) ;
00096   virtual void resizeKeep(int Pu, int Pv, int DegU, int DegV) ;
00097   int ok();
00098   
00099   // Basis functions
00100   virtual HPoint_nD<T,N> operator()(T u, T v) const ;
00101 
00102   void basisFuns(T u, T v, int spanU, int spanV, Vector<T>& Nu, Vector<T>& Nv) const ;
00103   void basisFunsU(T u, int span, Vector<T>& N) const ;
00104   void basisFunsV(T u, int span, Vector<T>& N) const ;
00105   void dersBasisFuns(T u, T v, int dU, int dV,int uspan, int vspan,Matrix<T> & Niku, Matrix<T>& Njkv ) const ; 
00106 
00107   // Derivative functions
00108   void deriveAt(T u, T v, int d, Matrix< Point_nD<T,N> >& skl) const ;
00109   void deriveAtH(T u, T v, int d, Matrix< HPoint_nD<T,N> >& skl) const;
00110   Point_nD<T,N> normal(T u, T v) const ;
00111 
00112   
00113   // Surface fitting functions
00114 
00115   void globalInterp(const Matrix< Point_nD<T,N> >& Q, int pU, int pV);
00116   void globalInterpH(const Matrix< HPoint_nD<T,N> >& Q, int pU, int pV);
00117   void globalInterpClosedU(const Matrix< Point_nD<T,N> >& Q, int pU, int pV);
00118   void globalInterpClosedUH(const Matrix< HPoint_nD<T,N> >& Q, int pU, int pV);
00119   void leastSquares(const Matrix< Point_nD<T,N> >& Q, int pU, int pV, int nU, int nV) ;
00120   void leastSquaresClosedU(const Matrix< Point_nD<T,N> >& Q, int pU, int pV, int nU, int nV) ;
00121 
00122 #ifndef HAVE_ISO_FRIEND_DECL
00123   friend void gordonSurface (NurbsCurveArray<T,N>& lU, NurbsCurveArray<T,N>& lV, const Matrix< Point_nD<T,N> >& intersections, NurbsSurface<T,N>& gS);
00124   friend void globalSurfInterpXY (const Matrix< Point_nD<T,N> >& Q, int pU, int pV, NurbsSurface<T,N>& S);
00125   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);
00126   friend void globalSurfApprox (const Matrix< Point_nD<T,N> >& Q, int pU, int pV, NurbsSurface<T,N>& S, double error);
00127 #else
00128   friend void gordonSurface <> (NurbsCurveArray<T,N>& lU, NurbsCurveArray<T,N>& lV, const Matrix< Point_nD<T,N> >& intersections, NurbsSurface<T,N>& gS);
00129   friend void globalSurfInterpXY <> (const Matrix< Point_nD<T,N> >& Q, int pU, int pV, NurbsSurface<T,N>& S);
00130   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);
00131   friend void globalSurfApprox <> (const Matrix< Point_nD<T,N> >& Q, int pU, int pV, NurbsSurface<T,N>& S, double error);
00132 #endif
00133 
00134   // Surface generation function
00135   int skinV(NurbsCurveArray<T,N>& ca, int degV);
00136   int skinU(NurbsCurveArray<T,N>& ca, int degU);
00137   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) ;
00138   void sweep(const NurbsCurve<T,N>& t, const NurbsCurve<T,N>& C, int K,int useAy=0, int invAz=0) ;
00139   void makeFromRevolution(const NurbsCurve<T,N>& profile, const Point_nD<T,N>& S, const Point_nD<T,N>& T, double theta) ;
00140   void makeFromRevolution(const NurbsCurve<T,N>& profile, const Point_nD<T,N>& S, const Point_nD<T,N>& T) ;
00141   void makeFromRevolution(const NurbsCurve<T,N>& profile) ;
00142 
00143   void makeSphere(const Point_nD<T,N>& O, T r) ; 
00144   void makeTorus(const Point_nD<T,N>& O, T R, T r);
00145 
00146 
00147   void degreeElevate(int tU, int tV) ;
00148   virtual void degreeElevateU(int tU) ;
00149   virtual void degreeElevateV(int tV) ;
00150 
00151   
00152   int decompose(NurbsSurfaceArray<T,N>& Sa) const ;
00153 
00154   // Knot functions
00155   void findSpan(T u, T v, int& spanU, int& spanV) const ;
00156   int findSpanU(T u) const ;
00157   int findSpanV(T v) const ;  
00158   
00159   int findMultU(int r) const ;
00160   int findMultV(int r) const ;
00161 
00162   virtual void refineKnots(const Vector<T>& nU, const Vector<T>& nV) ;
00163   virtual void refineKnotU(const Vector<T>& X);
00164   virtual void refineKnotV(const Vector<T>& X);
00165   
00166   virtual void mergeKnots(const Vector<T>& nU, const Vector<T>& nV) ;
00167   virtual void mergeKnotU(const Vector<T>& X);
00168   virtual void mergeKnotV(const Vector<T>& X);
00169   
00170   // Measuring functions
00171   T area(T eps=0.001,int n=100) const ;
00172   T areaIn(T us, T ue, T vs, T ve, T eps, int n) const ;
00173   T areaF(T u, T v) const ;
00174 
00175   // special functions
00176   void isoCurveU(T u, NurbsCurve<T,N>& c) const ;
00177   void isoCurveV(T v, NurbsCurve<T,N>& c) const ;
00178 
00179   // I/O functions
00180   int read(const char* filename);
00181   int write(const char* filename) const;
00182   virtual int read(ifstream &fin) ;
00183   int write(ofstream &fout) const ;
00184   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);}
00185   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);}
00186   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);}
00187   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);}
00188   ostream& print(ostream& os) const ; 
00189 
00190   int writeVRML(const char* filename,const Color& color=whiteColor,int Nu=20,int Nv=20) const 
00191     { return ParaSurface<T,N>::writeVRML(filename,color,Nu,Nv,U[0],U[U.n()-1],V[0],V[V.n()-1]); } 
00192   int writeVRML(ostream& fout,const Color& color=whiteColor,int Nu=20,int Nv=20) const 
00193     { return ParaSurface<T,N>::writeVRML(fout,color,Nu,Nv,U[0],U[U.n()-1],V[0],V[V.n()-1]); } 
00194 
00195   int writeVRML97(const char* filename,const Color& color=whiteColor,int Nu=20,int Nv=20) const 
00196     { return ParaSurface<T,N>::writeVRML97(filename,color,Nu,Nv,U[0],U[U.n()-1],V[0],V[V.n()-1]); } 
00197   int writeVRML97(ostream& fout,const Color& color=whiteColor,int Nu=20,int Nv=20) const 
00198     { return ParaSurface<T,N>::writeVRML97(fout,color,Nu,Nv,U[0],U[U.n()-1],V[0],V[V.n()-1]); } 
00199 
00200   int writePOVRAY(ostream& povray, int patch_type=1, double flatness=0.01, int num_u_steps=8, int num_v_steps=8) const ;
00201   int writePOVRAY(T, ostream& povray, const Color& color=Color(250,250,250),int smooth=0 , T ambient=0.2, T diffuse=0.6) const ;
00202   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 ;
00203   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 ;
00204 
00205   int writeRIB(ostream& rib) const ;
00206   int writeRIB(const char* filename, const Color& color, const Point_nD<T,N>& view) const ;
00207  
00208   // tesselate is deprecated...
00209   void tesselate(T tolerance, BasicList<Point_nD<T,N> > &points, BasicList<int> &connect, BasicList<Point_nD<T,N> > *normal=0) const ;
00210 
00211   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 ;
00212   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 ;
00213   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 ;
00214   int writeOOGL(const char* filename) const ;
00215   
00216   int writeDisplayQUADMESH(const char* filename, int iNu=100,int iNv=100,const Color& color=blueColor,T fA=.25, T  fO=0.2) const;
00217 
00218 
00219   // Modifies the shape of the surface
00220   void transform(const MatrixRT<T>& A) ;
00221   void modCP(int i, int j, const HPoint_nD<T,N>& p) 
00222     { P(i,j) = p ; } 
00223   void modCPby(int i, int j, const HPoint_nD<T,N>& p) 
00224     { P(i,j) += p ; } 
00225   
00226   T& modU(int i) { return U[i] ; }  
00227   T modU(int i) const { return U[i]; } 
00228   T& modV(int i) { return V[i] ; } 
00229   T modV(int i) const { return V[i]; } 
00230   
00231   void modKnotU(const Vector<T>& uKnot) { if(P.rows()+degU+1==uKnot.n()) U=uKnot ; } 
00232   void modKnotV(const Vector<T>& vKnot) { if(P.cols()+degV+1==vKnot.n()) V=vKnot ; } 
00233   
00234   int movePoint(T u, T v, const Point_nD<T,N>& delta);
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) ;
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) ;
00237   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) ;
00238 
00239   NurbsSurface<T,N>& transpose(void) ;
00240 
00241 
00242 protected:
00243   Vector<T> U ; 
00244   Vector<T> V ; 
00245   Matrix< HPoint_nD<T,N> > P ; 
00246   int degU ; 
00247   int degV ; 
00248 
00249 };
00250 
00251 typedef NurbsSurface<float,3> NurbsSurfacef ;
00252 typedef NurbsSurface<double,3> NurbsSurfaced ;
00253 
00254 } // end namespace
00255 
00256 typedef PLib::NurbsSurface<float,3> PlNurbsSurfacef ;
00257 typedef PLib::NurbsSurface<double,3> PlNurbsSurfaced ;
00258 
00261 namespace PLib {
00262 
00272 template <class T, int N>
00273 class NurbsSurfaceArray {
00274 public:
00275   int n() const 
00276     { return sze ; }
00277   NurbsSurfaceArray(NurbsSurface<T,N>* Sa, int size) ;
00278   NurbsSurfaceArray() { S = 0 ; sze = 0 ; rsize = 0 ;} //<! Default constructor
00279   virtual ~NurbsSurfaceArray(){ if(S){ for(int i=0;i<rsize;i++) delete S[i];  delete []S ; }}
00280   
00281   virtual NurbsSurface<T,N>& operator[](int i) 
00282     { return *(S[i]) ; } 
00283   virtual NurbsSurface<T,N> operator[](int i) const 
00284     { return *(S[i]) ; } 
00285 
00286   virtual void resize(int s) ;
00287   void init(NurbsSurface<T,N>* Sa, int size) ;
00288 
00289   NurbsSurfaceArray<T,N>& operator=(const NurbsSurfaceArray<T,N>& Sa) ;
00290 
00291 protected:
00292   int sze ; 
00293   int rsize ; 
00294   NurbsSurface<T,N>** S ; 
00295 };
00296 
00297 }//end namespace
00298 
00299 // In case someone wants the old behavior for degree elevation
00300 template <class T, int N>
00301 inline void degreeElevate(const PLib::NurbsSurface<T,N>& S, int tU, int tV, PLib::NurbsSurface<T,N>& nS) { nS = S ; nS.degreeElevate(tU,tV) ; }
00302 template <class T, int N>
00303 inline void degreeElevateU(const PLib::NurbsSurface<T,N>& S, int tU, PLib::NurbsSurface<T,N>& nS) { nS = S ; nS.degreeElevateU(tU) ; }
00304 template <class T, int N>
00305 inline void degreeElevateV(const PLib::NurbsSurface<T,N>& S, int tV, PLib::NurbsSurface<T,N>& nS) { nS = S ; nS.degreeElevateV(tV) ; }
00306 
00307 
00308 #ifdef INCLUDE_TEMPLATE_SOURCE
00309 #include "nurbsS.cpp"
00310 #endif
00311 
00312 
00313 #endif 

Generated on Tue Jun 24 13:26:58 2003 for NURBS++ by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002