Example4 – Zones

Example4 – Zones, defined areas in triangulations

Zones are among the most powerful concepts in Fade. A zone defines an area in a triangulation. Zones can be combined using boolean set operations such as union and difference, a quality mesh can be constructed inside a zone and the triangles of a zone can be extracted. Zones can be defined in several ways:

  • Area inside a polygon
  • Area outside a polygon
  • Area grown from a seed point
  • Area of the whole triangulation (global zone)
  • Area of arbitrary triangles

The code examples below demonstrate that.

Preparing the initial situation

Two polygons (ConstraintGraph2 objects) are made, then applyConstraintsAndZones() is called and the triangulation is drawn.

	Fade_2D dt;

	// 2) Prepare and insert two constraint graphs
	std::vector<Point2> vConstraintPoints;

	std::vector<Segment2> vSegments1;
	std::vector<Segment2> vSegments2;
	for(size_t i=0;i<vConstraintPoints.size();++i) 
		Point2& p0(vConstraintPoints[i]); 
		Point2& p1(vConstraintPoints[(i+1)%vConstraintPoints.size()]); 

		Point2 p0a(p0.x(),p0.y()+170); 
		Point2 p1a(p1.x(),p1.y()+170); 
	ConstraintGraph2* pCG1(NULL); 
	ConstraintGraph2* pCG2(NULL); 

	// 3) Apply and show the triangulation and constraints 

	// Verify that the ConstraintGraph2 objects pCG1 and pCG2 are closed if(!pCG1->isPolygon() || !pCG2->isPolygon() )
		cout<<"pCG1 and pCG2 must be closed polygons"<<endl;
		return 1;

Two polygons in a triangulation

Two polygons in a triangulation

Creating an inside and outside zone

ConstraintGraph pCG1 is the lower polygon in the above image. The two code lines below code create one zone inside this circle and one zone outside.

	Zone2* pZoneInside(dt.createZone(pCG1,ZL_INSIDE));
	Zone2* pZoneOutside(dt.createZone(pCG1,ZL_OUTSIDE));
Inside Zone

Inside Zone

Outside Zone

Outside Zone

Zone growing from a seed point

The code below uses vCG (a vector of polygons) and a seedPoint near the lower left corner of the below image. Then it grows a zone from this seedPoint. The edges of the polygons in vCG act as fence which stops the growing process.

	vector<ConstraintGraph2*> vCG;
	Point2 seedPoint(-99,-99); // near the lower left corner
	Zone2* pZoneGrow(dt.createZone(vCG,ZL_GROW,seedPoint));

Zone growing from a seed point

Zone growing from a seed point

The global zone

The global zone is a zone consisting of all existing triangles.

	Zone2* pZoneGlobal(dt.createZone(NULL,ZL_GLOBAL));

Zone creation from arbitrary triangles

A zone can be created from an arbitrary set of triangles. This set does not need to be connected. The example code below first fetches all triangles from the triangulation. Then it chooses a random sample of them and uses it to create a zone.

	vector<Triangle2*> vT;
	Zone2* pZoneRandomTriangles(dt.createZone(vT));

A Zone defined by triangles

A Zone defined by triangles

This article covered creation of zones. The next post Zone Operations shows how the union, the intersection, the difference and symmetric difference of two zones can be computed.

Leave A Reply

Your email address will not be published. Required fields are marked *


By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.