ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
plot_border.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2017-2020 German Aerospace Center (DLR).
3  * Eclipse ADORe, Automated Driving Open Research https://eclipse.org/adore
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License 2.0 which is available at
7  * http://www.eclipse.org/legal/epl-2.0.
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  * Robert Markowski
13  ********************************************************************************/
14 #pragma once
15 
17 #include <plotlablib/plcommands.h>
19 #include "plot_shape.h"
20 #include "laneplot_config.h"
21 
22 namespace adore
23 {
24 
25 namespace PLOT
26 {
27 
28 inline void plotBorderLine(std::string name,std::string options,adore::env::BorderBased::Border* b,double z,DLR_TS::PlotLab::AFigureStub* figure)
29 {
30  if(b==nullptr||b->m_path==nullptr)return;
31  static const int Nmax = DLR_TS::PlotLab::PLCom::max_size_points;
32  const int M = b->m_path->getData().nc();
33  double Xt[Nmax];
34  double Yt[Nmax];
35  int count = 0;
36  int it = 0;
37  for(int k=0;k<M;k++)
38  {
39  Xt[count] = b->m_path->getData()(1,k);
40  Yt[count] = b->m_path->getData()(2,k);
41  count ++;
42  if(count>=Nmax-1 || (k==M-1))
43  {
44  std::stringstream ss;
45  ss<<name<<"/"<<it;
46  figure->plot(ss.str(),Xt,Yt,z,count,options);
47  Xt[0] = Xt[count-1];
48  Yt[0] = Yt[count-1];
49  count = 1;
50  it ++;
51  }
52  }
53 }
54 
58 inline void plotBorder(std::string name,adore::env::BorderBased::Border* right,adore::env::BorderBased::Border* left,double z,std::string options,DLR_TS::PlotLab::AFigureStub* figure,bool plotarrows = false)
59 {
60  if(right->isCenterLine())
61  {
62  plotBorderLine(name + "/c","LineWidth=3.0;LineColor=0.8,0.8,0.3",left,z+0.4,figure);
63  return;
64  }
65  std::vector<double> tristrip;
66  if(left!=0)
67  {
68  //another tristrip variant
69  int i=0;int j=0;
70  int imax = left->m_path->getData().nc()-1;
71  int jmax = right->m_path->getData().nc()-1;
72  double xl0,yl0,xr0,yr0,xl1,yl1,xr1,yr1;
73  while(true)
74  {
75  xl0 = left->m_path->getData()(1,i);
76  yl0 = left->m_path->getData()(2,i);
77  xr0 = right->m_path->getData()(1,j);
78  yr0 = right->m_path->getData()(2,j);
79 
80  tristrip.push_back(xl0);
81  tristrip.push_back(yl0);
82  tristrip.push_back(xr0);
83  tristrip.push_back(yr0);
84 
85  if(i==imax && j==jmax)break;
86 
87  xl1 = left->m_path->getData()(1,i<imax?i+1:i);
88  yl1 = left->m_path->getData()(2,i<imax?i+1:i);
89  xr1 = right->m_path->getData()(1,j<jmax?j+1:j);
90  yr1 = right->m_path->getData()(2,j<jmax?j+1:j);
91 
92  if(i==imax)
93  {
94  j++;
95  }
96  else
97  {
98  if(j==jmax)
99  {
100  i++;
101  }
102  else
103  {
104  double ddij = (xl1-xr1)*(xl1-xr1)+(yl1-yr1)*(yl1-yr1);//advance both
105  double ddi = (xl1-xr0)*(xl1-xr0)+(yl1-yr0)*(yl1-yr0);//advance left
106  double ddj = (xl0-xr1)*(xl0-xr1)+(yl0-yr1)*(yl0-yr1);//advance right
107  if(ddij<=ddi && ddij<=ddj)
108  {
109  i++;
110  j++;
111  }
112  else
113  {
114  if(ddi<=ddj)
115  {
116  i++;
117  }
118  else
119  {
120  j++;
121  }
122  }
123 
124  }
125  }
126  }
127  }
128 
129  static const int Nmax = DLR_TS::PlotLab::PLCom::max_size_points;
130  double Xt[Nmax];
131  double Yt[Nmax];
132  int count = 0;
133  int it = 0;
134  for(int k=0;k<tristrip.size();k+=4)
135  {
136  Xt[count] = tristrip[k];
137  Yt[count] = tristrip[k+1];
138  Xt[count+1] = tristrip[k+2];
139  Yt[count+1] = tristrip[k+3];
140  count +=2;
141  if(count>=Nmax-1 || (k==tristrip.size()-4))
142  {
143  std::stringstream ss;
144  ss<<name<<"/p/"<<it;
145  figure->tristrip(name+"/h",Xt,Yt,z+0.2,count,options);
146  Xt[0] = Xt[count-2];
147  Yt[0] = Yt[count-2];
148  Xt[1] = Xt[count-1];
149  Yt[1] = Yt[count-1];
150  count = 2;
151  it ++;
152  }
153  }
154  plotBorderLine(name + "/l","LineWidth=3.0;LineColor=0.8,0.8,0.3",left,z,figure);
155  plotBorderLine(name + "/r","LineWidth=3.0;LineColor=0.8,0.8,0.3",right,z,figure);
156 }
158 {
159  std::stringstream ss;
160  ss << "FillColor=" << std::max<double>(std::min<double>(1,normedCost),0) << "," << std::min<double>(std::max<double>(0,1-normedCost),1) << ",0.0";
161  plotBorder(right->m_id.toString(),right,left,0.5,ss.str().c_str(),figure);
162 }
164 {
165  std::string str = "";
166  switch(right->m_type)
167  {
169  {
170  str = "FillColor=0.8,0.8,0.8";
171  break;
172  }
174  {
175  str = "FillColor=1.0,0.5,0.15";
176  break;
177  }
179  {
180  str = "FillColor=1,1,1";
181  break;
182  }
183  default:
184  {
185  str = "FillColor=0.75,0,0";
186  break;
187  }
188  };
189  plotBorder(right->m_id.toString(),right,left,0.0,str,figure);
190 }
195 {
196  for(auto it=borderSet.getAllBorders();it.first!=it.second;it.first++)
197  {
198  adore::env::BorderBased::Border* border = it.first->second;
199  adore::env::BorderBased::Border* neighbor = 0;
200  if(border->m_left!=0)
201  {
202  neighbor = borderSet.getBorder(*(border->m_left));
203  }
204  plotBorder(border,neighbor,figure);
205  }
206 }
211 {
212  figure->erase(rightId.toString());
213  figure->erase(rightId.toString()+"/h");
214  figure->erase(rightId.toString()+"/p");
215 }
220 {
221  unPlotBorder(right->m_id, figure);
222 }
227 {
228  unPlotBorder(right->m_id, figure);
229 }
230 
235 {
236  static const int max_points = DLR_TS::PlotLab::PLCom::max_size_points;
237  int n = 0;
238  int m = 0;
239  std::string options = "";
240 
241  if(right!=0)
242  {
243  switch(right->m_type)
244  {
246  {
247  options = config.lane_fill_driveable_plotoptions;
248  break;
249  }
251  {
252  options = config.lane_fill_emergency_plotoptions;
253  break;
254  }
256  {
257  options = config.lane_fill_other_plotoptions;
258  break;
259  }
260  default:
261  {
262  options = config.lane_fill_default_plotoptions;
263  break;
264  }
265  }
266  }
267  else
268  {
269  options = config.lane_fill_default_plotoptions;
270  }
271 
272 
273 
274  // // MATRX VARIANTE 1
275  adoreMatrix<double,4L,0L> *r_data;
276  adoreMatrix<double,4L,0L> *l_data;
277  if (right!= 0)
278  {
279  r_data = &(right->m_path->getData());
280  n = right->m_path->getData().nc();
281  }
282  if (left!=0)
283  {
284  l_data = &(left->m_path->getData());
285  m = left->m_path->getData().nc();
286  }
287  // TODO investigate and fix : the following block seems to be no longer in use
288  // if(n!=0 && m!=0)
289  // {
290  // double XX[max_points];
291  // double YY[max_points];
292  // double * x_left = &((*l_data)(1,0));
293  // double * y_left = &((*l_data)(2,0));
294  // double * x_right = &((*r_data)(1,0));
295  // double * y_right = &((*r_data)(2,0));
296  // for (int i = 0; i < n; i++)
297  // {
298  // XX[i] = x_right[i];
299  // YY[i] = y_right[i];
300  // }
301  // if(right->getNeighborDirection()==adore::env::BorderBased::Border::SAME_DIRECTION)
302  // {
303  // for(int i=0;i<m;i++)
304  // {
305  // XX[n+m-i-1] = x_left[i];
306  // YY[n+m-i-1] = y_left[i];
307  // }
308  // }
309  // else
310  // {
311  // for(int i=0;i<m;i++)
312  // {
313  // XX[n+i] = x_left[i];
314  // YY[n+i] = y_left[i];
315  // }
316  // }
317  // // figure->patch(name+"/h",XX,YY,z,n+m,options);
318  // }
319 
320  if(right!=0 && left!=0)
321  {
322  //the tristrip variant
323  double Xt[max_points];
324  double Yt[max_points];
325  double rightsmin = right->m_path->limitLo();
326  double rightsmax = right->m_path->limitHi();
327  double leftsmin = left->m_path->limitLo();
328  double leftsmax = left->m_path->limitHi();
329  int k = max_points/2;
330  for(int i=0;i<k;i++)
331  {
332  double sright = rightsmin + (rightsmax-rightsmin)/(double)(k-1)*(double)i;
333  double sleft;
334  if(right->getNeighborDirection()==adore::env::BorderBased::Border::SAME_DIRECTION)
335  {
336  sleft = leftsmin + (leftsmax-leftsmin)/(double)(k-1)*(double)i;
337  }
338  else
339  {
340  sleft = leftsmax - (leftsmax-leftsmin)/(double)(k-1)*(double)i;
341  }
342  auto rightpos = right->m_path->f(sright);
343  auto leftpos = left->m_path->f(sleft);
344  Xt[i*2+0] = rightpos(0);
345  Xt[i*2+1] = leftpos(0);
346  Yt[i*2+0] = rightpos(1);
347  Yt[i*2+1] = leftpos(1);
348  }
349  figure->tristrip(name+"/h",Xt,Yt,z,k*2,options);
350  }
351 
352 
353  if ( outlineRight )
354  {
355  figure->plot(name+"/r",&((*r_data)(1,0)),&((*r_data)(2,0)),z+0.1,n,config.border_outer_right_plotoptions);
356  }
357  if ( outlineLeft )
358  {
359  figure->plot(name+"/l",&((*l_data)(1,0)),&((*l_data)(2,0)),z+0.1,m,config.border_outer_left_plotoptions);
360  }
361 }
362 
363 
364 } // end PLOT namespace
365 
366 } // end adore namespace
Definition: afigurestub.h:24
virtual void tristrip(std::string hashtag, double *X, double *Y, double *Z, int size, std::string options)=0
virtual void plot(std::string hashtag, double *X, double *Y, double *Z, int size, std::string options)=0
virtual void erase(std::string hashtag)=0
Definition: laneplot_config.h:24
std::string lane_fill_driveable_plotoptions
Definition: laneplot_config.h:28
std::string border_outer_left_plotoptions
Definition: laneplot_config.h:26
std::string lane_fill_emergency_plotoptions
Definition: laneplot_config.h:29
std::string lane_fill_default_plotoptions
Definition: laneplot_config.h:31
std::string border_outer_right_plotoptions
Definition: laneplot_config.h:27
std::string lane_fill_other_plotoptions
Definition: laneplot_config.h:30
efficiently store borders in boost R-tree
Definition: borderset.h:99
BorderIteratorPair2 getAllBorders()
get all borders in this
Definition: borderset.h:356
Border * getBorder(const BorderID &id) const
retrieve a border by ID
Definition: borderset.h:628
adoreMatrix< T, n+1, 0 > & getData()
Definition: llinearpiecewisefunction.h:147
static const int max_size_points
Definition: plcommands.h:24
void plotBorder_fancy(std::string name, adore::env::BorderBased::Border *right, adore::env::BorderBased::Border *left, double z, bool outlineLeft, bool outlineRight, adore::PLOT::LanePlotConfig config, DLR_TS::PlotLab::AFigureStub *figure)
plots a border object, including left neighbor if !=0 into figure object
Definition: plot_border.h:234
void plotBorderSet(adore::env::BorderBased::BorderSet &borderSet, DLR_TS::PlotLab::AFigureStub *figure)
Definition: plot_border.h:194
void plotBorderNavigation(adore::env::BorderBased::Border *right, adore::env::BorderBased::Border *left, double normedCost, DLR_TS::PlotLab::AFigureStub *figure)
Definition: plot_border.h:157
void plotBorderLine(std::string name, std::string options, adore::env::BorderBased::Border *b, double z, DLR_TS::PlotLab::AFigureStub *figure)
Definition: plot_border.h:28
void plotBorder(std::string name, adore::env::BorderBased::Border *right, adore::env::BorderBased::Border *left, double z, std::string options, DLR_TS::PlotLab::AFigureStub *figure, bool plotarrows=false)
Definition: plot_border.h:58
void unPlotBorder(adore::env::BorderBased::BorderID rightId, DLR_TS::PlotLab::AFigureStub *figure)
Definition: plot_border.h:210
@ OTHER
Definition: border.h:38
@ EMERGENCY
Definition: border.h:41
@ DRIVING
Definition: border.h:39
@ right
Definition: indicator_hint.h:36
@ left
Definition: indicator_hint.h:35
z
Definition: adore_set_goal.py:32
Definition: areaofeffectconverter.h:20
This struct identifies a Border by the coordinates of the starting and the end point.
Definition: borderid.h:31
std::string toString() const
Write information of the BorderID to a string.
Definition: borderid.h:131
The border struct contains data of the smallest.
Definition: border.h:62
@ SAME_DIRECTION
Definition: border.h:507
Tborderpath * m_path
Definition: border.h:70
BorderID * m_left
Definition: border.h:69