NavMap
Loading...
Searching...
No Matches
NavMapDisplay.hpp
Go to the documentation of this file.
1// Copyright 2025 Intelligent Robotics Lab
2//
3// This file is part of the project Easy Navigation (EasyNav in short)
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16
17#ifndef NAVMAP_RVIZ_PLUGIN__NAVMAPDISPLAY_HPP_
18#define NAVMAP_RVIZ_PLUGIN__NAVMAPDISPLAY_HPP_
19
20#include <cstdint>
21#include <string>
22#include <unordered_map>
23
24#include "QObject"
25#include "OgreHardwareVertexBuffer.h"
26#include "OgreMesh.h"
27#include "rclcpp/qos.hpp"
28#include "rclcpp/subscription.hpp"
29#include "rviz_common/message_filter_display.hpp"
30#include "rviz_common/properties/bool_property.hpp"
31#include "rviz_common/properties/enum_property.hpp"
32#include "rviz_common/properties/float_property.hpp"
33#include "rviz_common/properties/qos_profile_property.hpp"
34#include "rviz_common/properties/ros_topic_property.hpp"
35#include "rviz_common/properties/string_property.hpp"
36#include "rviz_common/display_context.hpp"
37#include "navmap_ros_interfaces/msg/nav_map.hpp"
38#include "navmap_ros_interfaces/msg/nav_map_layer.hpp"
40
41#if defined _WIN32 || defined __CYGWIN__
42 #ifdef __GNUC__
43 #define NAVMAP_RVIZ_PLUGIN_EXPORT __attribute__ ((dllexport))
44 #define NAVMAP_RVIZ_PLUGIN_IMPORT __attribute__ ((dllimport))
45 #else
46 #define NAVMAP_RVIZ_PLUGIN_EXPORT __declspec(dllexport)
47 #define NAVMAP_RVIZ_PLUGIN_IMPORT __declspec(dllimport)
48 #endif
49 #ifdef navmap_rviz_plugin_EXPORTS
50 #define NAVMAP_RVIZ_PLUGIN_PUBLIC NAVMAP_RVIZ_PLUGIN_EXPORT
51 #else
52 #define NAVMAP_RVIZ_PLUGIN_PUBLIC NAVMAP_RVIZ_PLUGIN_IMPORT
53 #endif
54 #define NAVMAP_RVIZ_PLUGIN_PUBLIC_TYPE NAVMAP_RVIZ_PLUGIN_PUBLIC
55 #define NAVMAP_RVIZ_PLUGIN_LOCAL
56#else
57 #define NAVMAP_RVIZ_PLUGIN_PUBLIC __attribute__ ((visibility ("default")))
58 #define NAVMAP_RVIZ_PLUGIN_PUBLIC_TYPE
59 #define NAVMAP_RVIZ_PLUGIN_LOCAL __attribute__ ((visibility ("hidden")))
60#endif
61
62// Forward declarations to avoid hard coupling here
63namespace Ogre
64{
65class SceneNode;
66class ManualObject;
67class Entity;
68class Mesh;
69class HardwareVertexBuffer;
70}
71
72namespace navmap_rviz_plugin
73{
74
76
78 : public rviz_common::MessageFilterDisplay<navmap_ros_interfaces::msg::NavMap>
79{
80 Q_OBJECT
81
82 using MFDClass = rviz_common::MessageFilterDisplay<navmap_ros_interfaces::msg::NavMap>;
83 using NavMapMsg = navmap_ros_interfaces::msg::NavMap;
84 using NavMapLayerMsg = navmap_ros_interfaces::msg::NavMapLayer;
85
86public:
88 ~NavMapDisplay() override;
89
90 void onInitialize() override;
91 void reset() override;
92 void onEnable() override;
93 void onDisable() override;
94
95protected:
96 void processMessage(const NavMapMsg::ConstSharedPtr msg) override;
97
98private Q_SLOTS:
99 void updateLayerUpdateTopic();
100 void onLayerSelectionChanged();
101 void onDrawNormalsChanged();
102 void onDrawLinksChanged();
103 void onAlphaChanged();
104 void onNormalScaleChanged();
105 void onColorSchemeChanged();
106
107private:
108 // Subscriptions
109 void subscribeToLayerTopic();
110 void unsubscribeToLayerTopic();
111 void incomingLayer(const NavMapLayerMsg::ConstSharedPtr & msg);
112
113 // Data helpers
114 void rebuildLayerIndex_();
115 std::string currentSelectedLayer_() const;
116 void repopulateLayerEnum_();
117 void applyOrCacheLayer_(const NavMapLayerMsg & layer);
118
119 // Rendering
120 void updateGeometry_(); // Build geometry (first time) and update colors.
121 void updateNormals_(); // Rebuild normals debug object.
122 void updateLinks_(); // Rebuild the links between non-adjacent NavCels.
123 void updateColorSchemeOptions_(); // Refresh color-scheme choices for current layer.
124
125 // Mesh/Entity path (Option B)
126 void ensureMeshBuilt_(); // Build static mesh once from last_msg_.
127 void destroyMesh_(); // Destroy entity/mesh and related buffers.
128 void updateColorsOnly_(); // Overwrite color buffer (fast path, no geometry rebuild).
129
130private:
131 // ---- RViz properties ----
132 rviz_common::properties::EnumProperty * layer_property_{nullptr};
133 rviz_common::properties::RosTopicProperty * layer_topic_property_{nullptr};
134 rviz_common::properties::QosProfileProperty * layer_profile_property_{nullptr};
135 rviz_common::properties::EnumProperty * color_scheme_property_{nullptr};
136 rviz_common::properties::BoolProperty * draw_normals_property_{nullptr};
137 rviz_common::properties::BoolProperty * draw_links_property_{nullptr};
138 rviz_common::properties::FloatProperty * normal_scale_property_{nullptr};
139 rviz_common::properties::FloatProperty * alpha_property_{nullptr};
140 rviz_common::properties::StringProperty * info_property_{nullptr};
141
142 // ---- QoS and layer subscription ----
143 rclcpp::QoS layer_profile_{rclcpp::QoS(5)};
144 rclcpp::Subscription<NavMapLayerMsg>::SharedPtr layer_subscription_;
145 rclcpp::Time layer_subscription_start_time_;
146
147 // ---- Status counters ----
148 std::uint64_t navmap_msg_count_{0};
149 std::uint64_t layer_update_count_{0};
150 rclcpp::Time last_navmap_stamp_;
151 rclcpp::Time last_layer_stamp_;
152
153 // ---- Data state ----
154 NavMapMsg::SharedPtr last_msg_;
155 std::unordered_map<std::string, const NavMapLayerMsg *> layers_by_name_;
156
157 // ---- OGRE scene objects ----
158 Ogre::SceneNode * root_node_{nullptr};
159 Ogre::ManualObject * normals_obj_{nullptr};
160 Ogre::ManualObject * links_obj_{nullptr};
161
162 // Option B: static mesh + entity + dynamic colour buffer
163 Ogre::Entity * entity_{nullptr};
164 Ogre::SharedPtr<Ogre::Mesh> mesh_; // Ogre::MeshPtr
165 Ogre::HardwareVertexBufferSharedPtr colour_vbuf_;
166 uint16_t colour_vbuf_source_{0}; // which stream holds VES_DIFFUSE
167 bool mesh_built_{false};
168};
169
170} // namespace navmap_rviz_plugin
171
172#endif // NAVMAP_RVIZ_PLUGIN__NAVMAPDISPLAY_HPP_
#define NAVMAP_RVIZ_PLUGIN_PUBLIC
Definition NavMapDisplay.hpp:57
Core container and data structures for EasyNav navigable meshes.
Definition NavMap.hpp:561
void onInitialize() override
Definition NavMapDisplay.cpp:167
void onEnable() override
Definition NavMapDisplay.cpp:216
void processMessage(const NavMapMsg::ConstSharedPtr msg) override
Definition NavMapDisplay.cpp:228
NavMapDisplay()
Definition NavMapDisplay.cpp:104
void reset() override
Definition NavMapDisplay.cpp:194
void onDisable() override
Definition NavMapDisplay.cpp:222
Definition NavMapDisplay.hpp:64
Definition navmap_goal_tool.hpp:39
navmap::NavMap received_navmap
Definition NavMapDisplay.hpp:75