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