Zone and Area – Example4

This is the right article if you want to triangulate a polygon. Zones are among the most powerful concepts in Fade. A zone defines an area in a (Constrained) Delaunay 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 (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 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

A Zone2 object can not only be made inside or outside a polygon. The code below uses a vector of polygons vCG and a point seedPoint near the lower left corner of the below image. Then it grows a zone from this seed point. The edges of the ConstraintGraph2 objects 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.

Spread the word. Share this post!

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.