00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 # ifndef shape_parametric_surface_hpp
00014 # define shape_parametric_surface_hpp
00015
00016 # include <shape/bounding_box.hpp>
00017 # include <realroot/Seq.hpp>
00018 # include <shape/point_set.hpp>
00019 # include <shape/surface.hpp>
00020
00021 # define TMPL template<class C, class V>
00022 # define TMPL1 template<class V>
00023 # define SELF parametric_surface<C,V>
00024 # define Surface surface<V>
00025
00026 namespace mmx { namespace shape {
00027
00028 template<class C, class V=default_env>
00029 class parametric_surface : public surface<V>
00030 {
00031 public:
00032
00033 typedef C Scalar;
00034
00035 typedef typename use<point_def,C,V>::Point Point;
00036 typedef typename point_set<C>::PointIterator PointIterator;
00037
00038
00039 parametric_surface(void) {} ;
00040
00041
00042
00043
00044
00045
00046 virtual void eval(Scalar&, Scalar&,Scalar&, Scalar u, Scalar v) const = 0 ;
00047
00048 virtual void eval(Scalar* lp, const Scalar* u, int n) const ;
00049
00050 virtual void sample ( PointIterator lp, const Scalar* u, unsigned m, const Scalar* v, unsigned n ) const ;
00051
00052
00053
00054 virtual void sample ( PointIterator lp, unsigned m, unsigned n ) const ;
00055 virtual void sample ( Scalar* lp, unsigned m, unsigned n, Scalar* u, Scalar* v) const;
00056
00057
00058
00059
00060
00061
00062
00063 virtual double umin(void) const = 0 ;
00064 virtual double umax(void) const = 0 ;
00065 virtual double vmin(void) const = 0 ;
00066 virtual double vmax(void) const = 0 ;
00067
00068
00069
00070 } ;
00071
00072 TMPL void
00073 SELF::eval(Scalar* r, const Scalar* u, int n) const {
00074 Point p;
00075 for (int i=0; i<n;i++) {
00076 this->eval(p.x(),p.y(),p.z(),u[0],u[1]);
00077 *r=p.x();r++;
00078 *r=p.y();r++;
00079 *r=p.z();r++;
00080 u+=2;
00081 }
00082 }
00083
00084
00085 TMPL void
00086 SELF::sample( PointIterator p, unsigned m, unsigned n ) const {
00087 assert(m>1 && n>1);
00088 Scalar
00089 hu=(this->umax() - this->umin())/(m-1), u=this->umin(),
00090 hv=(this->vmax() - this->vmin())/(n-1), v;
00091 Point pp;
00092 for (unsigned i=0; i<m;i++) {
00093 v=vmin();
00094 for (unsigned j=0; j<n;j++,p++) {
00095 this->eval(p->x(),p->y(),p->z(),u,v);
00096 v+=hv;
00097 }
00098 u+=hu;
00099 }
00100 }
00101
00102 TMPL void
00103 SELF::sample (Scalar* r, unsigned m, unsigned n, Scalar* u, Scalar* v) const {
00104 assert(m>1 && n>1);
00105 Scalar
00106 hu=(this->umax() - this->umin())/(m-1),
00107 hv=(this->vmax() - this->vmin())/(n-1);
00108
00109 Scalar * u0 =u, su=umin(), * v0=v, sv=vmin();
00110 for (unsigned i=0; i<m;i++){ *u=su; su+=hu; u++; }
00111 for (unsigned j=0; j<n;j++){ *v=sv; sv+=hv; v++; }
00112
00113 u=u0;
00114 for (unsigned i=0; i<m;i++,u++) {
00115 v=v0;
00116 for (unsigned j=0; j<n;j++,v++) {
00117 this->eval(r[0],r[1],r[2],*u,*v);
00118
00119 r+=3;
00120
00121
00122
00123
00124
00125 }
00126 }
00127 }
00128
00129 TMPL void
00130 SELF::sample (PointIterator p, const Scalar* u, unsigned m, const Scalar* v, unsigned n) const {
00131 assert(m>1 && n>1);
00132 const Scalar * v0=v;
00133
00134 for (unsigned i=0; i<m;i++,u++) {
00135 v=v0;
00136 for (unsigned j=0; j<n;j++,p++,v++) {
00137 this->eval(p->x(),p->y(),p->z(),*u,*v);
00138 }
00139 }
00140 }
00141
00142
00143 } ;
00144 } ;
00145 # undef TMPL
00146 # undef TMPL1
00147 # undef Point
00148 # undef Scalar
00149 # undef Surface
00150 # undef SELF
00151 # endif // PARAMETRICSURFACE_H