c++ - Polygon intersection with Boost::geometry severe performance deterioration -


i have particle system , using boost::geometry approximate elliptical particles polygons , use intersection function of library find overlap area. calculating "inner" , "outer" ellipse(polygon) area assign "potential" each particle-particle interaction.

my potential function this:

    double potential(cell* current, cell* next) {     double arearep, areaatt;     double distance = distance(current,next);     double a1 = current->getlength();     double b1 = a1/2.0;     double theta1 = current->gettheta(); //*180.0/m_pi     double x1 = current->getcurrx();     double y1 = current->getcurry();     double a2 = next->getlength();     double b2 = a2/2.0;     double theta2 = next->gettheta();     double x2 = next->getcurrx();     double y2 = next->getcurry();     polygon_2d poly1, poly2, poly3, poly4;     double lamda1, lamda2;     lamda1 = 0.0005; lamda2 = 0.00001;     if(distance < 2.0*1.5*a1) {         ellipse2poly(theta1, a1, b1, x1, y1, &poly1);         ellipse2poly(theta2, a2, b2, x2, y2, &poly2);         arearep = getoverlapingareapoly(poly1,poly2);         ellipse2poly(theta1, 1.5*a1, 1.5*b1, x1, y1, &poly3);         ellipse2poly(theta2, 1.5*a2, 1.5*b2, x2, y2, &poly4);         areaatt = getoverlapingareapoly(poly3, poly4);         return (lamda1*arearep - lamda2*areaatt);      }     else         return 0.0; } 

the "polygonizing" function is:

int ellipse2poly(double theta, double a1, double b1, double h1, double k1, polygon_2d *po) {     using namespace boost::geometry;     polygon_2d  poly;     const int n = 20;     double angle = theta; // cell orientation     double = a1; // long semi-axis length     double b = b1; // short semi-axis length     double xc = h1; // current x position     double yc = k1; // current y position      if(!n)     {         std::cout << "error ellipse(): n should >0\n" <<std::endl;         return 0;     }     double t = 0;     int = 0;     double coor[2*n+1][2];      double x, y;     double step = m_pi/(double)n;     double sinphi = sin(angle);     double cosphi = cos(angle);     for(i=0; i<2*n+1; i++)     {            x = xc + a*cos(t)*cosphi - b*sin(t)*sinphi;         y = yc + a*cos(t)*sinphi + b*sin(t)*cosphi;         coor[i][0] = x;         coor[i][1] = y;         t += step;     }     assign_points(poly, coor);     correct(poly);     *po = poly;     return 1; } 

and returned area is:

double getoverlapingareapoly(polygon_2d poly, polygon_2d poly2) {     point_2d cent; //centre of overlaping area     double overareapoly = 0.0;     typedef std::vector<polygon_2d > polygon_list;     polygon_list v;      intersection(poly,poly2,v);     (polygon_list::const_iterator = v.begin(); != v.end(); ++it)     {         centroid(*it, cent);         overareapoly = area(*it);     }      return overareapoly; } 

the function called every cell (particle) long not same one. previously, using method, 1 iteration of algorithm take approximately 43 ms 1 iteration 100 particles. takes approximately 1 min(!!!), guess have done horribly wrong!

i have tested in msvc2012 under win7 64bit. report linux mint qt 4.7.4.

edit: have tested on linux mint qt 4.7.4 , running reasonably; maybe 90-100 ms per iteration fine. don't know wrong in win7...

i have fixed it. started new project in visual studio , copied source , header files, recompiled , runs smoothly now. guess radically changing code , adding / subtracting stuff must have impact...


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -