shape_doc 0.1
/Users/mourrain/Devel/mmx/shape/include/shape/surface_rational.hpp
Go to the documentation of this file.
00001 /*****************************************************************************
00002  * M a t h e m a g i x
00003  *****************************************************************************
00004  * RationalSurface
00005  * 2009-05-08
00006  * Bernard Mourrain & Julien Wintz
00007  *****************************************************************************
00008  *               Copyright (C) 2006 INRIA Sophia-Antipolis
00009  *****************************************************************************
00010  * Comments :
00011  ****************************************************************************/
00012 # ifndef shape_surface_rational_hpp
00013 # define shape_surface_rational_hppx
00014 
00015 # include <realroot/ring_tens.hpp>
00016 # include <shape/surface_parametric.hpp>
00017 
00018 # define TMPL_DEF template<class K, int N=3>
00019 # define TMPL  template<class K, int N>
00020 # define ParametricSurface surface_parametric<K>
00021 # define SELF   surface_rational<K,N>
00022 //====================================================================
00023 namespace mmx {
00024 namespace shape {
00025 
00026 TMPL struct surface_rational;
00027 template<class K> struct surface_rational_def
00028   :public surface_def<K> {
00029   typedef surface_rational<K> RationalSurface;
00030   typedef polynom< ring<double, Bernstein> > Polynomial;
00031 };
00032 
00033 TMPL_DEF
00034 class surface_rational : public ParametricSurface {
00035 public:
00036   typedef typename surface_rational_def<K>::Scalar    Scalar;
00037   typedef typename surface_rational_def<K>::Point     Point;
00038   typedef bounding_box<K> BoundingBox;
00039   typedef typename surface_rational_def<K>::polynomial_type Polynomial;
00040 
00041   surface_rational(void) ;
00042   surface_rational(const BoundingBox &) ;
00043    
00044   surface_rational(const Polynomial& X, const Polynomial& Y, const Polynomial& Z, const Polynomial& W=1): 
00045     ParametricSurface(),m_umin(0), m_umax(1), m_vmin(0), m_vmax(1), m_w(W) {
00046     m_p[0]=X; m_p[1]=Y; m_p[2]=Z;
00047   }
00048   Point* eval(Scalar u, Scalar v) const ;
00049   void   eval(Point&, Scalar u, Scalar v) const ;
00050   Point* operator() (const Scalar& u, const Scalar& v) const ;
00051 
00052 
00053   Scalar umin(void) const { return m_umin ; }
00054   Scalar umax(void) const { return m_umax ; }
00055   Scalar vmin(void) const { return m_vmin ; }
00056   Scalar vmax(void) const { return m_vmax ; }
00057 
00058   void get_range(double & umin, double & umax, double & vmin, double & vmax ) const;
00059   void set_range(Scalar umin, Scalar umax, Scalar vmin, Scalar vmax) ;
00060   
00061 
00062   Polynomial denominator()    const { return m_w; }
00063   Polynomial numerator(int i) const { return m_p[i]; }
00064 
00065 
00066 private:
00067   Scalar m_umin, m_umax, m_vmin, m_vmax;
00068     
00069   Polynomial m_w, m_p[N];
00070 
00071 } ;
00072 
00073 
00074 TMPL typename SELF::Point* 
00075 SELF::eval(Scalar u, Scalar v) const {
00076   Scalar w = m_w(u,v);
00077   Point* p = new Point(m_p[0](u,v)/w, m_p[1](u,v)/w, m_p[2](u,v)/w);
00078   return p ;
00079 }
00080 
00081 TMPL void 
00082 SELF::eval(Point& p, Scalar u, Scalar v) const {
00083   Scalar w=m_w(u,v);
00084   p.setx(m_p[0](u,v)/w);
00085   p.sety(m_p[1](u,v)/w);
00086   p.setz(m_p[2](u,v)/w);
00087 }
00088 
00089 TMPL typename SELF::Point* 
00090 SELF::operator() (const Scalar& u, const Scalar& v) const {
00091   return this->eval(u,v); 
00092 }
00093 
00094 TMPL void 
00095 SELF::set_range(Scalar umin, Scalar umax, Scalar vmin, Scalar vmax) {
00096   m_umin=umin;                                           
00097   m_umax=umax;                                           
00098   m_vmin=vmin;                                           
00099   m_vmax=vmax;                                           
00100 }
00101 TMPL void 
00102 SELF::get_range(Scalar& umin, Scalar& umax, Scalar& vmin, Scalar& vmax) const {
00103   umin=m_umin;                                           
00104   umax=m_umax;                                           
00105   vmin=m_vmin;                                           
00106   vmax=m_vmax;                                           
00107 }
00108 
00109 //--------------------------------------------------------------------
00110 TMPL1 struct viewer;   
00111 TMPL AXEL&
00112 operator<<(AXEL& out, const SELF& c) {
00113   out<<"\n <surface type=\"rational\">\n";
00114   out<<"   <domain>"<< c.umin()<<" "<<c.umax()<<" "<<c.vmin()<<" "<<c.vmax()<<"</domain>\n";
00115   for(int i=0; i<N;i++){
00116     out<<"   <polynomial>";
00117     print(out,c.numerator(i),variables("t"));
00118     out<<"</polynomial>\n";
00119   }
00120   out<<"   <polynomial>";
00121   print(out,c.denominator(),variables("t"));
00122   out<<"</polynomial>\n";
00123   out<<" </surface>\n";
00124   return out;
00125 }
00126 //====================================================================
00127 } // namespace shape
00128 //====================================================================
00129 } // namespace mmx
00130 //====================================================================
00131 # undef TMPL
00132 # undef TMPL1
00133 # undef TMPL_DEF
00134 # undef Scalar
00135 # undef Point
00136 # undef SELF
00137 # undef ParametricSurface
00138 # undef AXEL
00139 # endif // RATIONALSURFACE_H