00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 # ifndef shape_cell2d_voronoi_site2d_hpp
00014 # define shape_cell2d_voronoi_site2d_hpp
00015
00016 # include <realroot/Interval.hpp>
00017 # include <realroot/ring_bernstein_tensor.hpp>
00018 # include <realroot/Seq.hpp>
00019 # include <shape/point.hpp>
00020 # include <shape/solver_implicit.hpp>
00021 # include <shape/bcell2d.hpp>
00022 # include <shape/voronoi_site2d.hpp>
00023
00024 # include <stack>
00025 # define STACK std::stack<Point*>
00026
00027 # define TMPL template<class C, class V>
00028 # define VoronoiSite2d voronoi_site2d<C,V>
00029 # define SELF bcell2d_voronoi_site2d<C,V>
00030 # define Cell2dAlgebraicCurve bcell2d_algebraic_curve<C,V>
00031 # define REF REF_OF(V)
00032
00033 # undef Cell_t
00034
00035 namespace mmx {
00036 namespace shape {
00037
00038
00039
00040
00041
00042
00043
00048 struct bcell2d_voronoi_site2d_def {};
00049 template<> struct use<bcell2d_voronoi_site2d_def>
00050
00051
00052
00053
00054 {
00055 typedef bounding_box<double,double> Bounding_Box;
00056
00057
00058 typedef polynomial< double, with<Bernstein> > Polynomial;
00059
00060
00061 typedef solver_implicit<double,double> Solver;
00062
00063
00064
00065
00066 };
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 TMPL struct bcell2d_voronoi_site2d : public bcell2d_algebraic_curve<C,V> {
00078 public:
00079 typedef typename mesher2d<C,V>::Point Point;
00080
00081 typedef point<C,2,REF> Vector;
00082
00083 typedef typename mesher2d<C,V>::Edge Edge;
00084 typedef bcell<C,REF> Cell;
00085
00086
00087 typedef typename bcell2d_voronoi_site2d<C,V>::Polynomial Polynomial;
00088 typedef bounding_box<C,REF> BoundingBox;
00089
00090
00091 typedef typename use<bcell2d_voronoi_site2d_def,C,V>::Solver Solver;
00092 typedef topology<C,V> Topology;
00093 typedef mesher2d<C,V> Mesher2d;
00094
00095 bcell2d_voronoi_site2d(const Polynomial &, const BoundingBox&);
00096 bcell2d_voronoi_site2d(const char*, const BoundingBox&);
00097
00098 bcell2d_voronoi_site2d(VoronoiSite2d*, const BoundingBox &);
00099 bcell2d_voronoi_site2d(const SELF& cl)
00100 : Cell2dAlgebraicCurve(cl) {}
00101
00102 Polynomial equation(void) { return this->m_polynomial; }
00103
00104 bool is_active (void) ;
00105 bool is_regular(void) ;
00106 bool is_intersected(void) {return (this->nb_intersect()>0);};
00107
00108 virtual Point * pair(Point * p, int& sgn) ;
00109 virtual Point * starting_point( int sgn) ;
00110
00111 virtual bool insert_regular (Topology*);
00112 virtual bool insert_singular(Topology*);
00113 virtual void subdivide(Cell*& left, Cell*& right, int v, double s);
00114 Vector gradient(const Point& p);
00115
00116 inline double lower();
00117 inline double upper();
00118
00119 void compute_boundary();
00120
00121 private:
00122
00123
00124 };
00125
00126
00127 TMPL inline double
00128 SELF::lower()
00129 {
00130 return double(*std::min_element( this->m_polynomial.begin(),
00131 this->m_polynomial.end() ) );
00132 }
00133
00134 TMPL inline double
00135 SELF::upper()
00136 {
00137 return double(*std::max_element( this->m_polynomial.begin(),
00138 this->m_polynomial.end() ) );
00139 }
00140
00141
00142 TMPL void
00143 SELF::compute_boundary()
00144 {
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 }
00160
00161
00162 TMPL inline void
00163 print(SELF* cv) {
00164 typedef typename SELF::Point Point;
00165 std::cout << "point(s) b: ";
00166 foreach(Point* p, cv->n_intersections)
00167 std::cout <<" ["<<p->x()<<" "<<p->y()<<"]";
00168 foreach(Point* p, cv->s_intersections)
00169 std::cout <<" ["<<p->x()<<" "<<p->y()<<"]";
00170 foreach(Point* p, cv->w_intersections)
00171 std::cout <<" ["<<p->x()<<" "<<p->y()<<"]";
00172 foreach(Point* p, cv->e_intersections)
00173 std::cout <<" ["<<p->x()<<" "<<p->y()<<"]";
00174 std::cout<<std::endl;
00175
00176 std::cout << "Point(s) s: ";
00177 foreach(Point* p, cv->m_singular)
00178 std::cout <<" ["<<p->x()<<" "<<p->y()<<"]";
00179 std::cout<<std::endl;
00180 }
00181
00182 TMPL
00183 SELF::bcell2d_voronoi_site2d(const Polynomial& pol, const BoundingBox& bx)
00184 : Cell2dAlgebraicCurve(pol,bx)
00185 {
00186
00187 }
00188
00189
00190 TMPL
00191 SELF::bcell2d_voronoi_site2d(const char* s, const BoundingBox & b)
00192 : Cell2dAlgebraicCurve(s,b)
00193 {
00194
00195 }
00196
00197 TMPL
00198 SELF::bcell2d_voronoi_site2d(VoronoiSite2d* cv, const BoundingBox & b)
00199 : Cell2dAlgebraicCurve(cv->distfunc(),b)
00200 {
00201
00202
00203
00204 }
00205
00206 TMPL bool
00207 SELF::is_regular() {
00208
00209 return true;
00210 }
00211
00212 TMPL bool
00213 SELF::is_active() {
00214
00215 return ( false );
00216
00217 }
00218
00219 TMPL bool
00220 SELF::insert_regular(Topology* t) {
00221
00222
00223 t->insert((BoundingBox*)this,false);
00224 return true;
00225
00226 }
00227
00228 TMPL bool
00229 SELF::insert_singular(Topology* t) {
00230
00231 return true;
00232 }
00233
00234
00235 TMPL void
00236 SELF::subdivide(Cell*& Left, Cell*& Right, int v, double s) {
00237 bcell2d_subdivisor<C,V>::subdivide( *this,(SELF*&)Left,(SELF*&)Right,v,s);
00238 }
00239
00240 TMPL typename SELF::Vector
00241 SELF::gradient(const Point& p) {
00242 Polynomial
00243 dx= diff(this->m_polynomial,0),
00244 dy= diff(this->m_polynomial,1);
00245 double
00246 u0= (p[0]-this->xmin())/(this->xmax()-this->xmin()),
00247 u1= (p[1]-this->ymin())/(this->ymax()-this->ymin());
00248 Vector v;
00249 v[0] = dx(u0,u1);
00250 v[1] = dy(u0,u1);
00251 return v;
00252 }
00253
00254
00255 TMPL typename SELF::Point*
00256 SELF::starting_point(int sgn) {
00257
00258
00259
00260 Seq<Point*> all;
00261 unsigned a;
00262 all = this->intersections();
00263 a = all.size();
00264
00265
00266
00267
00268
00269 assert(a==2);
00270
00271 int ev(0);
00272 int u ;
00273 unsigned
00274 s=this->s_intersections.size() ,
00275 e=this->e_intersections.size() ,
00276
00277 w=this->w_intersections.size() ;
00278
00279 u= ( 0<s ? 0 :
00280 ( 0<s+e ? 1 :
00281 ( 0<a-w ? 2 :
00282 3 )));
00283
00284 int * sz = this->m_polynomial.rep().szs();
00285 int * st = this->m_polynomial.rep().str();
00286
00287 switch (u){
00288 case 0:
00289 ev= (this->m_polynomial[0] >0 ? 1:-1);
00290 break;
00291 case 1:
00292 ev= (this->m_polynomial[(sz[0]-1)*st[0]] >0 ? 1:-1);
00293 break;
00294 case 2:
00295 ev= (this->m_polynomial[sz[0]*sz[1]-1]>0 ? 1:-1);
00296 break;
00297 case 3:
00298 ev= (this->m_polynomial[(sz[1]-1)*st[1]] >0 ? 1:-1);
00299 break;
00300 }
00301
00302 if (ev*sgn>0)
00303 return all[0];
00304 else
00305 return all[1];
00306 }
00307
00308
00309 TMPL typename SELF::Point*
00310 SELF::pair( typename SELF::Point* p, int& sgn) {
00311
00312
00313
00314 Seq<Point*> all;
00315 int a;
00316 all= this->intersections();
00317 a = all.size();
00318 if (a==2)
00319 { return (all[0]==p ? all[1]: all[0]); }
00320
00321 std::cout<<"...pair Trouble"<< this<<std::endl;
00322 return (all[0]);
00323 }
00324
00325
00326 } ;
00327 } ;
00328 # undef Solver
00329 # undef SELF
00330 # undef TMPL
00331 # undef Cell2dAlgebraicCurve
00332 # undef STACK
00333 # undef REF
00334 # undef VoronoiSite2d
00335 # endif // shape_cell2d_voronoi_site2d_hpp