shape_doc 0.1
/Users/mourrain/Devel/mmx/shape/include/shape/surface_parametric.hpp
Go to the documentation of this file.
00001 /*****************************************************************************
00002  * M a t h e m a g i x
00003  *****************************************************************************
00004  * ParametricSurface
00005  * 2008-03-28
00006  * Julien Wintz
00007  *****************************************************************************
00008  *               Copyright (C) 2006 INRIA Sophia-Antipolis
00009  *****************************************************************************
00010  * Comments :
00011  ****************************************************************************/
00012 
00013 # ifndef shape_surface_parametric_hpp
00014 # define shape_surface_parametric_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 Scalar double
00024 # define SELF surface_parametric<C,V> 
00025 # define Surface surface<V> 
00026 //====================================================================
00027 namespace mmx {
00028 namespace shape {
00029 
00030 TMPL struct surface_parametric;
00031 
00032 // struct surface_parametric_def {};
00033 // TMPL1 struct use<surface_parametric_def,V>
00034 // {
00035 //   typedef surface_parametric<V> ParametricSurface;
00036 // };
00037 
00038 template<class C, class V=default_env>
00039 class surface_parametric : public surface<V>
00040 {
00041 public:
00042   
00043   typedef typename use<point_def,V>::Point          Point;
00044   typedef typename point_set<V>::PointIterator PointIterator;
00045 
00046 
00047   surface_parametric(void) {} ;
00048   //  surface_parametric(const BoundingBox & box): surface(box){}
00049 
00050   //  virtual void set_grid( int m, int n ) = 0;
00051 
00052   virtual Point* eval(double u, double v)            const = 0 ;
00053   virtual void   eval(Point& p, double u, double v)  const = 0 ;
00054   virtual Point* operator() (double u, double v)     const { return this->eval(u,v); }
00055   virtual void   eval(Scalar* lp, const Scalar* u, int n) const ;
00056 
00057   virtual void sample ( PointIterator lp, const Scalar* u, unsigned m, const Scalar* v, unsigned n ) const ;
00058 
00059 
00060   //  virtual void sample ( Point* lp, const double * uv, int n );
00061   virtual void sample ( PointIterator lp, unsigned m, unsigned n ) const ;
00062   virtual void sample ( Scalar* lp, unsigned m, unsigned n, Scalar* u, Scalar* v) const ;
00063 
00064   //  virtual ParametricCurve * iso_u( Scalar u )                                               const = 0;
00065   //  virtual ParametricCurve * iso_v( Scalar v )                                               const = 0;
00066 
00067   //  IParametricSurface * gauss_map() const = 0;
00068   //  virtual IGLGood * triangulate(void) = 0 ;
00069 
00070   virtual double umin(void) const = 0 ;
00071   virtual double umax(void) const = 0 ;
00072   virtual double vmin(void) const = 0 ;
00073   virtual double vmax(void) const = 0 ;
00074   virtual void   get_range(double & umin, double & umax, double & vmin, double & vmax )              const = 0;
00075   
00076 } ;
00077 
00078 TMPL void 
00079 SELF::eval(Scalar* r, const Scalar* u, int n) const {
00080   Point p;
00081   for (int i=0; i<n;i++) {
00082     this->eval(p,u[0],u[1]);
00083     *r=p.x();r++; 
00084     *r=p.y();r++;
00085     *r=p.z();r++;
00086     u+=2;
00087   }
00088 }
00089 
00090 
00091 TMPL void
00092 SELF::sample( PointIterator p, unsigned m, unsigned n ) const {
00093   assert(m>1 && n>1);
00094   Scalar 
00095     hu=(this->umax() - this->umin())/(m-1), u=umin(),
00096     hv=(this->vmax() - this->vmin())/(n-1), v;
00097   Point pp;
00098   for (unsigned i=0; i<m;i++) {
00099     v=vmin();
00100     for (unsigned j=0; j<n;j++,p++) {
00101       this->eval(*p,u,v);
00102       v+=hv;
00103     }
00104     u+=hu;
00105   }
00106 }
00107 
00108 TMPL void 
00109 SELF::sample (Scalar* r, unsigned m,  unsigned n, Scalar* u, Scalar* v) const {
00110   assert(m>1 && n>1);
00111   Scalar 
00112     hu=(this->umax() - this->umin())/(m-1), 
00113     hv=(this->vmax() - this->vmin())/(n-1);
00114   Scalar * u0 =u, su=umin(), * v0=v, sv=vmin();
00115   for (unsigned i=0; i<m;i++){ *u=su; su+=hu; u++; }
00116   for (unsigned j=0; j<n;j++){ *v=sv; sv+=hv; v++; }
00117 
00118   Point p;
00119   u=u0;
00120   for (unsigned i=0; i<m;i++,u++) {
00121     v=v0;
00122     for (unsigned j=0; j<n;j++,v++) {
00123       this->eval(p,*u,*v);
00124       *r=p.x();r++; 
00125       *r=p.y();r++;
00126       *r=p.z();r++;
00127     }
00128   }
00129 }
00130 
00131 TMPL void 
00132 SELF::sample (PointIterator p, const Scalar* u, unsigned m, const   Scalar* v, unsigned n) const {
00133   assert(m>1 && n>1);
00134   const Scalar * v0=v;
00135 
00136   for (unsigned i=0; i<m;i++,u++) {
00137     v=v0;
00138     for (unsigned j=0; j<n;j++,p++,v++) {
00139       this->eval(*p,*u,*v);
00140     }
00141   }
00142 }
00143 
00144 
00145 } ; // namespace shape
00146 } ; // namespace mmx
00147 # undef TMPL
00148 # undef Point
00149 # undef Scalar
00150 # undef Surface
00151 # undef SELF
00152 # endif // PARAMETRICSURFACE_H