Personal License $49.99

1 application Binary restricted distribution Commercial use allowed Can modify source Read full license | More Info

You need to log-in or create an account
  • Create an account
  • Log-in
  • Please use your real name.
  • Account activation link will be sent to this address.
  • Minimum 8 characters

Clicking this button confirms you read and agreed to the terms of use and privacy policy.

Price: $ 49.99

View Pricing 14 days money-back guarantee
(1 ratings)

Delaunay + Voronoi diagram generator

Voronoi diagram generator with triangulation pre-computation.

Share and win up to $15k in prizes each month!Learn more

Share

Description

This single include file will first triangulate then compute a voronoi diagram decomposition from an unordered set of points in bi-dimensional space. The voronoi diagram is an important method for game development for map generation, navigation, influence map computation and more. It is also used as a biology simulator for bacteria growth simulation.

This class is very simple to use - create a random set of points then pass them to the class like this

// this will triangulate the points set

T.Triangulate( Px,Py,N );

// this will compute the voronoi diagram
T.Voronoi();

Assuming you are working under mfc, to trace the diagram you will need to have low level access to the data structure. For example:

void DrawPoly( CDC *pDC,int i ,COLORREF &c,COLORREF& b )
{
        const DELAUNAYVERTEX* VertexPtr=T.GetVertexPtr();
        const DELAUNAYTRIANGLE* TrianglePtr=T.GetTrianglePtr();

        int p1,p2,p3;
        CPoint pts[3];

        p1=TrianglePtr[ i ].p1;
        p2=TrianglePtr[ i ].p2;
        p3=TrianglePtr[ i ].p3;

        // draw with a thick blue pen
       CPen penBlue(PS_SOLID, 1, b);
       CPen* pOldPen = pDC->SelectObject(&penBlue);

       // and a solid red brush
       CBrush brushRed(c);
       CBrush* pOldBrush = pDC->SelectObject(&brushRed);

       // Find the midpoints of the top, right, left, and bottom
       // of the client area. They will be the vertices of our polygon.

       pts[0].x = (int)VertexPtr[ p1 ].x;
       pts[0].y = (int)VertexPtr[ p1 ].y;

       pts[1].x = (int)VertexPtr[ p2 ].x;
       pts[1].y = (int)VertexPtr[ p2 ].y;

       pts[2].x = (int)VertexPtr[ p3 ].x;
       pts[2].y = (int)VertexPtr[ p3 ].y;

       // Calling Polygon() on that array will draw three lines
       // between the points, as well as an additional line to
       // close the shape--from the last point to the first point
       // we specified.

       pDC->Polygon(pts, 3);

       // Put back the old objects.

       pDC->SelectObject(pOldPen);
       pDC->SelectObject(pOldBrush);

}


void Rend(CDC *pDC)
{

    int i,j;

    for ( i=0; i::iterator it;

    for ( i=0; iSelectObject(&penBlue);
            for ( i=0; i<(int)CellPtr[j].p.size()-1; i++ )
                DrawLine( pDC,(int)CellPtr[j].p[i].x,(int)CellPtr[j].p[i].y,(int)CellPtr[j].p[i+1].x,(int)CellPtr[j].p[i+1].y,&penBlue );
            DrawLine( pDC,(int)CellPtr[j].p[i].x,(int)CellPtr[j].p[i].y,(int)CellPtr[j].p[0].x,(int)CellPtr[j].p[0].y,&penBlue );
           pDC->SelectObject(pOldPen);
         DrawPoint( pDC,(int)CellPtr[j].cx-2,(int)CellPtr[j].cy-2,col2 );
    }

Is important to call the functions in order. If you want only triangulation there is no need to call the vonoroi computation, but if you need the vonoroi diagram you need to triangulate first.

Plus you have access to adjacency data structures, for each point is stored the triangle it belongs to and for each triangle which triangle is adjacent. This class doesn't use the Fortune's code for vonoroi computation it obtains from the delaunay triangulator on the fly.

Read all 4 comments »

Questions & Comments

Leave a comment

You must be logged-in to leave a comment.
Log-in now or register for a free account.
  • perera malinda said:

    3 weeks ago
    Thanks very much
  • Simon Jackson License holder?Personal License said:

    9 months ago
    Thanks very much. After looking at other solutions, such as Voro++ (and finding out it doesn't do 2d), this seemed like a good solution as I only wanted something small which could return the Voronoi cells. Will rate it once I've tried it
  • vincenzo panella Author said:

    9 months ago
    You can buy the single user version and since its basically yours , i cannot stop you from using into a commercial package. I don't know if i am going against Binpress rules, but you have my permission , just give me some credits if you like ;-).
You must be logged-in to vote. Log-in to your account or register now.
View all 1 reviews »

User Reviews

    Does exactly what it describes and is very easy to integrate and use. Two function calls is enough to turn a set of random points into a Voronoi diagram which can be accessed by individual Voronoi cells; very useful for map generation.
    - Simon Jackson, 9 months ago
    Flag review
    Was this helpful? Yes No

Price: $ 49.99

View Pricing 14 days money-back guarantee