00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
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.hpp>
00019 # include <realroot/ring_sparse.hpp>
00020
00021 #include <realroot/solver_uv_sleeve.hpp>
00022 # include <shape/algebraic_set.hpp>
00023 # include <shape/viewer_axel.hpp>
00024
00025 # define TMPL template<class C, class V>
00026 # define SELF voronoi_site2d<C,V>
00027 # define REF REF_OF(V)
00028 # define Point point<double>
00029 # define Viewer viewer<V>
00030
00031 namespace mmx {
00032 namespace shape {
00033
00034
00035 template<class C, class V=default_env>
00036 class voronoi_site2d
00037 {
00038
00039 public:
00040
00041 typedef typename algebraic_set<C,V>::Polynomial Polynomial;
00042
00043
00044 typedef bounding_box<C,REF> BoundingBox;
00045
00046 voronoi_site2d(void) {} ;
00047 voronoi_site2d(const Point & p, const int& k= 2);
00048 voronoi_site2d(const Point & p, double a, double b,double c);
00049 voronoi_site2d(const double & w, const Point & p);
00050 voronoi_site2d(const Point & p, const char * s);
00051 voronoi_site2d(const Point & p, const Polynomial &) ;
00052
00053 voronoi_site2d(const Point & p, const double & r) ;
00054
00055 ~voronoi_site2d(void) {};
00056
00057 Polynomial distfunc() const { return this->func ; }
00058
00059 Point coordinates() const { return this->coords ; }
00060 double x() const { return this->coords.x() ; }
00061 double y() const { return this->coords.y() ; }
00062 double z() const { return this->coords.z() ; }
00063
00064 double upper_bound(BoundingBox& bx) const;
00065 Polynomial offset( const C& z){ return (this->func - Polynomial(z,0,0) ); }
00066
00067
00068
00069 Polynomial lp(const int& n, const Point& p )
00070 {
00071
00072
00073 Polynomial a= Polynomial(1,0,0);
00074
00075 C c= C(1);
00076 if( p.x()!=0.0)
00077 for(int i=0; i<=n; i++ ) {
00078 a+= Polynomial( c*binomial<C>(n,i),n-i,0);
00079 c*= -p.x(); }
00080 else a+= Polynomial(1,n,0);
00081 c=1.0;
00082 if( p.y()!=0.0)
00083 for(int i=0; i<=n; i++ ) {
00084 a+= Polynomial( c*binomial<double>(n,i),n-i,1);
00085 c*= -p.y(); }
00086 else a+= Polynomial(1,n,1);
00087
00088 a-=C(1);
00089 return a;
00090 }
00091
00092
00093 private:
00094
00095 Point coords;
00096 Polynomial func;
00097
00098 } ;
00099
00100
00101
00102 TMPL
00103 SELF::voronoi_site2d(const Point & p, const char * s)
00104 {
00105
00106 polynomial<double, with<Sparse,DegRevLex> >t(s, variables("x y"));
00107 Polynomial e; let::assign(func,t);
00108
00109
00110
00111 coords= p;
00112 }
00113
00114
00115
00116
00117
00118
00119 TMPL
00120 SELF::voronoi_site2d(const Point & p, double a,double b,double c)
00121 {
00122
00123
00124 func= Polynomial(a,2,0)+Polynomial(b+c*c,2,1) +
00125
00126 ( c!=0? Polynomial(2*c*std::sqrt(a),1,0)*Polynomial(1,1,1):0) +
00127 Polynomial(-2*std::sqrt(a)*c*p.x()-2*p.y()*c*c-2*p.y()*b ,1,1) -
00128 (p.x()!=0? Polynomial(2*a*p.x(), 1 , 0): 0) -
00129 ( c!=0? Polynomial(2*std::sqrt(a)*c*p.y(), 1, 0 ): 0 ) +
00130 Polynomial( p.y()*p.y()*b+a*p.x()*p.x()+p.y()*p.y()*c*c+
00131 2*std::sqrt(a)*c*p.y()*p.x(),0,0) ;
00132
00133
00134 std::cout<<"site "<< func <<std::endl;
00135 coords= p;
00136
00137 }
00138
00139
00140 TMPL
00141 SELF::voronoi_site2d(const Point & p, const int& k)
00142 {
00143 func= this->lp(k , p );
00144 coords= p;
00145
00146 }
00147
00148
00149 TMPL
00150 SELF::voronoi_site2d(const double & w, const Point & p)
00151 {
00152 func= Polynomial(1,2,0)+Polynomial(1,2,1);
00153
00154 func += Polynomial(-2*p.x(),1,0)
00155 + Polynomial(-2*p.y(),1,1)
00156 + Polynomial(p.x()*p.x()+p.y()*p.y(),0,0)
00157 - Polynomial( w*w ,0,0);
00158
00159 coords= p;
00160 std::cout<<"Point: "<< p<<", w: "<< w <<std::endl;
00161 }
00162
00163
00164 TMPL
00165 SELF::voronoi_site2d(const Point& p, const Polynomial& f)
00166 {
00167 func = f;
00168 coords= p;
00169 }
00170
00171
00172 TMPL
00173 SELF::voronoi_site2d(const Point & p, const double & r)
00174 {
00175 func= Polynomial(1,2,0)+Polynomial(1,2,1) - Polynomial(1,2,2);
00176
00177 func += Polynomial(-2*p.x(),1,0)
00178 + Polynomial(-2*p.y(),1,1)
00179 + Polynomial(p.x()*p.x()+p.y()*p.y() -r*r ,0,0)
00180 - Polynomial( 2*r ,1,2);
00181
00182 coords= p;
00183
00184
00185
00186
00187
00188
00189 }
00190
00191 TMPL double
00192 SELF::upper_bound(BoundingBox& bx) const
00193 {
00194
00195
00196
00197
00198
00199 Interval<double> ev(0.3434,0.3434);
00200 Seq< Interval<double> > bb;
00201 bb<< Interval<double>(bx.xmin(), bx.xmax() ) ;
00202 bb<< Interval<double>(bx.ymin(), bx.ymax() ) ;
00203 polynomial<Interval<double>,with<Sparse, DegRevLex> > pol(1.4,1,1);
00204 polynomial<double, with<Sparse, DegRevLex> > upol;
00205 let::assign(pol,func);
00206
00207
00208
00209 if ( func.nbvar()==2 )
00210 {
00211 sparse::eval_at( ev , pol.rep() ,bb );
00212
00213
00214
00215
00216
00217
00218 return ev.upper();
00219 }
00220 else
00221 {
00222
00223
00224
00225 pol= sparse::subs(pol, 0, bb[0] ) ;
00226 std::cout<<"sub= " << pol <<"\n";
00227 pol= sparse::subs(pol, 1, bb[1] ) ;
00228 std::cout<<"sub= " << pol <<"\n";
00229
00230
00231 typedef typename mmx::polynomial<double, with<Sparse, DegRevLex> >::Monomial mon;
00232
00233 for ( typename mmx::polynomial<Interval<double>,with<Sparse, DegRevLex> >::const_iterator it =pol.begin(); it != pol.end(); ++it )
00234 upol+= mon(it->coeff().upper(), it->rep() ) ;
00235
00236
00237 std::cout<<"upol=" << upol <<"\n";
00238
00239
00240
00241
00242
00243
00244 return 1;
00245 }
00246 }
00247
00248
00249 } ;
00250 } ;
00251
00252
00253
00254 # undef TMPL
00255 # undef SELF
00256 # undef REF
00257 # undef Point
00258 # undef Viewer
00259 # endif // shape_voronoi_site2d_hpp
00260
00261
00262