|
@@ -541,6 +541,99 @@ struct nearoption
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+int xodrfunc::GetNearPointAtRoad(const double x, const double y, Road *pRoad, GeometryBlock **pgeo, double &fdis, double &nearx, double &neary, double &nearhead, const double nearthresh, double *pfs, int *pnlane, bool bnotuselane)
|
|
|
+{
|
|
|
+ double dismin = std::numeric_limits<double>::infinity();
|
|
|
+ fdis = dismin;
|
|
|
+ unsigned int i;
|
|
|
+ std::vector<iv::nearoption> xvectornearopt;
|
|
|
+
|
|
|
+ unsigned int j;
|
|
|
+ Road * proad = pRoad;
|
|
|
+ double nx,ny,nh,frels;
|
|
|
+
|
|
|
+ for(j=0;j<proad->GetGeometryBlockCount();j++)
|
|
|
+ {
|
|
|
+ GeometryBlock * pgb = proad->GetGeometryBlock(j);
|
|
|
+ double dis;
|
|
|
+ RoadGeometry * pg;
|
|
|
+ int nlane = 1000;
|
|
|
+ pg = pgb->GetGeometryAt(0);
|
|
|
+
|
|
|
+ if((sqrt(pow(x-pg->GetX(),2)+pow(y- pg->GetY(),2))-pg->GetLength())>nearthresh)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (pg->GetGeomType()) {
|
|
|
+ case 0: //line
|
|
|
+ dis = GetLineDis((GeometryLine *) pg,x,y,nx,ny,nh,frels);
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ dis = GetSpiralDis((GeometrySpiral *)pg,x,y,nx,ny,nh,frels);
|
|
|
+ break;
|
|
|
+ case 2: //arc
|
|
|
+ dis = GetArcDis((GeometryArc *)pg,x,y,nx,ny,nh,frels);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 3:
|
|
|
+ dis = GetPoly3Dis((GeometryPoly3 *)pg,x,y,nx,ny,nh,frels);
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ dis = GetParamPoly3Dis((GeometryParamPoly3 *)pg,x,y,nx,ny,nh,frels);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ dis = 100000.0;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ double fgeodis;
|
|
|
+
|
|
|
+ fgeodis = dis;
|
|
|
+ if((dis < 100)&&(bnotuselane == false))
|
|
|
+ {
|
|
|
+ double faccuratedis;
|
|
|
+ faccuratedis = GetAcurateDis(x,y,proad,frels+pg->GetS(),nx,ny,nh,&nlane);
|
|
|
+ if(faccuratedis < dis)dis = faccuratedis;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if(dis == 0)
|
|
|
+ {
|
|
|
+ iv::nearoption xopt;
|
|
|
+ xopt.fdis = dis;
|
|
|
+ xopt.fgeodis = fgeodis;
|
|
|
+ xopt.fs = frels +pg->GetS();
|
|
|
+ xopt.nearhead = nh;
|
|
|
+ xopt.nearx = nx;
|
|
|
+ xopt.neary = ny;
|
|
|
+ xopt.nlane = nlane;
|
|
|
+ xopt.pgeob = pgb;
|
|
|
+ xopt.pRoad = proad;
|
|
|
+ xvectornearopt.push_back(xopt);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(dis < dismin)
|
|
|
+ {
|
|
|
+ dismin = dis;
|
|
|
+ nearx = nx;
|
|
|
+ neary = ny;
|
|
|
+ nearhead = nh;
|
|
|
+ fdis = dis;
|
|
|
+ *pgeo = pgb;
|
|
|
+ if(pfs != 0)*pfs = frels +pg->GetS();
|
|
|
+ if(pnlane != 0)*pnlane = nlane;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(fdis<nearthresh)return 0;
|
|
|
+ return -1;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
int xodrfunc::GetNearPoint(const double x, const double y, OpenDrive *pxodr, Road **pObjRoad, GeometryBlock **pgeo,
|
|
|
double &fdis, double &nearx, double &neary, double &nearhead,
|
|
|
const double nearthresh,double * pfs,int * pnlane,bool bnotuselane)
|
|
@@ -1039,6 +1132,32 @@ int xodrfunc::GetParamPoly3XY(GeometryParamPoly3 *pparam3d, double soff, double
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+int xodrfunc::GetRoadHeightByS(Road *pRoad, const double s, double &fheight)
|
|
|
+{
|
|
|
+ if(pRoad->GetElevationCount() == 0)
|
|
|
+ {
|
|
|
+ fheight = 0;
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ Elevation * pEle = pRoad->GetElevation(0);
|
|
|
+ unsigned int i;
|
|
|
+ for(i=0;i<(pRoad->GetElevationCount()-1);i++)
|
|
|
+ {
|
|
|
+ if(s<pRoad->GetElevation(i+1)->GetS())
|
|
|
+ {
|
|
|
+ pEle = pRoad->GetElevation(i);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ double frels = s - pEle->GetS();
|
|
|
+ fheight = pEle->GetA() + pEle->GetB() * frels
|
|
|
+ + pEle->GetC() * frels * frels + pEle->GetD() * frels * frels * frels;
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
int xodrfunc::GetRoadXYByS(Road *pRoad, const double s, double &x, double &y, double &hdg)
|
|
|
{
|
|
|
if(s<0)return -1;
|
|
@@ -1053,7 +1172,7 @@ int xodrfunc::GetRoadXYByS(Road *pRoad, const double s, double &x, double &y, do
|
|
|
if(s<pRoad->GetGeometryBlock(i+1)->GetGeometryAt(0)->GetS())
|
|
|
{
|
|
|
|
|
|
- pgeosel = pRoad->GetGeometryBlock(0)->GetGeometryAt(0);
|
|
|
+ pgeosel = pRoad->GetGeometryBlock(i)->GetGeometryAt(0);
|
|
|
break;
|
|
|
}
|
|
|
}
|