void Voronoi::RemoveParabola(VEvent * e) { VParabola * p1 = e->arch; VParabola * xl = VParabola::GetLeftParent(p1); VParabola * xr = VParabola::GetRightParent(p1); VParabola * p0 = VParabola::GetLeftChild(xl); VParabola * p2 = VParabola::GetRightChild(xr); if(p0 == p2) std::cout << "chyba - pravá a levá parabola má stejné ohnisko!\n"; if(p0->cEvent){ deleted.insert(p0->cEvent); p0->cEvent = 0; } if(p2->cEvent){ deleted.insert(p2->cEvent); p2->cEvent = 0; } VPoint * p = new VPoint(e->point->x, GetY(p1->site, e->point->x)); points.push_back(p); xl->edge->end = p; xr->edge->end = p; VParabola * higher = nullptr; VParabola * par = p1; while(par != root) { par = par->parent; if(par == xl) higher = xl; if(par == xr) higher = xr; } higher->edge = new VEdge(p, p0->site, p2->site); edges->push_back(higher->edge); VParabola * gparent = p1->parent->parent; if(p1->parent->Left() == p1) { if(gparent->Left() == p1->parent) gparent->SetLeft ( p1->parent->Right() ); if(gparent->Right() == p1->parent) gparent->SetRight( p1->parent->Right() ); } else { if(gparent->Left() == p1->parent) gparent->SetLeft ( p1->parent->Left() ); if(gparent->Right() == p1->parent) gparent->SetRight( p1->parent->Left() ); } delete p1->parent; delete p1; CheckCircle(p0); CheckCircle(p2); }
void Voronoi::InsertParabola(VPoint * p) { if(!root){root = new VParabola(p); return;} if(root->isLeaf && root->site->y - p->y < 1) { VPoint * fp = root->site; root->isLeaf = false; root->SetLeft( new VParabola(fp) ); root->SetRight(new VParabola(p) ); VPoint * s = new VPoint((p->x + fp->x)/2, height); points.push_back(s); if(p->x > fp->x) root->edge = new VEdge(s, fp, p); else root->edge = new VEdge(s, p, fp); edges->push_back(root->edge); return; } VParabola * par = GetParabolaByX(p->x); if(par->cEvent) { deleted.insert(par->cEvent); par->cEvent = 0; } VPoint * start = new VPoint(p->x, GetY(par->site, p->x)); points.push_back(start); VEdge * el = new VEdge(start, par->site, p); VEdge * er = new VEdge(start, p, par->site); el->neighbour = er; edges->push_back(el); par->edge = er; par->isLeaf = false; VParabola * p0 = new VParabola(par->site); VParabola * p1 = new VParabola(p); VParabola * p2 = new VParabola(par->site); par->SetRight(p2); par->SetLeft(new VParabola()); par->Left()->edge = el; par->Left()->SetLeft(p0); par->Left()->SetRight(p1); CheckCircle(p0); CheckCircle(p2); }
void Voronoi::InsertParabola(Vec2d * p){ if(!root){root = new VParabola(p); return;} if(root->isLeaf && root->site->y - p->y < 1){ // degenerovaný pripad - obì spodní místa ve stejné výce Vec2d * fp = root->site; root->isLeaf = false; root->SetLeft( new VParabola(fp) ); root->SetRight(new VParabola(p) ); //Vec2d * s = new Vec2d( (p->x + fp->x)/2, height ); // zaèátek hrany uprostøed míst Vec2d * s = new Vec2d(); s->set( (p->x + fp->x)/2, height ); // zaèátek hrany uprostøed míst points.push_back(s); if(p->x > fp->x) root->edge = new VEdge(s, fp, p); // rozhodnu, který vlevo, který vpravo else root->edge = new VEdge(s, p, fp); edges->push_back(root->edge); return; } VParabola * par = GetParabolaByX(p->x); if(par->cEvent) { deleted.insert(par->cEvent); par->cEvent = 0; } //Vec2d * start = new Vec2d(p->x, GetY(par->site, p->x)); Vec2d * start = new Vec2d(); start->set( p->x, GetY(par->site, p->x) ); points.push_back(start); VEdge * el = new VEdge(start, par->site, p); VEdge * er = new VEdge(start, p, par->site); el->neighbour = er; edges->push_back(el); // pøestavuju strom .. vkládám novou parabolu par->edge = er; par->isLeaf = false; VParabola * p0 = new VParabola(par->site); VParabola * p1 = new VParabola(p); VParabola * p2 = new VParabola(par->site); par->SetRight(p2); par->SetLeft(new VParabola()); par->Left()->edge = el; par->Left()->SetLeft(p0); par->Left()->SetRight(p1); CheckCircle(p0); CheckCircle(p2); }