Nav2 Navigation Stack - humble  humble
ROS 2 Navigation Stack
particle_cloud_display.hpp
1 /*
2  * Copyright (c) 2012, Willow Garage, Inc.
3  * Copyright (c) 2018, Bosch Software Innovations GmbH.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * * Neither the name of the Willow Garage, Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 // Copyright (c) 2019 Intel Corporation
32 // Copyright (c) 2020 Sarthak Mittal
33 //
34 // Licensed under the Apache License, Version 2.0 (the "License");
35 // you may not use this file except in compliance with the License.
36 // You may obtain a copy of the License at
37 //
38 // http://www.apache.org/licenses/LICENSE-2.0
39 //
40 // Unless required by applicable law or agreed to in writing, software
41 // distributed under the License is distributed on an "AS IS" BASIS,
42 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43 // See the License for the specific language governing permissions and
44 // limitations under the License.
45 
46 #ifndef NAV2_RVIZ_PLUGINS__PARTICLE_CLOUD_DISPLAY__PARTICLE_CLOUD_DISPLAY_HPP_
47 #define NAV2_RVIZ_PLUGINS__PARTICLE_CLOUD_DISPLAY__PARTICLE_CLOUD_DISPLAY_HPP_
48 
49 #include <memory>
50 #include <vector>
51 
52 #include "nav2_msgs/msg/particle_cloud.hpp"
53 
54 #include "rviz_rendering/objects/shape.hpp"
55 #include "rviz_common/message_filter_display.hpp"
56 
57 namespace Ogre
58 {
59 class ManualObject;
60 } // namespace Ogre
61 
62 namespace rviz_common
63 {
64 namespace properties
65 {
66 class EnumProperty;
67 class ColorProperty;
68 class FloatProperty;
69 } // namespace properties
70 } // namespace rviz_common
71 
72 namespace rviz_rendering
73 {
74 class Arrow;
75 class Axes;
76 } // namespace rviz_rendering
77 
78 namespace nav2_rviz_plugins
79 {
80 class FlatWeightedArrowsArray;
82 {
83  Ogre::Vector3 position;
84  Ogre::Quaternion orientation;
85  float weight;
86 };
87 
89 class ParticleCloudDisplay : public rviz_common::MessageFilterDisplay<nav2_msgs::msg::ParticleCloud>
90 {
91  Q_OBJECT
92 
93 public:
94  // TODO(botteroa-si): Constructor for testing, remove once ros_nodes can be mocked and call
95  // initialize instead
97  rviz_common::DisplayContext * display_context,
98  Ogre::SceneNode * scene_node);
100  ~ParticleCloudDisplay() override;
101 
102  void processMessage(nav2_msgs::msg::ParticleCloud::ConstSharedPtr msg) override;
103  void setShape(QString shape); // for testing
104 
105 protected:
106  void onInitialize() override;
107  void reset() override;
108 
109 private Q_SLOTS:
111  void updateShapeChoice();
112 
114  void updateArrowColor();
115 
117  void updateGeometry();
118 
119 private:
120  void initializeProperties();
121  bool validateFloats(const nav2_msgs::msg::ParticleCloud & msg);
122  bool setTransform(std_msgs::msg::Header const & header);
123  void updateDisplay();
124  void updateArrows2d();
125  void updateArrows3d();
126  void updateAxes();
127  void updateArrow3dGeometry();
128  void updateAxesGeometry();
129 
130  std::unique_ptr<rviz_rendering::Axes> makeAxes();
131  std::unique_ptr<rviz_rendering::Arrow> makeArrow3d();
132 
133  std::vector<OgrePoseWithWeight> poses_;
134  std::unique_ptr<FlatWeightedArrowsArray> arrows2d_;
135  std::vector<std::unique_ptr<rviz_rendering::Arrow>> arrows3d_;
136  std::vector<std::unique_ptr<rviz_rendering::Axes>> axes_;
137 
138  Ogre::SceneNode * arrow_node_;
139  Ogre::SceneNode * axes_node_;
140 
141  rviz_common::properties::EnumProperty * shape_property_;
142  rviz_common::properties::ColorProperty * arrow_color_property_;
143  rviz_common::properties::FloatProperty * arrow_alpha_property_;
144 
145  rviz_common::properties::FloatProperty * arrow_min_length_property_;
146  rviz_common::properties::FloatProperty * arrow_max_length_property_;
147 
148  float min_length_;
149  float max_length_;
150  float length_scale_;
151  float head_radius_scale_;
152  float head_length_scale_;
153  float shaft_radius_scale_;
154 };
155 
156 } // namespace nav2_rviz_plugins
157 
158 #endif // NAV2_RVIZ_PLUGINS__PARTICLE_CLOUD_DISPLAY__PARTICLE_CLOUD_DISPLAY_HPP_
Displays a nav2_msgs/ParticleCloud message as a bunch of line-drawn weighted arrows.