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 <memory>
22#include <string>
23#include <unordered_map>
24#include <vector>
25
26#include <QObject>
27
28#include <rclcpp/qos.hpp>
29#include <rclcpp/subscription.hpp>
30
31#include <rviz_common/message_filter_display.hpp>
32#include <rviz_common/properties/bool_property.hpp>
33#include <rviz_common/properties/enum_property.hpp>
34#include <rviz_common/properties/float_property.hpp>
35#include <rviz_common/properties/qos_profile_property.hpp>
36#include <rviz_common/properties/ros_topic_property.hpp>
37#include <rviz_common/properties/string_property.hpp>
38#include <rviz_common/display_context.hpp>
39
40#include <navmap_ros_interfaces/msg/nav_map.hpp>
41#include <navmap_ros_interfaces/msg/nav_map_layer.hpp>
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
75{
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 onAlphaChanged();
103 void onNormalScaleChanged();
104 void onColorSchemeChanged();
105
106private:
107 // Subscriptions
108 void subscribeToLayerTopic();
109 void unsubscribeToLayerTopic();
110 void incomingLayer(const NavMapLayerMsg::ConstSharedPtr & msg);
111
112 // Data helpers
113 void rebuildLayerIndex_();
114 std::string currentSelectedLayer_() const;
115 void repopulateLayerEnum_();
116 void applyOrCacheLayer_(const NavMapLayerMsg & layer);
117
118 // Rendering
119 void updateGeometry_(); // Build geometry (first time) and update colors.
120 void updateNormals_(); // Rebuild normals debug object.
121 void updateColorSchemeOptions_(); // Refresh color-scheme choices for current layer.
122
123 // Mesh/Entity path (Option B)
124 void ensureMeshBuilt_(); // Build static mesh once from last_msg_.
125 void destroyMesh_(); // Destroy entity/mesh and related buffers.
126 void updateColorsOnly_(); // Overwrite color buffer (fast path, no geometry rebuild).
127
128private:
129 // ---- RViz properties ----
130 rviz_common::properties::EnumProperty * layer_property_{nullptr};
131 rviz_common::properties::RosTopicProperty * layer_topic_property_{nullptr};
132 rviz_common::properties::QosProfileProperty * layer_profile_property_{nullptr};
133 rviz_common::properties::EnumProperty * color_scheme_property_{nullptr};
134 rviz_common::properties::BoolProperty * draw_normals_property_{nullptr};
135 rviz_common::properties::FloatProperty * normal_scale_property_{nullptr};
136 rviz_common::properties::FloatProperty * alpha_property_{nullptr};
137 rviz_common::properties::StringProperty * info_property_{nullptr};
138
139 // ---- QoS and layer subscription ----
140 rclcpp::QoS layer_profile_{rclcpp::QoS(5)};
141 rclcpp::Subscription<NavMapLayerMsg>::SharedPtr layer_subscription_;
142 rclcpp::Time layer_subscription_start_time_;
143
144 // ---- Status counters ----
145 std::uint64_t navmap_msg_count_{0};
146 std::uint64_t layer_update_count_{0};
147 rclcpp::Time last_navmap_stamp_;
148 rclcpp::Time last_layer_stamp_;
149
150 // ---- Data state ----
151 NavMapMsg::SharedPtr last_msg_;
152 std::unordered_map<std::string, const NavMapLayerMsg *> layers_by_name_;
153
154 // ---- OGRE scene objects ----
155 Ogre::SceneNode * root_node_{nullptr};
156 Ogre::ManualObject * normals_obj_{nullptr};
157
158 // Option B: static mesh + entity + dynamic colour buffer
159 Ogre::Entity * entity_{nullptr};
160 Ogre::SharedPtr<Ogre::Mesh> mesh_; // Ogre::MeshPtr
161 Ogre::HardwareVertexBufferSharedPtr colour_vbuf_;
162 unsigned short colour_vbuf_source_{0}; // which stream holds VES_DIFFUSE
163 bool mesh_built_{false};
164};
165
166} // namespace navmap_rviz_plugin
167
168#endif // NAVMAP_RVIZ_PLUGIN__NAVMAP_DISPLAY_HPP_
#define NAVMAP_RVIZ_PLUGIN_PUBLIC
Definition NavMapDisplay.hpp:59
void onInitialize() override
Definition NavMapDisplay.cpp:153
void onEnable() override
Definition NavMapDisplay.cpp:196
void processMessage(const NavMapMsg::ConstSharedPtr msg) override
Definition NavMapDisplay.cpp:208
NavMapDisplay()
Definition NavMapDisplay.cpp:99
void reset() override
Definition NavMapDisplay.cpp:175
void onDisable() override
Definition NavMapDisplay.cpp:202
Definition NavMapDisplay.hpp:66
Definition NavMapDisplay.hpp:75