Skip to content

Commit

Permalink
Conversion of Rviz Plugin to Ros 1, currently building successfully.
Browse files Browse the repository at this point in the history
  • Loading branch information
tutunarsl committed Jun 22, 2023
1 parent f400112 commit 07ba1db
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 108 deletions.
112 changes: 58 additions & 54 deletions nvblox_rviz_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 #
Expand All @@ -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}/
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
#include <unordered_set>
#include <utility>

#include <nvblox_msgs/msg/index3_d.hpp>
#include <nvblox_msgs/Index3D.h>

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
Expand Down
22 changes: 10 additions & 12 deletions nvblox_rviz_plugin/include/nvblox_rviz_plugin/nvblox_mesh_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,20 @@

#include <memory>

#include <rviz_common/message_filter_display.hpp>
#include <rviz_common/properties/bool_property.hpp>
#include <rviz_common/properties/enum_property.hpp>
#include <rviz_common/properties/float_property.hpp>
#include <rviz/message_filter_display.h>
#include <rviz/properties/bool_property.h>
#include <rviz/properties/enum_property.h>
#include <rviz/properties/float_property.h>

#include <nvblox_msgs/msg/mesh.hpp>
#include <nvblox_msgs/Mesh.h>

#include "nvblox_rviz_plugin/nvblox_mesh_visual.h"

namespace nvblox_rviz_plugin {

class NvbloxMeshVisual;

class __attribute__((visibility("default"))) NvbloxMeshDisplay
: public rviz_common::MessageFilterDisplay<nvblox_msgs::msg::Mesh> {
class NvbloxMeshDisplay : public rviz::MessageFilterDisplay<nvblox_msgs::Mesh> {
Q_OBJECT
public:
NvbloxMeshDisplay();
Expand All @@ -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<NvbloxMeshVisual> visual_;
};
Expand Down
18 changes: 12 additions & 6 deletions nvblox_rviz_plugin/include/nvblox_rviz_plugin/nvblox_mesh_visual.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@

#pragma once

#include <OgreManualObject.h>
#include <OGRE/OgreManualObject.h>
#include <OGRE/OgreQuaternion.h>
#include <OGRE/OgreSceneManager.h>
#include <OGRE/OgreSceneNode.h>
#include <OGRE/OgreVector3.h>

#include <nvblox_msgs/msg/mesh.hpp>
#include <std_msgs/ColorRGBA.h>
#include <geometry_msgs/Point32.h>
#include <nvblox_msgs/Mesh.h>

#include "nvblox_rviz_plugin/nvblox_hash_utils.h"

Expand All @@ -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);
Expand All @@ -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_;
Expand Down
23 changes: 15 additions & 8 deletions nvblox_rviz_plugin/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,28 @@
<version>0.31.0</version>
<description>RViz visualization plugin for Nvblox meshes</description>

<maintainer email="[email protected]">Helen Oleynikova</maintainer>
<maintainer email="[email protected]">Helen Oleynikova</maintainer>
<maintainer email="[email protected]">Turcan Tuna</maintainer>
<license>Apache-2.0</license>
<url type="website">https://developer.nvidia.com/isaac-ros/</url>
<author>Helen Oleynikova</author>
<author>Alexander Millane</author>

<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>catkin</buildtool_depend>

<depend>nvblox_msgs</depend>
<depend>pluginlib</depend>
<depend>rviz_common</depend>
<depend>rviz_ogre_vendor</depend>
<depend>rviz_rendering</depend>
<build_depend>nvblox_msgs</build_depend>
<build_depend>pluginlib</build_depend>
<build_depend>rviz</build_depend>
<build_depend>geometry_msgs</build_depend>
<build_depend>std_msgs</build_depend>

<exec_depend>pluginlib</exec_depend>
<exec_depend>rviz</exec_depend>
<exec_depend>nvblox_msgs</exec_depend>
<exec_depend>geometry_msgs</exec_depend>
<exec_depend>std_msgs</exec_depend>

<export>
<build_type>ament_cmake</build_type>
<rviz plugin="${prefix}/plugins_description.xml"/>
</export>
</package>
4 changes: 2 additions & 2 deletions nvblox_rviz_plugin/plugins_description.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<library path="nvblox_rviz_plugin">
<library path="libnvblox_rviz_plugin">
<class
name="nvblox_rviz_plugin/NvbloxMesh"
type="nvblox_rviz_plugin::NvbloxMeshDisplay"
base_class_type="rviz_common::Display"
base_class_type="rviz::Display"
>
<description>
Displays incremental nvblox mesh messages.
Expand Down
23 changes: 10 additions & 13 deletions nvblox_rviz_plugin/src/nvblox_mesh_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@
//
// SPDX-License-Identifier: Apache-2.0

#include <rviz_common/frame_manager_iface.hpp>
#include <rviz_common/visualization_manager.hpp>
#include <rviz/frame_manager.h>
#include <rviz/visualization_manager.h>

#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()));

Expand Down Expand Up @@ -68,24 +68,21 @@ 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.
Ogre::Quaternion orientation;
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<NvbloxMeshVisual::MeshColor>(
Expand All @@ -100,6 +97,6 @@ void NvbloxMeshDisplay::processMessage(

} // namespace nvblox_rviz_plugin

#include <pluginlib/class_list_macros.hpp>
#include <pluginlib/class_list_macros.h>
PLUGINLIB_EXPORT_CLASS(nvblox_rviz_plugin::NvbloxMeshDisplay,
rviz_common::Display)
rviz::Display)
Loading

0 comments on commit 07ba1db

Please sign in to comment.