mercredi 17 mai 2017

vector of vector in for loop

So I am trying to write a code to find out the maximum values of z in Point3f and get all other coordinates for that. I wrote code as below but it's not working.

vector< vector<Point3f> > clusters;
vector<Point3f> maxi;
maxi.clear();

for( int i = 0; i < clusters.size(); i++)
{
    int idx = -1;
    int mini = 0;

    for( int j = 0; j < clusters[i].size(); j++)
    {
        if(clusters[i][j].z > mini || clusters[i][j].z == mini )
        {
            mini = clusters[i][j].z;
            idx = j;
        }
    }
    maxi.push_back(clusters[i][idx]);
}

Whenever I run this code it just terminate without any error or warning. I think I am just missing some small logic, but couldn't get it. Can anyone tell me what's wrong with this code?

Aucun commentaire:

Enregistrer un commentaire