SHARE
TWEET

Untitled

a guest May 26th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void calculate_adjacency() {
  2.  
  3.     //Sorting the vector from smallest to biggest
  4.     sort(regions.begin(), regions.end(), [](const Region& r1, const Region& r2) { return r1.pixel_num < r2.pixel_num; });
  5.  
  6.     //aux tmp regions variables
  7.     Region analyzed, extracted;
  8.  
  9.     //for the entire regions vector, extracting the current analyzed region
  10.     for(int i=0; i<regions.size(); i++) {
  11.    
  12.         //analyzed is the region being analyzed to all the other region
  13.         analyzed = regions.at(i);
  14.        
  15.         //calculate the center of the rect
  16.         int row_cen = round((analyzed.area.height + analyzed.area.y)/2);
  17.         int col_cen = round((analyzed.area.width + analyzed.area.x)/2);
  18.         Point c(col_cen, row_cen);
  19.        
  20.         //the distance from the center to any of the side
  21.         int distance = (c.y - analyzed.area.y);
  22.                
  23.         //calculating the middle point +- 2 to get a point into the adjacent regions
  24.         Point N(c.x, (c.y - distance)-2);
  25.         Point E((c.x - distance)-2, c.y);
  26.         Point S(c.x, (c.y + distance)+2);
  27.         Point W((c.x + distance)+2, c.y);
  28.        
  29.         //analyze all the vector
  30.         for(int j=0; j<regions.size(); j++) {
  31.             if(j==i) continue;
  32.            
  33.             extracted = regions.at(j);
  34.                    
  35.             //if the size of the region is <= than the extracted region from the list
  36.             if(analyzed.pixel_num <= extracted.pixel_num) {
  37.                 //and if the extracted region contains any of the point calculated before
  38.                 if(extracted.contains(N) || extracted.contains(S) || extracted.contains(E) || extracted.contains(W)) {
  39.                     //update both of the adjacent set of the region
  40.                     regions.at(i).adjacency.insert(extracted);
  41.                     regions.at(j).adjacency.insert(analyzed);
  42.                 }  
  43.             }
  44.         }  
  45.        
  46.     }
  47.    
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top