# ofxDelaunay2D triangulation of user shape

Hi
I’m implementing ofxDelaunay2D to triangulate a human silhouette. The triangulation basically works, however it draws triangles outside the user shape.
I calculated the centre triangle and then checked if there is a human shape on that point, having a kind of descent better shape, but still with errors, for example when user rises the arms, that calculated centre point touches the head and then it paints a triangle from the hands through the head. What would be the best technique?
My approach is this one:
m_points are the user silhouette points
userTriangulation is the result after filtering.

``````   m_triangulation = ofxDelaunay2D::triangulate(m_points);
userTriangulation.clear();

int numTtiangles = m_triangulation.getNumIndices() / 3;
if (numTtiangles > 3){
for (int t=0; t<numTtiangles; t++) {
//Get indices of the triangle t
int i1 = m_triangulation.getIndex( 3 * t );
int i2 = m_triangulation.getIndex( 3 * t + 1 );
int i3 = m_triangulation.getIndex( 3 * t + 2 );

//Get vertices of the triangle
const ofPoint &p1 = m_triangulation.getVertex( i1 );
const ofPoint &p2 = m_triangulation.getVertex( i2 );
const ofPoint &p3 = m_triangulation.getVertex( i3 );

//find the center point for each triangle
float x = (p1.x + p2.x + p3.x)/3.0;
float y = (p1.y + p2.y + p3.y)/3.0;

centerPoints.push_back(ofVec2f(x,y));

int px = CLAMP(x,0,W);
int py = CLAMP(y,0,H);
int index = py*W + px;
int gray = spixels[index];

if(gray == 255){
}
}
}
``````

you can do a point in poly for the center of every triangle and drop triangles that are not in the polygon. I think that’s what I do here:

(that addon can also work, look at the forks for more up to date support)

2 Likes

Ah, that’s great! It works smoothly. I have a technical question. I’m deleting and creating the triangle mesh in every frame which causes the triangles inside the human shape polygon to be different. What would be the approach to make it stable? Do I have to create the mesh only once and then update the number of points?
`````` userTriangulation.triangulate(lineRespaced, -1, -1);