Search code examples
c++voronoidelaunay

Fade library Delaunay Triangulation site neighbors


In the Delaunay triangulation using Fade library it is possible to visit incident triangle to a site and visit its neighbors as explained here: http://www.geom.at/example2-traversing/

I could not figure how to traverse the site neighbor-sites by exploiting the incident triangle and its neighbors. Which triangle neighbor should I visit at each iteration to accomplish this?

In the below example, the main site is in the blue circle, and I want to save all the neighbor sites in the red circles in some array. .

example


Solution

  • I'm the author of Fade2D. It is much easier when you use the TriangleAroundVertexIterator or the Fade_2D::getIncidentTriangles() method, see the demo function below: It creates a random triangulation, extracts for a certain point the surrounding vertices and draws the result:

    2D Delaunay triangulation, extract incident vertices

    vector<Point2> vRandomPoints;
    generateRandomPoints(50,0,1000,vRandomPoints,1);
    
    Fade_2D dt;
    vector<Point2*> vVertexHandles;
    dt.insert(vRandomPoints,vVertexHandles);
    
    // Your point index to be checked and the corresponding pointer
    size_t pointToCheck=5;
    Point2* pVertexToCheck(vVertexHandles[pointToCheck]);
    
    // Fetch the incident triangles
    std::vector<Triangle2*> vIncidentTriangles;
    dt.getIncidentTriangles(pVertexToCheck,vIncidentTriangles);
    
    // Extract the vertices
    set<Point2*> sResultVertices;
    for(std::vector<Triangle2*>::iterator it(vIncidentTriangles.begin());
        it!=vIncidentTriangles.end();++it)
    {
        Triangle2* pIncidentT(*it);
        int intraTriangleIndex(pIncidentT->getIntraTriangleIndex(pVertexToCheck));
        sResultVertices.insert(pIncidentT->getCorner((intraTriangleIndex+1)%3));
        sResultVertices.insert(pIncidentT->getCorner((intraTriangleIndex+2)%3));
    }
    cout<<"number of points: "<<sResultVertices.size()<<endl;
    
    // Verify: Postscript Visualization
    Visualizer2 vis("result.ps");
    dt.show(&vis,false);
    vis.addObject(Label(*pVertexToCheck,"base"),Color(CGREEN));
    for(set<Point2*>::iterator it(sResultVertices.begin());it!=sResultVertices.end();++it)
    {
        vis.addObject(Label(**it,"VTX"),Color(CRED));
    }
    vis.writeFile();