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