Beispiel #1
0
VParabola * VParabola::GetRightChild	(VParabola * p)
{
	if(!p) return 0;
	VParabola * par = p->Right();
	while(!par->isLeaf) par = par->Left();
	return par;
}
Beispiel #2
0
VParabola * VParabola::GetRightParent	(VParabola * p)
{
	VParabola * par		= p->parent;
	VParabola * pLast	= p;
	while(par->Right() == pLast) 
	{ 
		if(!par->parent) return 0;
		pLast = par; par = par->parent; 
	}
	return par;
}
VParabola * Voronoi::GetParabolaByX(double xx)
{
	VParabola * par = root;
	double x = 0.0;

	while(!par->isLeaf)
	{
		x = GetXOfEdge(par, ly);
		if(x>xx) par = par->Left();
		else par = par->Right();				
	}
	return par;
}
VParabola * Voronoi::GetParabolaByX(double xx){
	VParabola * par = root;
	double x = 0.0;

	while(!par->isLeaf) {
		// projdu stromem dokud nenarazím na vhodný list
		x = GetXOfEdge(par, ly);
		if(x>xx){
			par = par->Left();
		}else{
			par = par->Right();
		}
	}
	return par;
}
Beispiel #5
0
VParabola * Voronoi::getParabolaByX(double xx) {
	VParabola *par = root;
	double x = 0.0;

	// TRANSLATEME projdu stromem dokud nenarazím na vhodný list
	while (!par->isLeaf) {
		x = getXOfEdge(par, ly);

		if (x > xx)
			par = par->left();
		else
			par = par->right();
	}

	return par;
}
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);
}
Beispiel #7
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);
}
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);
}