shape_doc 0.1
/Users/mourrain/Devel/mmx/shape/include/shape/voronoi_site2d.hpp
Go to the documentation of this file.
00001 /*****************************************************************************
00002  * M a t h e m a g i x
00003  *****************************************************************************
00004  * Voronoi_site2d
00005  * 2010-04-05 
00006 * Angelos Mantzaflaris
00007  *****************************************************************************
00008  *               Copyright (C) 2010 INRIA Sophia-Antipolis
00009  *****************************************************************************
00010  * Comments :
00011  ****************************************************************************/
00012 
00013 # ifndef shape_voronoi_site2d_hpp
00014 # define shape_voronoi_site2d_hpp
00015 
00016 # include <realroot/GMP.hpp>
00017 # include <shape/point.hpp>
00018 # include <realroot/polynomial_sparse.hpp>
00019 # include <shape/algebraic_set.hpp>
00020 # include <shape/viewer_axel.hpp>
00021 
00022 # define TMPL template<class C, class V>
00023 # define SELF voronoi_site2d<C,V>
00024 # define REF REF_OF(V)
00025 # define AlgebraicCurve algebraic_curve<C,V>
00026 # define Point point<double>
00027 # define Viewer viewer<V>
00028 //====================================================================
00029 namespace mmx {
00030 namespace shape {
00031 //====================================================================
00032 
00033 template<class C, class V=default_env>
00034 class voronoi_site2d 
00035 {
00036 
00037 public:
00038 
00039   typedef typename algebraic_set<C,V>::Polynomial Polynomial;
00040     //typedef polynomial<C, with<Sparse, DegRevLex> > Polynomial;
00041 
00042   voronoi_site2d(void) {} ;
00043   voronoi_site2d(const Point & p);
00044   voronoi_site2d(const Point & p, double a11, double a22,double a12);
00045   voronoi_site2d(const double & w, const Point & p);
00046   voronoi_site2d(const Point & p, const char * s);
00047   voronoi_site2d(const Point & p, const Polynomial &) ;
00048   ~voronoi_site2d(void) {};
00049 
00050   Polynomial distfunc() const  { return this->func ; }
00051   Point      coordinates() const { return this->coords ; }
00052   double      x() const { return this->coords.x() ; }
00053   double      y() const { return this->coords.y() ; } 
00054   double      z() const { return this->coords.z() ; }
00055 
00056 private:
00057   Point coords;
00058 
00059   Polynomial func;
00060 
00061 } ;
00062 
00063 TMPL
00064 SELF::voronoi_site2d(const Point & p, const char * s)
00065  { 
00066   typedef typename use<numeric_def,V>::Rational Coefficients;
00067   polynomial<Coefficients, with<Sparse,DegRevLex> >t(s, variables("x y"));
00068   Polynomial e; let::assign(func,t);
00069 
00070   coords= p; 
00071 }
00072 
00073 TMPL// Anisotropic site
00074 SELF::voronoi_site2d(const Point & p, double a11,double a22,double a12)
00075 {
00076 
00077   func= ( a11*( Polynomial(1,1,0)-p.x() ) + a12*( Polynomial(1,1,1)-p.y() ) ) * ( Polynomial(1,1,0) - p.x() ) + 
00078       ( a12*( Polynomial(1,1,0)-p.x() ) + a22*( Polynomial(1,1,1)-p.y() ) ) * ( Polynomial(1,1,1) - p.y() );
00079 
00080   coords= p; 
00081 }
00082 
00083 TMPL
00084 SELF::voronoi_site2d(const Point & p)
00085 { 
00086   func= Polynomial(1,2,0)+Polynomial(1,2,1);
00087   func
00088     += ( p.x()!=0? Polynomial(-2*p.x(),1,0):0) //0 produces erroneous coeff
00089     +  ( p.y()!=0? Polynomial(-2*p.y(),1,1):0)
00090     +  Polynomial(p.x()*p.x()+p.y()*p.y(),0,0);
00091 
00092   //std::cout<<"site "<< func <<std::endl;
00093   coords= p;
00094 }
00095 
00096 TMPL
00097 SELF::voronoi_site2d(const double & w, const Point & p)
00098 { 
00099   func= Polynomial(1,2,0)+Polynomial(1,2,1);
00100 
00101   func += Polynomial(-2*p.x(),1,0) // (coeff,degree,variable)
00102     +  Polynomial(-2*p.y(),1,1)
00103     +  Polynomial(p.x()*p.x()+p.y()*p.y(),0,0)
00104     -  Polynomial( w*w ,0,0);//adding weight 
00105 
00106   coords= p;
00107 }
00108 
00109 TMPL
00110 SELF::voronoi_site2d(const Point& p, const Polynomial& f) 
00111     {
00112       func  = f;
00113       coords= p; 
00114     }
00115 
00116 
00117 //====================================================================
00118 } ; // namespace shape
00119 } ; // namespace mmx
00120 //====================================================================
00121 # undef TMPL 
00122 # undef SELF
00123 # undef Point
00124 # undef Viewer
00125 # endif // shape_voronoi_site2d_hpp
00126 
00127 // 
00128 // voronoi_site2d.hpp ends here