|
@@ -1,14 +1,17 @@
|
|
#include "autoroadcontact.h"
|
|
#include "autoroadcontact.h"
|
|
|
|
|
|
#include <math.h>
|
|
#include <math.h>
|
|
|
|
+#include <iostream>
|
|
|
|
|
|
AutoRoadContact::AutoRoadContact()
|
|
AutoRoadContact::AutoRoadContact()
|
|
{
|
|
{
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-int AutoRoadContact::CalcContact(Road *pRoad1, Road *pRoad2,int & contacttype,int & turnstraight)
|
|
|
|
|
|
+int AutoRoadContact::CalcContact(Road *pRoad1, Road *pRoad2,int & contacttype,int & turnstraight,
|
|
|
|
+ std::vector<iv::ARC> & xARCLane,std::vector<iv::ARC> & xARCOpLane)
|
|
{
|
|
{
|
|
|
|
+
|
|
double road1_start_x,road1_start_y,road1_end_x,road1_end_y,road1_start_hdg,road1_end_hdg;
|
|
double road1_start_x,road1_start_y,road1_end_x,road1_end_y,road1_start_hdg,road1_end_hdg;
|
|
double road2_start_x,road2_start_y,road2_end_x,road2_end_y,road2_start_hdg,road2_end_hdg;
|
|
double road2_start_x,road2_start_y,road2_end_x,road2_end_y,road2_start_hdg,road2_end_hdg;
|
|
pRoad1->GetGeometryCoords(0,road1_start_x,road1_start_y,road1_start_hdg);
|
|
pRoad1->GetGeometryCoords(0,road1_start_x,road1_start_y,road1_start_hdg);
|
|
@@ -32,7 +35,7 @@ int AutoRoadContact::CalcContact(Road *pRoad1, Road *pRoad2,int & contacttype,in
|
|
|
|
|
|
double fdismin = 100000;
|
|
double fdismin = 100000;
|
|
int index = -1;
|
|
int index = -1;
|
|
- int i;
|
|
|
|
|
|
+ unsigned int i;
|
|
for(i=0;i<4;i++)
|
|
for(i=0;i<4;i++)
|
|
{
|
|
{
|
|
if(fdismin>fdis[i])
|
|
if(fdismin>fdis[i])
|
|
@@ -49,6 +52,8 @@ int AutoRoadContact::CalcContact(Road *pRoad1, Road *pRoad2,int & contacttype,in
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ LaneSection * pLS1 = 0;
|
|
|
|
+ LaneSection * pLS2 = 0;
|
|
double from_x,from_y,from_hdg,to_x,to_y,to_hdg;
|
|
double from_x,from_y,from_hdg,to_x,to_y,to_hdg;
|
|
switch (contacttype) {
|
|
switch (contacttype) {
|
|
case 0:
|
|
case 0:
|
|
@@ -58,6 +63,8 @@ int AutoRoadContact::CalcContact(Road *pRoad1, Road *pRoad2,int & contacttype,in
|
|
to_y = road2_start_y;
|
|
to_y = road2_start_y;
|
|
from_hdg = road1_start_hdg + M_PI;
|
|
from_hdg = road1_start_hdg + M_PI;
|
|
to_hdg = road2_start_hdg;
|
|
to_hdg = road2_start_hdg;
|
|
|
|
+ pLS1 = pRoad1->GetLaneSection(0);
|
|
|
|
+ pLS2 = pRoad2->GetLaneSection(0);
|
|
break;
|
|
break;
|
|
case 1:
|
|
case 1:
|
|
from_x = road1_start_x;
|
|
from_x = road1_start_x;
|
|
@@ -66,6 +73,8 @@ int AutoRoadContact::CalcContact(Road *pRoad1, Road *pRoad2,int & contacttype,in
|
|
to_y = road2_end_y;
|
|
to_y = road2_end_y;
|
|
from_hdg = road1_start_hdg + M_PI;
|
|
from_hdg = road1_start_hdg + M_PI;
|
|
to_hdg = road2_end_hdg+ M_PI;
|
|
to_hdg = road2_end_hdg+ M_PI;
|
|
|
|
+ pLS1 = pRoad1->GetLaneSection(0);
|
|
|
|
+ pLS2 = pRoad2->GetLastLaneSection();
|
|
break;
|
|
break;
|
|
case 2:
|
|
case 2:
|
|
from_x = road1_end_x;
|
|
from_x = road1_end_x;
|
|
@@ -74,6 +83,8 @@ int AutoRoadContact::CalcContact(Road *pRoad1, Road *pRoad2,int & contacttype,in
|
|
to_y = road2_start_y;
|
|
to_y = road2_start_y;
|
|
from_hdg = road1_end_hdg ;
|
|
from_hdg = road1_end_hdg ;
|
|
to_hdg = road2_start_hdg;
|
|
to_hdg = road2_start_hdg;
|
|
|
|
+ pLS1 = pRoad1->GetLastLaneSection();
|
|
|
|
+ pLS2 = pRoad1->GetLaneSection(0);
|
|
break;
|
|
break;
|
|
case 3:
|
|
case 3:
|
|
from_x = road1_end_x;
|
|
from_x = road1_end_x;
|
|
@@ -82,6 +93,8 @@ int AutoRoadContact::CalcContact(Road *pRoad1, Road *pRoad2,int & contacttype,in
|
|
to_y = road2_end_y;
|
|
to_y = road2_end_y;
|
|
from_hdg = road1_end_hdg ;
|
|
from_hdg = road1_end_hdg ;
|
|
to_hdg = road2_end_hdg + M_PI;
|
|
to_hdg = road2_end_hdg + M_PI;
|
|
|
|
+ pLS1 = pRoad1->GetLastLaneSection();
|
|
|
|
+ pLS2 = pRoad1->GetLastLaneSection();
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
break;
|
|
break;
|
|
@@ -93,7 +106,8 @@ int AutoRoadContact::CalcContact(Road *pRoad1, Road *pRoad2,int & contacttype,in
|
|
double hdgdiff = to_hdg - from_hdg;
|
|
double hdgdiff = to_hdg - from_hdg;
|
|
while(hdgdiff>=2.0*M_PI)hdgdiff = hdgdiff - 2.0*M_PI;
|
|
while(hdgdiff>=2.0*M_PI)hdgdiff = hdgdiff - 2.0*M_PI;
|
|
while(hdgdiff<0)hdgdiff = hdgdiff + 2.0*M_PI;
|
|
while(hdgdiff<0)hdgdiff = hdgdiff + 2.0*M_PI;
|
|
- if((hdgdiff<1.0)||(hdgdiff>(2.0*M_PI-1.0)))
|
|
|
|
|
|
+ bool bTurnRight = true;
|
|
|
|
+ if((hdgdiff<0.5)||(hdgdiff>(2.0*M_PI-0.5)))
|
|
{
|
|
{
|
|
turnstraight = 1;
|
|
turnstraight = 1;
|
|
}
|
|
}
|
|
@@ -105,8 +119,241 @@ int AutoRoadContact::CalcContact(Road *pRoad1, Road *pRoad2,int & contacttype,in
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
|
|
+ if(hdgdiff>M_PI)
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"turn right"<<std::endl;
|
|
|
|
+ bTurnRight = true;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"turn left"<<std::endl;
|
|
|
|
+ bTurnRight = false;
|
|
|
|
+ }
|
|
turnstraight = 0;
|
|
turnstraight = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ vector<Lane *> xroad1lane1,xroad1lane2;
|
|
|
|
+ vector<Lane *> xroad2lane1,xroad2lane2;
|
|
|
|
+ for(i=0;i<pLS1->GetLeftLaneCount();i++)
|
|
|
|
+ {
|
|
|
|
+ Lane * pLane = pLS1->GetLeftLaneAt(i+1);
|
|
|
|
+ if(pLane == NULL)
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"GetLeftLaneError i:"<<i<<std::endl;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ xroad1lane1.push_back(pLane);
|
|
|
|
+ }
|
|
|
|
+ for(i=0;i<pLS1->GetRightLaneCount();i++)
|
|
|
|
+ {
|
|
|
|
+ Lane * pLane = pLS1->GetRightLaneAt(i+1);
|
|
|
|
+ if(pLane == NULL)
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"GetRightLaneAt i:"<<i<<std::endl;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ xroad1lane2.push_back(pLane);
|
|
|
|
+ }
|
|
|
|
+ for(i=0;i<pLS2->GetLeftLaneCount();i++)
|
|
|
|
+ {
|
|
|
|
+ Lane * pLane = pLS2->GetLeftLaneAt(i+1);
|
|
|
|
+ if(pLane == NULL)
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"GetLeftLaneError i:"<<i<<std::endl;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ xroad2lane1.push_back(pLane);
|
|
|
|
+ }
|
|
|
|
+ for(i=0;i<pLS2->GetRightLaneCount();i++)
|
|
|
|
+ {
|
|
|
|
+ Lane * pLane = pLS2->GetRightLaneAt(i+1);
|
|
|
|
+ if(pLane == NULL)
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"GetRightLaneAt i:"<<i<<std::endl;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ xroad2lane2.push_back(pLane);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ vector<Lane *> xroad1leftlane,xroad1rightlane;
|
|
|
|
+ vector<Lane *> xroad2leftlane,xroad2rightlane;
|
|
|
|
+
|
|
|
|
+ if((contacttype == 0)||(contacttype == 1))
|
|
|
|
+ {
|
|
|
|
+ xroad1leftlane = xroad1lane2;
|
|
|
|
+ xroad1rightlane = xroad1lane1;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ xroad1leftlane = xroad1lane1;
|
|
|
|
+ xroad1rightlane = xroad1lane2;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if((contacttype == 1)||(contacttype == 3))
|
|
|
|
+ {
|
|
|
|
+ xroad2leftlane = xroad2lane2;
|
|
|
|
+ xroad2rightlane = xroad2lane1;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ xroad2leftlane = xroad2lane1;
|
|
|
|
+ xroad2rightlane = xroad2lane2;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(turnstraight == 1) //
|
|
|
|
+ {
|
|
|
|
+ for(i=0;i<xroad1rightlane.size();i++)
|
|
|
|
+ {
|
|
|
|
+ Lane * pLane1 = xroad1rightlane.at(i);
|
|
|
|
+ Lane * pLane2 = xroad2rightlane.at(i);
|
|
|
|
+ if((pLane1 == NULL)||(pLane2 == NULL))
|
|
|
|
+ {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ if(pLane1->GetType() != pLane2->GetType())
|
|
|
|
+ {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ iv::ARC xARC;
|
|
|
|
+ xARC.from = pLane1->GetId();
|
|
|
|
+ xARC.to = pLane2->GetId();
|
|
|
|
+ xARCLane.push_back(xARC);
|
|
|
|
+ }
|
|
|
|
+ for(i=0;i<xroad1leftlane.size();i++)
|
|
|
|
+ {
|
|
|
|
+ Lane * pLane1 = xroad1leftlane.at(i);
|
|
|
|
+ Lane * pLane2 = xroad2leftlane.at(i);
|
|
|
|
+ if((pLane1 == NULL)||(pLane2 == NULL))
|
|
|
|
+ {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ if(pLane1->GetType() != pLane2->GetType())
|
|
|
|
+ {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ iv::ARC xARC;
|
|
|
|
+ xARC.from = pLane1->GetId();
|
|
|
|
+ xARC.to = pLane2->GetId();
|
|
|
|
+ xARCOpLane.push_back(xARC);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ if(turnstraight == 0)
|
|
|
|
+ {
|
|
|
|
+ int nindex1 = -1;
|
|
|
|
+ int nindex2 = -1;
|
|
|
|
+ for(i=0;i<xroad1rightlane.size();i++)
|
|
|
|
+ {
|
|
|
|
+ if(xroad1rightlane.at(i)->GetType() == "driving")
|
|
|
|
+ {
|
|
|
|
+ nindex1 = i;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for(i=0;i<xroad2rightlane.size();i++)
|
|
|
|
+ {
|
|
|
|
+ if(xroad2rightlane.at(i)->GetType() == "driving")
|
|
|
|
+ {
|
|
|
|
+ nindex2 = i;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if((nindex1<0)||(nindex2<0))
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"can't find driving lane"<<std::endl;
|
|
|
|
+ }
|
|
|
|
+ if(bTurnRight)
|
|
|
|
+ {
|
|
|
|
+ for(i=nindex1;i<xroad1rightlane.size();i++)
|
|
|
|
+ {
|
|
|
|
+ Lane * pLane1 = xroad1rightlane.at(i);
|
|
|
|
+ Lane * pLane2 = xroad2rightlane.at(nindex2);nindex2++;
|
|
|
|
+ if((pLane1 == NULL)||(pLane2 == NULL))
|
|
|
|
+ {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ if(pLane1->GetType() != pLane2->GetType())
|
|
|
|
+ {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ iv::ARC xARC;
|
|
|
|
+ xARC.from = pLane1->GetId();
|
|
|
|
+ xARC.to = pLane2->GetId();
|
|
|
|
+ xARCLane.push_back(xARC);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ Lane * pLane1 = xroad1rightlane.at(nindex1);
|
|
|
|
+ Lane * pLane2 = xroad2rightlane.at(nindex2);
|
|
|
|
+ if((pLane1 == NULL)||(pLane2 == NULL))
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"Lane NULL"<<std::endl;
|
|
|
|
+ }
|
|
|
|
+ if(pLane1->GetType() != pLane2->GetType())
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"Type Not Rigth"<<std::endl;
|
|
|
|
+ }
|
|
|
|
+ iv::ARC xARC;
|
|
|
|
+ xARC.from = pLane1->GetId();
|
|
|
|
+ xARC.to = pLane2->GetId();
|
|
|
|
+ xARCLane.push_back(xARC);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ int nindex1 = -1;
|
|
|
|
+ int nindex2 = -1;
|
|
|
|
+ for(i=0;i<xroad1rightlane.size();i++)
|
|
|
|
+ {
|
|
|
|
+ if(xroad1rightlane.at(i)->GetType() == "driving")
|
|
|
|
+ {
|
|
|
|
+ nindex1 = i;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for(i=0;i<xroad2rightlane.size();i++)
|
|
|
|
+ {
|
|
|
|
+ if(xroad2rightlane.at(i)->GetType() == "driving")
|
|
|
|
+ {
|
|
|
|
+ nindex2 = i;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if((nindex1<0)||(nindex2<0))
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"can't find driving lane"<<std::endl;
|
|
|
|
+ }
|
|
|
|
+ Lane * pLane1 = xroad1rightlane.at(nindex1);
|
|
|
|
+ Lane * pLane2 = xroad2rightlane.at(nindex2);
|
|
|
|
+ if((pLane1 == NULL)||(pLane2 == NULL))
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"Lane NULL"<<std::endl;
|
|
|
|
+ }
|
|
|
|
+ if(pLane1->GetType() != pLane2->GetType())
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"Type Not Rigth"<<std::endl;
|
|
|
|
+ }
|
|
|
|
+ iv::ARC xARC;
|
|
|
|
+ xARC.from = pLane1->GetId();
|
|
|
|
+ xARC.to = pLane2->GetId();
|
|
|
|
+ xARCLane.push_back(xARC);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ std::cout<<"Lane Contact"<<std::endl;
|
|
|
|
+ for(i=0;i<xARCLane.size();i++)
|
|
|
|
+ {
|
|
|
|
+ std::cout<<" From "<<xARCLane.at(i).from<<" To"<<xARCLane.at(i).to<<std::endl;
|
|
|
|
+ }
|
|
|
|
+ std::cout<<"OpLane Contact"<<std::endl;
|
|
|
|
+ for(i=0;i<xARCOpLane.size();i++)
|
|
|
|
+ {
|
|
|
|
+ std::cout<<" From "<<xARCOpLane.at(i).from<<" To"<<xARCOpLane.at(i).to<<std::endl;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+
|
|
}
|
|
}
|