|
@@ -15,9 +15,18 @@ void service_roi_xodr::SetXODR(OpenDrive *pxodr)
|
|
|
updateroadarea();
|
|
|
}
|
|
|
|
|
|
-int service_roi_xodr::GetROI(std::shared_ptr<iv::roi::request> xreq_ptr, std::shared_ptr<iv::roi::resultarray> &xres_prt)
|
|
|
+
|
|
|
+#include <QTime>
|
|
|
+int service_roi_xodr::GetROI(std::shared_ptr<iv::roi::request> xreq_ptr, std::shared_ptr<iv::roi::resultarray> &xres_ptr)
|
|
|
{
|
|
|
|
|
|
+ xres_ptr = std::shared_ptr<iv::roi::resultarray>(new iv::roi::resultarray);
|
|
|
+ xres_ptr->set_lat(xreq_ptr->lat());
|
|
|
+ xres_ptr->set_lon(xreq_ptr->lon());
|
|
|
+ xres_ptr->set_heading(xreq_ptr->heading());
|
|
|
+ xres_ptr->set_range(xreq_ptr->range());
|
|
|
+ xres_ptr->set_gridsize(xreq_ptr->gridsize());
|
|
|
+
|
|
|
double x0,y0;
|
|
|
double x,y;
|
|
|
GaussProjCal(xreq_ptr->lon(),xreq_ptr->lat(),&x,&y);
|
|
@@ -26,7 +35,13 @@ int service_roi_xodr::GetROI(std::shared_ptr<iv::roi::request> xreq_ptr, std::sh
|
|
|
y = y - y0;
|
|
|
unsigned int nroadsize = mvectorarea.size();
|
|
|
unsigned int i;
|
|
|
+ unsigned int j;
|
|
|
std::vector<iv::roi::area> xvectorarea;
|
|
|
+
|
|
|
+ QTime xTime;
|
|
|
+ xTime.start();
|
|
|
+
|
|
|
+ //Find Near ROI area
|
|
|
for(i=0;i<nroadsize;i++)
|
|
|
{
|
|
|
double fdis1;
|
|
@@ -37,7 +52,7 @@ int service_roi_xodr::GetROI(std::shared_ptr<iv::roi::request> xreq_ptr, std::sh
|
|
|
continue;
|
|
|
}
|
|
|
unsigned int nareasize = proadarea->mvectorarea.size();
|
|
|
- unsigned int j;
|
|
|
+
|
|
|
for(j=0;j<nareasize;j++)
|
|
|
{
|
|
|
iv::roi::area * parea = &proadarea->mvectorarea[j];
|
|
@@ -67,6 +82,46 @@ int service_roi_xodr::GetROI(std::shared_ptr<iv::roi::request> xreq_ptr, std::sh
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ std::cout<<"xTime: "<<xTime.elapsed()<<std::endl;
|
|
|
+
|
|
|
+ if(xreq_ptr->gridsize() <= 0.0)
|
|
|
+ {
|
|
|
+ return -1; //grid size is error
|
|
|
+ }
|
|
|
+
|
|
|
+ unsigned int xarea = (unsigned int)(xreq_ptr->range()*2.0/xreq_ptr->gridsize()) + 1;
|
|
|
+ unsigned int yarea = (unsigned int)(xreq_ptr->range()*2.0/xreq_ptr->gridsize()) + 1;
|
|
|
+
|
|
|
+ std::vector<iv::roi::Point> xvectorpoint;
|
|
|
+ for(i=0;i<xarea;i++)
|
|
|
+ {
|
|
|
+ for(j=0;j<yarea;j++)
|
|
|
+ {
|
|
|
+ double xr = i*xreq_ptr->gridsize() - xreq_ptr->range();
|
|
|
+ double yr = j*xreq_ptr->gridsize() - xreq_ptr->range();
|
|
|
+ double hdg_o = (90-xreq_ptr->heading())*M_PI/180.0;
|
|
|
+ double rel_x = xr * cos(hdg_o) - yr * sin(hdg_o);
|
|
|
+ double rel_y = xr * sin(hdg_o) + yr * cos(hdg_o);
|
|
|
+ if(CheckPointInROI(rel_x,rel_y,xvectorarea))
|
|
|
+ {
|
|
|
+ iv::roi::Point xpoint;
|
|
|
+ xpoint.x = rel_x;
|
|
|
+ xpoint.y = rel_y;
|
|
|
+ xvectorpoint.push_back(xpoint);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ std::cout<<"xTime: "<<xTime.elapsed()<<std::endl;
|
|
|
+
|
|
|
+ for(i=0;i<xvectorpoint.size();i++)
|
|
|
+ {
|
|
|
+ iv::roi::resultunit * padd = xres_ptr->add_res();
|
|
|
+ padd->set_x(xvectorpoint[i].x);
|
|
|
+ padd->set_y(xvectorpoint[i].y);
|
|
|
+ }
|
|
|
+
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -155,6 +210,7 @@ iv::roi::roadarea service_roi_xodr::GetRoadArea(Road *pRoad, const double fstep)
|
|
|
xarea.refPoint.x = x;
|
|
|
xarea.refPoint.y = y;
|
|
|
xarea.s = snow;
|
|
|
+ xarea.fmaxlen = fleftwidth + frigthwidth;
|
|
|
xroadarea.mvectorarea.push_back(xarea);
|
|
|
// double fleftwidth = pRoad->GetRoadLeftWidth(snow);
|
|
|
// double frigthwidth = pRoad->GetRoadRightWidth(snow);
|
|
@@ -190,3 +246,36 @@ iv::roi::roadarea service_roi_xodr::GetRoadArea(Road *pRoad, const double fstep)
|
|
|
return xroadarea;
|
|
|
}
|
|
|
|
|
|
+bool service_roi_xodr::CheckPointInArea(double x, double y, iv::roi::area &xarea)
|
|
|
+{
|
|
|
+ double a = (xarea.P2.x - xarea.P1.x)*(y - xarea.P1.y) - (xarea.P2.y-xarea.P1.y)*(x-xarea.P1.x);
|
|
|
+ double b = (xarea.P3.x - xarea.P2.x)*(y - xarea.P2.y) - (xarea.P3.y-xarea.P2.y)*(x-xarea.P2.x);
|
|
|
+ double c = (xarea.P4.x - xarea.P3.x)*(y - xarea.P3.y) - (xarea.P4.y-xarea.P3.y)*(x-xarea.P3.x);
|
|
|
+ double d = (xarea.P1.x - xarea.P4.x)*(y - xarea.P4.y) - (xarea.P1.y-xarea.P4.y)*(x-xarea.P4.x);
|
|
|
+
|
|
|
+ if((a > 0 && b > 0 && c > 0 && d > 0) || (a < 0 && b < 0 && c < 0 && d < 0)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+bool service_roi_xodr::CheckPointInROI(double x, double y, std::vector<iv::roi::area> &xvectorroi)
|
|
|
+{
|
|
|
+ unsigned int i;
|
|
|
+ unsigned nsize = xvectorroi.size();
|
|
|
+ for(i=0;i<nsize;i++)
|
|
|
+ {
|
|
|
+ iv::roi::area xarea = xvectorroi[i];
|
|
|
+ double fdis = sqrt(pow(xarea.refPoint.x-x,2)+pow(xarea.refPoint.y-y,2));
|
|
|
+ if(fdis>(xarea.fmaxlen+0.1))
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(CheckPointInArea(x,y,xarea))
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|