ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
plot_satimages.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  * Thomas Lobig
14  ********************************************************************************/
15 
16 #pragma once
19 #include <adore/env/afactory.h>
20 #include <plotlablib/afigurestub.h>
21 #include <plotlablib/plcommands.h>
22 
23 namespace adore
24 {
25  namespace apps
26  {
32  {
33  private:
35 
39  std::string prefix_;
40 
42  std::set<std::pair<int,int>> visibleTiles_;
43  double fov_width_;
44  double fov_height_;
46 
47  double X0_;
48  double Y0_;
49  double X1_;
50  double Y1_;
51  double res_;
53 
54  struct info
55  {
56  std::string name_;
57  bool visible_;
58  info(bool visible,std::string name):name_(name),visible_(visible){}
59  };
60 
61  public:
62  PlotSatImages(DLR_TS::PlotLab::AFigureStub* figure, std::string prefix, const adore::PLOT::GeoTilesConfig geoTiles_config)
63  {
65  figure_ = figure;
66  prefix_ = prefix;
67  fov_width_ = 640.0;
68  fov_height_ = 480.0;
69  urlPreset_ = 0;
70  geoTiles_ = new adore::PLOT::GeoTiles(geoTiles_config.base_url,geoTiles_config.tile_width_meters);
71  mapImageParamsSet_ = false;
72  map_figure_ = nullptr;
73  }
74 
76  {
77  geoTiles_->~GeoTiles();
78  }
79  void setMapImageParams(double X0,double Y0,double X1,double Y1,double res,DLR_TS::PlotLab::AFigureStub* value)
80  {
81  map_figure_ = value;
82  X0_=X0;Y0_=Y0;X1_=X1;Y1_=Y1;
83  res_=res;
84  mapImageParamsSet_=true;
85  }
86 
87  void run()
88  {
90  {
92  plotPosition(prefix_+"/measuredPos",position_.getX(),position_.getY());
94  {
95  std::string url = geoTiles_->getURL(X0_,Y0_,X1_,Y1_,res_);
96  std::cout<<url<<std::endl;
97  map_figure_->plotTexture("satmap",url,(X0_+X1_)*0.5,(Y0_+Y1_)*0.5,-1,0.0,std::abs(Y1_-Y0_),std::abs(X1_-X0_));
98  map_figure_->setFixAxis(X0_,Y0_,-10.0,X1_,Y1_,10.0);
99  }
100  }
101  }
102 
103 
117  // void plotPosition(const std::string& name,double gX,double gY,double psi,double L,double c,double d,double w,const std::string& options,bool follow_vehicle=true)
118  void plotPosition(const std::string& name,double gX,double gY)
119  {
120  double xmin = gX-fov_width_*0.5;
121  double xmax = gX+fov_width_*0.5;
122  double ymin = gY-fov_height_*0.5;
123  double ymax = gY+fov_height_*0.5;
124 
125  //remove tiles which are no longer visible
126  std::vector<std::pair<int,int>> remove;
127  for(auto it = visibleTiles_.begin();it!=visibleTiles_.end();it++)
128  {
129  if(!geoTiles_->overlapsBox(*it,xmin-10.0,ymin-10.0,xmax+10.0,ymax+10.0))
130  {
131  remove.push_back(*it);
133  }
134  }
135  for(auto it = remove.begin();it!=remove.end();it++)
136  {
137  visibleTiles_.erase(*it);
138  // eraseCount_ ++;
139  }
140 
141  //find newly visible tiles
142  int i0,j0,i1,j1;
143  geoTiles_->getVisibleRange(xmin,ymin,xmax,ymax,i0,j0,i1,j1);
144  for(int i=i0;i<=i1;i++)
145  {
146  for(int j=j0;j<=j1;j++)
147  {
148  auto id = std::make_pair(i,j);
149  if(geoTiles_->overlapsBox(id,xmin,ymin,xmax,ymax))
150  {
151  if( visibleTiles_.find(id)==visibleTiles_.end() )
152  {
153  visibleTiles_.insert(id);
154  std::string url = geoTiles_->getURL(id);
155  std::cout<<url<<std::endl;
156  std::string hashtag = geoTiles_->getPlotID(id);
158  // plotCount_++;
159  }
160  }
161  }
162  }
163  }
164  };
165  }
166 }
Definition: afigurestub.h:24
virtual void setFixAxis(double x0, double y0, double z0, double x1, double y1, double z1)=0
virtual void plotTexture(std::string hashtag, std::string url, double x, double y, double z, double psi, double w, double l)=0
virtual void erase(std::string hashtag)=0
Class to help with handling of tile servers used for satellite image background tiles.
Definition: geoTiles.h:33
double getCenterY(std::pair< int, int > id)
Definition: geoTiles.h:99
double getWidthM()
Definition: geoTiles.h:48
double getCenterX(std::pair< int, int > id)
Definition: geoTiles.h:95
std::string getURL(double xUTM, double yUTM)
Definition: geoTiles.h:52
void getVisibleRange(double xUTM0, double yUTM0, double xUTM1, double yUTM1, int &imin, int &jmin, int &imax, int &jmax)
Definition: geoTiles.h:115
std::string getPlotID(std::pair< int, int > id)
Definition: geoTiles.h:122
bool overlapsBox(std::pair< int, int > id, double xUTM0, double yUTM0, double xUTM1, double yUTM1)
Definition: geoTiles.h:107
a optimzed plotting application to display satellite images in the background
Definition: plot_satimages.h:32
bool mapImageParamsSet_
Definition: plot_satimages.h:52
adore::PLOT::GeoTiles * geoTiles_
Definition: plot_satimages.h:41
std::set< std::pair< int, int > > visibleTiles_
Definition: plot_satimages.h:42
double X0_
Definition: plot_satimages.h:47
double res_
Definition: plot_satimages.h:51
std::string prefix_
Definition: plot_satimages.h:39
double fov_width_
Definition: plot_satimages.h:43
adore::mad::AReader< adore::env::VehicleMotionState9d > * positionReader_
Definition: plot_satimages.h:34
DLR_TS::PlotLab::AFigureStub * map_figure_
Definition: plot_satimages.h:37
int urlPreset_
Definition: plot_satimages.h:45
double Y1_
Definition: plot_satimages.h:50
double X1_
Definition: plot_satimages.h:49
double fov_height_
Definition: plot_satimages.h:44
void plotPosition(const std::string &name, double gX, double gY)
plotting a vehicle
Definition: plot_satimages.h:118
adore::env::VehicleMotionState9d position_
Definition: plot_satimages.h:38
~PlotSatImages()
Definition: plot_satimages.h:75
double Y0_
Definition: plot_satimages.h:48
void run()
Definition: plot_satimages.h:87
PlotSatImages(DLR_TS::PlotLab::AFigureStub *figure, std::string prefix, const adore::PLOT::GeoTilesConfig geoTiles_config)
Definition: plot_satimages.h:62
DLR_TS::PlotLab::AFigureStub * figure_
Definition: plot_satimages.h:36
void setMapImageParams(double X0, double Y0, double X1, double Y1, double res, DLR_TS::PlotLab::AFigureStub *value)
Definition: plot_satimages.h:79
virtual TVehicleMotionStateReader * getVehicleMotionStateReader()=0
static adore::env::AFactory * get()
Definition: afactory.h:236
virtual void getData(T &value)=0
virtual bool hasUpdate() const =0
Definition: areaofeffectconverter.h:20
Definition: geoTiles_config.h:24
std::string base_url
Definition: geoTiles_config.h:25
double tile_width_meters
Definition: geoTiles_config.h:26
Definition: plot_satimages.h:55
bool visible_
Definition: plot_satimages.h:57
info(bool visible, std::string name)
Definition: plot_satimages.h:58
std::string name_
Definition: plot_satimages.h:56
This struct holds the motion state of the vehicle in 9d.
Definition: vehiclemotionstate9d.h:39
double getX() const
Get the x-coordinate.
Definition: vehiclemotionstate9d.h:54
double getY() const
Get the y-coordinate.
Definition: vehiclemotionstate9d.h:60