ofxDelaunay2D triangulation of user shape

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. :blush:
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);
    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;
            ofPixels spixels  = userMask.getPixels();
            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)


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?
Thanks for the link!

Well, I think I found the answer. It was simple, both values in -1 is just what I was trying to have

 userTriangulation.triangulate(lineRespaced, -1, -1);