@@ -40,7 +40,8 @@ void TrajectoryVisualizer::on_configure(
4040 getParam (time_step_, " time_step" , 3 );
4141 getParam (publish_optimal_trajectory_, " publish_optimal_trajectory" , false );
4242 getParam (publish_trajectories_with_total_cost_, " publish_trajectories_with_total_cost" , false );
43- getParam (publish_trajectories_with_individual_cost_, " publish_trajectories_with_individual_cost" , false );
43+ getParam (publish_trajectories_with_individual_cost_, " publish_trajectories_with_individual_cost" ,
44+ false );
4445
4546 reset ();
4647}
@@ -115,9 +116,9 @@ void TrajectoryVisualizer::add(
115116 const builtin_interfaces::msg::Time & cmd_stamp)
116117{
117118 // Check if we should visualize per-critic costs
118- bool visualize_per_critic = !individual_critics_cost.empty () &&
119- publish_trajectories_with_individual_cost_ &&
120- trajectories_publisher_->get_subscription_count () > 0 ;
119+ bool visualize_per_critic = !individual_critics_cost.empty () &&
120+ publish_trajectories_with_individual_cost_ &&
121+ trajectories_publisher_->get_subscription_count () > 0 ;
121122
122123 size_t n_rows = trajectories.x .rows ();
123124 size_t n_cols = trajectories.x .cols ();
@@ -128,91 +129,91 @@ void TrajectoryVisualizer::add(
128129 const Eigen::ArrayXf & costs,
129130 const std::string & ns,
130131 bool use_collision_coloring) {
131-
132+
132133 // Find min/max cost for normalization
133- float min_cost = std::numeric_limits<float >::max ();
134- float max_cost = std::numeric_limits<float >::lowest ();
135-
136- for (Eigen::Index i = 0 ; i < costs.size (); ++i) {
134+ float min_cost = std::numeric_limits<float >::max ();
135+ float max_cost = std::numeric_limits<float >::lowest ();
136+
137+ for (Eigen::Index i = 0 ; i < costs.size (); ++i) {
137138 // Skip collision trajectories for min/max calculation if using collision coloring
138- if (use_collision_coloring && costs (i) >= 1000000 .0f ) {
139- continue ;
139+ if (use_collision_coloring && costs (i) >= 1000000 .0f ) {
140+ continue ;
141+ }
142+ min_cost = std::min (min_cost, costs (i));
143+ max_cost = std::max (max_cost, costs (i));
140144 }
141- min_cost = std::min (min_cost, costs (i));
142- max_cost = std::max (max_cost, costs (i));
143- }
144-
145- float cost_range = max_cost - min_cost;
146-
145+
146+ float cost_range = max_cost - min_cost;
147+
147148 // Avoid division by zero
148- if (cost_range < 1e-6f ) {
149- cost_range = 1 .0f ;
150- }
149+ if (cost_range < 1e-6f ) {
150+ cost_range = 1 .0f ;
151+ }
151152
152- for (size_t i = 0 ; i < n_rows; i += trajectory_step_) {
153- float red_component, green_component, blue_component;
153+ for (size_t i = 0 ; i < n_rows; i += trajectory_step_) {
154+ float red_component, green_component, blue_component;
154155
155156 // Check if this trajectory is in collision (cost >= 1000000)
156- bool in_collision = use_collision_coloring && costs (i) >= 1000000 .0f ;
157-
157+ bool in_collision = use_collision_coloring && costs (i) >= 1000000 .0f ;
158+
158159 // Check if cost is zero (no contribution from this critic)
159- bool zero_cost = std::abs (costs (i)) < 1e-6f ;
160-
161- if (in_collision) {
160+ bool zero_cost = std::abs (costs (i)) < 1e-6f ;
161+
162+ if (in_collision) {
162163 // Fixed red color for collision trajectories
163- red_component = 1 .0f ;
164- green_component = 0 .0f ;
165- blue_component = 0 .0f ;
166- } else if (zero_cost) {
164+ red_component = 1 .0f ;
165+ green_component = 0 .0f ;
166+ blue_component = 0 .0f ;
167+ } else if (zero_cost) {
167168 // Gray color for zero cost (no contribution)
168- red_component = 0 .5f ;
169- green_component = 0 .5f ;
170- blue_component = 0 .5f ;
171- } else {
169+ red_component = 0 .5f ;
170+ green_component = 0 .5f ;
171+ blue_component = 0 .5f ;
172+ } else {
172173 // Normal gradient for non-collision trajectories
173- float normalized_cost = (costs (i) - min_cost) / cost_range;
174- normalized_cost = std::clamp (normalized_cost, 0 .0f , 1 .0f );
174+ float normalized_cost = (costs (i) - min_cost) / cost_range;
175+ normalized_cost = std::clamp (normalized_cost, 0 .0f , 1 .0f );
175176
176177 // Color scheme: Green (low cost) -> Yellow -> Red (high cost)
177- blue_component = 0 .0f ;
178- if (normalized_cost < 0 .5f ) {
178+ blue_component = 0 .0f ;
179+ if (normalized_cost < 0 .5f ) {
179180 // Green to Yellow (0.0 - 0.5)
180- red_component = normalized_cost * 2 .0f ;
181- green_component = 1 .0f ;
182- } else {
181+ red_component = normalized_cost * 2 .0f ;
182+ green_component = 1 .0f ;
183+ } else {
183184 // Yellow to Red (0.5 - 1.0)
184- red_component = 1 .0f ;
185- green_component = 2 .0f * (1 .0f - normalized_cost);
185+ red_component = 1 .0f ;
186+ green_component = 2 .0f * (1 .0f - normalized_cost);
187+ }
186188 }
187- }
188189
189190 // Create line strip marker for this trajectory
190- visualization_msgs::msg::Marker marker;
191- marker.header .frame_id = frame_id_;
192- marker.header .stamp = cmd_stamp;
193- marker.ns = ns;
194- marker.id = marker_id_++;
195- marker.type = visualization_msgs::msg::Marker::LINE_STRIP;
196- marker.action = visualization_msgs::msg::Marker::ADD;
197- marker.pose .orientation .w = 1.0 ;
198- marker.scale .x = 0.01 ; // Line width
199- marker.color .r = red_component;
200- marker.color .g = green_component;
201- marker.color .b = blue_component;
202- marker.color .a = 1.0 ;
191+ visualization_msgs::msg::Marker marker;
192+ marker.header .frame_id = frame_id_;
193+ marker.header .stamp = cmd_stamp;
194+ marker.ns = ns;
195+ marker.id = marker_id_++;
196+ marker.type = visualization_msgs::msg::Marker::LINE_STRIP;
197+ marker.action = visualization_msgs::msg::Marker::ADD;
198+ marker.pose .orientation .w = 1.0 ;
199+ marker.scale .x = 0.01 ; // Line width
200+ marker.color .r = red_component;
201+ marker.color .g = green_component;
202+ marker.color .b = blue_component;
203+ marker.color .a = 1.0 ;
203204
204205 // Add all points in this trajectory to the line strip
205- for (size_t j = 0 ; j < n_cols; j += time_step_) {
206- geometry_msgs::msg::Point point;
207- point.x = trajectories.x (i, j);
208- point.y = trajectories.y (i, j);
209- point.z = 0 .0f ;
210- marker.points .push_back (point);
206+ for (size_t j = 0 ; j < n_cols; j += time_step_) {
207+ geometry_msgs::msg::Point point;
208+ point.x = trajectories.x (i, j);
209+ point.y = trajectories.y (i, j);
210+ point.z = 0 .0f ;
211+ marker.points .push_back (point);
212+ }
213+
214+ points_->markers .push_back (marker);
211215 }
212-
213- points_->markers .push_back (marker);
214- }
215- };
216+ };
216217
217218 // If visualizing per-critic costs
218219 if (visualize_per_critic) {
0 commit comments