00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 # ifndef shape_arrangement2d_hpp
00013 # define shape_arrangement2d_hpp
00014
00015 # include <shape/mesher2d.hpp>
00016
00017 # include <stack>
00018 # define STACK std::stack<Cell2d*>
00019
00020 # define TMPL template<class C, class V>
00021 # define Shape SHAPE_OF(V)
00022 # define AlgebraicCurve algebraic_curve<C,REF>
00023 # define ArrangementCurve arrangement_curve<C,REF>
00024 # define ParametricCurve parametric_curve<C,REF>
00025 # define Cell2dAlgebraicCurve bcell2d_algebraic_curve<C,REF>
00026 # define Cell2dParametricCurve bcell2d_parametric_curve<C,REF>
00027 # define Cell2dArrangementCurve bcell2d_arrangement_curve<C,REF>
00028 # define Cell2dInter bcell2d_intersection<C,REF>
00029 # define SELF arrangement2d<C,V>
00030 # undef Cell
00031
00032 namespace mmx {
00033 namespace shape {
00034
00035
00036
00037 template<class C, class V=default_env>
00038 class arrangement2d: public mesher2d<C,V> {
00039
00040 public:
00041
00042 typedef typename mesher2d<C,V>::Point Point;
00043 typedef typename mesher2d<C,V>::Edge Edge;
00044 typedef typename mesher2d<C,V>::Face Face;
00045
00046 typedef typename mesher2d<C,V>::BoundingBox BoundingBox;
00047
00048 typedef typename mesher2d<C,V>::Cell Cell;
00049 typedef typename mesher2d<C,V>::Cell2d Cell2d;
00050 typedef typename mesher2d<C,V>::Curve Curve;
00051
00052 typedef node<Cell*> Node;
00053 typedef kdtree<Cell*> Kdtree;
00054 typedef topology<C,V> Topology;
00055
00056 public:
00057
00058 arrangement2d(): mesher2d<C,V>(){ };
00059
00060 arrangement2d(Curve * curve) ;
00061 ~arrangement2d(void) { delete this->m_tree ; };
00062
00063 void run(void) ;
00064
00065
00066
00067
00068
00069
00070 virtual void insert_singular(Point*);
00071
00072 protected:
00073 bool is_regular (Cell * bcell) ;
00074 bool insert_regular(Cell * bcell) ;
00075 bool singularity(Cell * bcell) ;
00076 bool subdivide(Cell * bcell, Node * node) ;
00077
00078
00079 private:
00080 Kdtree * m_tree ;
00081 std::list<Node *> m_nodes ;
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 };
00095
00096
00097
00098 TMPL void
00099 SELF::run() {
00100
00101 mesher2d<C,V>::run();
00102
00103
00104 std::cout<<"Computing arrangement." <<std::endl;
00105
00106 Seq<Cell2d*> nlist;
00107 this->b_leaves.dfs(nlist);
00108 Cell2d* pr;
00109 pr= nlist[nlist.size()-1];
00110
00111 foreach(Cell2d* cl2, nlist)
00112 {
00113 if ( cl2->is_corner() )
00114 pr=cl2;
00115 else {
00116 if ( (cl2->s_neighbors.size()==0 &&
00117 cl2->intersections(0).size()==0 ) ||
00118 (cl2->e_neighbors.size()==0 &&
00119 cl2->intersections(1).size()==0 ) ||
00120 (cl2->n_neighbors.size()==0 &&
00121 cl2->intersections(2).size()==0 ) ||
00122 (cl2->w_neighbors.size()==0 &&
00123 cl2->intersections(3).size()==0 ) )
00124 {
00125 this->b_leaves.push_edge(pr, this->b_leaves.next(cl2) ) ;
00126 this->b_leaves.delete_vertex( cl2 ) ;
00127 }
00128 else
00129 pr=cl2;
00130 }
00131 }
00132
00133 std::cout<<"Border Ok." <<std::endl;
00134
00135
00136 nlist.clear();
00137 this->m_leaves.dfs(nlist);
00138 foreach(Cell2d* cl2, nlist)
00139 {
00140
00141 foreach(Cell2d* nb, cl2->neighbors() )
00142 this->m_leaves.push_edge( cl2,nb ) ;
00143 }
00144
00145 if (0)
00146 foreach(Cell2d* cl, nlist) {
00147 if (!cl->is_active() )
00148 {
00149 this->m_leaves.delete_vertex(cl);
00150 }
00151 }
00152
00153
00154 std::cout<<"Leaf graph Ok." <<std::endl;
00155
00157
00158
00159
00160
00161
00162
00163
00164
00165 Point *p= NULL;
00166 Face * f= NULL;
00167 int aux;
00168 int sgn(1);
00169 assert( nlist.size()>1);
00170
00171 Cell2d *s= NULL,
00172 *t= NULL,
00173 *b= NULL;
00174 STACK stack;
00175
00176
00177 foreach(Cell2d* cl, nlist)
00178 if (
00179 cl->is_regular() &&
00180 cl->nb_intersect()==2 &&
00181 !cl->is_border() )
00182 stack.push(cl);
00183
00184
00185 while ( !stack.empty() )
00186 {
00187 s= stack.top();
00188 aux=s->m_gnode->aux();
00189
00190
00191
00192 switch ( aux )
00193 {
00194 case (0): sgn=1;
00195 break;
00196 case (2): sgn=-1;
00197 break;
00198 case (-1):sgn=1;
00199 break;
00200 default: stack.pop();
00201 continue;
00202 }
00203
00204
00205
00206 f= new Face();
00207
00208
00209 p= s->starting_point(sgn);
00210 std::cout<<"Getting ("<<(sgn==1 ? "+": "-")
00211 <<") face starting at "<< *s<< std::endl;
00212
00213
00214 p= s->pair(p,sgn);
00215 f->insert(p);
00216 b=s;
00217
00218
00219
00220 do {
00221
00222
00223
00224
00225
00226 if( this->m_leaves.member(b) ) {
00227 aux=b->m_gnode->aux();
00228 b->m_gnode->aux(aux + (sgn==1 ? 2:-1) );}
00229
00230 t= b->neighbor(p);
00231
00232 if ( t==NULL)
00233 {
00234
00235
00236 if (b->s_neighbors.size()==0 &&
00237 b->e_neighbors.size()==0 && b->intersections(1).size()==0)
00238 f->insert(new Point(b->xmax(),b->ymin(),0.0) );
00239 else if (b->e_neighbors.size()==0 &&
00240 b->n_neighbors.size()==0 && b->intersections(2).size()==0)
00241 f->insert(new Point(b->xmax(),b->ymax(),0.0) );
00242 else if (b->n_neighbors.size()==0 &&
00243 b->w_neighbors.size()==0 && b->intersections(3).size()==0)
00244 f->insert(new Point(b->xmin(),b->ymax(),0.0) );
00245 else if (b->w_neighbors.size()==0 &&
00246 b->s_neighbors.size()==0 && b->intersections(0).size()==0)
00247 f->insert(new Point(b->xmin(),b->ymin(),0.0) );
00248
00249 b=this->b_leaves.next(b);
00250
00251
00252 if (b->s_neighbors.size()==0 &&
00253 b->e_neighbors.size()==0 && b->intersections(0).size()==0 )
00254 { f->insert(new Point(b->xmax(),b->ymin(),0.0) );
00255 } else if (b->e_neighbors.size()==0 &&
00256 b->n_neighbors.size()==0 && b->intersections(1).size()==0)
00257 { f->insert(new Point(b->xmax(),b->ymax(),0.0) );
00258 } else if (b->n_neighbors.size()==0 &&
00259 b->w_neighbors.size()==0 && b->intersections(2).size()==0)
00260 { f->insert(new Point(b->xmin(),b->ymax(),0.0) );
00261 } else if (b->w_neighbors.size()==0 &&
00262 b->s_neighbors.size()==0 && b->intersections(3).size()==0)
00263 { f->insert(new Point(b->xmin(),b->ymin(),0.0) );
00264 }
00265
00266 if ( this->m_leaves.member(b) )
00267 {
00268 p= b->starting_point(sgn);
00269 f->insert(p);
00270 p= b->pair(p,sgn);
00271 f->insert(p);
00272 }
00273 }
00274 else
00275 {
00276 b=t;
00277 if ( b->m_singular.size()==1 )
00278 f->insert(b->m_singular[0]);
00279 p= b->pair(p,sgn);
00280 f->insert(p);
00281 }
00282
00283 } while (b!=s);
00284
00285
00286
00287 this->get_output()->m_faces<< f;
00288
00289
00290
00291 }
00292
00293 std::cout<<" # faces= "<< this->get_output()->m_faces.size() << std::endl;
00294
00295 }
00296
00297 TMPL bool
00298 SELF::is_regular(Cell * cl) {
00299 return cl->is_regular();
00300 }
00301
00302 TMPL bool
00303 SELF::insert_regular(Cell * cl) {
00304 return cl->insert_regular(this);
00305 }
00306
00307 TMPL bool
00308 SELF::singularity(Cell * cl) {
00309 return cl->insert_singular(this) ;
00310 }
00311
00312 TMPL void
00313 SELF::insert_singular(Point * p) {
00314 this->m_specials<<p;
00315 }
00316
00317 TMPL bool
00318 SELF::subdivide(Cell * cl, Node * node) {
00319 int v=0;
00320
00321 Cell* left, * right;
00322 v = cl->subdivide(left, right) ;
00323
00324 node->m_left = new Node(node, left, Node::LEFT, v);
00325 m_nodes << node->m_left ;
00326 node->m_right = new Node(node, right, Node::RIGHT, v);
00327 m_nodes << node->m_right;
00328
00329 return true ;
00330 }
00331
00332
00333
00334 }
00335 }
00336
00337 # undef TMPL
00338 # undef AlgebraicCurve
00339 # undef ArrangementCurve
00340 # undef Cell
00341 # undef Cell2dAlgebraicCurve
00342 # undef Cell2dParametricCurve
00343 # undef Cell2dArrangementCurve
00344 # undef Cell2dInter
00345 # undef Cell2dFactory
00346 # undef ParametricCurve
00347 # undef Curve
00348 # undef SELF
00349 # undef Shape
00350 # undef STACK
00351 # endif