00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 # ifndef shape_bcell2d_voronoi_diagram
00013 # define shape_bcell2d_voronoi_diagram
00014
00015 # include <shape/topology.hpp>
00016 # include <shape/bcell_list.hpp>
00017 # include <shape/bcell2d_algebraic_curve.hpp>
00018
00019 # include <shape/bcell2d_voronoi_site2d.hpp>
00020 # include <shape/solver_implicit.hpp>
00021
00022 # define EPSILON .000001
00023
00024 # define TMPL template<class C, class V>
00025 # define Shape geometric<V>
00026 # define Cell2dAlgebraicCurve bcell2d_algebraic_curve<C,V>
00027 # define Intersection2dFactory intersection2d_factory<C,V>
00028 # define Solver solver_implicit<C,V>
00029
00030 # define Cell bcell<C,V>
00031 # define VSite bcell2d_voronoi_site2d<C,V>
00032 # define Cell2d bcell2d<C,V>
00033 # define CellList bcell2d_list<C,V>
00034 # define SELF bcell2d_voronoi_diagram<C,V>
00035 namespace mmx {
00036 namespace shape {
00037
00038 TMPL class voronoi2d;
00039
00040 template<class C, class V=default_env>
00041 class bcell2d_voronoi_diagram
00042
00043
00044 : public bcell2d<C,V>
00045 {
00046 public:
00047 typedef typename Cell::BoundingBox BoundingBox;
00048 typedef typename bcell2d<C,V>::Point Point;
00049 typedef typename mesher2d<C,V>::Edge Edge;
00050 typedef topology<C,V> Topology;
00051
00052 typedef polynomial< Interval<double>, with<Bernstein> > Polynomial;
00053 typedef Interval<double> coeff;
00054
00055 bcell2d_voronoi_diagram(void) ;
00056 bcell2d_voronoi_diagram(double xmin, double xmax) ;
00057 bcell2d_voronoi_diagram(double xmin, double xmax, double ymin, double ymax) ;
00058 bcell2d_voronoi_diagram(double xmin, double xmax, double ymin, double ymax, bool itr) ;
00059 bcell2d_voronoi_diagram(const BoundingBox& bx);
00060 virtual ~bcell2d_voronoi_diagram(void) ;
00061
00062 virtual bool is_regular (void) ;
00063 virtual bool is_active (void) ;
00064 virtual bool is_intersected(void) ;
00065
00066 virtual bool insert_regular(Topology*);
00067 virtual bool process_singular();
00068
00069 virtual bool insert_singular(Topology*) {return false;};
00070
00071 virtual void subdivide (Cell*& left, Cell*& right, int v, double s);
00072
00073 virtual void split_position(int& v, double& t);
00074
00075 virtual Point* pair(Point * p, int & sgn);
00076 virtual Point* starting_point( int sgn);
00077
00078 virtual bool is_touching (void) {return true; };
00079
00080 virtual unsigned nb_intersect(void) const;
00081
00082
00083 Cell2d * neighbor(Point * p);
00084 Seq<Point *> intersections() const;
00085
00086 virtual Seq<Point *> intersections(int i) const{
00087 Seq<Point*> l;
00088 Cell2dAlgebraicCurve* c;
00089
00090 foreach(Cell*m, this->m_objects)
00091 {
00092 c = dynamic_cast<Cell2dAlgebraicCurve*>(m);
00093 l<< c->intersections(i);
00094 }
00095 return l;
00096 }
00097
00098 void push_back(Cell * cv)
00099 {
00100 m_sites<< unsigned(m_objects.size() );
00101 m_objects.push_back(cv);
00102 };
00103
00104 void push_back(Cell * cv, unsigned k) {
00105 m_sites << k ;
00106
00107 m_objects.push_back(cv);
00108 };
00109
00110 void push_bisector(Cell2dAlgebraicCurve * cv, Seq<unsigned> k) {
00111 m_sites << k ;
00112 m_objects.push_back(cv);
00113 };
00114
00115
00116 int count(void) { return m_objects.size() ; }
00117 inline Polynomial func(const int i) const{
00118 return ((VSite*)(this->m_objects[0]))->m_polynomial;
00119 };
00120
00121 inline int signature(int & i, int & j) {
00122 int c(0);
00123 for ( int u=0; u<i; u++)
00124 for ( int v=u+1; v<m_sites.size(); v++)
00125 c++;
00126 return c + j-i-1; }
00127
00128 unsigned site(int sgn, unsigned bs=0) {
00129 unsigned n=this->count();
00130 unsigned i,k(bs+1);
00131
00132 for (i=1;i<n;i++)
00133 if ( k>n-i )
00134 k-= n-i;
00135 else
00136 break;
00137
00138
00139 return ( m_sites[i-1 + (sgn>0?k:0)] ) ;
00140 }
00141
00142 int signof(unsigned st, unsigned bs=0) {
00143
00144 if (this->m_objects.size()==1 )
00145 return ( st==m_sites[0]? -1 :1 );
00146
00147
00148
00149 unsigned n=this->count() - 1;
00150 unsigned i,j(0),k(0);
00151
00152 for (i=0;i<=bs;i++)
00153 if ( k<n )
00154 k++ ;
00155 else
00156 j++ ;
00157
00158 if (st==this->m_sites[j]) return (-1);
00159 if (st==this->m_sites[k]) return (1);
00160
00161 std::cout<<"problem at \"signof\" "<<i <<", "<< *this <<"sites= "<<m_sites<<std::endl;
00162 return 0;
00163 };
00164
00165 Seq<unsigned> sites() const { return m_sites;};
00166 void addsite(unsigned i){m_sites<<i;};
00167
00168 Seq<Cell *> m_objects ;
00169
00170 protected:
00171
00172
00173 Seq<unsigned> m_sites;
00174 bool m_intersected;
00175 bool m_bisector;
00176 bool m_treated;
00177
00178 private:
00179
00180 template<int i> static bool
00181 coord(Point*u,Point*v) { return ( (*u)[i]< (*v)[i]); }
00182
00183 static bool comp_up( VSite* a, VSite* b)
00184 {
00185 return ( a->upper() < b->upper() );
00186 }
00187
00188 static bool intersect( VSite* a, VSite* b)
00189 {
00190 return has_sign_variation( a->equation() - b->equation() );
00191 }
00192
00193
00194 inline bool over( VSite* a, double bound)
00195 {
00196 return ( a->lower() > bound );
00197 }
00198
00199 bool is_bisector()
00200 {
00201 if ( this->m_objects.size() > 2)
00202 return false;
00203
00204
00205
00206 if ( !this->m_bisector && this->m_objects.size() == 2 )
00208 {
00209 Polynomial p= ((VSite*)(this->m_objects[0]))->m_polynomial ;
00210 p -= ((VSite*)(this->m_objects[1]))->m_polynomial;
00211
00212 Cell2dAlgebraicCurve* cc=
00213 new Cell2dAlgebraicCurve( p, (BoundingBox)(*this), false);
00214
00215
00216
00218
00219
00220 if ( this->s_neighbors.size()==0)
00221 {
00222 Seq<Point *> ip;
00223 Solver::edge_point(ip,
00224 cc->m_polynomial,
00225 Solver::south_edge,
00226 *cc);
00227 cc->s_intersections << ip;
00228 }
00229 else
00230 foreach( Cell2d *c, this->s_neighbors )
00231 if ( ((SELF*)c)->m_bisector )
00232 {
00233 foreach(Point * p, ((SELF*)c)->intersections(2) )
00234 if (this->xmin()<p->x() && this->xmax()>p->x())
00235 cc->s_intersections << p;
00236 }
00237 else
00238 {
00239 Seq<Point *> ip;
00240 Solver::edge_point(ip,
00241 cc->m_polynomial,
00242 Solver::south_edge,
00243 *cc );
00244 foreach(Point * p, ip )
00245 if (c->xmin()<p->x() && c->xmax()>p->x())
00246 cc->s_intersections << p;
00247
00248 }
00249
00250
00251 if (this->e_neighbors.size()==0)
00252 {
00253 Seq<Point *> ip;
00254 Solver::edge_point(ip,
00255 cc->m_polynomial,
00256 Solver::east_edge,
00257 *cc);
00258 cc->e_intersections << ip;
00259 }
00260 else
00261 foreach( Cell2d *c, this->e_neighbors )
00262 if ( ((SELF*)c)->m_bisector )
00263 {
00264
00265
00266 foreach(Point * p, ((SELF*)c)->intersections(3) )
00267 if (this->ymin()<p->y() && this->ymax()>p->y())
00268 cc->e_intersections << p;
00269 }
00270 else
00271 {
00272 Seq<Point *> ip;
00273 Solver::edge_point(ip,
00274 cc->m_polynomial,
00275 Solver::east_edge,
00276 *cc );
00277 foreach(Point * p, ip )
00278 if (c->ymin()<p->y() && c->ymax()>p->y())
00279 cc->e_intersections << p;
00280 }
00281
00282
00283 if (this->n_neighbors.size()==0 )
00284 {
00285 Seq<Point *> ip;
00286 Solver::edge_point(ip,
00287 cc->m_polynomial,
00288 Solver::north_edge,
00289 *cc);
00290 cc->n_intersections << ip;
00291 }
00292 else
00293 foreach( Cell2d *c, this->n_neighbors )
00294 if ( ((SELF*)c)->m_bisector )
00295 {
00296
00297
00298 foreach(Point * p, ((SELF*)c)->intersections(0) )
00299 if (this->xmin()<p->x() && this->xmax()>p->x())
00300 cc->n_intersections << p;
00301 }
00302 else
00303 {
00304 Seq<Point *> ip;
00305 Solver::edge_point(ip,
00306 cc->m_polynomial,
00307 Solver::north_edge,
00308 *cc );
00309 foreach(Point * p, ip )
00310 if (c->xmin()<p->x() && c->xmax()>p->x())
00311 cc->n_intersections << p;
00312 }
00313
00314
00315 if (this->w_neighbors.size()==0)
00316 {
00317 Seq<Point *> ip;
00318 Solver::edge_point(ip,
00319 cc->m_polynomial,
00320 Solver::west_edge,
00321 *cc);
00322 cc->w_intersections << ip;
00323 }
00324 else
00325 foreach( Cell2d *c, this->w_neighbors )
00326 if ( ((SELF*)c)->m_bisector )
00327 {
00328
00329
00330 foreach(Point * p, ((SELF*)c)->intersections(1) )
00331 if (this->ymin()<p->y() && this->ymax()>p->y())
00332 cc->w_intersections << p;
00333
00334 }
00335 else
00336 {
00337 Seq<Point *> ip;
00338 Solver::edge_point(ip,
00339 cc->m_polynomial,
00340 Solver::west_edge,
00341 *cc );
00342 foreach(Point * p, ip )
00343 if (c->ymin()<p->y() && c->ymax()>p->y())
00344 cc->w_intersections << p;
00345
00346
00347 }
00348
00349
00351
00352
00353
00354 this->m_objects.clear();
00355
00356 this->m_objects<< (Cell*)(cc);
00357
00358
00359
00360
00361
00362
00363 }
00364
00365 this->m_bisector=true;
00366 return true;
00367
00368 }
00369
00370 public:
00371
00372 bool compute_boundary()
00373 {
00374 int i(0),j(0), r(m_sites.size()-1);
00375 foreach ( Cell* obj, this->m_objects)
00376 {
00377 Cell2dAlgebraicCurve* cc= dynamic_cast<Cell2dAlgebraicCurve*>(obj);
00378 if (j<r)
00379 j++;
00380 else
00381 { i++; j=i+1;}
00382
00383
00384 if ( this->s_neighbors.size()==0)
00385 {
00386 Seq<Point *> ip;
00387 Solver::edge_point(ip,
00388 cc->m_polynomial,
00389 Solver::south_edge,
00390 *cc);
00391 cc->s_intersections << ip;
00392 }
00393 else
00394 foreach( Cell2d *c, this->s_neighbors )
00395 if ( ((SELF*)c)->m_bisector )
00396 {
00397 Seq<unsigned> a= ((SELF*)c)->sites();
00398 if ( a.member( m_sites[i]) && a.member(m_sites[j]) )
00399 {
00400 foreach(Point * p, ((SELF*)c)->intersections(2) )
00401 if (this->xmin()<p->x() && this->xmax()>p->x())
00402 cc->s_intersections << p;
00403 }
00404 }
00405 else if ( ((SELF*)c)->m_treated )
00406 {
00407 int u(0),v(0);
00408 foreach( Cell *nc, ((SELF*)c)->m_objects )
00409 {
00410 if (v<r)
00411 v++;
00412 else
00413 { u++; v=u+1;}
00414 if ( ((SELF*)c)->m_sites[u]==m_sites[i] &&
00415 ((SELF*)c)->m_sites[v]==m_sites[j] )
00416 foreach(Point * p, ((SELF*)nc)->intersections(2) )
00417 if (this->xmin()<p->x() && this->xmax()>p->x())
00418 cc->s_intersections << p;
00419 }
00420 }
00421 else
00422 {
00423 Seq<Point *> ip;
00424 Solver::edge_point(ip,
00425 cc->m_polynomial,
00426 Solver::south_edge,
00427 *cc );
00428 foreach(Point * p, ip )
00429 if (c->xmin()<p->x() && c->xmax()>p->x())
00430 cc->s_intersections << p;
00431
00432 }
00433
00434
00435 if (this->e_neighbors.size()==0)
00436 {
00437 Seq<Point *> ip;
00438 Solver::edge_point(ip,
00439 cc->m_polynomial,
00440 Solver::east_edge,
00441 *cc);
00442 cc->e_intersections << ip;
00443 }
00444 else
00445 foreach( Cell2d *c, this->e_neighbors )
00446 if ( ((SELF*)c)->m_bisector )
00447 {
00448 Seq<unsigned> a= ((SELF*)c)->sites();
00449 if ( a.member( m_sites[i]) && a.member(m_sites[j]) )
00450 {
00451 foreach(Point * p, ((SELF*)c)->intersections(3) )
00452 if (this->ymin()<p->y() && this->ymax()>p->y())
00453 cc->e_intersections << p;
00454 }
00455 }
00456 else if ( ((SELF*)c)->m_treated )
00457 {
00458 int u(0),v(0);
00459 foreach( Cell *nc, ((SELF*)c)->m_objects )
00460 {
00461 if (v<r)
00462 v++;
00463 else
00464 { u++; v=u+1;}
00465 if ( ((SELF*)c)->m_sites[u]==m_sites[i] &&
00466 ((SELF*)c)->m_sites[v]==m_sites[j] )
00467 foreach(Point * p, ((SELF*)nc)->intersections(3) )
00468 if (this->ymin()<p->y() && this->ymax()>p->y())
00469 cc->e_intersections << p;
00470 }
00471 }
00472 else
00473 {
00474 Seq<Point *> ip;
00475 Solver::edge_point(ip,
00476 cc->m_polynomial,
00477 Solver::east_edge,
00478 *cc );
00479 foreach(Point * p, ip )
00480 if (c->ymin()<p->y() && c->ymax()>p->y())
00481 cc->e_intersections << p;
00482 }
00483
00484
00485 if (this->n_neighbors.size()==0 )
00486 {
00487 Seq<Point *> ip;
00488 Solver::edge_point(ip,
00489 cc->m_polynomial,
00490 Solver::north_edge,
00491 *cc);
00492 cc->n_intersections << ip;
00493 }
00494 else
00495 foreach( Cell2d *c, this->n_neighbors )
00496 if ( ((SELF*)c)->m_bisector )
00497 {
00498 Seq<unsigned> a= ((SELF*)c)->sites();
00499 if ( a.member( m_sites[i]) && a.member(m_sites[j]) )
00500 {
00501 foreach(Point * p, ((SELF*)c)->intersections(0) )
00502 if (this->xmin()<p->x() && this->xmax()>p->x())
00503 cc->n_intersections << p;
00504 }
00505 }
00506 else if ( ((SELF*)c)->m_treated )
00507 {
00508 int u(0),v(0);
00509 foreach( Cell *nc, ((SELF*)c)->m_objects )
00510 {
00511 if (v<r)
00512 v++;
00513 else
00514 { u++; v=u+1;}
00515 if ( ((SELF*)c)->m_sites[u]==m_sites[i] &&
00516 ((SELF*)c)->m_sites[v]==m_sites[j] )
00517 foreach(Point * p, ((SELF*)nc)->intersections(0) )
00518 if (this->xmin()<p->x() && this->xmax()>p->x())
00519 cc->n_intersections << p;
00520 }
00521 }
00522 else
00523 {
00524 Seq<Point *> ip;
00525 Solver::edge_point(ip,
00526 cc->m_polynomial,
00527 Solver::north_edge,
00528 *cc );
00529 foreach(Point * p, ip )
00530 if (c->xmin()<p->x() && c->xmax()>p->x())
00531 cc->n_intersections << p;
00532 }
00533
00534
00535 if (this->w_neighbors.size()==0)
00536 {
00537 Seq<Point *> ip;
00538 Solver::edge_point(ip,
00539 cc->m_polynomial,
00540 Solver::west_edge,
00541 *cc);
00542 cc->w_intersections << ip;
00543 }
00544 else
00545 foreach( Cell2d *c, this->w_neighbors )
00546 if ( ((SELF*)c)->m_bisector )
00547 {
00548 Seq<unsigned> a= ((SELF*)c)->sites();
00549 if ( a.member( m_sites[i]) && a.member(m_sites[j]) )
00550 {
00551
00552
00553 foreach(Point * p, ((SELF*)c)->intersections(1) )
00554 if (this->ymin()<p->y() && this->ymax()>p->y())
00555 cc->w_intersections << p;
00556 }
00557 }
00558 else if ( ((SELF*)c)->m_treated )
00559 {
00560 int u(0),v(0);
00561 foreach( Cell *nc, ((SELF*)c)->m_objects )
00562 {
00563 if (v<r)
00564 v++;
00565 else
00566 { u++; v=u+1;}
00567 if ( ((SELF*)c)->m_sites[u]==m_sites[i] &&
00568 ((SELF*)c)->m_sites[v]==m_sites[j] )
00569 foreach(Point * p, ((SELF*)nc)->intersections(1) )
00570 if (this->ymin()<p->y() && this->ymax()>p->y())
00571 cc->w_intersections << p;
00572 }
00573 }
00574 else
00575 {
00576 Seq<Point *> ip;
00577 Solver::edge_point(ip,
00578 cc->m_polynomial,
00579 Solver::west_edge,
00580 *cc );
00581 foreach(Point * p, ip )
00582 if (c->ymin()<p->y() && c->ymax()>p->y())
00583 cc->w_intersections << p;
00584
00585
00586 }
00587
00588 }
00589 this->m_treated=true;
00590 return true;
00591 }
00592
00593 } ;
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637 TMPL
00638 SELF::bcell2d_voronoi_diagram(void): m_intersected(false), m_treated(false) {}
00639
00640 TMPL
00641 SELF::bcell2d_voronoi_diagram(double xmin, double xmax, double ymin, double ymax) : bcell2d<C,V>(xmin, xmax, ymin, ymax), m_intersected(false), m_bisector(false), m_treated(false) {}
00642
00643 TMPL
00644 SELF::bcell2d_voronoi_diagram(double xmin, double xmax, double ymin, double ymax, bool itr) : bcell2d<C,V>(xmin, xmax, ymin, ymax), m_intersected(itr), m_bisector(false), m_treated(false) {}
00645
00646 TMPL
00647 SELF::bcell2d_voronoi_diagram(const BoundingBox& bx): bcell2d<C,V>(bx), m_intersected(false), m_bisector(false), m_treated(false) {};
00648
00649 TMPL
00650 SELF::~bcell2d_voronoi_diagram(void) {
00651 foreach (Cell* m, this->m_objects) delete m;
00652 }
00653
00654 TMPL bool
00655 SELF::is_regular()
00656 {
00657
00658 if ( this->is_bisector() )
00659 {
00660 return (this->m_objects[0])->is_regular();
00661 }
00662 else
00663 {
00664 return false;
00665 }
00666 }
00667
00668 TMPL bool
00669 SELF::is_intersected() {
00670
00671 if(this->m_objects.size() >1 && !m_intersected) {
00672
00673 for(unsigned i=0; i<this->m_objects.size();i++)
00674 for(unsigned j=i+1; j<this->m_objects.size(); j++)
00675 Intersection2dFactory::instance()->compute(this->m_singular, (Shape*)this->m_objects[i], (Shape*)this->m_objects[j], (BoundingBox)*this);
00676 m_intersected = true;
00677 }
00678
00679 if (this->m_singular.size() > 0) return true;
00680 return false;
00681 }
00682
00683
00684 TMPL bool
00685 SELF::insert_regular(Topology* s) {
00686
00687 Seq<Point*> l;
00688 l= this->intersections();
00689
00690
00691
00692
00693
00694
00695 int * sz;
00696 int * st;
00697 Point *q;
00698
00699 if ( l.size()==2 )
00700 {
00701 s->insert( l[0] );
00702 s->insert( l[1] );
00703 s->insert( new Edge(l[0],l[1]) );
00704 return true;
00705 }
00706
00707 if ( l.size()==4 )
00708 {
00709 s->insert( l[0] );
00710 s->insert( l[1] );
00711 s->insert( new Edge(l[0],l[1]) );
00712 return true;
00713 }
00714
00715 if ( l.size()==1)
00716 {
00717 std::cout<< "SIZE ONE, "<< *this<<std::endl;
00718
00719 s->insert( l[0] );
00720 foreach( Cell* c, this->m_objects )
00721 if ( ((Cell2d*)c)->nb_intersect()==1 )
00722 {
00723 sz= ((VSite*)c)->m_polynomial.rep().szs();
00724 st= ((VSite*)c)->m_polynomial.rep().str();
00725 if ( ((VSite*)c)->m_polynomial[0]<EPSILON )
00726 {
00727 q= new Point(this->xmin(),this->ymin(),0);
00728 std::cout<< "1.add ("<< *q <<")->("<< *l[0] << ") in "<< *this<<std::endl;
00729 s->insert(q);
00730 s->insert( new Edge(l[0],q) );
00731 ((VSite*)c)->n_intersections<< q;
00732
00733 foreach( Cell2d *nb, this->s_neighbors )
00734 foreach( Cell* cc, ((SELF*)nb)->m_objects )
00735 if ( cc->is_active() )
00736 {
00737 ((VSite*)cc)->n_intersections<< q;
00738 std::cout<<"This Intersections: "<< this->intersections().size() << std::endl;
00739 std::cout<<"Neib Intersections: "<< nb->intersections().size() << std::endl;
00740 return true;
00741 }
00742 foreach( Cell2d *nb, this->w_neighbors )
00743 foreach( Cell* cc, ((SELF*)nb)->m_objects )
00744 if ( cc->is_active() )
00745 {
00746 ((VSite*)cc)->e_intersections<< q;
00747 std::cout<<"This Intersections: "<< this->intersections().size() << std::endl;
00748 std::cout<<"Neib Intersections: "<< nb->intersections().size() << std::endl;
00749 return true;
00750 }
00751
00752 } else if ( ((VSite*)c)->m_polynomial[(sz[0]-1)*st[0]]<EPSILON )
00753 {
00754 q= new Point(this->xmax(),this->ymax(),0);
00755 std::cout<< "2.add ("<< *q <<")->("<< *l[0] << ") in "<< *this<<std::endl;
00756 s->insert(q);
00757 s->insert( new Edge(l[0],q) );
00758 ((VSite*)c)->s_intersections<< q;
00759
00760
00761 foreach( Cell2d *nb, this->e_neighbors )
00762 foreach( Cell* cc, ((SELF*)nb)->m_objects )
00763 if ( cc->is_active() )
00764 {
00765 ((VSite*)cc)->w_intersections<< q;
00766 std::cout<<"This Intersections: "<< this->intersections().size() << std::endl;
00767 std::cout<<"Neib Intersections: "<< nb->intersections().size() << std::endl;
00768 return true;
00769 }
00770 foreach( Cell2d *nb, this->n_neighbors )
00771 foreach( Cell* cc, ((SELF*)nb)->m_objects )
00772 if ( cc->is_active() )
00773 {
00774 ((VSite*)cc)->s_intersections<< q;
00775 std::cout<<"This Intersections: "<< this->intersections().size() << std::endl;
00776 std::cout<<"Neib Intersections: "<< nb->intersections().size() << std::endl;
00777 return true;
00778 }
00779
00780 } else if ( ((VSite*)c)->m_polynomial[sz[0]*sz[1]-1]<EPSILON )
00781 {
00782 q= new Point(this->xmin(),this->ymax(),0);
00783 std::cout<< "3.add ("<< *q <<")->("<< *l[0] << ") in "<< *this<<std::endl;
00784 s->insert(q);
00785 s->insert( new Edge(l[0],q) );
00786 ((VSite*)c)->w_intersections<< q;
00787 return true;
00788 } else if ( ((VSite*)c)->m_polynomial[(sz[1]-1)*st[1]]<EPSILON )
00789 {
00790 q= new Point(this->xmax(),this->ymin(),0);
00791 std::cout<< "4.add ("<< *q <<")->("<< *l[0] << ") in "<< *this<<std::endl;
00792 s->insert(q);
00793 s->insert( new Edge(l[0],q) );
00794 ((VSite*)c)->e_intersections<< q;
00795 return true;
00796 }
00797 }
00798 }
00799
00800 if ( l.size()==0)
00801 {
00802 std::cout<< "SIZE ZERO, "<< *this<<std::endl;
00803 return true;
00804
00805 foreach( Cell* c, this->m_objects )
00806 {
00807 sz= ((VSite*)c)->m_polynomial.rep().szs();
00808 st= ((VSite*)c)->m_polynomial.rep().str();
00809 if ( ((VSite*)c)->m_polynomial[0]<EPSILON )
00810 {
00811 q= new Point(this->xmin(),this->ymin(),0);
00812 std::cout<< "1.add ("<< *q <<") in "<< *this<<std::endl;
00813 s->insert(q);
00814 ((VSite*)c)->n_intersections<< q;
00815 return true;
00816 } else if ( ((VSite*)c)->m_polynomial[(sz[0]-1)*st[0]]<EPSILON )
00817 {
00818 q= new Point(this->xmax(),this->ymax(),0);
00819 std::cout<< "1.add ("<< *q <<") in "<< *this<<std::endl;
00820 s->insert(q);
00821 ((VSite*)c)->s_intersections<< q;
00822 return true;
00823 } else if ( ((VSite*)c)->m_polynomial[sz[0]*sz[1]-1]<EPSILON )
00824 {
00825 q= new Point(this->xmin(),this->ymax(),0);
00826 std::cout<< "1.add ("<< *q <<") in "<< *this<<std::endl;
00827 s->insert( new Edge(l[0],q) );
00828 ((VSite*)c)->w_intersections<< q;
00829 return true;
00830 } else if ( ((VSite*)c)->m_polynomial[(sz[1]-1)*st[1]]<EPSILON )
00831 {
00832 q= new Point(this->xmax(),this->ymin(),0);
00833 std::cout<< "1.add ("<< *q <<") in "<< *this<<std::endl;
00834 s->insert(q);
00835 s->insert( new Edge(l[0],q) );
00836 ((VSite*)c)->e_intersections<< q;
00837 return true;
00838 }
00839 }
00840 }
00841
00842 std::cout<< "nb_in= "<< this->nb_intersect() <<std::endl;
00843
00844
00845
00846 print((Cell2dAlgebraicCurve*)m_objects[0]);
00847 return true;
00848 }
00849
00850 TMPL bool
00851 SELF::process_singular() {
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861 Seq<Cell2dAlgebraicCurve*> l;
00862 Cell2dAlgebraicCurve* cc;
00863
00864
00865
00866 Polynomial p;
00867 for ( unsigned i=0; i< this->m_objects.size(); i++ )
00868 for ( unsigned j=i+1; j< this->m_objects.size(); j++ )
00869 {
00870 p = ((VSite*)(this->m_objects[i]))->m_polynomial ;
00871 p -= ((VSite*)(this->m_objects[j]))->m_polynomial ;
00872
00873 cc= new Cell2dAlgebraicCurve( p, (BoundingBox)(*this), false );
00874
00875 l<< cc;
00876 }
00877
00878 this->m_objects.clear();
00879 this->m_objects<< l;
00880 this->is_intersected();
00881
00882
00883 return true;
00884
00885 this->m_bisector=true;
00886
00887
00888
00889
00890
00891
00892 }
00893
00894 TMPL void
00895 SELF::split_position(int& v, double& s) {
00896 double sx = (this->xmax()-this->xmin());
00897 double sy = (this->ymax()-this->ymin());
00898 if(sx<sy) {
00899 v=1;
00900 s=(this->ymax()+this->ymin())/2;
00901 } else {
00902 v=0;
00903 s=(this->xmax()+this->xmin())/2;
00904 }
00905 }
00906
00907 TMPL void
00908 SELF::subdivide(Cell *& left, Cell *& right, int v, double c) {
00909
00910
00911
00912 typedef SELF Cell_t;
00913
00914 if(v==1) {
00915 left =(Cell*)new Cell_t(this->xmin(), this->xmax(), this->ymin(), c, m_intersected) ;
00916 right=(Cell*)new Cell_t(this->xmin(), this->xmax(), c, this->ymax(), m_intersected) ;
00917
00918 foreach(Point * p, this->m_singular) {
00919 if(p->y() <= c)
00920 ((Cell_t*) left)->m_singular << p ;
00921 else
00922 ((Cell_t*)right)->m_singular << p ;
00923 }
00924
00925
00926 this->connect1( (Cell_t*)left, (Cell_t*)right);
00927 ((Cell_t*)left)->join1((Cell_t*)right);
00928
00929 } else {
00930 left = (Cell*)new Cell_t(this->xmin(), c, this->ymin(), this->ymax(), m_intersected) ;
00931 right= (Cell*)new Cell_t(c, this->xmax(), this->ymin(), this->ymax(), m_intersected) ;
00932
00933 foreach(Point * p, this->m_singular) {
00934 if(p->x() <= c )
00935 ((Cell_t*)left)->m_singular << p ;
00936 else
00937 ((Cell_t*)right)->m_singular << p ;
00938 }
00939
00940
00941 this->connect0((Cell_t*)left, (Cell_t*)right);
00942 ((Cell_t*)left)->join0((Cell_t*)right);
00943
00944 }
00945
00946
00947 this->disconnect( );
00948
00949 if (!this->is_bisector() )
00950 {
00951
00952 Seq<VSite*> ll, rr;
00953 Cell * cv_left, * cv_right;
00954
00955 foreach(Cell* cv, this->m_objects) {
00956 cv->subdivide( cv_left, cv_right);
00957 ll<< (VSite*)cv_left;
00958 rr<< (VSite*)cv_right;
00959 }
00960
00961
00962
00963
00964
00965
00966
00967 double mm;
00968 unsigned cnt;
00969 mm= ( (VSite*)ll.min(this->comp_up) )->upper();
00970
00971 cnt=0;
00972 foreach(VSite* vs, ll)
00973 {
00974
00975 if ( !this->over(vs,mm) )
00976 {
00977 ((Cell_t*)left)->push_back( vs, m_sites[cnt] );
00978
00979 }
00980 cnt++;
00981
00982
00983
00984
00985
00986 }
00987
00988
00989 mm= ( (VSite*)rr.min(this->comp_up) )->upper();
00990
00991 cnt=0;
00992 foreach(VSite* vs, rr)
00993 {
00994 if ( !this->over(vs,mm) )
00995 {
00996 ((Cell_t*)right)->push_back( vs, m_sites[cnt] );
00997
00998 }
00999
01000
01001
01002
01003
01004 cnt++;
01005 }
01006 }
01007 else
01008 {
01009
01010 Cell * cv_left, * cv_right;
01011
01012 this->m_objects[0]->subdivide( cv_left, cv_right);
01013 ((Cell_t*)left)->push_bisector( (Cell2dAlgebraicCurve*)cv_left, m_sites );
01014 ((Cell_t*)right)->push_bisector((Cell2dAlgebraicCurve*)cv_right, m_sites );
01015
01016 ((Cell_t*)left)->m_bisector=true;
01017 ((Cell_t*)right)->m_bisector=true;
01018
01019 }
01020
01021
01022 }
01023
01024
01025
01026 TMPL bool
01027 SELF::is_active() {
01028 if ( this->is_bisector() )
01029 {
01030 return (this->m_objects[0])->is_active();
01031 }
01032 else
01033 {
01034 return true;
01035 }
01036
01037 }
01038
01039 TMPL unsigned
01040 SELF::nb_intersect(void) const {
01041 unsigned sum(0);
01042 Cell2d* c;
01043 foreach (Cell* m, m_objects)
01044 {
01045 c = dynamic_cast<Cell2d*>(m);
01046 sum+= c->nb_intersect();
01047 }
01048 return sum;
01049 }
01050
01051
01052 TMPL typename SELF::Point*
01053 SELF::pair(Point * p, int & sgn)
01054 {
01055
01056
01057
01058 if ( this->is_intersected() )
01059 {
01060
01061
01062
01063
01064
01065
01066
01067 unsigned st, cnt(0);
01068 foreach (Cell* mm, this->m_objects)
01069 {
01070 Cell2d* m = dynamic_cast<Cell2d*>(mm);
01071
01072 if ( m->intersections().member(p) )
01073
01074
01075 {
01076
01077
01078
01079 st=this->site(sgn,cnt);
01080
01081
01082 unsigned cnt2(0);
01083 foreach (Cell* cc, this->m_objects)
01084 {
01085 Cell2d* c = dynamic_cast<Cell2d*>(cc);
01086 if ( c!=m &&
01087 (st==this->site(1,cnt2) ||
01088 st==this->site(-1,cnt2) ))
01089 {
01090 sgn= this->signof(st,cnt2);
01091
01092
01093
01094
01095
01096 return c->pair(c->starting_point(sgn), sgn );
01097 }
01098 cnt2++;
01099 }
01100 }
01101 cnt++;
01102 }
01103
01104 } else {
01105
01106 Cell2d* c;
01107 foreach (Cell* m, m_objects)
01108 {
01109 c = dynamic_cast<Cell2d*>(m);
01110 if ( c->intersections().member(p) )
01111
01112
01113 {
01114
01115 return c->pair(p,sgn);
01116 }
01117 }
01118 }
01119 std::cout<<"... Cell list pair trouble"<<std::endl;
01120 return NULL;
01121 }
01122
01123 TMPL typename SELF::Point*
01124 SELF::starting_point( int sgn)
01125 {
01126
01127
01128 Cell2d* c;
01129 foreach (Cell* m, m_objects)
01130 {
01131 if ( m->is_active() )
01132 {
01133 c = dynamic_cast<Cell2d*>(m);
01134 return ((VSite*)c)->starting_point(sgn);
01135 }
01136 }
01137 return NULL;
01138 }
01139
01140 TMPL Cell2d*
01141 SELF::neighbor( Point* p)
01142 {
01143 foreach( Cell2d *c, this->s_neighbors )
01144 if ( c->intersections(2).member(p) )
01145
01146
01147 return c;
01148
01149 foreach( Cell2d *c, this->e_neighbors )
01150 if ( c->intersections(3).member(p) )
01151
01152
01153 return c;
01154
01155 foreach( Cell2d *c, this->n_neighbors )
01156 if ( c->intersections(0).member(p) )
01157
01158
01159 return c;
01160
01161 foreach( Cell2d *c, this->w_neighbors )
01162 if ( c->intersections(1).member(p) )
01163
01164
01165 return c;
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179 return NULL;
01180 }
01181
01182 TMPL Seq<typename mmx::shape::bcell2d<C,V>::Point*>
01183 SELF::intersections() const{
01184 Seq<Point *> s,e,n,w,r;
01185
01186 Cell2d* cl;
01187 foreach (Cell* m, m_objects)
01188 {
01189 cl = dynamic_cast<Cell2d*>(m);
01190 s<< cl->s_intersections;
01191 e<< cl->e_intersections;
01192 n<< cl->n_intersections;
01193 w<< cl->w_intersections;
01194 }
01195 s.sort(this->coord<0>);
01196 e.sort(this->coord<1>);
01197 n.sort(this->coord<0>);
01198 w.sort(this->coord<1>);
01199
01200 r<<s;
01201 r<<e;
01202 r<<n.reversed();
01203 r<<w.reversed();
01204
01205
01206 return ( r );
01207 }
01208
01209
01210 } ;
01211 } ;
01212
01213 # undef TMPL
01214 # undef Solver
01215 # undef Cell
01216 # undef Cell2d
01217 # undef CellList
01218 # undef SELF
01219 # undef AlgebraicCurve
01220 # undef Intersection2dFactory
01221 # undef Cell2dAlgebraicCurve
01222 # undef Shape
01223 # undef VSite
01224
01225 # endif