Skip to content

Commit

Permalink
Make fade out distance configurable (ros#674)
Browse files Browse the repository at this point in the history
  • Loading branch information
spielawa authored and wally-the-cartographer committed Jan 22, 2018
1 parent 7cc4fec commit f61e513
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
14 changes: 6 additions & 8 deletions cartographer_rviz/cartographer_rviz/drawable_submap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ namespace cartographer_rviz {
namespace {

constexpr std::chrono::milliseconds kMinQueryDelayInMs(250);

// Distance before which the submap will be shown at full opacity, and distance
// over which the submap will then fade out.
constexpr double kFadeOutStartDistanceInMeters = 1.;
constexpr double kFadeOutDistanceInMeters = 2.;
constexpr float kAlphaUpdateThreshold = 0.2f;

const Ogre::ColourValue kSubmapIdColor(Ogre::ColourValue::Red);
Expand Down Expand Up @@ -154,13 +149,16 @@ bool DrawableSubmap::QueryInProgress() {
return query_in_progress_;
}

void DrawableSubmap::SetAlpha(const double current_tracking_z) {
void DrawableSubmap::SetAlpha(const double current_tracking_z,
const float fade_out_start_distance_in_meters) {
const float fade_out_distance_in_meters =
2.f * fade_out_start_distance_in_meters;
const double distance_z =
std::abs(pose_.translation().z() - current_tracking_z);
const double fade_distance =
std::max(distance_z - kFadeOutStartDistanceInMeters, 0.);
std::max(distance_z - fade_out_start_distance_in_meters, 0.);
const float target_alpha = static_cast<float>(
std::max(0., 1. - fade_distance / kFadeOutDistanceInMeters));
std::max(0., 1. - fade_distance / fade_out_distance_in_meters));

if (std::abs(target_alpha - current_alpha_) > kAlphaUpdateThreshold ||
target_alpha == 0.f || target_alpha == 1.f) {
Expand Down
6 changes: 4 additions & 2 deletions cartographer_rviz/cartographer_rviz/drawable_submap.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ class DrawableSubmap : public QObject {
bool QueryInProgress();

// Sets the alpha of the submap taking into account its slice height and the
// 'current_tracking_z'.
void SetAlpha(double current_tracking_z);
// 'current_tracking_z'. 'fade_out_start_distance_in_meters' defines the
// distance in z direction in meters, before which the submap will be shown
// at full opacity.
void SetAlpha(double current_tracking_z, float fade_out_distance_in_meters);

// Sets the visibility of a slice. It will be drawn if the parent submap
// is also visible.
Expand Down
8 changes: 7 additions & 1 deletion cartographer_rviz/cartographer_rviz/submaps_display.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ SubmapsDisplay::SubmapsDisplay() : tf_listener_(tf_buffer_) {
"All", true,
"Whether submaps from all trajectories should be displayed or not.",
trajectories_category_, SLOT(AllEnabledToggled()), this);
fade_out_start_distance_in_meters_ =
new ::rviz::FloatProperty("Fade-out distance", 1.f,
"Distance in meters in z-direction beyond "
"which submaps will start to fade out.",
this);
const std::string package_path = ::ros::package::getPath(ROS_PACKAGE_NAME);
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
package_path + kMaterialsDirectory, "FileSystem", ROS_PACKAGE_NAME);
Expand Down Expand Up @@ -208,7 +213,8 @@ void SubmapsDisplay::update(const float wall_dt, const float ros_dt) {
for (auto& trajectory : trajectories_) {
for (auto& submap_entry : trajectory->submaps) {
submap_entry.second->SetAlpha(
transform_stamped.transform.translation.z);
transform_stamped.transform.translation.z,
fade_out_start_distance_in_meters_->getFloat());
}
}
} catch (const tf2::TransformException& ex) {
Expand Down
3 changes: 3 additions & 0 deletions cartographer_rviz/cartographer_rviz/submaps_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "cartographer_ros_msgs/SubmapList.h"
#include "cartographer_rviz/drawable_submap.h"
#include "rviz/message_filter_display.h"
#include "rviz/properties/bool_property.h"
#include "rviz/properties/float_property.h"
#include "tf2_ros/buffer.h"
#include "tf2_ros/transform_listener.h"

Expand Down Expand Up @@ -93,6 +95,7 @@ class SubmapsDisplay
::rviz::BoolProperty* slice_low_resolution_enabled_;
::rviz::Property* trajectories_category_;
::rviz::BoolProperty* visibility_all_enabled_;
::rviz::FloatProperty* fade_out_start_distance_in_meters_;
};

} // namespace cartographer_rviz
Expand Down

0 comments on commit f61e513

Please sign in to comment.