lanelet2_map_server v1.2.3
Loading...
Searching...
No Matches
lanelet2_map_helpers.hpp
Go to the documentation of this file.
1// Copyright (c) 2017, FZI Forschungszentrum Informatik, Karlsruhe, Germany (www.fzi.de)
2// and KIT, Institute of Measurement and Control, Karlsruhe, Germany (www.mrt.kit.edu)
3// Copyright Institute for Automotive Engineering (ika), RWTH Aachen University
4// SPDX-License-Identifier: BSD-3-Clause
5
6/*
7 * Derived in part from:
8 * https://github.com/coincar-sim/lanelet_rviz_plugin_ros/tree/9a36cb891ef0d175e0a893526980ea515712e1b9
9 * - src/map_element.cpp
10 * - src/map_element_ogre_helper.hpp
11 */
12
13#ifndef LANELET2_RVIZ_DISPLAY__LANELET2_MAP_HELPERS_HPP_
14#define LANELET2_RVIZ_DISPLAY__LANELET2_MAP_HELPERS_HPP_
15
17
18#include <OgreColourValue.h>
19#include <OgreManualObject.h>
20#include <OgreSceneNode.h>
21#include <OgreVector.h>
22
23#include <rviz_rendering/objects/movable_text.hpp>
24
25#include <lanelet2_core/primitives/BasicRegulatoryElements.h>
26#include <lanelet2_core/primitives/Lanelet.h>
27
28#include <boost/numeric/conversion/cast.hpp>
29
30#include <algorithm>
31#include <cassert>
32#include <iterator>
33#include <vector>
34
35namespace rviz_rendering::detail {
36
38 public:
40 explicit Lanelet2MapHelpers(Lanelet2Map& owner) : owner_(owner) {}
41
43 void clearObjects();
45 void addLaneletToManualObject(const lanelet::ConstLanelet& lanelet, Ogre::ManualObject* manual);
47 void addSeperatorToManualObject(const lanelet::ConstLanelet& lanelet, Ogre::ManualObject* manual);
49 void addAreaToManualObject(const lanelet::ConstArea& area, Ogre::ManualObject* manual);
51 void addParkingAreaToManualObject(const lanelet::ConstArea& area, Ogre::ManualObject* manual);
53 void addLaneFillToManualObject(const lanelet::ConstLanelet& lanelet, Ogre::ManualObject* manual);
55 void addSidewalkToManualObject(const lanelet::ConstArea& area, Ogre::ManualObject* manual);
57 void addCrosswalkToManualObject(const lanelet::ConstArea& area, Ogre::ManualObject* manual);
59 void addRegulatoryElements(const lanelet::ConstLanelet& lanelet, Ogre::SceneNode* parent_node);
61 void attachRefLinesToSceneNode(std::vector<lanelet::ConstLineString3d>& stop_lines, Ogre::SceneNode* parent_node);
63 void attachTrafficLightsToSceneNode(std::vector<lanelet::ConstPolygon3d>& traffic_lights, Ogre::SceneNode* parent_node);
65 void attachLaneletIdToSceneNode(const lanelet::ConstLanelet& lanelet, Ogre::SceneNode* parent_node);
66
67 private:
69 std::vector<Ogre::Vector3> ogreLineFromLLetLineString(const lanelet::ConstLineString3d& line_string) const;
71 std::vector<Ogre::Vector3> ogreLineFromLLetPolygon(const lanelet::CompoundPolygon3d& polygon) const;
73 std::vector<Ogre::Vector3> ogreLineFromLLetTrafficLight(const lanelet::ConstPolygon3d& polygon) const;
75 std::vector<Ogre::Vector3> ogreLineFromLLetPts(const lanelet::ConstPoints3d& pts_vector) const;
77 Ogre::Vector3 ogreVec3FromLLetPoint(lanelet::ConstPoint3d point) const;
79 static Ogre::Vector3 ogreVec3FromLLetTrafficLight(lanelet::ConstPoint3d point, double z_offset);
80
82 static std::vector<Ogre::Vector3> bufferSegment(const std::vector<Ogre::Vector3>& line, double buffer_length);
83
85 template <typename Iter>
86 static Ogre::Vector3 getNormal(Iter it, Iter begin, Iter end) {
87 Ogre::Vector3 zero(0, 0, 0);
88 auto dir_before = zero;
89 int i = 1;
90 while (it != begin && dir_before == zero) {
91 dir_before = *it - *std::prev(it, i);
92 i++;
93 }
94
95 auto dir_after = zero;
96 i = 1;
97 while (std::next(it) != end && dir_after == zero) {
98 dir_after = *std::next(it, i) - *it;
99 i++;
100 }
101
102 if (dir_before == zero && dir_after == zero) {
103 return zero;
104 }
105 if (dir_after == zero) {
106 dir_after = dir_before;
107 }
108 if (dir_before == zero) {
109 dir_before = dir_after;
110 }
111
112 auto dir_combined = dir_after * (1 / dir_after.length()) + dir_before * (1 / dir_before.length());
113 dir_combined *= 1 / dir_combined.length();
114 return Ogre::Vector3(dir_combined.y, -dir_combined.x, 0);
115 }
116
118 static void drawLine(const std::vector<Ogre::Vector3>& line,
119 Ogre::ManualObject* obj,
120 Ogre::ColourValue color = Ogre::ColourValue::White,
121 double width = 0.1,
122 double z_offset = 0.0);
124 static void drawArea(const std::vector<Ogre::Vector3>& line,
125 Ogre::ManualObject* obj,
126 Ogre::ColourValue color = Ogre::ColourValue::White,
127 double z_offset = 0.0);
129 static void drawMonoPolygon(const std::vector<Ogre::Vector3>& poly,
130 Ogre::ManualObject* obj,
131 Ogre::ColourValue color = Ogre::ColourValue::White);
133 static void drawLaneFillStrip(const std::vector<Ogre::Vector3>& left,
134 const std::vector<Ogre::Vector3>& right,
135 Ogre::ManualObject* obj,
136 Ogre::ColourValue color,
137 double z_offset = 0.0);
138
139 Lanelet2Map& owner_; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members)
140};
141
142} // namespace rviz_rendering::detail
143
144#endif // LANELET2_RVIZ_DISPLAY__LANELET2_MAP_HELPERS_HPP_
static void drawArea(const std::vector< Ogre::Vector3 > &line, Ogre::ManualObject *obj, Ogre::ColourValue color=Ogre::ColourValue::White, double z_offset=0.0)
Draw an area outline or fill into a manual object.
void addLaneFillToManualObject(const lanelet::ConstLanelet &lanelet, Ogre::ManualObject *manual)
Add a filled lanelet surface to a manual object.
void addLaneletToManualObject(const lanelet::ConstLanelet &lanelet, Ogre::ManualObject *manual)
Add lanelet boundary lines to a manual object.
static Ogre::Vector3 ogreVec3FromLLetTrafficLight(lanelet::ConstPoint3d point, double z_offset)
Convert a traffic light point to an OGRE point with a height offset.
std::vector< Ogre::Vector3 > ogreLineFromLLetTrafficLight(const lanelet::ConstPolygon3d &polygon) const
Convert a traffic light polygon to OGRE points.
static Ogre::Vector3 getNormal(Iter it, Iter begin, Iter end)
Return the local 2D normal at an iterator position.
static std::vector< Ogre::Vector3 > bufferSegment(const std::vector< Ogre::Vector3 > &line, double buffer_length)
Create a buffered segment around a line.
static void drawLaneFillStrip(const std::vector< Ogre::Vector3 > &left, const std::vector< Ogre::Vector3 > &right, Ogre::ManualObject *obj, Ogre::ColourValue color, double z_offset=0.0)
Draw a filled strip between lanelet boundaries.
void addCrosswalkToManualObject(const lanelet::ConstArea &area, Ogre::ManualObject *manual)
Add a crosswalk surface to a manual object.
std::vector< Ogre::Vector3 > ogreLineFromLLetPolygon(const lanelet::CompoundPolygon3d &polygon) const
Convert a Lanelet2 polygon to OGRE points.
void addSeperatorToManualObject(const lanelet::ConstLanelet &lanelet, Ogre::ManualObject *manual)
Add lanelet separator lines to a manual object.
std::vector< Ogre::Vector3 > ogreLineFromLLetLineString(const lanelet::ConstLineString3d &line_string) const
Convert a Lanelet2 line string to OGRE points.
Ogre::Vector3 ogreVec3FromLLetPoint(lanelet::ConstPoint3d point) const
Convert a Lanelet2 point to an OGRE point.
void attachTrafficLightsToSceneNode(std::vector< lanelet::ConstPolygon3d > &traffic_lights, Ogre::SceneNode *parent_node)
Attach traffic light geometry to a scene node.
std::vector< Ogre::Vector3 > ogreLineFromLLetPts(const lanelet::ConstPoints3d &pts_vector) const
Convert Lanelet2 points to OGRE points.
Lanelet2MapHelpers(Lanelet2Map &owner)
Create helper routines bound to the owning map renderer.
void clearObjects()
Remove all helper-owned OGRE objects.
static void drawLine(const std::vector< Ogre::Vector3 > &line, Ogre::ManualObject *obj, Ogre::ColourValue color=Ogre::ColourValue::White, double width=0.1, double z_offset=0.0)
Draw a line strip into a manual object.
static void drawMonoPolygon(const std::vector< Ogre::Vector3 > &poly, Ogre::ManualObject *obj, Ogre::ColourValue color=Ogre::ColourValue::White)
Draw a single polygon into a manual object.
void addRegulatoryElements(const lanelet::ConstLanelet &lanelet, Ogre::SceneNode *parent_node)
Attach regulatory element visuals for a lanelet.
void attachRefLinesToSceneNode(std::vector< lanelet::ConstLineString3d > &stop_lines, Ogre::SceneNode *parent_node)
Attach stop-line reference geometry to a scene node.
void addAreaToManualObject(const lanelet::ConstArea &area, Ogre::ManualObject *manual)
Add area outlines or fills to a manual object.
void addSidewalkToManualObject(const lanelet::ConstArea &area, Ogre::ManualObject *manual)
Add a sidewalk surface to a manual object.
void attachLaneletIdToSceneNode(const lanelet::ConstLanelet &lanelet, Ogre::SceneNode *parent_node)
Attach the lanelet ID text to a scene node.
void addParkingAreaToManualObject(const lanelet::ConstArea &area, Ogre::ManualObject *manual)
Add parking area outlines or fills to a manual object.