Gambit King
Gambit King

Reputation: 483

Searching multi-dimensional vectors

I'm reading an image file and storing each points location. I then combine these points together to find straight,horizontal and slopes lines. For each of these segments i then add features like the start & end of x & y axis, its height, width and so on. In my previous version i created a multi-dimensional vector to implement the above. I then used a find_if to find nearby segments.

My previous implementation :

newSequence = find_if( points.begin(), points.end(), [&](vector<int>&v1) -> bool 
{ 
    return  
    v1[0]   >=  index_a1    &&  
    v1[0]   <=  index_a2    &&
    v1[1]   >=  index_b1    &&
    v1[1]   <=  index_b2    &&
    v1[4]   !=  index_a4    &&  
    v1[8]   ==  index_a8;
}); 

It worked but now i want to improve its performance and am looking into binary_search and lower_bound but it throws a error.

vector <vector<int>>::iterator newSequence;
vector <vector<int>> points;
newSequence = lower_bound( points.begin(), points.end(),[](vector<int>&v1)->bool{
                    return v1[0] = 1;
                    });

I was also wondering if there was a better of storing and searching this kind of data with more than 4 columns.

Upvotes: 0

Views: 141

Answers (2)

user2656151
user2656151

Reputation:

I had an image process problem a couple of years ago (was using douglas peucker algorithm) and I had severe performance issues. It ran forever. Then I changed to use a spatial index library and then it ran in no time. I can check which. Therefore if you really like to boost performance then go for a spatial index.

Upvotes: 2

Some programmer dude
Some programmer dude

Reputation: 409196

If you look at e.g. this reference, you will see that the std::lower_bound function takes a value to compare to. You're not passing that. For this, you can't use e.g. std::lower_bound but have to use some other algorithm.

Upvotes: 0

Related Questions