有没有人在C ++项目中使用过Triangle / Triangle ++库? (delaunay三角测量)

时间:2013-11-21 22:24:05

标签: c++ visual-c++ triangulation delaunay

我正在使用SFML,我想对一组随机点进行delaunay三角测量。

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

我正在使用triangle ++,一个c ++包装器

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

我添加了#defines

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

这个编译,它运行罚款,但现在它计算了这些东西,我如何获得顶点之间的边缘?

2 个答案:

答案 0 :(得分:0)

使用numberoftriangles,trianglelist,pointlist。对于每个三角形,您在三角形列表中有3个数字,它们是三角形的三个角点的点列表内的索引。它们不直接为您提供顶点,但您可以从那里轻松地派生它们。

如果还不清楚,请告诉我。

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.  

答案 1 :(得分:0)

这不是很清楚,但是fiterator意味着面对迭代器,而面是三角形。 Org,Dest和Apex是这些顶点的索引。

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 = " 
}

不要忘记Triangle ++并不真正要求你放置实际的Triangle.c代码,因此它非常容易使用。