All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
nurbs_surface.h
1 #ifndef NURBS_SURFACE_FMATVEC_H_
2 #define NURBS_SURFACE_FMATVEC_H_
3 
4 #include <mbsim/numerics/nurbs/nurbs_defs.h>
5 #include "nurbs_curve.h"
6 
7 namespace fmatvec {
8  typedef Matrix<General, Fixed<4>, Var, double> Mat4xV;
9 
10  typedef Matrix<General, Var, Fixed<4>, double> MatVx4;
11 }
12 
13 namespace MBSim {
14 
15 // enum Direction { u_direction=1, v_direction=2, both_direction=3} ;
16 //
17 // template <class T, int N> class NurbsSurfaceArray ;
18 //
19 // template <class T, int N> void gordonSurface(NurbsCurveArray<T,N>& , NurbsCurveArray<T,N>& , const Matrix< Point_nD<T,N> >& , NurbsSurface<T,N>& );
20  int surfMeshParams(const GeneralMatrix<fmatvec::Vec3>& Q, Vec& uk, Vec& vl);
21 // template <class T, int N> int surfMeshParamsH(const Matrix< HPoint_nD<T,N> >& , Vector<T>& , Vector<T>& );
22 // template <class T, int N> int surfMeshParamsClosedU(const Matrix< Point_nD<T,N> >& Qw, Vector<T>& uk, Vector<T>& vl, int degU );
23  int surfMeshParamsClosedU(const GeneralMatrix<fmatvec::Vec3>& Q, Vec& uk, Vec& vl, int degU);
24 // template <class T, int N> int surfMeshParamsClosedUH(const Matrix< HPoint_nD<T,N> >& Qw, Vector<T>& uk, Vector<T>& vl, int degU );
25 //
26 // template <class T, int N> void globalSurfInterpXY(const Matrix< Point_nD<T,N> >& , int , int , NurbsSurface<T,N>& );
27 // template <class T, int N> void globalSurfInterpXY(const Matrix< Point_nD<T,N> >& , int , int , NurbsSurface<T,N>& , const Vector<T>& , const Vector<T>& );
28 // template <class T, int N> void globalSurfApprox(const Matrix< Point_nD<T,N> >& , int , int , NurbsSurface<T,N>& , double=0);
29 // template <class T, int N> void wrapPointMatrix(const Matrix< Point_nD<T,N> >& Q, int , int, Matrix< Point_nD<T,N> >& Qw);
30 
38 //template <class T, int N>
39  class NurbsSurface {
40  public:
41  NurbsSurface();
42  NurbsSurface(const NurbsSurface& nS);
43 // NurbsSurface(int DegU, int DegV, const Vector<T>& Uk, const Vector<T>& Vk, const Matrix< HPoint_nD<T,N> >& Cp) ;
44 // NurbsSurface(int DegU, int DegV, Vector<T>& Uk, Vector<T>& Vk, Matrix< Point_nD<T,N> >& Cp, Matrix<T>& W) ;
46  virtual ~NurbsSurface()
47  {
48  ;
49  }
50 
51  public:
52  // Reference to internal data
54  const Vec& knotU() const
55  {
56  return U;
57  }
59  const Vec& knotV() const
60  {
61  return V;
62  }
64  double knotU(int i) const
65  {
66  return U(i);
67  }
69  double knotV(int i) const
70  {
71  return V(i);
72  }
75  {
76  return P;
77  }
79  const fmatvec::Vec4 ctrlPnts(int i, int j) const
80  {
81  return P(i, j);
82  }
84  int degreeU() const
85  {
86  return degU;
87  }
89  int degreeV() const
90  {
91  return degV;
92  }
93 
94  // Basic operators
95  virtual NurbsSurface& operator=(const NurbsSurface&);
96  void resize(int Pu, int Pv, int DegU, int DegV);
97 // virtual void resizeKeep(int Pu, int Pv, int DegU, int DegV) ;
98 // int ok();
99 
100  // Basis functions
101  fmatvec::HPoint<3> operator()(double u, double v) const;
103  fmatvec::Point<3> pointAt(double u, double v) const;
104 // void basisFuns(T u, T v, int spanU, int spanV, Vector<T>& Nu, Vector<T>& Nv) const ;
105 // void basisFunsU(T u, int span, Vector<T>& M) const ;
106 // void basisFunsV(T u, int span, Vector<T>& M) const ;
107 // void dersBasisFuns(T u, T v, int dU, int dV,int uspan, int vspan,Matrix<T> & Niku, Matrix<T>& Njkv ) const ;
108 
109  // Derivative functions
110  void deriveAt(double u, double v, int d, GeneralMatrix<Vec3> &skl) const;
111  void deriveAtH(double u, double v, int d, GeneralMatrix<Vec4> &skl) const;
112  Vec3 normal(double u, double v) const;
113 
114  // Surface fitting functions
115 
116  void globalInterp(const GeneralMatrix<fmatvec::Vec3>& Q, int DegU, int DegV);
117  void globalInterp(const GeneralMatrix<fmatvec::Vec3>& Q, const Vec& uk, const Vec& vk, int DegU, int DegV);
118  void globalInterpClosedU(const GeneralMatrix<fmatvec::Vec3>& Q, int DegU, int DegV);
119  void globalInterpClosedU(const GeneralMatrix<fmatvec::Vec3>& Q, const Vec& uk, const Vec& vk, int DegU, int DegV);
120 // 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
121 // void globalInterpClosedUH(const Matrix< HPoint_nD<T,N> >& Q, int pU, int pV);
122 // 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
123 // void leastSquares(const Matrix< Point_nD<T,N> >& Q, int pU, int pV, int nU, int nV) ;
124 // void leastSquaresClosedU(const Matrix< Point_nD<T,N> >& Q, int pU, int pV, int nU, int nV) ;
125 //
126 //#ifndef HAVE_ISO_FRIEND_DECL
127 // friend void gordonSurface (NurbsCurveArray<T,N>& lU, NurbsCurveArray<T,N>& lV, const Matrix< Point_nD<T,N> >& intersections, NurbsSurface<T,N>& gS);
128 // friend void globalSurfInterpXY (const Matrix< Point_nD<T,N> >& Q, int pU, int pV, NurbsSurface<T,N>& S);
129 // 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);
130 // friend void globalSurfApprox (const Matrix< Point_nD<T,N> >& Q, int pU, int pV, NurbsSurface<T,N>& S, double error);
131 //#else
132 // friend void gordonSurface <> (NurbsCurveArray<T,N>& lU, NurbsCurveArray<T,N>& lV, const Matrix< Point_nD<T,N> >& intersections, NurbsSurface<T,N>& gS);
133 // friend void globalSurfInterpXY <> (const Matrix< Point_nD<T,N> >& Q, int pU, int pV, NurbsSurface<T,N>& S);
134 // 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);
135 // friend void globalSurfApprox <> (const Matrix< Point_nD<T,N> >& Q, int pU, int pV, NurbsSurface<T,N>& S, double error);
136 //#endif
137 //
138 // // Surface generation function
139 // int skinV(NurbsCurveArray<T,N>& ca, int degV);
140 // int skinU(NurbsCurveArray<T,N>& ca, int degU);
141 // 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) ;
142 // void sweep(const NurbsCurve<T,N>& t, const NurbsCurve<T,N>& C, int K,int useAy=0, int invAz=0) ;
143 // void makeFromRevolution(const NurbsCurve<T,N>& profile, const Point_nD<T,N>& S, const Point_nD<T,N>& Z, double theta) ;
144 // void makeFromRevolution(const NurbsCurve<T,N>& profile, const Point_nD<T,N>& S, const Point_nD<T,N>& Z) ;
145 // void makeFromRevolution(const NurbsCurve<T,N>& profile) ;
146 //
147 // void makeSphere(const Point_nD<T,N>& O, T r) ;
148 // void makeTorus(const Point_nD<T,N>& O, T R, T r);
149 //
150 //
151 // void degreeElevate(int tU, int tV) ;
152 // virtual void degreeElevateU(int tU) ;
153 // virtual void degreeElevateV(int tV) ;
154 //
155 //
156 // int decompose(NurbsSurfaceArray<T,N>& Sa) const ;
157 //
158 //
159 //
160 // virtual void refineKnots(const Vector<T>& nU, const Vector<T>& nV) ;
161 // virtual void refineKnotU(const Vector<T>& X);
162 // virtual void refineKnotV(const Vector<T>& X);
163 //
164 // virtual void mergeKnots(const Vector<T>& nU, const Vector<T>& nV) ;
165 // virtual void mergeKnotU(const Vector<T>& X);
166 // virtual void mergeKnotV(const Vector<T>& X);
167 //
168 // // Measuring functions
169 // T area(T eps=0.001,int n=100) const ;
170 // T areaIn(T us, T ue, T vs, T ve, T eps, int n) const ;
171 // T areaF(T u, T v) const ;
172 //
173 // // special functions
174 // void isoCurveU(T u, NurbsCurve<T,N>& c) const ;
175 // void isoCurveV(T v, NurbsCurve<T,N>& c) const ;
176 //
177 // // I/O functions
178 // int read(const char* filename);
179 // int write(const char* filename) const;
180 // virtual int read(ifstream &fin) ;
181 // int write(ofstream &fout) const ;
182 // 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);}
183 // 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);}
184 // 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);}
185 // 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);}
186 // ostream& print(ostream& os) const ;
187 //
188 // //! Calls the ParaSurface routine with proper values
189 // int writeVRML(const char* filename,const Color& color=whiteColor,int Nu=20,int Nv=20) const
190 // { return ParaSurface<T,N>::writeVRML(filename,color,Nu,Nv,U[0],U[U.n()-1],V[0],V[V.n()-1]); }
191 // //! Calls the ParaSurface routine with proper values
192 // int writeVRML(ostream& fout,const Color& color=whiteColor,int Nu=20,int Nv=20) const
193 // { return ParaSurface<T,N>::writeVRML(fout,color,Nu,Nv,U[0],U[U.n()-1],V[0],V[V.n()-1]); }
194 //
195 // //! Calls the ParaSurface routine with proper values
196 // int writeVRML97(const char* filename,const Color& color=whiteColor,int Nu=20,int Nv=20) const
197 // { return ParaSurface<T,N>::writeVRML97(filename,color,Nu,Nv,U[0],U[U.n()-1],V[0],V[V.n()-1]); }
198 // //! Calls the ParaSurface routine with proper values
199 // int writeVRML97(ostream& fout,const Color& color=whiteColor,int Nu=20,int Nv=20) const
200 // { return ParaSurface<T,N>::writeVRML97(fout,color,Nu,Nv,U[0],U[U.n()-1],V[0],V[V.n()-1]); }
201 //
202 // int writePOVRAY(ostream& povray, int patch_type=1, double flatness=0.01, int num_u_steps=8, int num_v_steps=8) const ;
203 // int writePOVRAY(T, ostream& povray, const Color& color=Color(250,250,250),int smooth=0 , T ambient=0.2, T diffuse=0.6) const ;
204 // 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 ;
205 // 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 ;
206 //
207 // int writeRIB(ostream& rib) const ;
208 // int writeRIB(char* filename, const Color& color, const Point_nD<T,N>& view) const ;
209 //
210 // // tesselate is deprecated...
211 // void tesselate(T tolerance, BasicList<Point_nD<T,N> > &points, BasicList<int> &connect, BasicList<Point_nD<T,N> > *normal=0) const ;
212 //
213 // 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 ;
214 // 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 ;
215 // 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 ;
216 // int writeOOGL(const char* filename) const ;
217 //
218 // int writeDisplayQUADMESH(const char* filename, int iNu=100,int iNv=100,const Color& color=blueColor,T fA=.25, T fO=0.2) const;
219 //
220 //
221 // // Modifies the shape of the surface
222 // void transform(const MatrixRT<T>& A) ;
223 // //! Modifies a control point
224 // void modCP(int i, int j, const HPoint_nD<T,N>& p)
225 // { P(i,j) = p ; }
226 // //! Modifies a control point
227 // void modCPby(int i, int j, const HPoint_nD<T,N>& p)
228 // { P(i,j) += p ; }
229 //
230 // T& modU(int i) { return U[i] ; }
231 // //! modifies a knot
232 // T modU(int i) const { return U[i]; }
233 // //! modifies a knot
234 // T& modV(int i) { return V[i] ; }
235 // //! modifies a knot
236 // T modV(int i) const { return V[i]; }
237 //
238 // //! modifies the U knot vector if uKnot is of a proper size
239 // void modKnotU(const Vector<T>& uKnot) { if(P.rows()+degU+1==uKnot.n()) U=uKnot ; }
240 // //! modifies the U knot vector if uKnot is of a proper size
241 // void modKnotV(const Vector<T>& vKnot) { if(P.cols()+degV+1==vKnot.n()) V=vKnot ; }
242 //
243 // int movePoint(T u, T v, const Point_nD<T,N>& delta);
244 // 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) ;
245 // 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) ;
246 // 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) ;
247 //
248 // NurbsSurface<T,N>& transpose(void) ;
249 
250  protected:
254  int degU;
255  int degV;
256 
257  //changed
260 
261  // Knot functions
262  void findSpan(double u, double v, int spanU, int spanV) const;
263  int findSpanU(double u) const;
264  int findSpanV(double v) const;
265 
266  int findMultU(int r) const;
267  int findMultV(int r) const;
268 
269  };
270 
271 } // end namespace
272 
274 // */
275 //namespace PLib {
276 //
278 // \class NurbsSurfaceArray nurbsS.h
279 // \brief An array of NurbsSurface
280 //
281 // This class represents an array of NurbsSurface.
282 //
283 // \author Philippe Lavoie
284 // \date 4 Oct. 1996
285 //*/
286 //template <class T, int N>
287 //class NurbsSurfaceArray {
288 //public:
289 // //! a reference to the size of the array
290 // int n() const
291 // { return sze ; }
292 // NurbsSurfaceArray(NurbsSurface<T,N>* Sa, int size) ;
293 // NurbsSurfaceArray() { S = 0 ; sze = 0 ; rsize = 0 ;} //<! Default constructor
294 // virtual ~NurbsSurfaceArray(){ if(S){ for(int i=0;i<rsize;i++) delete S[i]; delete []S ; }}
295 //
296 // //! the ith surface
297 // virtual NurbsSurface<T,N>& operator[](int i)
298 // { return *(S[i]) ; }
299 // //! the ith surface
300 // virtual NurbsSurface<T,N> operator[](int i) const
301 // { return *(S[i]) ; }
302 //
303 // virtual void resize(int s) ;
304 // void init(NurbsSurface<T,N>* Sa, int size) ;
305 //
306 // NurbsSurfaceArray<T,N>& operator=(const NurbsSurfaceArray<T,N>& Sa) ;
307 //
308 //protected:
309 // int sze ; //!< the number of NURBS curves in the array
310 // int rsize ; //!< the number of space allocated for the array
311 // NurbsSurface<T,N>** S ; //!< An array of pointers to NURBS curves
312 //};
313 //
314 //}//end namespace
315 //
317 //template <class T, int N>
318 //inline void degreeElevate(const PLib::NurbsSurface<T,N>& S, int tU, int tV, PLib::NurbsSurface<T,N>& nS) { nS = S ; nS.degreeElevate(tU,tV) ; }
319 //template <class T, int N>
320 //inline void degreeElevateU(const PLib::NurbsSurface<T,N>& S, int tU, PLib::NurbsSurface<T,N>& nS) { nS = S ; nS.degreeElevateU(tU) ; }
321 //template <class T, int N>
322 //inline void degreeElevateV(const PLib::NurbsSurface<T,N>& S, int tV, PLib::NurbsSurface<T,N>& nS) { nS = S ; nS.degreeElevateV(tV) ; }
323 //
324 //
325 //#ifdef INCLUDE_TEMPLATE_SOURCE
326 //#include "nurbsS.cpp"
327 //#endif
328 
329 #endif
double knotU(int i) const
Returns the i-th knot from U.
Definition: nurbs_surface.h:64
int findSpanV(double v) const
finds the span in the V direction
Definition: nurbs_surface.cc:448
Vec3 normal(double u, double v) const
Computes the normal of the surface at (u,v)
Definition: nurbs_surface.cc:672
fmatvec::Vec U
the U knot vector
Definition: nurbs_surface.h:251
void globalInterpClosedU(const GeneralMatrix< fmatvec::Vec3 > &Q, int DegU, int DegV)
Generates a closed surface using global interpolation.
Definition: nurbs_surface.cc:214
virtual NurbsSurface & operator=(const NurbsSurface &)
NurbsSurface assignment.
Definition: nurbs_surface.cc:45
GeneralMatrix< fmatvec::Vec4 > P
The matrix of control points.
Definition: nurbs_surface.h:253
const Vec & knotV() const
A reference to the V knot vector.
Definition: nurbs_surface.h:59
virtual ~NurbsSurface()
Empty desctructor.
Definition: nurbs_surface.h:46
int degreeV() const
A reference to the degree in V of the surface.
Definition: nurbs_surface.h:89
NurbsSurface()
Default constructor.
Definition: nurbs_surface.cc:25
wrapper class for nurbs type HPoint
Definition: nurbs_defs.h:43
A class to represent a NURBS surface.
Definition: nurbs_surface.h:39
void findSpan(double u, double v, int spanU, int spanV) const
Finds the multiplicity of a knot in the U knot.
Definition: nurbs_surface.cc:388
void deriveAt(double u, double v, int d, GeneralMatrix< Vec3 > &skl) const
Find the non-zero basis functions in the U and V direction.
Definition: nurbs_surface.cc:574
int degV
the degree of the surface in V
Definition: nurbs_surface.h:255
Mat InverseU
The matrix for the computation of the control points in U-direction.
Definition: nurbs_surface.h:258
fmatvec::Vec V
the V knot vector
Definition: nurbs_surface.h:252
void resize(int Pu, int Pv, int DegU, int DegV)
Resize the surface.
Definition: nurbs_surface.cc:70
wrapper class for nurbs type Point
Definition: nurbs_defs.h:13
fmatvec::HPoint< 3 > operator()(double u, double v) const
Returns the point on the surface at u,v.
Definition: nurbs_surface.cc:694
double knotV(int i) const
Returns the i-th knot from V.
Definition: nurbs_surface.h:69
int degreeU() const
A reference to the degree in U of the surface.
Definition: nurbs_surface.h:84
int findSpanU(double u) const
finds the span in the U direction
Definition: nurbs_surface.cc:410
void deriveAtH(double u, double v, int d, GeneralMatrix< Vec4 > &skl) const
computes the point and the derivatives of degree d and below at (u,v)
Definition: nurbs_surface.cc:623
const fmatvec::Vec4 ctrlPnts(int i, int j) const
A reference to the control point at (i,j)
Definition: nurbs_surface.h:79
int degU
the degree of the surface in U
Definition: nurbs_surface.h:254
fmatvec::Point< 3 > pointAt(double u, double v) const
rojects the point in the normal space
Definition: nurbs_surface.cc:725
const Vec & knotU() const
A reference to the U knot vector.
Definition: nurbs_surface.h:54
void globalInterp(const GeneralMatrix< fmatvec::Vec3 > &Q, int DegU, int DegV)
Generates a surface using global interpolation.
Definition: nurbs_surface.cc:89
Mat InverseV
The matrix for the computation of the control points in V-direction.
Definition: nurbs_surface.h:259
const GeneralMatrix< Vec4 > & ctrlPnts() const
A reference to the control points.
Definition: nurbs_surface.h:74
wrapper class for nurbs surface interpolating data point
Definition: nurbs_defs.h:105

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Home