This project is read-only.

Iterate over triangles within an interior polygonal boundry

Feb 2, 2014 at 12:22 PM
Is there a procedure using triangle properties/methods to iterate over all triangles contained within an interior polygonal boundary?
Feb 2, 2014 at 1:35 PM
Edited Feb 2, 2014 at 1:44 PM
There are two ways:
  1. You specify regions in your input geometry and then iterate over all triangles of the mesh, looking at the triangle's Region attribute.
  2. You use the RegionIterator class.
Here's some example code:

using System;
using System.Collections.Generic;
using TriangleNet;
using TriangleNet.Data;
using TriangleNet.Tools;

public static class Example
    public static void RegionIteratorTest()
        var generator = new MeshExplorer.Generators.CircleWithHole();

        // The geometry will have two regions with ids 1 (inner) and 2 (outer).
        var geometry = generator.Generate(25, 25, 50);

        var mesh = new Mesh();


        var dict = new Dictionary<int, bool>();

        foreach (var t in mesh.Triangles)
            // Use the region attribute to identify triangles.
            if (t.Region == 1)
                // Add triangles of inner region.
                dict.Add(t.ID, false);

        // Actually, in this example there's no point using the region
        // iterator since we are processing all triangles in the above
        // loop.

        var iterator = new RegionIterator(mesh);

        var tree = new QuadTree(mesh);

        // The iterator needs a triangle as starting point. We use a quadtree
        // to find a triangle in region 1.
        var start = tree.Query(0.0, 2.0) as Triangle;

            // This would throw if the iterator processed a triangle
            // outside of region 1.
            iterator.Process(start, tri => { dict[tri.ID] = true; });
        catch (Exception)

        foreach (var success in dict.Values)
            if (!success)
                // This would throw if the iterator had missed
                // a triangle in region 1.
                throw new Exception();
Marked as answer by smoothflite on 2/4/2014 at 7:35 AM
Feb 4, 2014 at 3:36 PM
Thank you very much for your reply and sharing you hard work. Excellent coding.