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__NAVMAP_DISPLAY_HPP_
18#define NAVMAP_RVIZ_PLUGIN__NAVMAP_DISPLAY_HPP_
19
20#include <cstdint>
21#include <string>
22#include <unordered_map>
23
24#include <QObject>
25
26#include <rclcpp/qos.hpp>
27#include <rclcpp/subscription.hpp>
28
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
38#include <navmap_ros_interfaces/msg/nav_map.hpp>
39#include <navmap_ros_interfaces/msg/nav_map_layer.hpp>
40
42
43#if defined _WIN32 || defined __CYGWIN__
44 #ifdef __GNUC__
45 #define NAVMAP_RVIZ_PLUGIN_EXPORT __attribute__ ((dllexport))
46 #define NAVMAP_RVIZ_PLUGIN_IMPORT __attribute__ ((dllimport))
47 #else
48 #define NAVMAP_RVIZ_PLUGIN_EXPORT __declspec(dllexport)
49 #define NAVMAP_RVIZ_PLUGIN_IMPORT __declspec(dllimport)
50 #endif
51 #ifdef navmap_rviz_plugin_EXPORTS
52 #define NAVMAP_RVIZ_PLUGIN_PUBLIC NAVMAP_RVIZ_PLUGIN_EXPORT
53 #else
54 #define NAVMAP_RVIZ_PLUGIN_PUBLIC NAVMAP_RVIZ_PLUGIN_IMPORT
55 #endif
56 #define NAVMAP_RVIZ_PLUGIN_PUBLIC_TYPE NAVMAP_RVIZ_PLUGIN_PUBLIC
57 #define NAVMAP_RVIZ_PLUGIN_LOCAL
58#else
59 #define NAVMAP_RVIZ_PLUGIN_PUBLIC __attribute__ ((visibility ("default")))
60 #define NAVMAP_RVIZ_PLUGIN_PUBLIC_TYPE
61 #define NAVMAP_RVIZ_PLUGIN_LOCAL __attribute__ ((visibility ("hidden")))
62#endif
63
64// Forward declarations to avoid hard coupling here
65namespace Ogre
66{
67class SceneNode;
68class ManualObject;
69class Entity;
70class Mesh;
71class HardwareVertexBuffer;
72}
73
74namespace navmap_rviz_plugin
75{
76
78
80 : public rviz_common::MessageFilterDisplay<navmap_ros_interfaces::msg::NavMap>
81{
82 Q_OBJECT
83
84 using MFDClass = rviz_common::MessageFilterDisplay<navmap_ros_interfaces::msg::NavMap>;
85 using NavMapMsg = navmap_ros_interfaces::msg::NavMap;
86 using NavMapLayerMsg = navmap_ros_interfaces::msg::NavMapLayer;
87
88public:
90 ~NavMapDisplay() override;
91
92 void onInitialize() override;
93 void reset() override;
94 void onEnable() override;
95 void onDisable() override;
96
97protected:
98 void processMessage(const NavMapMsg::ConstSharedPtr msg) override;
99
100private Q_SLOTS:
101 void updateLayerUpdateTopic();
102 void onLayerSelectionChanged();
103 void onDrawNormalsChanged();
104 void onAlphaChanged();
105 void onNormalScaleChanged();
106 void onColorSchemeChanged();
107
108private:
109 // Subscriptions
110 void subscribeToLayerTopic();
111 void unsubscribeToLayerTopic();
112 void incomingLayer(const NavMapLayerMsg::ConstSharedPtr & msg);
113
114 // Data helpers
115 void rebuildLayerIndex_();
116 std::string currentSelectedLayer_() const;
117 void repopulateLayerEnum_();
118 void applyOrCacheLayer_(const NavMapLayerMsg & layer);
119
120 // Rendering
121 void updateGeometry_(); // Build geometry (first time) and update colors.
122 void updateNormals_(); // Rebuild normals debug object.
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::FloatProperty * normal_scale_property_{nullptr};
138 rviz_common::properties::FloatProperty * alpha_property_{nullptr};
139 rviz_common::properties::StringProperty * info_property_{nullptr};
140
141 // ---- QoS and layer subscription ----
142 rclcpp::QoS layer_profile_{rclcpp::QoS(5)};
143 rclcpp::Subscription<NavMapLayerMsg>::SharedPtr layer_subscription_;
144 rclcpp::Time layer_subscription_start_time_;
145
146 // ---- Status counters ----
147 std::uint64_t navmap_msg_count_{0};
148 std::uint64_t layer_update_count_{0};
149 rclcpp::Time last_navmap_stamp_;
150 rclcpp::Time last_layer_stamp_;
151
152 // ---- Data state ----
153 NavMapMsg::SharedPtr last_msg_;
154 std::unordered_map<std::string, const NavMapLayerMsg *> layers_by_name_;
155
156 // ---- OGRE scene objects ----
157 Ogre::SceneNode * root_node_{nullptr};
158 Ogre::ManualObject * normals_obj_{nullptr};
159
160 // Option B: static mesh + entity + dynamic colour buffer
161 Ogre::Entity * entity_{nullptr};
162 Ogre::SharedPtr<Ogre::Mesh> mesh_; // Ogre::MeshPtr
163 Ogre::HardwareVertexBufferSharedPtr colour_vbuf_;
164 unsigned short colour_vbuf_source_{0}; // which stream holds VES_DIFFUSE
165 bool mesh_built_{false};
166};
167
168} // namespace navmap_rviz_plugin
169
170#endif // NAVMAP_RVIZ_PLUGIN__NAVMAP_DISPLAY_HPP_
#define NAVMAP_RVIZ_PLUGIN_PUBLIC
Definition NavMapDisplay.hpp:59
Core container and data structures for EasyNav navigable meshes.
Main container for navigable surfaces, geometry, and layers.
Definition NavMap.hpp:465
void onInitialize() override
Definition NavMapDisplay.cpp:140
void onEnable() override
Definition NavMapDisplay.cpp:183
void processMessage(const NavMapMsg::ConstSharedPtr msg) override
Definition NavMapDisplay.cpp:195
NavMapDisplay()
Definition NavMapDisplay.cpp:86
void reset() override
Definition NavMapDisplay.cpp:162
void onDisable() override
Definition NavMapDisplay.cpp:189
Definition NavMapDisplay.hpp:66
Definition navmap_goal_tool.hpp:39
navmap::NavMap received_navmap
Definition NavMapDisplay.hpp:77