|
@@ -3,13 +3,26 @@
|
|
|
#include <math.h>
|
|
|
#include <iostream>
|
|
|
|
|
|
+#include "xodrfunc.h"
|
|
|
+
|
|
|
AutoRoadContact::AutoRoadContact()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @brief AutoRoadContact::CalcContact
|
|
|
+ * @param pRoad1
|
|
|
+ * @param pRoad2
|
|
|
+ * @param contacttype 0:start to start 1:start to end 2:end to start 3:end to end
|
|
|
+ * @param turnstraight 0: turn 1:straight 2:u-turn
|
|
|
+ * @param xARCLane right lane contact
|
|
|
+ * @param xARCOpLane left lane contact
|
|
|
+ * @param fDisTolerance distance must below this value
|
|
|
+ * @return
|
|
|
+ */
|
|
|
int AutoRoadContact::CalcContact(Road *pRoad1, Road *pRoad2,int & contacttype,int & turnstraight,
|
|
|
- std::vector<iv::ARC> & xARCLane,std::vector<iv::ARC> & xARCOpLane)
|
|
|
+ std::vector<iv::ARC> & xARCLane,std::vector<iv::ARC> & xARCOpLane, const double fDisTolerance)
|
|
|
{
|
|
|
|
|
|
double road1_start_x,road1_start_y,road1_end_x,road1_end_y,road1_start_hdg,road1_end_hdg;
|
|
@@ -49,6 +62,18 @@ int AutoRoadContact::CalcContact(Road *pRoad1, Road *pRoad2,int & contacttype,in
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if(fdismin > fDisTolerance)
|
|
|
+ {
|
|
|
+ std::cout<<"dis is grater than Distance Tolerance. Tolerance is "<<fDisTolerance<<std::endl;
|
|
|
+ return -3;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(fdismin < 0.1)
|
|
|
+ {
|
|
|
+ std::cout<<"dis is less than 0.1"<<std::endl;
|
|
|
+ return -4;
|
|
|
+ }
|
|
|
+
|
|
|
contacttype = index;
|
|
|
|
|
|
if(contacttype == -1)
|
|
@@ -381,3 +406,250 @@ int AutoRoadContact::CalcContact(Road *pRoad1, Road *pRoad2,int & contacttype,in
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+std::vector<Road *> AutoRoadContact::GetRelaRoad(OpenDrive *pxodr, Road *pRoad)
|
|
|
+{
|
|
|
+ std::vector<Road *> xvectorRoadRela;
|
|
|
+ unsigned int i;
|
|
|
+ if(pRoad->GetPredecessor() != 0)
|
|
|
+ {
|
|
|
+ if(pRoad->GetPredecessor()->GetElementType() == "road")
|
|
|
+ {
|
|
|
+ std::string roadid = pRoad->GetPredecessor()->GetElementId();
|
|
|
+ Road * pRoadTem = xodrfunc::GetRoadByID(pxodr,roadid);
|
|
|
+ if(pRoadTem != 0)
|
|
|
+ {
|
|
|
+ xvectorRoadRela.push_back(pRoadTem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(pRoad->GetPredecessor()->GetElementType() == "junction")
|
|
|
+ {
|
|
|
+ std::string junctionid = pRoad->GetPredecessor()->GetElementId();
|
|
|
+ Junction * pJunction = xodrfunc::GetJunctionByID(pxodr,junctionid);
|
|
|
+ if(pJunction != 0)
|
|
|
+ {
|
|
|
+ unsigned int njucntionconcount = pJunction->GetJunctionConnectionCount();
|
|
|
+ for(i=0;i<njucntionconcount;i++)
|
|
|
+ {
|
|
|
+ JunctionConnection * pJC = pJunction->GetJunctionConnection(i);
|
|
|
+ if(pJC == NULL)continue;
|
|
|
+ if(pJC->GetIncomingRoad() == pRoad->GetRoadId())
|
|
|
+ {
|
|
|
+ std::string roadid = pJC->GetConnectingRoad();
|
|
|
+ Road * pRoadTem = xodrfunc::GetRoadByID(pxodr,roadid);
|
|
|
+ if(pRoadTem != 0)
|
|
|
+ {
|
|
|
+ xvectorRoadRela.push_back(pRoadTem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(pJC->GetConnectingRoad() == pRoad->GetRoadId())
|
|
|
+ {
|
|
|
+ std::string roadid = pJC->GetIncomingRoad();
|
|
|
+ Road * pRoadTem = xodrfunc::GetRoadByID(pxodr,roadid);
|
|
|
+ if(pRoadTem != 0)
|
|
|
+ {
|
|
|
+ xvectorRoadRela.push_back(pRoadTem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(pRoad->GetSuccessor() != 0)
|
|
|
+ {
|
|
|
+ if(pRoad->GetSuccessor()->GetElementType() == "road")
|
|
|
+ {
|
|
|
+ std::string roadid = pRoad->GetSuccessor()->GetElementId();
|
|
|
+ Road * pRoadTem = xodrfunc::GetRoadByID(pxodr,roadid);
|
|
|
+ if(pRoadTem != 0)
|
|
|
+ {
|
|
|
+ xvectorRoadRela.push_back(pRoadTem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(pRoad->GetSuccessor()->GetElementType() == "junction")
|
|
|
+ {
|
|
|
+ std::string junctionid = pRoad->GetSuccessor()->GetElementId();
|
|
|
+ Junction * pJunction = xodrfunc::GetJunctionByID(pxodr,junctionid);
|
|
|
+ if(pJunction != 0)
|
|
|
+ {
|
|
|
+ unsigned int njucntionconcount = pJunction->GetJunctionConnectionCount();
|
|
|
+ for(i=0;i<njucntionconcount;i++)
|
|
|
+ {
|
|
|
+ JunctionConnection * pJC = pJunction->GetJunctionConnection(i);
|
|
|
+ if(pJC == NULL)continue;
|
|
|
+ if(pJC->GetIncomingRoad() == pRoad->GetRoadId())
|
|
|
+ {
|
|
|
+ std::string roadid = pJC->GetConnectingRoad();
|
|
|
+ Road * pRoadTem = xodrfunc::GetRoadByID(pxodr,roadid);
|
|
|
+ if(pRoadTem != 0)
|
|
|
+ {
|
|
|
+ xvectorRoadRela.push_back(pRoadTem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(pJC->GetConnectingRoad() == pRoad->GetRoadId())
|
|
|
+ {
|
|
|
+ std::string roadid = pJC->GetIncomingRoad();
|
|
|
+ Road * pRoadTem = xodrfunc::GetRoadByID(pxodr,roadid);
|
|
|
+ if(pRoadTem != 0)
|
|
|
+ {
|
|
|
+ xvectorRoadRela.push_back(pRoadTem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return xvectorRoadRela;
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+bool AutoRoadContact::RoadToRoad(OpenDrive * pxodr,Road * pRoad1,bool bRoad1Start,Road * pRoad2,bool bRoad2Start,std::vector<Road *> & xvectorthroughroad)
|
|
|
+{
|
|
|
+ RoadLink * pLink;
|
|
|
+ if(bRoad1Start == false)
|
|
|
+ {
|
|
|
+ pLink = pRoad1->GetSuccessor();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pLink = pRoad1->GetPredecessor();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(pLink->GetElementType() == "road")
|
|
|
+ {
|
|
|
+ std::string strroadid = pLink->GetElementId();
|
|
|
+ Road * pcenterroad = xodrfunc::GetRoadByID(pxodr,strroadid);
|
|
|
+
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+bool AutoRoadContact::IsExist(OpenDrive *pxodr, iv::RoadContactUnit xRCU)
|
|
|
+{
|
|
|
+ Road * pRoad1 = xRCU.mpRoad1;
|
|
|
+ Road * pRoad2 = xRCU.mpRoad2;
|
|
|
+ std::vector<Road *> xvectorRoad1Rela;
|
|
|
+ std::vector<Road *> xvectorRoad2Rela;
|
|
|
+ xvectorRoad1Rela = AutoRoadContact::GetRelaRoad(pxodr,pRoad1);
|
|
|
+ xvectorRoad2Rela = AutoRoadContact::GetRelaRoad(pxodr,pRoad2);
|
|
|
+
|
|
|
+ if((xRCU.mcontactype ==0)||(xRCU.mcontactype == 1))
|
|
|
+ {
|
|
|
+ if(pRoad1->GetPredecessor() == NULL)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ RoadLink * pLink = pRoad1->GetPredecessor();
|
|
|
+ if(pLink->GetElementType() == "road")
|
|
|
+ {
|
|
|
+ Road * pRoadCenter = xodrfunc::GetRoadByID(pxodr,pLink->GetElementId());
|
|
|
+ if(pRoadCenter != 0)
|
|
|
+ {
|
|
|
+ if(pRoadCenter == pRoad2)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(pLink->GetContactPoint() == "end")
|
|
|
+ {
|
|
|
+ RoadLink * pLinkCenter = pRoadCenter->GetPredecessor();
|
|
|
+ if(pLinkCenter == NULL)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //Not turn
|
|
|
+ if(xRCU.mturnstraight != 0)
|
|
|
+ {
|
|
|
+ unsigned int i;
|
|
|
+ for(i=0;i<xvectorRoad2Rela.size();i++)
|
|
|
+ {
|
|
|
+ if(xvectorRoad2Rela[i] == pRoad1)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(i=0;i<xvectorRoad1Rela.size();i++)
|
|
|
+ {
|
|
|
+ if(xvectorRoad1Rela[i] == pRoad2)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+int AutoRoadContact::MakeAllContact(OpenDrive *pxodr, const double fDisTolerance)
|
|
|
+{
|
|
|
+ unsigned int nRoadCount = pxodr->GetRoadCount();
|
|
|
+ unsigned i;
|
|
|
+ std::vector<iv::RoadContactUnit> xvectorRCU;
|
|
|
+ for(i=0;i<nRoadCount;i++)
|
|
|
+ {
|
|
|
+ Road * pnowRoad = pxodr->GetRoad(i);
|
|
|
+ unsigned int j;
|
|
|
+ for(j=0;j<nRoadCount;j++)
|
|
|
+ {
|
|
|
+ if(j != i)
|
|
|
+ {
|
|
|
+ Road * potherRoad = pxodr->GetRoad(j);
|
|
|
+ int contactype;
|
|
|
+ int turnstraight;
|
|
|
+ std::vector<iv::ARC> xARCLane,xARCOpLane;
|
|
|
+ int nARCRtn = CalcContact(pnowRoad,potherRoad,contactype,turnstraight,xARCLane,xARCOpLane);
|
|
|
+ if(nARCRtn == 0)
|
|
|
+ {
|
|
|
+ std::cout<<" Road:"<<pnowRoad->GetRoadId()<<" Road:"<<potherRoad->GetRoadId()
|
|
|
+ <<" contact type: "<<turnstraight<<std::endl;
|
|
|
+
|
|
|
+ if(xARCLane.size()>0 || (xARCOpLane.size()>0))
|
|
|
+ {
|
|
|
+ iv::RoadContactUnit rcu;
|
|
|
+ rcu.mARCLane = xARCLane;
|
|
|
+ rcu.mARCOpLane = xARCOpLane;
|
|
|
+ rcu.mcontactype = contactype;
|
|
|
+ rcu.mturnstraight = turnstraight;
|
|
|
+ rcu.mpRoad1 = pnowRoad;
|
|
|
+ rcu.mpRoad2 = potherRoad;
|
|
|
+ xvectorRCU.push_back(rcu);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //Delete Repeate strait
|
|
|
+ for(i=0;i<xvectorRCU.size();i++)
|
|
|
+ {
|
|
|
+ unsigned int j;
|
|
|
+ for(j=(i+1);j<xvectorRCU.size();j++)
|
|
|
+ {
|
|
|
+ if((xvectorRCU[i].mpRoad1 == xvectorRCU[j].mpRoad2)&&(xvectorRCU[i].mpRoad2 == xvectorRCU[j].mpRoad1))
|
|
|
+ {
|
|
|
+ if((xvectorRCU[i].mturnstraight == 1)&&(xvectorRCU[j].mturnstraight == 1))
|
|
|
+ {
|
|
|
+ std::cout<<"because repeate straight.erase Road:"<<xvectorRCU[j].mpRoad1->GetRoadId()
|
|
|
+ <<" Road:"<<xvectorRCU[j].mpRoad2->GetRoadId()
|
|
|
+ <<" contact type: "<<xvectorRCU[j].mturnstraight<<std::endl;
|
|
|
+ xvectorRCU.erase(xvectorRCU.begin()+j);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|