To perform a triangulation, use the IDelaBella2<T>::Create() factory method to instantiate the engine. You then call Triangulate by providing the number of points and pointers to the X and Y coordinate arrays.
Workflow:
- Define a coordinate type (e.g.,
double). - Prepare your point cloud in a contiguous memory layout where X and Y coordinates are accessible via offsets.
- Call
Triangulate(num_points, x_ptr, y_ptr, stride). - If the return value is greater than 0, use
GetNumPolygons() to get the triangle count and GetFirstDelaunaySimplex() to iterate through the resulting triangles. - Use
Destroy() to clean up the engine instance.
#include "delabella.h"
int POINTS = 1000000;
typedef double MyCoord;
struct MyPoint
{
MyCoord x;
MyCoord y;
};
MyPoint* cloud = new MyPoint[POINTS];
// ... populate cloud ...
// Create the engine
IDelaBella2<MyCoord>* idb = IDelaBella2<MyCoord>::Create();
// Perform triangulation
// Returns number of vertices if successful, else <= 0
int verts = idb->Triangulate(POINTS, &cloud->x, &cloud->y, sizeof(MyPoint));
if (verts > 0)
{
int tris = idb->GetNumPolygons();
const IDelaBella2<MyCoord>::Simplex* dela = idb->GetFirstDelaunaySimplex();
for (int i = 0; i < tris; i++)
{
// Access triangle data via dela
dela = dela->next;
}
}
// Cleanup
delete[] cloud;
idb->Destroy();