ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
plot_gaps.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  * Daniel Heß - initial implementation
13  ********************************************************************************/
14 
15 #pragma once
17 #include <adore/env/afactory.h>
18 #include <unordered_set>
19 #include <vector>
20 
21 
22 namespace adore
23 {
24  namespace apps
25  {
27  {
28  private:
29  std::unordered_set<std::string> current_tags_;
30  std::vector<std::string> last_tags_;
32  std::string prefix_;
35  public:
37  std::string prefix,
40  : figure_(figure),prefix_(prefix),gapReader_(gapReader),egoStateReader_(egoStateReader)
41  {}
42  void update()
43  {
47  if(gapReader_->hasUpdate())
48  {
49  int i=0;
50  gapReader_->getData(q);
51  double rating_min = 1e10;
52  double rating_max =-1e10;
53  for( auto& g:q )
54  {
55  rating_min = (std::min)(rating_min,g.rating);
56  rating_max = (std::max)(rating_max,g.rating);
57  }
58  for( auto& g:q )
59  {
60  std::stringstream ss;
61  ss<<prefix_<<"/"<<i++;
62  plot(g,x,ss.str(),rating_min,rating_max);
63  }
64  for( auto& s: last_tags_)if(current_tags_.find(s)==current_tags_.end())figure_->erase(s);
65  last_tags_.clear();
66  for( auto& s: current_tags_) last_tags_.push_back(s);
67  current_tags_.clear();
68  }
69 
70  }
71  void plot(adore::env::GapData& g,adore::env::VehicleMotionState9d x,std::string tag,double rating_min,double rating_max)
72  {
73  current_tags_.emplace(tag);
74  static const int N=6;//number of plot points with arrow
75  static const double a = 1.0;//length of arrow shaft
76  static const double b = 0.5;//length of arrow head
77  static const double rmin = 0.0;//color mix
78  static const double rmax = 1.0;
79  static const double gmin = 0.7;
80  static const double gmax = 0.0;
81  static const double bmin = 0.0;
82  static const double bmax = 0.0;
83  double X[N];
84  double Y[N];
85  X[0] = x.getX();
86  Y[0] = x.getY();
87  X[1] = g.anchor_X;
88  Y[1] = g.anchor_Y;
89  const double L = std::sqrt(g.anchor_dX *g.anchor_dX + g.anchor_dY*g.anchor_dY);
90  std::stringstream options;
91  if(rating_max<=rating_min)
92  {
93  options<<"LineColor=0,0.7,0;LineWidth=1";
94  }
95  else
96  {
97  const double p = (g.rating-rating_min)/(rating_max-rating_min);
98  options<<"LineColor=";
99  options<<( p * (rmax-rmin) + rmin)<<",";
100  options<<( p * (gmax-gmin) + gmin)<<",";
101  options<<( p * (bmax-bmin) + bmin)<<";";
102  options<<"LineWidth=1";
103  }
104  if(L>0.1)
105  {
106  const double hx = std::cos(M_PI*0.75) * g.anchor_dX/L * b - std::sin(M_PI*0.75) * g.anchor_dY/L * b;
107  const double hy = std::sin(M_PI*0.75) * g.anchor_dX/L * b + std::cos(M_PI*0.75) * g.anchor_dY/L * b;
108  X[2] = g.anchor_X + g.anchor_dX/L * a;
109  Y[2] = g.anchor_Y + g.anchor_dY/L * a;
110  X[3] = X[2] + hx;
111  Y[3] = Y[2] + hy;
112  X[4] = X[2];
113  Y[4] = Y[2];
114  X[5] = X[2] - hy;
115  Y[5] = Y[2] + hx;
116  figure_->plot(tag,X,Y,x.getZ()+2.0,N,options.str());
117  }
118  else
119  {
120  figure_->plot(tag,X,Y,x.getZ()+2.0,2,options.str());
121  }
122  }
123  };
128  class PlotGaps
129  {
130  private:
133  std::string prefix_;
136 
137  public:
138 
139  PlotGaps(std::string prefix):prefix_(prefix)
140  {
142  figure_ = fig_factory.createFigureStub(2);
145  adore::env::EnvFactoryInstance::get()->getGapQueueReaderLeftLane(),
146  egoStateReader);
148  adore::env::EnvFactoryInstance::get()->getGapQueueReaderRightLane(),
149  egoStateReader);
150  }
152  {
153  delete leftPlotter_;
154  delete rightPlotter_;
155  delete figure_;
156  }
157  void update()
158  {
159  leftPlotter_->update();
161  }
162  };
163  }
164 }
#define M_PI
Definition: arraymatrixtools.h:24
Definition: afigurestub.h:24
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: figurestubfactory.h:25
AFigureStub * createFigureStub(int windowID)
Definition: figurestubfactory.h:45
Definition: plot_gaps.h:27
adore::env::AFactory::TGapQueueReader * gapReader_
Definition: plot_gaps.h:33
std::string prefix_
Definition: plot_gaps.h:32
std::unordered_set< std::string > current_tags_
Definition: plot_gaps.h:29
void plot(adore::env::GapData &g, adore::env::VehicleMotionState9d x, std::string tag, double rating_min, double rating_max)
Definition: plot_gaps.h:71
void update()
Definition: plot_gaps.h:42
std::vector< std::string > last_tags_
Definition: plot_gaps.h:30
GapQueuePlotter(DLR_TS::PlotLab::AFigureStub *figure, std::string prefix, adore::env::AFactory::TGapQueueReader *gapReader, adore::env::AFactory::TVehicleMotionStateReader *egoStateReader)
Definition: plot_gaps.h:36
adore::env::AFactory::TVehicleMotionStateReader * egoStateReader_
Definition: plot_gaps.h:34
DLR_TS::PlotLab::AFigureStub * figure_
Definition: plot_gaps.h:31
plots markers for traffic gaps
Definition: plot_gaps.h:129
std::string prefix_
Definition: plot_gaps.h:133
adore::env::AFactory::TGapQueueReader * rightGapsReader_
Definition: plot_gaps.h:131
void update()
Definition: plot_gaps.h:157
GapQueuePlotter * leftPlotter_
Definition: plot_gaps.h:134
GapQueuePlotter * rightPlotter_
Definition: plot_gaps.h:135
DLR_TS::PlotLab::AFigureStub * figure_
Definition: plot_gaps.h:132
PlotGaps(std::string prefix)
Definition: plot_gaps.h:139
~PlotGaps()
Definition: plot_gaps.h:151
virtual TVehicleMotionStateReader * getVehicleMotionStateReader()=0
static adore::env::AFactory * get()
Definition: afactory.h:236
Definition: com_patterns.h:68
virtual void getData(T &value)=0
virtual bool hasUpdate() const =0
std::vector< GapData > GapQueue
Definition: gapdata.h:53
interval< T > cos(interval< T > x)
Definition: intervalarithmetic.h:225
T min(T a, T b, T c, T d)
Definition: adoremath.h:663
interval< T > sin(interval< T > x)
Definition: intervalarithmetic.h:204
adoreMatrix< T, N, M > max(adoreMatrix< T, N, M > a, const adoreMatrix< T, N, M > &b)
Definition: adoremath.h:686
x
Definition: adore_set_goal.py:30
g
Definition: adore_set_goal.py:29
Definition: areaofeffectconverter.h:20
Definition: gapdata.h:27
This struct holds the motion state of the vehicle in 9d.
Definition: vehiclemotionstate9d.h:39