showxodrinvtk.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #include "showxodrinvtk.h"
  2. #include <OpenDrive/OpenDrive.h>
  3. #include <OpenDrive/OpenDriveXmlParser.h>
  4. #include "xodrfunc.h"
  5. static int gnLineIndex = 0;
  6. void DrawLine(std::vector<iv::LanePoint> & xveclastlp,std::vector<iv::LanePoint> & xveclp,pcl::visualization::PCLVisualizer& viewer, double fz)
  7. {
  8. unsigned int i,j;
  9. for(i=0;i<xveclp.size();i++)
  10. {
  11. iv::LanePoint xNow = xveclp[i];
  12. for(j=0;j<xveclastlp.size();j++)
  13. {
  14. if(xveclastlp[j].mnlane == xNow.mnlane)
  15. {
  16. iv::LanePoint xLast = xveclastlp[j];
  17. pcl::PointXYZ mass_center(xLast.mfX,xLast.mfY,fz);
  18. pcl::PointXYZ kinectZ(xNow.mfX,xNow.mfY,fz);
  19. char strgeoname[256];
  20. snprintf(strgeoname,256,"xodr%d",gnLineIndex);
  21. gnLineIndex++;
  22. if(xNow.mnlane != 0)
  23. viewer.addLine(mass_center,kinectZ,1.0f,1.0f,1.0f,strgeoname);
  24. else
  25. viewer.addLine(mass_center,kinectZ,1.0f,1.0f,0.0f,strgeoname);
  26. break;
  27. }
  28. }
  29. }
  30. }
  31. void ShowRoad(pcl::visualization::PCLVisualizer& viewer,Road * pRoad,double fz)
  32. {
  33. if(pRoad->GetLaneSectionCount()<1)
  34. {
  35. qDebug("no lane,return;");
  36. return;
  37. }
  38. double fRoadLen = pRoad->GetRoadLength();
  39. double s = 0;
  40. double fSpace = 0.1;
  41. double x,y,fhdg;
  42. double flasthdg = 0;
  43. double flastS = 0;
  44. pRoad->GetGeometryCoords(s,x,y,fhdg);
  45. std::vector<iv::LanePoint> xveclp = xodrfunc::GetAllLanePoint(pRoad,s,x,y,fhdg);
  46. std::vector<iv::LanePoint> xveclastlp = xveclp;
  47. flasthdg = fhdg;
  48. flastS = s;
  49. s = s+ fSpace;
  50. while(s<fRoadLen)
  51. {
  52. pRoad->GetGeometryCoords(s,x,y,fhdg);
  53. xveclp = xodrfunc::GetAllLanePoint(pRoad,s,x,y,fhdg);
  54. double fhdgdiff = fhdg - flasthdg;
  55. double fSDiff = s - flastS;
  56. if((fabs(fhdgdiff) > 0.01) || (fSDiff>= 10.0))
  57. {
  58. //Draw Line
  59. DrawLine(xveclastlp,xveclp,viewer,fz);
  60. xveclastlp = xveclp;
  61. flasthdg = fhdg;
  62. flastS = s;
  63. }
  64. s= s + fSpace;
  65. }
  66. if(flastS<fRoadLen)
  67. {
  68. pRoad->GetGeometryCoords(fRoadLen,x,y,fhdg);
  69. xveclp = xodrfunc::GetAllLanePoint(pRoad,s,x,y,fhdg);
  70. DrawLine(xveclastlp,xveclp,viewer,fz);
  71. }
  72. }
  73. void ShowXODRINVTK(pcl::visualization::PCLVisualizer& viewer,double & flon,double & flat,bool & bxodr,double fz)
  74. {
  75. char strpath[256];
  76. snprintf(strpath,256,"%s/map/map.xodr",getenv("HOME"));
  77. OpenDrive xxodr;
  78. OpenDriveXmlParser xp(&xxodr);
  79. bxodr = xp.ReadFile(strpath);
  80. if(bxodr)
  81. {
  82. xxodr.GetHeader()->GetLat0Lon0(flat,flon);
  83. }
  84. unsigned int i;
  85. for(i=0;i<xxodr.GetRoadCount();i++)
  86. {
  87. ShowRoad(viewer,xxodr.GetRoad(i),fz);
  88. }
  89. // pcl::PointXYZ mass_center(0,0,0);
  90. // pcl::PointXYZ kinectZ(0,0,-100);
  91. // viewer.addLine(mass_center,kinectZ,1.0f,1.0f,1.0f,"xodr1");
  92. // pcl::PointXYZ kinectZ2(0,0,100);
  93. // viewer.addLine(mass_center,kinectZ2,1.0f,1.0f,1.0f,"xodr2");
  94. }