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