15#include <OgreMovableObject.h>
16#include <OgreSceneManager.h>
25 switch (
object.first) {
35 auto man_object =
dynamic_cast<Ogre::ManualObject*
>(
object.second);
36 if (man_object !=
nullptr) {
37 man_object->detachFromParent();
44 auto mov_text =
dynamic_cast<rviz_rendering::MovableText*
>(
object.second);
45 if (mov_text !=
nullptr) {
46 mov_text->detachFromParent();
55 if (
object.second !=
nullptr) {
56 object.second->detachFromParent();
70 auto left_bound = lanelet.leftBound();
74 auto right_bound = lanelet.rightBound();
80 lanelet::ConstPoints3d first_points;
81 first_points.push_back(lanelet.leftBound().front());
82 first_points.push_back(lanelet.rightBound().front());
86 lanelet::ConstPoints3d last_points;
87 last_points.push_back(lanelet.leftBound().back());
88 last_points.push_back(lanelet.rightBound().back());
94 const lanelet::CompoundPolygon3d outer_polygon = area.outerBoundPolygon();
104 const lanelet::CompoundPolygon3d outer_polygon = area.outerBoundPolygon();
130 Ogre::SceneNode* regulatory_elements_node = parent_node->createChildSceneNode();
131 auto regulatory_elements = lanelet.regulatoryElements();
132 auto traffic_light_regelems = lanelet.regulatoryElementsAs<lanelet::TrafficLight>();
135 for (
auto&& reg_element : regulatory_elements) {
136 auto ref_lines = reg_element->getParameters<lanelet::ConstLineString3d>(lanelet::RoleName::RefLine);
142 for (
auto&& traffic_light : traffic_light_regelems) {
143 auto traffic_lights = traffic_light->getParameters<lanelet::ConstPolygon3d>(lanelet::RoleName::Refers);
150 Ogre::SceneNode* parent_node) {
151 Ogre::ManualObject* stop_lines_manual_object =
153 stop_lines_manual_object->begin(
owner_.
material_line_->getName(), Ogre::RenderOperation::OT_TRIANGLE_LIST,
"rviz_rendering");
154 stop_lines_manual_object->setRenderQueueGroup(Ogre::RENDER_QUEUE_MAIN + 6);
155 for (
auto&& stop_line : stop_lines) {
162 if (stop_lines_manual_object->getNumSections() != 0U) {
163 parent_node->attachObject(stop_lines_manual_object);
166 stop_lines_manual_object->end();
170 Ogre::SceneNode* parent_node) {
171 Ogre::ManualObject* traffic_light_manual_object =
173 traffic_light_manual_object->begin(
owner_.
material_surface_->getName(), Ogre::RenderOperation::OT_TRIANGLE_LIST,
175 traffic_light_manual_object->setRenderQueueGroup(Ogre::RENDER_QUEUE_MAIN + 4);
176 for (
auto&& traffic_light : traffic_lights) {
182 if (traffic_light_manual_object->getNumSections() != 0U) {
183 parent_node->attachObject(traffic_light_manual_object);
186 traffic_light_manual_object->end();
190 Ogre::SceneNode* child_node = parent_node->createChildSceneNode();
192 auto* msg =
new rviz_rendering::MovableText(std::to_string(lanelet.id()));
195 msg->setTextAlignment(rviz_rendering::MovableText::H_CENTER, rviz_rendering::MovableText::V_ABOVE);
197 lanelet::ConstPoint3d text_pos(
198 lanelet::utils::getId(), lanelet.centerline()[lanelet.centerline().size() / 2].x(),
199 lanelet.centerline()[lanelet.centerline().size() / 2].y(),
203 child_node->attachObject(msg);
208 std::vector<Ogre::Vector3> line;
209 for (lanelet::ConstPoint3d point : line_string) {
216 std::vector<Ogre::Vector3> line;
217 for (lanelet::ConstPoint3d point : polygon) {
224 if (polygon.empty()) {
228 std::vector<Ogre::Vector3> line;
229 const lanelet::ConstPoint3d lowest_point =
230 *std::min_element(polygon.begin(), polygon.end(),
231 [](
const lanelet::ConstPoint3d& p1,
const lanelet::ConstPoint3d& p2) { return p1.z() < p2.z(); });
233 for (lanelet::ConstPoint3d point : polygon) {
240 std::vector<Ogre::Vector3> line;
241 for (lanelet::ConstPoint3d point : pts_vector) {
248 using boost::numeric_cast;
249 return Ogre::Vector3(numeric_cast<Ogre::Real>(point.x()), numeric_cast<Ogre::Real>(point.y()),
254 using boost::numeric_cast;
255 return Ogre::Vector3(numeric_cast<Ogre::Real>(point.x()), numeric_cast<Ogre::Real>(point.y()),
256 numeric_cast<Ogre::Real>(point.z() + z_offset));
260 std::vector<Ogre::Vector3> buffered;
261 buffered.reserve(line.size());
262 assert(line.size() >= 2);
263 for (
auto it = line.begin(); it != line.end(); ++it) {
264 auto normal =
getNormal(it, line.begin(), line.end());
265 buffered.push_back(*it + normal * boost::numeric_cast<Ogre::Real>(buffer_length / 2.0));
267 for (
auto it = line.rbegin(); it != line.rend(); ++it) {
268 auto normal =
getNormal(it, line.rbegin(), line.rend());
269 buffered.push_back(*it + normal * boost::numeric_cast<Ogre::Real>(buffer_length / 2.0));
275 const std::vector<Ogre::Vector3>& line, Ogre::ManualObject* obj, Ogre::ColourValue color,
double width,
double z_offset) {
276 if (width <= 0 || line.size() < 2) {
280 if (z_offset != 0.0) {
281 for (
auto& v : buffered) {
282 v.z += boost::numeric_cast<Ogre::Real>(z_offset);
289 Ogre::ManualObject* obj,
290 Ogre::ColourValue color,
292 if (line.size() < 2) {
295 if (z_offset != 0.0) {
296 std::vector<Ogre::Vector3> elevated;
297 elevated.reserve(line.size());
298 for (
auto v : line) {
299 v.z += boost::numeric_cast<Ogre::Real>(z_offset);
300 elevated.push_back(v);
309 Ogre::ManualObject* obj,
310 Ogre::ColourValue color) {
311 if (poly.size() < 3) {
315 auto it_left = poly.begin();
316 auto it_right = --poly.end();
317 const auto start_index = obj->getCurrentVertexCount();
319 for (; it_right >= it_left; ++it_left, --it_right) {
320 obj->position(*it_left);
321 obj->normal(0, 0, 1);
324 assert(obj->getCurrentVertexCount() > start_index + count);
325 obj->triangle(start_index + count - 2, start_index + count - 1, start_index + count);
328 obj->position(*it_right);
329 obj->normal(0, 0, 1);
332 assert(obj->getCurrentVertexCount() > start_index + count);
333 obj->triangle(start_index + count, start_index + count - 1, start_index + count - 2);
340 const std::vector<Ogre::Vector3>& right,
341 Ogre::ManualObject* obj,
342 Ogre::ColourValue color,
344 if (left.size() < 2 || right.size() < 2) {
348 const size_t n_left = left.size();
349 const size_t n_right = right.size();
350 const size_t max_steps = std::max(n_left, n_right) - 1;
351 for (
size_t i = 0; i < max_steps; ++i) {
352 double t0 =
static_cast<double>(i) /
static_cast<double>(max_steps);
353 double t1 =
static_cast<double>(i + 1) /
static_cast<double>(max_steps);
355 size_t i_left0 =
static_cast<size_t>(t0 *
static_cast<double>(n_left - 1));
356 size_t i_left1 = std::min(
static_cast<size_t>(t1 *
static_cast<double>(n_left - 1)), n_left - 1);
357 size_t i_right0 =
static_cast<size_t>(t0 *
static_cast<double>(n_right - 1));
358 size_t i_right1 = std::min(
static_cast<size_t>(t1 *
static_cast<double>(n_right - 1)), n_right - 1);
360 Ogre::Vector3 left0 = left[i_left0];
361 Ogre::Vector3 left1 = left[i_left1];
362 Ogre::Vector3 right0 = right[i_right0];
363 Ogre::Vector3 right1 = right[i_right1];
364 const auto z_offset_real = boost::numeric_cast<Ogre::Real>(z_offset);
365 left0.z += z_offset_real;
366 left1.z += z_offset_real;
367 right0.z += z_offset_real;
368 right1.z += z_offset_real;
370 const auto base = obj->getCurrentVertexCount();
371 obj->position(left0);
372 obj->normal(0, 0, 1);
374 obj->position(right0);
375 obj->normal(0, 0, 1);
377 obj->position(left1);
378 obj->normal(0, 0, 1);
380 obj->triangle(base + 0, base + 1, base + 2);
382 obj->position(left1);
383 obj->normal(0, 0, 1);
385 obj->position(right0);
386 obj->normal(0, 0, 1);
388 obj->position(right1);
389 obj->normal(0, 0, 1);
391 obj->triangle(base + 3, base + 4, base + 5);
Lanelet2Map::RenderingOptions rend_opts_
static int manual_object_counter_
std::vector< ClassifiedMovableObject > objects_
std::shared_ptr< Ogre::Material > material_line_
std::shared_ptr< Ogre::Material > material_surface_
Ogre::SceneManager * scene_manager_
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.
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.
Ogre::ColourValue colorLaneletId
Ogre::ColourValue colorSeperator
Ogre::ColourValue colorStopLine
Ogre::ColourValue colorLaneFill
Ogre::ColourValue colorParking
double trafficLightHeightAboveGround
Ogre::ColourValue colorLeft
Ogre::ColourValue colorSidewalk
Ogre::ColourValue colorArea
Ogre::ColourValue colorTrafficLight
Ogre::ColourValue colorCrosswalk
Ogre::ColourValue colorRight