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