From 07ba1db6d720b5a9cba4e3c5efd5c84d953db469 Mon Sep 17 00:00:00 2001 From: tutuna Date: Thu, 22 Jun 2023 09:18:13 +0200 Subject: [PATCH] Conversion of Rviz Plugin to Ros 1, currently building successfully. --- nvblox_rviz_plugin/CMakeLists.txt | 112 +++++++++--------- .../nvblox_rviz_plugin/nvblox_hash_utils.h | 4 +- .../nvblox_rviz_plugin/nvblox_mesh_display.h | 22 ++-- .../nvblox_rviz_plugin/nvblox_mesh_visual.h | 18 ++- nvblox_rviz_plugin/package.xml | 23 ++-- nvblox_rviz_plugin/plugins_description.xml | 4 +- .../src/nvblox_mesh_display.cpp | 23 ++-- nvblox_rviz_plugin/src/nvblox_mesh_visual.cpp | 19 ++- 8 files changed, 117 insertions(+), 108 deletions(-) diff --git a/nvblox_rviz_plugin/CMakeLists.txt b/nvblox_rviz_plugin/CMakeLists.txt index 641bd6f..99dd5c7 100644 --- a/nvblox_rviz_plugin/CMakeLists.txt +++ b/nvblox_rviz_plugin/CMakeLists.txt @@ -21,10 +21,11 @@ project(nvblox_rviz_plugin) # Default to C++17 if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) endif() if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") - add_compile_options(-Wall -Wextra -Wpedantic) + add_compile_options(-Wall -Wextra -Wpedantic -O3) endif() # Default to release build @@ -37,17 +38,37 @@ message( STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}" ) ## This setting causes Qt's "MOC" generation to happen automatically. set(CMAKE_AUTOMOC ON) -# find dependencies -find_package(ament_cmake REQUIRED) -find_package(rviz_common REQUIRED) -find_package(rviz_rendering REQUIRED) -find_package(rviz_ogre_vendor REQUIRED) -find_package(Qt5 REQUIRED COMPONENTS Widgets) -find_package(rviz_default_plugins REQUIRED) -find_package(nvblox_msgs REQUIRED) -find_package(pluginlib REQUIRED) +find_package(catkin REQUIRED COMPONENTS + rviz + pluginlib + nvblox_msgs + std_msgs + geometry_msgs +) + +# QT5 +find_package(Qt5 COMPONENTS Widgets REQUIRED) + +catkin_package( + INCLUDE_DIRS + include + LIBRARIES + ${PROJECT_NAME} + Qt5::Widgets + CATKIN_DEPENDS + rviz + pluginlib + nvblox_msgs + std_msgs + geometry_msgs +) -include_directories(include) +include_directories( + include + ${catkin_INCLUDE_DIRS} + ${QT_INCLUDE_DIRS} + ${CMAKE_CURRENT_BINARY_DIR} + ) ############# # LIBRARIES # @@ -59,59 +80,42 @@ add_library(${PROJECT_NAME} SHARED src/nvblox_mesh_display.cpp src/nvblox_mesh_visual.cpp ) -target_link_libraries(${PROJECT_NAME} PUBLIC - rviz_ogre_vendor::OgreMain - rviz_ogre_vendor::OgreOverlay -) -ament_target_dependencies(${PROJECT_NAME} PUBLIC - nvblox_msgs - rviz_common - rviz_rendering - pluginlib - rviz_ogre_vendor - rviz_default_plugins -) - -target_compile_definitions(${PROJECT_NAME} PRIVATE "RVIZ_DEFAULT_PLUGINS_BUILDING_LIBRARY") +add_dependencies(${PROJECT_NAME} + ${catkin_EXPORTED_TARGETS} +) -# prevent pluginlib from using boost -target_compile_definitions(${PROJECT_NAME} PUBLIC "PLUGINLIB__DISABLE_BOOST_FUNCTIONS") +target_include_directories(${PROJECT_NAME} PUBLIC + ${catkin_INCLUDE_DIRS} +) +target_link_libraries(${PROJECT_NAME} PUBLIC + Qt5::Widgets + ${catkin_LIBRARIES} +) ########## # EXPORT # ########## -ament_export_include_directories(include) -ament_export_targets(${PROJECT_NAME} HAS_LIBRARY_TARGET) -ament_export_dependencies( - Qt5 - rviz_common - rviz_rendering - rviz_ogre_vendor - rviz_default_plugins - rclcpp - nvblox_msgs -) +# prevent pluginlib from using boost +target_compile_definitions(${PROJECT_NAME} PUBLIC "PLUGINLIB__DISABLE_BOOST_FUNCTIONS") install( - TARGETS ${PROJECT_NAME} - EXPORT ${PROJECT_NAME} - ARCHIVE DESTINATION lib - LIBRARY DESTINATION lib - RUNTIME DESTINATION bin - INCLUDES DESTINATION include -) + FILES plugins_description.xml + DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}) install( - DIRECTORY include/ - DESTINATION include -) + DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/icons" + DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}) install( - DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/icons" - DESTINATION "share/${PROJECT_NAME}" -) - -pluginlib_export_plugin_description_file(rviz_common plugins_description.xml) + DIRECTORY include/${PROJECT_NAME}/ + DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}) -ament_package() +install( + TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME} + ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} + INCLUDES DESTINATION include/${PROJECT_NAME}/ +) \ No newline at end of file diff --git a/nvblox_rviz_plugin/include/nvblox_rviz_plugin/nvblox_hash_utils.h b/nvblox_rviz_plugin/include/nvblox_rviz_plugin/nvblox_hash_utils.h index aded6b5..caf0003 100644 --- a/nvblox_rviz_plugin/include/nvblox_rviz_plugin/nvblox_hash_utils.h +++ b/nvblox_rviz_plugin/include/nvblox_rviz_plugin/nvblox_hash_utils.h @@ -22,14 +22,14 @@ #include #include -#include +#include namespace nvblox_rviz_plugin { // Minimal functions taken from nvblox/core/hash.h to remove dependency and // uses the ROS types instead. -typedef nvblox_msgs::msg::Index3D Index3D; +typedef nvblox_msgs::Index3D Index3D; /** * Performs deco hashing on block indexes. Based on recommendations of diff --git a/nvblox_rviz_plugin/include/nvblox_rviz_plugin/nvblox_mesh_display.h b/nvblox_rviz_plugin/include/nvblox_rviz_plugin/nvblox_mesh_display.h index ceb305f..690af05 100644 --- a/nvblox_rviz_plugin/include/nvblox_rviz_plugin/nvblox_mesh_display.h +++ b/nvblox_rviz_plugin/include/nvblox_rviz_plugin/nvblox_mesh_display.h @@ -19,12 +19,12 @@ #include -#include -#include -#include -#include +#include +#include +#include +#include -#include +#include #include "nvblox_rviz_plugin/nvblox_mesh_visual.h" @@ -32,8 +32,7 @@ namespace nvblox_rviz_plugin { class NvbloxMeshVisual; -class __attribute__((visibility("default"))) NvbloxMeshDisplay - : public rviz_common::MessageFilterDisplay { +class NvbloxMeshDisplay : public rviz::MessageFilterDisplay { Q_OBJECT public: NvbloxMeshDisplay(); @@ -50,12 +49,11 @@ class __attribute__((visibility("default"))) NvbloxMeshDisplay virtual void reset(); private: - void processMessage( - const nvblox_msgs::msg::Mesh::ConstSharedPtr msg) override; + void processMessage(const nvblox_msgs::Mesh::ConstPtr& msg) override; - rviz_common::properties::BoolProperty* cut_ceiling_property_; - rviz_common::properties::FloatProperty* ceiling_height_property_; - rviz_common::properties::EnumProperty* mesh_color_property_; + rviz::BoolProperty* cut_ceiling_property_; + rviz::FloatProperty* ceiling_height_property_; + rviz::EnumProperty* mesh_color_property_; std::unique_ptr visual_; }; diff --git a/nvblox_rviz_plugin/include/nvblox_rviz_plugin/nvblox_mesh_visual.h b/nvblox_rviz_plugin/include/nvblox_rviz_plugin/nvblox_mesh_visual.h index c5b9463..15f3b45 100644 --- a/nvblox_rviz_plugin/include/nvblox_rviz_plugin/nvblox_mesh_visual.h +++ b/nvblox_rviz_plugin/include/nvblox_rviz_plugin/nvblox_mesh_visual.h @@ -17,9 +17,15 @@ #pragma once -#include +#include +#include +#include +#include +#include -#include +#include +#include +#include #include "nvblox_rviz_plugin/nvblox_hash_utils.h" @@ -34,7 +40,7 @@ class NvbloxMeshVisual { Ogre::SceneNode* parent_node); virtual ~NvbloxMeshVisual(); - void setMessage(const nvblox_msgs::msg::Mesh::ConstSharedPtr& msg); + void setMessage(const nvblox_msgs::Mesh::ConstPtr& msg); /// Set the coordinate frame pose. void setFramePosition(const Ogre::Vector3& position); @@ -49,9 +55,9 @@ class NvbloxMeshVisual { const Ogre::Vector3& light, const Ogre::Vector3& color) const; - std_msgs::msg::ColorRGBA getMeshColorFromColorAndNormal( - const std_msgs::msg::ColorRGBA& color, - const geometry_msgs::msg::Point32& normal) const; + std_msgs::ColorRGBA getMeshColorFromColorAndNormal( + const std_msgs::ColorRGBA& color, + const geometry_msgs::Point32& normal) const; Ogre::SceneNode* frame_node_; Ogre::SceneManager* scene_manager_; diff --git a/nvblox_rviz_plugin/package.xml b/nvblox_rviz_plugin/package.xml index 32f4fb6..725c1bb 100644 --- a/nvblox_rviz_plugin/package.xml +++ b/nvblox_rviz_plugin/package.xml @@ -24,21 +24,28 @@ 0.31.0 RViz visualization plugin for Nvblox meshes - Helen Oleynikova + Helen Oleynikova + Turcan Tuna Apache-2.0 https://developer.nvidia.com/isaac-ros/ Helen Oleynikova Alexander Millane - ament_cmake + catkin - nvblox_msgs - pluginlib - rviz_common - rviz_ogre_vendor - rviz_rendering + nvblox_msgs + pluginlib + rviz + geometry_msgs + std_msgs + + pluginlib + rviz + nvblox_msgs + geometry_msgs + std_msgs - ament_cmake + diff --git a/nvblox_rviz_plugin/plugins_description.xml b/nvblox_rviz_plugin/plugins_description.xml index 3ec52cc..93bd198 100644 --- a/nvblox_rviz_plugin/plugins_description.xml +++ b/nvblox_rviz_plugin/plugins_description.xml @@ -1,8 +1,8 @@ - + Displays incremental nvblox mesh messages. diff --git a/nvblox_rviz_plugin/src/nvblox_mesh_display.cpp b/nvblox_rviz_plugin/src/nvblox_mesh_display.cpp index b142629..7ab509d 100644 --- a/nvblox_rviz_plugin/src/nvblox_mesh_display.cpp +++ b/nvblox_rviz_plugin/src/nvblox_mesh_display.cpp @@ -15,25 +15,25 @@ // // SPDX-License-Identifier: Apache-2.0 -#include -#include +#include +#include #include "nvblox_rviz_plugin/nvblox_mesh_display.h" namespace nvblox_rviz_plugin { NvbloxMeshDisplay::NvbloxMeshDisplay() { - cut_ceiling_property_ = new rviz_common::properties::BoolProperty( + cut_ceiling_property_ = new rviz::BoolProperty( "Cut Ceiling", false, "If set to true, will not visualize anything above a certain z value.", this, SLOT(updateCeilingOptions())); - ceiling_height_property_ = new rviz_common::properties::FloatProperty( + ceiling_height_property_ = new rviz::FloatProperty( "Ceiling Height", 0.0, "Height above which the visualization will be cut off.", this, SLOT(updateCeilingOptions())); - mesh_color_property_ = new rviz_common::properties::EnumProperty( + mesh_color_property_ = new rviz::EnumProperty( "Mesh Color", "Color + Shading", "How to color the displayed mesh.", this, SLOT(updateMeshColorOptions())); @@ -68,8 +68,7 @@ void NvbloxMeshDisplay::reset() { visual_.reset(); } -void NvbloxMeshDisplay::processMessage( - const nvblox_msgs::msg::Mesh::ConstSharedPtr msg) { +void NvbloxMeshDisplay::processMessage(const nvblox_msgs::Mesh::ConstPtr& msg) { // Here we call the rviz::FrameManager to get the transform from the // fixed frame to the frame in the header of this Imu message. If // it fails, we can't do anything else so we return. @@ -77,15 +76,13 @@ void NvbloxMeshDisplay::processMessage( Ogre::Vector3 position; if (!context_->getFrameManager()->getTransform( msg->header.frame_id, msg->header.stamp, position, orientation)) { - RCLCPP_ERROR(rclcpp::get_logger("nvblox"), - "Error transforming from frame '%s' to frame '%s'", + ROS_ERROR("Error transforming from frame '%s' to frame '%s'", msg->header.frame_id.c_str(), qPrintable(fixed_frame_)); return; } if (visual_ == nullptr) { - visual_.reset( - new NvbloxMeshVisual(context_->getSceneManager(), scene_node_)); + visual_.reset(new NvbloxMeshVisual(context_->getSceneManager(), scene_node_)); visual_->setCeilingCutoff(cut_ceiling_property_->getBool(), ceiling_height_property_->getFloat()); visual_->setMeshColor(static_cast( @@ -100,6 +97,6 @@ void NvbloxMeshDisplay::processMessage( } // namespace nvblox_rviz_plugin -#include +#include PLUGINLIB_EXPORT_CLASS(nvblox_rviz_plugin::NvbloxMeshDisplay, - rviz_common::Display) + rviz::Display) diff --git a/nvblox_rviz_plugin/src/nvblox_mesh_visual.cpp b/nvblox_rviz_plugin/src/nvblox_mesh_visual.cpp index c591ee6..6fd6d7f 100644 --- a/nvblox_rviz_plugin/src/nvblox_mesh_visual.cpp +++ b/nvblox_rviz_plugin/src/nvblox_mesh_visual.cpp @@ -18,9 +18,6 @@ #include #include -#include -#include - #include "nvblox_rviz_plugin/nvblox_mesh_visual.h" namespace nvblox_rviz_plugin { @@ -71,10 +68,10 @@ Ogre::Vector3 NvbloxMeshVisual::lambertShading( return std::max(normal.dotProduct(light), 0.0f) * color; } -std_msgs::msg::ColorRGBA NvbloxMeshVisual::getMeshColorFromColorAndNormal( - const std_msgs::msg::ColorRGBA& color, - const geometry_msgs::msg::Point32& normal) const { - std_msgs::msg::ColorRGBA output_color; +std_msgs::ColorRGBA NvbloxMeshVisual::getMeshColorFromColorAndNormal( + const std_msgs::ColorRGBA& color, + const geometry_msgs::Point32& normal) const { + std_msgs::ColorRGBA output_color; output_color.a = 1.0f; if (mesh_color_ == MeshColor::kColor) { output_color = color; @@ -104,7 +101,7 @@ std_msgs::msg::ColorRGBA NvbloxMeshVisual::getMeshColorFromColorAndNormal( } void NvbloxMeshVisual::setMessage( - const nvblox_msgs::msg::Mesh::ConstSharedPtr& msg) { + const nvblox_msgs::Mesh::ConstPtr& msg) { block_size_ = msg->block_size; // First, check if we need to clear the existing map. @@ -117,8 +114,8 @@ void NvbloxMeshVisual::setMessage( // Iterate over all the blocks in the message and make sure to add them. for (size_t i = 0; i < msg->block_indices.size(); i++) { - const nvblox_msgs::msg::Index3D& block_index = msg->block_indices[i]; - const nvblox_msgs::msg::MeshBlock& mesh_block = msg->blocks[i]; + const nvblox_msgs::Index3D& block_index = msg->block_indices[i]; + const nvblox_msgs::MeshBlock& mesh_block = msg->blocks[i]; // create ogre object Ogre::ManualObject* ogre_object; @@ -167,7 +164,7 @@ void NvbloxMeshVisual::setMessage( ogre_object->normal(mesh_block.normals[i].x, mesh_block.normals[i].y, mesh_block.normals[i].z); - std_msgs::msg::ColorRGBA color; + std_msgs::ColorRGBA color; if (!mesh_block.colors.empty()) { color = mesh_block.colors[i]; }