4242#include < tf2_eigen/tf2_eigen.hpp>
4343
4444#include " hydra_visualizer/color/color_parsing.h"
45+ #include " hydra_visualizer/utils/polygon_utilities.h"
4546
4647namespace hydra {
4748namespace {
@@ -68,8 +69,11 @@ void declare_config(RegionGrowingBoundaryPlugin::Config& config) {
6869 field (config.use_node_color , " use_node_color" );
6970 field (config.colors , " colors" );
7071 field (config.line_width , " line_width" );
72+ field (config.fill_alpha , " fill_alpha" );
73+ field (config.fill_boundaries , " fill_boundaries" );
7174 checkCondition (config.colors .size () == 4 , " colors.size() must be 4" );
7275 check (config.line_width , GT , 0 .0f , " line_width" );
76+ checkInRange (config.fill_alpha , 0 .0f , 1 .0f , " fill_alpha" , false );
7377}
7478
7579RegionGrowingBoundaryPlugin::RegionGrowingBoundaryPlugin (const Config& config,
@@ -96,28 +100,44 @@ void RegionGrowingBoundaryPlugin::draw(const std_msgs::msg::Header& header,
96100 marker.scale .x = config.line_width ;
97101 marker.scale .y = config.line_width ;
98102 marker.scale .z = config.line_width ;
103+
104+ Marker fill_marker;
105+ fill_marker.header = header;
106+ fill_marker.ns = ns_ + " _region_growing_polygons" ;
107+ fill_marker.id = 0 ;
108+ fill_marker.type = Marker::TRIANGLE_LIST ;
109+ fill_marker.action = Marker::ADD ;
110+ fill_marker.pose .orientation .w = 1.0 ;
111+ fill_marker.color .a = config.fill_alpha ;
112+ fill_marker.scale .x = 1.0 ;
113+ fill_marker.scale .y = 1.0 ;
114+ fill_marker.scale .z = 1.0 ;
115+
99116 for (const auto & [node_id, node] : layer.nodes ()) {
100117 if (info.filter && !info.filter (*node)) {
101118 continue ;
102119 }
103120
104121 auto attrs = node->tryAttributes <spark_dsg::TravNodeAttributes>();
105- if (!attrs) {
122+ if (!attrs || attrs-> radii . empty () ) {
106123 continue ;
107124 }
108125
126+ Eigen::MatrixXd points (3 , attrs->radii .size ());
127+ const auto color =
128+ visualizer::makeColorMsg (info.node_color (*node), info.config .nodes .alpha );
109129 for (size_t i = 1 ; i <= attrs->radii .size (); ++i) {
110130 const auto start_idx = i - 1 ;
111131 const auto end_idx = i % attrs->radii .size ();
112132 auto start = attrs->getBoundaryPoint (start_idx);
113133 start.z () += info.z_offset ;
134+ points.col (start_idx) = start;
135+
114136 tf2::convert (start, marker.points .emplace_back ());
115137 auto end = attrs->getBoundaryPoint (end_idx);
116138 end.z () += info.z_offset ;
117139 tf2::convert (end, marker.points .emplace_back ());
118140 if (config.use_node_color ) {
119- const auto color =
120- visualizer::makeColorMsg (info.node_color (*node), info.config .nodes .alpha );
121141 marker.colors .emplace_back (color);
122142 marker.colors .emplace_back (color);
123143 } else {
@@ -129,9 +149,18 @@ void RegionGrowingBoundaryPlugin::draw(const std_msgs::msg::Header& header,
129149 marker.colors .emplace_back (end_color);
130150 }
131151 }
152+
153+ if (config.fill_boundaries ) {
154+ auto mesh_color = color;
155+ mesh_color.a = config.fill_alpha ;
156+ makeFilledPolygon (points, mesh_color, fill_marker);
157+ }
132158 }
133159
134160 tracker.add (marker, msg);
161+ if (config.fill_boundaries ) {
162+ tracker.add (fill_marker, msg);
163+ }
135164}
136165
137166YAML ::Node RegionGrowingBoundaryPlugin::dumpConfig () const {
0 commit comments