Ask Your Question
0

Subdiv2D: get indices of vertices of all triangles

asked 2015-11-16 20:32:22 -0600

Jiang gravatar image

I know that Subdiv2D::getTriangleList() will return coordinates of vertices of a all triangles.

But in my case, I'd like to get indices, instead of coordinates.

So, does Subdiv2D provide some function or attribute that can give me those indices?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-11-17 05:12:14 -0600

berak gravatar image

it's not possible directly (those indices do not exist), but you can subclass Subdiv2D, and generate them:

class MyDelauny : public Subdiv2D
{
    // skips "outer" triangles.
    void indices(vector<int> &ind) const
    {    
        int i, total = (int)(qedges.size()*4);
        vector<bool> edgemask(total, false);
        for( i = 4; i < total; i += 2 )
        {
            if( edgemask[i] )
                continue;
            Point2f a, b, c;
            int edge = i;
            int A = edgeOrg(edge, &a);
            if ( A < 4 ) continue;
            edgemask[edge] = true;
            edge = getEdge(edge, NEXT_AROUND_LEFT);
            int B = edgeOrg(edge, &b);
            if ( B < 4 ) continue;
            edgemask[edge] = true;
            edge = getEdge(edge, NEXT_AROUND_LEFT);
            int C = edgeOrg(edge, &c);
            if ( C < 4 ) continue;
            edgemask[edge] = true;

            ind.push_back(A);
            ind.push_back(B);
            ind.push_back(C);
        }
    }
};
edit flag offensive delete link more

Comments

this code dosen't work when vertex >3, try this answer: https://stackoverflow.com/questions/3...

gino0717 gravatar imagegino0717 ( 2018-10-30 01:20:14 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-11-16 20:32:22 -0600

Seen: 1,543 times

Last updated: Nov 17 '15