36
36
#include < OgreSceneNode.h>
37
37
38
38
#include < deque>
39
+ #include < limits>
39
40
#include < memory>
40
41
#include < vector>
41
42
@@ -60,24 +61,28 @@ std::unique_ptr<Ogre::ColourValue> gradation(
60
61
}
61
62
62
63
std::unique_ptr<Ogre::ColourValue> setColorDependsOnVelocity (
63
- const double vel_max, const double cmd_vel)
64
+ const double vel_max, const double cmd_vel,
65
+ const rviz_common::properties::ColorProperty & color_min,
66
+ const rviz_common::properties::ColorProperty & color_mid,
67
+ const rviz_common::properties::ColorProperty & color_max)
64
68
{
65
69
const double cmd_vel_abs = std::fabs (cmd_vel);
66
70
const double vel_min = 0.0 ;
67
71
68
72
std::unique_ptr<Ogre::ColourValue> color_ptr (new Ogre::ColourValue ());
69
73
if (vel_min < cmd_vel_abs && cmd_vel_abs <= (vel_max / 2.0 )) {
70
74
double ratio = (cmd_vel_abs - vel_min) / (vel_max / 2.0 - vel_min);
71
- color_ptr = gradation (Qt::red, Qt::yellow , ratio);
75
+ color_ptr = gradation (color_min. getColor (), color_mid. getColor () , ratio);
72
76
} else if ((vel_max / 2.0 ) < cmd_vel_abs && cmd_vel_abs <= vel_max) {
73
77
double ratio = (cmd_vel_abs - vel_max / 2.0 ) / (vel_max - vel_max / 2.0 );
74
- color_ptr = gradation (Qt::yellow, Qt::green , ratio);
78
+ color_ptr = gradation (color_mid. getColor (), color_max. getColor () , ratio);
75
79
} else if (vel_max < cmd_vel_abs) {
76
- *color_ptr = Ogre::ColourValue::Green;
80
+ // Use max color when velocity exceeds max
81
+ *color_ptr = rviz_common::properties::qtToOgre (color_max.getColor ());
77
82
} else {
78
- *color_ptr = Ogre::ColourValue::Red;
83
+ // Use min color when velocity is below min
84
+ *color_ptr = rviz_common::properties::qtToOgre (color_min.getColor ());
79
85
}
80
-
81
86
return color_ptr;
82
87
}
83
88
@@ -109,8 +114,10 @@ class AutowarePathBaseDisplay : public rviz_common::MessageFilterDisplay<T>
109
114
property_path_width_view_{" Constant Width" , false , " " , &property_path_view_},
110
115
property_path_width_{" Width" , 2.0 , " " , &property_path_view_},
111
116
property_path_alpha_{" Alpha" , 1.0 , " " , &property_path_view_},
112
- property_path_color_view_{" Constant Color" , false , " " , &property_path_view_},
113
- property_path_color_{" Color" , Qt::black, " " , &property_path_view_},
117
+ property_min_color_ (" Min Velocity Color" , QColor(" #3F2EE3" ), " " , &property_path_view_),
118
+ property_mid_color_ (" Mid Velocity Color" , QColor(" #208AAE" ), " " , &property_path_view_),
119
+ property_max_color_ (" Max Velocity Color" , QColor(" #00E678" ), " " , &property_path_view_),
120
+ property_fade_out_distance_{" Fade Out Distance" , 0.0 , " [m]" , &property_path_view_},
114
121
property_vel_max_{" Color Border Vel Max" , 3.0 , " [m/s]" , this },
115
122
// velocity
116
123
property_velocity_view_{" View Velocity" , true , " " , this },
@@ -356,6 +363,34 @@ class AutowarePathBaseDisplay : public rviz_common::MessageFilterDisplay<T>
356
363
const float right = property_path_width_view_.getBool () ? property_path_width_.getFloat () / 2.0
357
364
: info->width / 2.0 ;
358
365
366
+ // Initialize alphas with the default alpha value
367
+ std::vector<float > alphas (msg_ptr->points .size (), property_path_alpha_.getFloat ());
368
+
369
+ // Backward iteration to adjust alpha values for the last x meters
370
+ if (property_fade_out_distance_.getFloat () > std::numeric_limits<float >::epsilon ()) {
371
+ alphas.back () = 0 .0f ;
372
+ float cumulative_distance = 0 .0f ;
373
+ for (size_t point_idx = msg_ptr->points .size () - 1 ; point_idx > 0 ; point_idx--) {
374
+ const auto & curr_point = autoware::universe_utils::getPose (msg_ptr->points .at (point_idx));
375
+ const auto & prev_point =
376
+ autoware::universe_utils::getPose (msg_ptr->points .at (point_idx - 1 ));
377
+ float distance = std::sqrt (autoware::universe_utils::calcSquaredDistance2d (
378
+ prev_point.position , curr_point.position ));
379
+ cumulative_distance += distance;
380
+
381
+ if (cumulative_distance <= property_fade_out_distance_.getFloat ()) {
382
+ auto ratio =
383
+ static_cast <float >(cumulative_distance / property_fade_out_distance_.getFloat ());
384
+ float alpha = property_path_alpha_.getFloat () * ratio;
385
+ alphas.at (point_idx - 1 ) = alpha;
386
+ } else {
387
+ // If the distance exceeds the fade out distance, break the loop
388
+ break ;
389
+ }
390
+ }
391
+ }
392
+
393
+ // Forward iteration to visualize path
359
394
for (size_t point_idx = 0 ; point_idx < msg_ptr->points .size (); point_idx++) {
360
395
const auto & path_point = msg_ptr->points .at (point_idx);
361
396
const auto & pose = autoware::universe_utils::getPose (path_point);
@@ -364,15 +399,14 @@ class AutowarePathBaseDisplay : public rviz_common::MessageFilterDisplay<T>
364
399
// path
365
400
if (property_path_view_.getBool ()) {
366
401
Ogre::ColourValue color;
367
- if (property_path_color_view_.getBool ()) {
368
- color = rviz_common::properties::qtToOgre (property_path_color_.getColor ());
369
- } else {
370
- // color change depending on velocity
371
- std::unique_ptr<Ogre::ColourValue> dynamic_color_ptr =
372
- setColorDependsOnVelocity (property_vel_max_.getFloat (), velocity);
373
- color = *dynamic_color_ptr;
374
- }
375
- color.a = property_path_alpha_.getFloat ();
402
+
403
+ // color change depending on velocity
404
+ std::unique_ptr<Ogre::ColourValue> dynamic_color_ptr = setColorDependsOnVelocity (
405
+ property_vel_max_.getFloat (), velocity, property_min_color_, property_mid_color_,
406
+ property_max_color_);
407
+ color = *dynamic_color_ptr;
408
+ color.a = alphas.at (point_idx);
409
+
376
410
Eigen::Vector3f vec_in;
377
411
Eigen::Vector3f vec_out;
378
412
Eigen::Quaternionf quat_yaw_reverse (0 , 0 , 0 , 1 );
@@ -413,8 +447,9 @@ class AutowarePathBaseDisplay : public rviz_common::MessageFilterDisplay<T>
413
447
color = rviz_common::properties::qtToOgre (property_velocity_color_.getColor ());
414
448
} else {
415
449
/* color change depending on velocity */
416
- std::unique_ptr<Ogre::ColourValue> dynamic_color_ptr =
417
- setColorDependsOnVelocity (property_vel_max_.getFloat (), velocity);
450
+ std::unique_ptr<Ogre::ColourValue> dynamic_color_ptr = setColorDependsOnVelocity (
451
+ property_vel_max_.getFloat (), velocity, property_min_color_, property_mid_color_,
452
+ property_max_color_);
418
453
color = *dynamic_color_ptr;
419
454
}
420
455
color.a = property_velocity_alpha_.getFloat ();
@@ -616,8 +651,13 @@ class AutowarePathBaseDisplay : public rviz_common::MessageFilterDisplay<T>
616
651
rviz_common::properties::BoolProperty property_path_width_view_;
617
652
rviz_common::properties::FloatProperty property_path_width_;
618
653
rviz_common::properties::FloatProperty property_path_alpha_;
619
- rviz_common::properties::BoolProperty property_path_color_view_;
620
- rviz_common::properties::ColorProperty property_path_color_;
654
+ // Gradient points for velocity color
655
+ rviz_common::properties::ColorProperty property_min_color_;
656
+ rviz_common::properties::ColorProperty property_mid_color_;
657
+ rviz_common::properties::ColorProperty property_max_color_;
658
+ // Last x meters of the path will fade out to transparent
659
+ rviz_common::properties::FloatProperty property_fade_out_distance_;
660
+
621
661
rviz_common::properties::FloatProperty property_vel_max_;
622
662
rviz_common::properties::BoolProperty property_velocity_view_;
623
663
rviz_common::properties::FloatProperty property_velocity_alpha_;
0 commit comments