Beispiel #1
0
void Voronoi::insertParabola(VPoint *p) {
	if (!root) {
		root = new VParabola(p);
		return;
	}

	// TRANSLATEME degenerovaný pøípad - obì spodní místa ve stejné výšce
	if (root->isLeaf && root->site->y - p->y < 0.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); // TRANSLATEME zaèátek hrany uprostøed míst
		points.push_back(s);

		if (p->x > fp->x)
		    root->edge = new VEdge(s, fp, p); // TRANSLATEME 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;
	}

	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);

	// TRANSLATEME 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);
}
Beispiel #2
0
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 << "TRANSLATEME 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;
	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);
}