Has anyone already used the Triangle/Triangle++ library in a C++ project ? (delaunay triangulation)

StackOverflow https://stackoverflow.com/questions/20133223

I'm using SFML and I want to make a delaunay triangulation of a random set of points.

http://www.cs.cmu.edu/~quake/triangle.html

I'm using triangle++, a c++ wrapper

http://www.compgeom.com/~piyush/scripts/triangle/

I added those #defines

#define REDUCED  
#define ANSI_DECLARATORS  
#define TRILIBRARY  
#define CDT_ONLY  
#define NO_TIMER  
#define CYGWIN  

This compiles, it runs fines, but now that it calculated those things, how do I get the edges between vertices ?

有帮助吗?

解决方案 2

This was not really clear, but fiterator means face iterator, and a face is a triangle. Org, Dest and Apex are the indices of those vertices.

for(Delaunay::fIterator fit  = delobject.fbegin(); 
                        fit != delobject.fend(); 
                      ++fit)
{
    cout << " Org " <<  delobject.Org(fit)  << ", " 
         << " Dest " << delobject.Dest(fit) << ", " 
         << " Apex " << delobject.Apex(fit) << //" \t: Area = " 
}

Don't forget Triangle++ doesn't really require you to put the actual Triangle.c code, so it was really easy to use.

其他提示

Use numberoftriangles, trianglelist, pointlist. For each triangle you have 3 numbers in trianglelist, which are indexes inside pointlist for the 3 corners of the triangle. They don't give you vertices directly, but you can easily derive them from there.

Let me know if it's still not clear.

for (int i = 0; i < numberoftriangles; ++i) {
   int point1Index = trianglelist[i * 3 + 0];
   int point2Index = trianglelist[i * 3 + 1];
   int point3Index = trianglelist[i * 3 + 2];

   REAL point1X = pointlist[2 * point1Index + 0];
   REAL point1Y = pointlist[2 * point1Index + 1];
   ... etc
}

/*  `trianglelist':  An array of triangle corners.  The first triangle's     */
/*    first corner is at index [0], followed by its other two corners in     */
/*    counterclockwise order, followed by any other nodes if the triangle    */
/*    represents a nonlinear element.  Each triangle occupies                */
/*    `numberofcorners' ints.                                                */

/*  `pointlist':  An array of point coordinates.  The first point's x        */
/*    coordinate is at index [0] and its y coordinate at index [1], followed */
/*    by the coordinates of the remaining points.  Each point occupies two   */
/*    REALs.  
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top