Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void calculate_adjacency() {
- //Sorting the vector from smallest to biggest
- sort(regions.begin(), regions.end(), [](const Region& r1, const Region& r2) { return r1.pixel_num < r2.pixel_num; });
- //aux tmp regions variables
- Region analyzed, extracted;
- //for the entire regions vector, extracting the current analyzed region
- for(int i=0; i<regions.size(); i++) {
- //analyzed is the region being analyzed to all the other region
- analyzed = regions.at(i);
- //calculate the center of the rect
- int row_cen = round((analyzed.area.height + analyzed.area.y)/2);
- int col_cen = round((analyzed.area.width + analyzed.area.x)/2);
- Point c(col_cen, row_cen);
- //the distance from the center to any of the side
- int distance = (c.y - analyzed.area.y);
- //calculating the middle point +- 2 to get a point into the adjacent regions
- Point N(c.x, (c.y - distance)-2);
- Point E((c.x - distance)-2, c.y);
- Point S(c.x, (c.y + distance)+2);
- Point W((c.x + distance)+2, c.y);
- //analyze all the vector
- for(int j=0; j<regions.size(); j++) {
- if(j==i) continue;
- extracted = regions.at(j);
- //if the size of the region is <= than the extracted region from the list
- if(analyzed.pixel_num <= extracted.pixel_num) {
- //and if the extracted region contains any of the point calculated before
- if(extracted.contains(N) || extracted.contains(S) || extracted.contains(E) || extracted.contains(W)) {
- //update both of the adjacent set of the region
- regions.at(i).adjacency.insert(extracted);
- regions.at(j).adjacency.insert(analyzed);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement