First time here? Check out the FAQ!

Ask Your Question
0

Subdiv2D: get indices of vertices of all triangles

asked Nov 17 '15

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?

Preview: (hide)

1 answer

Sort by » oldest newest most voted
1

answered Nov 17 '15

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);
        }
    }
};
Preview: (hide)

Comments

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

gino0717 gravatar imagegino0717 (Oct 30 '18)edit

Question Tools

1 follower

Stats

Asked: Nov 17 '15

Seen: 1,599 times

Last updated: Nov 17 '15