Skip to content

Commit

Permalink
Migrate MarkerArrayDisplay (#296)
Browse files Browse the repository at this point in the history
* Migrate MarkerArrayDisplay

* Fix uncrustify

* Extract common code in marker displays into marker_common

* Add visual test

* Add visual test for MarkerArray messages in MarkerDisplay

* Implement review comments

* [REMOVE BEFORE MERGE] Fix moved file includes
  • Loading branch information
greimela-si authored and wjwwood committed Jun 15, 2018
1 parent 41e9e45 commit 467164b
Show file tree
Hide file tree
Showing 44 changed files with 1,218 additions and 804 deletions.
88 changes: 0 additions & 88 deletions rviz/src/rviz/default_plugin/marker_array_display.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class RVIZ_COMMON_PUBLIC QueueSizeProperty : public QObject
public:
QueueSizeProperty(_RosTopicDisplay * display, uint32_t default_size);

void setDescription(const QString & description);

private Q_SLOTS:
void updateQueueSize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ QueueSizeProperty::QueueSizeProperty(_RosTopicDisplay * display, uint32_t defaul
updateQueueSize();
}

void QueueSizeProperty::setDescription(const QString & description)
{
queue_size_property_->setDescription(description);
}

void QueueSizeProperty::updateQueueSize()
{
display_->updateQoSProfile([this](rmw_qos_profile_t profile) -> rmw_qos_profile_t {
Expand Down
30 changes: 25 additions & 5 deletions rviz_default_plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ set(rviz_default_plugins_headers_to_moc
include/rviz_default_plugins/displays/grid_cells/grid_cells_display.hpp
include/rviz_default_plugins/displays/image/image_display.hpp
include/rviz_default_plugins/displays/laser_scan/laser_scan_display.hpp
include/rviz_default_plugins/displays/marker/marker_common.hpp
include/rviz_default_plugins/displays/marker/marker_display.hpp
include/rviz_default_plugins/displays/marker_array/marker_array_display.hpp
include/rviz_default_plugins/displays/odometry/odometry_display.hpp
include/rviz_default_plugins/displays/path/path_display.hpp
include/rviz_default_plugins/displays/point/point_stamped_display.hpp
Expand Down Expand Up @@ -109,7 +111,9 @@ set(rviz_default_plugins_source_files
src/rviz_default_plugins/displays/marker/markers/shape_marker.cpp
src/rviz_default_plugins/displays/marker/markers/triangle_list_marker.cpp
src/rviz_default_plugins/displays/marker/markers/marker_factory.cpp
src/rviz_default_plugins/displays/marker/marker_common.cpp
src/rviz_default_plugins/displays/marker/marker_display.cpp
src/rviz_default_plugins/displays/marker_array/marker_array_display.cpp
src/rviz_default_plugins/displays/odometry/odometry_display.cpp
src/rviz_default_plugins/displays/path/path_display.cpp
src/rviz_default_plugins/displays/point/point_stamped_display.cpp
Expand Down Expand Up @@ -259,6 +263,7 @@ if(BUILD_TESTING)
${urdf_INCLUDE_DIRS}
${OGRE_INCLUDE_DIRS}
${rclcpp_INCLUDE_DIRS}
${rclcpp_INCLUDE_DIRS}
${nav_msgs_INCLUDE_DIRS}
${sensor_msgs_INCLUDE_DIRS}
${visualization_msgs_INCLUDE_DIRS}
Expand Down Expand Up @@ -388,16 +393,16 @@ if(BUILD_TESTING)
${TEST_LINK_LIBRARIES})
endif()

ament_add_gmock(marker_display_test
test/rviz_default_plugins/displays/marker/marker_display_test.cpp
ament_add_gmock(marker_common_test
test/rviz_default_plugins/displays/marker/marker_common_test.cpp
test/rviz_default_plugins/displays/display_test_fixture.cpp
test/rviz_default_plugins/displays/marker/marker_messages.cpp
test/rviz_default_plugins/scene_graph_introspection_helper.cpp
APPEND_ENV AMENT_PREFIX_PATH=${CMAKE_INSTALL_PREFIX} PATH=${CMAKE_INSTALL_PREFIX}/bin;${CMAKE_INSTALL_PREFIX}/opt/rviz_assimp_vendor/bin;${CMAKE_INSTALL_PREFIX}/opt/rviz_yaml_cpp_vendor/bin;${CMAKE_INSTALL_PREFIX}/opt/rviz_ogre_vendor/bin)
if(TARGET marker_display_test)
target_include_directories(marker_display_test PUBLIC
if(TARGET marker_common_test)
target_include_directories(marker_common_test PUBLIC
${TEST_INCLUDE_DIRS})
target_link_libraries(marker_display_test
target_link_libraries(marker_common_test
${TEST_LINK_LIBRARIES})
endif()

Expand Down Expand Up @@ -559,6 +564,21 @@ if(EnableVisualTests STREQUAL "True")
rviz_visual_testing_framework::rviz_visual_testing_framework)
endif()

ament_add_gtest(marker_array_display_visual_test
test/rviz_default_plugins/displays/marker_array/marker_array_display_visual_test.cpp
test/rviz_default_plugins/page_objects/marker_array_display_page_object.cpp
test/rviz_default_plugins/page_objects/marker_display_page_object.cpp
test/rviz_default_plugins/publishers/marker_array_publisher.hpp
TIMEOUT 180)
if(TARGET marker_array_display_visual_test)
target_include_directories(marker_array_display_visual_test PUBLIC
${TEST_INCLUDE_DIRS}
${rviz_visual_testing_framework_INCLUDE_DIRS})
target_link_libraries(marker_array_display_visual_test
${TEST_LINK_LIBRARIES}
rviz_visual_testing_framework::rviz_visual_testing_framework)
endif()

ament_add_gtest(marker_display_visual_test
test/rviz_default_plugins/displays/marker/marker_display_visual_test.cpp
test/rviz_default_plugins/page_objects/marker_display_page_object.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/*
* Copyright (c) 2008, Willow Garage, Inc.
* Copyright (c) 2018, Bosch Software Innovations GmbH.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Willow Garage, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef RVIZ_DEFAULT_PLUGINS__DISPLAYS__MARKER__MARKER_COMMON_HPP_
#define RVIZ_DEFAULT_PLUGINS__DISPLAYS__MARKER__MARKER_COMMON_HPP_

#include <map>
#include <memory>
#include <mutex>
#include <set>
#include <string>
#include <vector>
#include <utility>

#include <OgreSceneNode.h>

#include "visualization_msgs/msg/marker.hpp"
#include "visualization_msgs/msg/marker_array.hpp"

#include "rviz_common/properties/bool_property.hpp"
#include "rviz_common/properties/status_property.hpp"
#include "rviz_common/interaction/forwards.hpp"

#include "rviz_default_plugins/visibility_control.hpp"

namespace rviz_common
{
class Display;
class DisplayContext;
class QueueSizeProperty;

namespace properties
{
class IntProperty;
}
} // namespace rviz_common

using rviz_common::properties::StatusLevel;

namespace rviz_default_plugins
{
namespace displays
{
class MarkerNamespace;

namespace markers
{
class MarkerBase;
class MarkerSelectionHandler;
class MarkerFactory;
}

typedef std::shared_ptr<markers::MarkerSelectionHandler> MarkerSelectionHandlerPtr;
typedef std::shared_ptr<markers::MarkerBase> MarkerBasePtr;
typedef std::pair<std::string, int32_t> MarkerID;

/**
* \class MarkerCommon
* Common code shared by MarkerDisplay and MarkerArrayDisplay
*/
class RVIZ_DEFAULT_PLUGINS_PUBLIC MarkerCommon
{
public:
explicit MarkerCommon(rviz_common::Display * display);
~MarkerCommon();

void initialize(rviz_common::DisplayContext * context, Ogre::SceneNode * scene_node);
void load(const rviz_common::Config & config);

void update(float wall_dt, float ros_dt);

void deleteMarker(MarkerID id);

/** @brief Add a new message to the queue, will be drawn on the next update(). */
void addMessage(visualization_msgs::msg::Marker::ConstSharedPtr marker);
void addMessage(visualization_msgs::msg::MarkerArray::ConstSharedPtr array);

/**
* \brief Processes a marker message
* @param message The message to process
*/
void processMessage(visualization_msgs::msg::Marker::ConstSharedPtr message);

/**
* \brief Removes all the markers
*/
void clearMarkers();

/** @brief Delete all known markers to this plugin, regardless of id or namespace **/
void deleteAllMarkers();

void setMarkerStatus(MarkerID id, StatusLevel level, const std::string & text);
void deleteMarkerStatus(MarkerID id);

private:
/** @brief Delete all the markers within the given namespace. */
void deleteMarkersInNamespace(const std::string & ns);

/**
* \brief Processes an "Add" marker message
* @param message The message to process
*/
void processAdd(visualization_msgs::msg::Marker::ConstSharedPtr message);
/**
* \brief Processes a "Delete" marker message
* @param message The message to process
*/
void processDelete(visualization_msgs::msg::Marker::ConstSharedPtr message);

typedef std::vector<visualization_msgs::msg::Marker::ConstSharedPtr> V_MarkerMessage;
V_MarkerMessage takeSnapshotOfMessageQueue();
void processNewMessages(const V_MarkerMessage & local_queue);
void removeExpiredMarkers();

void updateMarkersWithLockedFrame() const;
QHash<QString, MarkerNamespace *>::const_iterator getMarkerNamespace(
const visualization_msgs::msg::Marker::ConstSharedPtr & message);
MarkerBasePtr createOrGetOldMarker(
const visualization_msgs::msg::Marker::ConstSharedPtr & message);
MarkerBasePtr createMarker(const visualization_msgs::msg::Marker::ConstSharedPtr & message);
void configureMarker(
const visualization_msgs::msg::Marker::ConstSharedPtr & message, MarkerBasePtr & marker);

typedef std::map<MarkerID, MarkerBasePtr> M_IDToMarker;
typedef std::set<MarkerBasePtr> S_MarkerBase;
M_IDToMarker markers_; ///< Map of marker id to the marker info structure
S_MarkerBase markers_with_expiration_;
S_MarkerBase frame_locked_markers_;
///< Marker message queue. Messages are added to this as they are received, and then processed
///< in our update() function
V_MarkerMessage message_queue_;
std::mutex queue_mutex_;

typedef QHash<QString, MarkerNamespace *> M_Namespace;
M_Namespace namespaces_;

rviz_common::properties::Property * namespaces_category_;

typedef std::map<QString, bool> M_EnabledState;
M_EnabledState namespace_config_enabled_state_;

std::unique_ptr<markers::MarkerFactory> marker_factory_;

rviz_common::Display * display_;
rviz_common::DisplayContext * context_;
Ogre::SceneNode * scene_node_;

friend class MarkerNamespace;
};

/** @brief Manager of a single marker namespace. Keeps a hash from
* marker IDs to MarkerBasePtr, and creates or destroys them when necessary. */
class RVIZ_DEFAULT_PLUGINS_PUBLIC MarkerNamespace : public rviz_common::properties::BoolProperty
{
Q_OBJECT

public:
MarkerNamespace(
const QString & name,
rviz_common::properties::Property * parent_property,
MarkerCommon * owner
);
bool isEnabled() const {return getBool();}

public Q_SLOTS:
void onEnableChanged();

private:
MarkerCommon * owner_;
};

} // namespace displays
} // namespace rviz_default_plugins

#endif // RVIZ_DEFAULT_PLUGINS__DISPLAYS__MARKER__MARKER_COMMON_HPP_
Loading

0 comments on commit 467164b

Please sign in to comment.