INET Framework for OMNeT++/OMNEST
inet::visualizer::OpenStreetMapSceneCanvasVisualizer Class Reference

#include <OpenStreetMapSceneCanvasVisualizer.h>

Inheritance diagram for inet::visualizer::OpenStreetMapSceneCanvasVisualizer:
inet::visualizer::SceneVisualizerBase inet::visualizer::VisualizerBase

Protected Member Functions

virtual void initialize (int stage) override
 
cFigure::Point toCanvas (const osm::OpenStreetMap &map, double lat, double lon)
 
cGroupFigure * createMapFigure (const osm::OpenStreetMap &map)
 
- Protected Member Functions inherited from inet::visualizer::SceneVisualizerBase
virtual Box getSceneBounds ()
 
- Protected Member Functions inherited from inet::visualizer::VisualizerBase
virtual int numInitStages () const override
 
virtual Coord getPosition (const cModule *networkNode) const
 
virtual Coord getContactPosition (const cModule *networkNode, const Coord &fromPosition, const char *contactMode, double contactSpacing) const
 
virtual Quaternion getOrientation (const cModule *networkNode) const
 
virtual void mapChunks (const Ptr< const Chunk > &chunk, const std::function< void(const Ptr< const Chunk > &, int)> &thunk) const
 

Protected Attributes

ModuleRefByPar< IGeographicCoordinateSystemcoordinateSystem
 
CanvasProjectioncanvasProjection = nullptr
 
- Protected Attributes inherited from inet::visualizer::SceneVisualizerBase
Coord sceneMin
 
Coord sceneMax
 
- Protected Attributes inherited from inet::visualizer::VisualizerBase
cModule * visualizationTargetModule = nullptr
 
cModule * visualizationSubjectModule = nullptr
 
const char * tags = nullptr
 

Member Function Documentation

◆ createMapFigure()

cGroupFigure * inet::visualizer::OpenStreetMapSceneCanvasVisualizer::createMapFigure ( const osm::OpenStreetMap map)
protected
53 {
54  const cFigure::Color COLOR_HIGHWAY_PRIMARY = { 255, 255, 120 };
55  const cFigure::Color COLOR_HIGHWAY_RESIDENTIAL = { 240, 240, 240 };
56  const cFigure::Color COLOR_HIGHWAY_PATH = { 128, 128, 128 };
57 
58  auto buildings = new cGroupFigure("buildings");
59  buildings->setTags("buildings");
60  auto primaryStreets = new cGroupFigure("primaryStreets");
61  primaryStreets->setTags("primary_streets");
62  auto residentialStreets = new cGroupFigure("residentialStreets");
63  residentialStreets->setTags("residential_streets");
64  auto pathways = new cGroupFigure("pathways");
65  pathways->setTags("pathways");
66 
67  auto mapFigure = new cGroupFigure("openStreetMap");
68  mapFigure->setTags("street_map");
69  mapFigure->addFigure(buildings);
70  mapFigure->addFigure(pathways);
71  mapFigure->addFigure(residentialStreets);
72  mapFigure->addFigure(primaryStreets);
73 
74  for (const auto& way : map.getWays()) {
75  std::vector<cFigure::Point> points;
76  for (const auto& node : way->getNodes())
77  points.push_back(toCanvas(map, node->getLat(), node->getLon()));
78  bool isArea = way->getNodes().front() == way->getNodes().back();
79 
80  if (!isArea) {
81  // road, street, footway, etc.
82  cPolylineFigure *polyline = new cPolylineFigure();
83  polyline->setPoints(points);
84  polyline->setZoomLineWidth(true);
85 
86  polyline->setName(std::to_string(way->getId()).c_str());
87  const char *name = way->getTag("name");
88  if (name != nullptr)
89  polyline->setTooltip(name);
90 
91  std::string highwayType = opp_nulltoempty(way->getTag("highway"));
92  if (highwayType == "primary" || highwayType == "secondary" || highwayType == "tertiary" ||
93  highwayType == "primary_link" || highwayType == "secondary_link" || highwayType == "tertiary_link")
94  {
95  polyline->setLineWidth(8);
96  polyline->setLineColor(COLOR_HIGHWAY_PRIMARY);
97  polyline->setCapStyle(cFigure::CAP_ROUND);
98  polyline->setJoinStyle(cFigure::JOIN_ROUND);
99  primaryStreets->addFigure(polyline);
100  }
101  else if (highwayType == "residential" || highwayType == "service") {
102  polyline->setLineWidth(4);
103  polyline->setLineColor(COLOR_HIGHWAY_RESIDENTIAL);
104  polyline->setCapStyle(cFigure::CAP_ROUND);
105  polyline->setJoinStyle(cFigure::JOIN_ROUND);
106  residentialStreets->addFigure(polyline);
107  }
108  else if (highwayType != "") { // footpath or similar
109  polyline->setLineStyle(cFigure::LINE_DOTTED);
110  polyline->setLineColor(COLOR_HIGHWAY_PATH);
111  pathways->addFigure(polyline);
112  }
113  else { // administrative boundary or some other non-path thing
114  delete polyline;
115  polyline = nullptr;
116  }
117  }
118  else {
119  // building, park, etc.
120  cPolygonFigure *polygon = new cPolygonFigure();
121  points.pop_back();
122  polygon->setPoints(points);
123 
124  polygon->setName(std::to_string(way->getId()).c_str());
125  const char *name = way->getTag("name");
126  if (name != nullptr)
127  polygon->setTooltip(name);
128 
129  polygon->setFilled(true);
130  polygon->setFillOpacity(0.1);
131  polygon->setLineOpacity(0.5);
132  polygon->setLineColor(cFigure::GREY);
133  if (!opp_isempty(way->getTag("building")))
134  polygon->setFillColor(cFigure::RED);
135  else
136  polygon->setFillColor(cFigure::GREEN);
137  buildings->addFigure(polygon);
138  }
139  }
140  return mapFigure;
141 }

◆ initialize()

void inet::visualizer::OpenStreetMapSceneCanvasVisualizer::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::visualizer::SceneVisualizerBase.

21 {
23  if (!hasGUI()) return;
24  if (stage == INITSTAGE_PHYSICAL_ENVIRONMENT) {
25  auto canvas = visualizationTargetModule->getCanvas();
26  coordinateSystem.reference(this, "coordinateSystemModule", true);
28 
29  cXMLElement *mapXml = par("mapFile").xmlValue();
30  OpenStreetMap map = OpenStreetMap::from(mapXml);
31  EV << "Loaded " << map.getNodes().size() << " nodes, " << map.getWays().size() << " ways\n";
32  auto mapGroupFigure = createMapFigure(map);
33  mapGroupFigure->setZIndex(par("zIndex"));
34  visualizationTargetModule->getCanvas()->addFigure(mapGroupFigure);
35 
36  cDisplayString& displayString = visualizationTargetModule->getDisplayString();
37  if (par("adjustBackgroundBox").boolValue()) {
38  const osm::Bounds& bounds = map.getBounds();
39  cFigure::Point bottomRight = toCanvas(map, bounds.minlat, bounds.maxlon);
40  displayString.setTagArg("bgb", 0, bottomRight.x);
41  displayString.setTagArg("bgb", 1, bottomRight.y);
42  }
43  }
44 }

◆ toCanvas()

cFigure::Point inet::visualizer::OpenStreetMapSceneCanvasVisualizer::toCanvas ( const osm::OpenStreetMap map,
double  lat,
double  lon 
)
protected
47 {
48  Coord coord = coordinateSystem->computeSceneCoordinate(GeoCoord(deg(lat), deg(lon), m(0)));
49  return canvasProjection->computeCanvasPoint(coord);
50 }

Member Data Documentation

◆ canvasProjection

CanvasProjection* inet::visualizer::OpenStreetMapSceneCanvasVisualizer::canvasProjection = nullptr
protected

◆ coordinateSystem

ModuleRefByPar<IGeographicCoordinateSystem> inet::visualizer::OpenStreetMapSceneCanvasVisualizer::coordinateSystem
protected

The documentation for this class was generated from the following files:
inet::visualizer::OpenStreetMapSceneCanvasVisualizer::createMapFigure
cGroupFigure * createMapFigure(const osm::OpenStreetMap &map)
Definition: OpenStreetMapSceneCanvasVisualizer.cc:52
inet::INITSTAGE_PHYSICAL_ENVIRONMENT
INET_API InitStage INITSTAGE_PHYSICAL_ENVIRONMENT
Initialization of the physical environment.
inet::osm::OpenStreetMap::getBounds
const Bounds & getBounds() const
Definition: OpenStreetMap.h:126
inet::visualizer::OpenStreetMapSceneCanvasVisualizer::toCanvas
cFigure::Point toCanvas(const osm::OpenStreetMap &map, double lat, double lon)
Definition: OpenStreetMapSceneCanvasVisualizer.cc:46
inet::units::units::deg
fscale< rad, rad2degScale > deg
Definition: Units.h:1158
inet::CanvasProjection::getCanvasProjection
static CanvasProjection * getCanvasProjection(const cCanvas *canvas)
Definition: CanvasProjection.cc:53
inet::visualizer::VisualizerBase::visualizationTargetModule
cModule * visualizationTargetModule
Definition: VisualizerBase.h:25
inet::osm::OpenStreetMap::getNodes
const std::vector< const Node * > & getNodes() const
Definition: OpenStreetMap.h:127
inet::DiffservUtil::RED
@ RED
Definition: DiffservUtil.h:17
inet::osm::OpenStreetMap
Represents OpenStreetMap map data, as loaded from an OSM file.
Definition: OpenStreetMap.h:107
inet::CanvasProjection::computeCanvasPoint
cFigure::Point computeCanvasPoint(const Coord &point) const
Definition: CanvasProjection.cc:34
inet::visualizer::OpenStreetMapSceneCanvasVisualizer::canvasProjection
CanvasProjection * canvasProjection
Definition: OpenStreetMapSceneCanvasVisualizer.h:25
inet::visualizer::OpenStreetMapSceneCanvasVisualizer::coordinateSystem
ModuleRefByPar< IGeographicCoordinateSystem > coordinateSystem
Definition: OpenStreetMapSceneCanvasVisualizer.h:24
inet::DiffservUtil::GREEN
@ GREEN
Definition: DiffservUtil.h:17
inet::DiffservUtil::Color
Color
Definition: DiffservUtil.h:17
inet::units::values::m
value< double, units::m > m
Definition: Units.h:1233
inet::visualizer::SceneVisualizerBase::initialize
virtual void initialize(int stage) override
Definition: SceneVisualizerBase.cc:20
inet::osm::OpenStreetMap::getWays
const std::vector< const Way * > & getWays() const
Definition: OpenStreetMap.h:128