@@ -549,15 +549,16 @@ visualization_msgs::msg::Marker::SharedPtr get_2d_shape_marker_ptr(
549
549
{
550
550
auto marker_ptr = std::make_shared<Marker>();
551
551
marker_ptr->ns = std::string (" shape" );
552
+ marker_ptr->scale .x = line_width;
552
553
553
554
using autoware_auto_perception_msgs::msg::Shape;
554
555
if (shape_msg.type == Shape::BOUNDING_BOX) {
555
- marker_ptr->type = visualization_msgs::msg::Marker::LINE_LIST;
556
- calc_2d_bounding_box_bottom_line_list (shape_msg, marker_ptr->points );
556
+ marker_ptr->type = visualization_msgs::msg::Marker::TRIANGLE_LIST;
557
+ calc_2d_bounding_box_bottom_triangle_list (shape_msg, marker_ptr->points );
558
+ marker_ptr->scale .x = 1.0 ; // Set scale to 1 for TRIANGLE_LIST
559
+ marker_ptr->scale .y = 1.0 ; // Set scale to 1 for TRIANGLE_LIST
560
+ marker_ptr->scale .z = 1.0 ; // Set scale to 1 for TRIANGLE_LIST
557
561
if (is_orientation_available) {
558
- calc_2d_bounding_box_bottom_direction_line_list (shape_msg, marker_ptr->points );
559
- } else {
560
- calc_2d_bounding_box_bottom_orientation_line_list (shape_msg, marker_ptr->points );
561
562
}
562
563
} else if (shape_msg.type == Shape::CYLINDER) {
563
564
marker_ptr->type = visualization_msgs::msg::Marker::LINE_LIST;
@@ -573,12 +574,82 @@ visualization_msgs::msg::Marker::SharedPtr get_2d_shape_marker_ptr(
573
574
marker_ptr->action = visualization_msgs::msg::Marker::MODIFY;
574
575
marker_ptr->pose = to_pose (centroid, orientation);
575
576
marker_ptr->lifetime = rclcpp::Duration::from_seconds (0.15 );
576
- marker_ptr->scale .x = line_width;
577
+
578
+ marker_ptr->mesh_use_embedded_materials = false ; // Ensure the material is not embedded
579
+
577
580
marker_ptr->color = color_rgba;
581
+ marker_ptr->color .a = 0 .75f ;
578
582
579
583
return marker_ptr;
580
584
}
581
585
586
+ void calc_2d_bounding_box_bottom_triangle_list (
587
+ const autoware_auto_perception_msgs::msg::Shape & shape,
588
+ std::vector<geometry_msgs::msg::Point > & points)
589
+ {
590
+ const double length_half = shape.dimensions .x * 0.5 ;
591
+ const double width_half = shape.dimensions .y * 0.5 ;
592
+ const double height_half = shape.dimensions .z * 0.5 ;
593
+
594
+ // Define Boost.Geometry types
595
+ using BoostPoint = boost::geometry::model::d2::point_xy<double >;
596
+ using BoostPolygon = boost::geometry::model::polygon<BoostPoint>;
597
+
598
+ // Create a rectangle polygon
599
+ BoostPolygon boost_polygon;
600
+ boost::geometry::append (boost_polygon.outer (), BoostPoint (length_half, width_half));
601
+ boost::geometry::append (boost_polygon.outer (), BoostPoint (length_half, -width_half));
602
+ boost::geometry::append (boost_polygon.outer (), BoostPoint (-length_half, -width_half));
603
+ boost::geometry::append (boost_polygon.outer (), BoostPoint (-length_half, width_half));
604
+ boost::geometry::append (boost_polygon.outer (), BoostPoint (length_half, width_half));
605
+ boost::geometry::correct (boost_polygon);
606
+
607
+ // Define buffer strategy with larger rounded corners and smoother approximation
608
+ boost::geometry::strategy::buffer::distance_symmetric<double > distance_strategy (
609
+ 0.4 ); // Adjust distance as needed
610
+ boost::geometry::strategy::buffer::join_round join_strategy (
611
+ 16 ); // Increase points per circle for smoother roundness
612
+ boost::geometry::strategy::buffer::end_flat end_strategy;
613
+ boost::geometry::strategy::buffer::point_circle point_strategy (16 ); // Points per circle
614
+ boost::geometry::strategy::buffer::side_straight side_strategy;
615
+
616
+ // Create buffered polygon with rounded corners
617
+ std::vector<BoostPolygon> buffered_polygons;
618
+ boost::geometry::buffer (
619
+ boost_polygon, buffered_polygons, distance_strategy, side_strategy, join_strategy, end_strategy,
620
+ point_strategy);
621
+
622
+ if (buffered_polygons.empty ()) {
623
+ RCLCPP_WARN (rclcpp::get_logger (" ObjectPolygonDisplayBase" ), " Buffering produced no output." );
624
+ return ;
625
+ }
626
+
627
+ // Convert buffered polygon to RViz marker points
628
+ const auto & outer_ring = buffered_polygons.front ().outer ();
629
+ std::vector<geometry_msgs::msg::Point > polygon_points;
630
+
631
+ for (const auto & point : outer_ring) {
632
+ geometry_msgs::msg::Point p;
633
+ p.x = point.x ();
634
+ p.y = point.y ();
635
+ p.z = -height_half; // Use the bottom part of the shape
636
+ polygon_points.push_back (p);
637
+ }
638
+
639
+ // Create triangles from polygon points
640
+ for (size_t i = 1 ; i < polygon_points.size () - 1 ; ++i) {
641
+ // Add front face
642
+ points.push_back (polygon_points[0 ]);
643
+ points.push_back (polygon_points[i]);
644
+ points.push_back (polygon_points[i + 1 ]);
645
+
646
+ // Add back face
647
+ points.push_back (polygon_points[0 ]);
648
+ points.push_back (polygon_points[i + 1 ]);
649
+ points.push_back (polygon_points[i]);
650
+ }
651
+ }
652
+
582
653
void calc_line_list_from_points (
583
654
const double point_list[][3 ], const int point_pairs[][2 ], const int & num_pairs,
584
655
std::vector<geometry_msgs::msg::Point > & points)
@@ -670,30 +741,104 @@ void calc_bounding_box_orientation_line_list(
670
741
calc_line_list_from_points (point_list, point_pairs, 2 , points);
671
742
}
672
743
744
+ // void calc_2d_bounding_box_bottom_line_list(
745
+ // const autoware_auto_perception_msgs::msg::Shape & shape,
746
+ // std::vector<geometry_msgs::msg::Point> & points)
747
+ // {
748
+ // const double length_half = shape.dimensions.x * 0.5;
749
+ // const double width_half = shape.dimensions.y * 0.5;
750
+ // const double height_half = shape.dimensions.z * 0.5;
751
+ // geometry_msgs::msg::Point point;
752
+
753
+ // // bounding box corner points
754
+ // // top surface, clockwise
755
+ // const double point_list[4][3] = {
756
+ // {length_half, width_half, -height_half},
757
+ // {length_half, -width_half, -height_half},
758
+ // {-length_half, -width_half, -height_half},
759
+ // {-length_half, width_half, -height_half},
760
+ // };
761
+ // const int point_pairs[4][2] = {
762
+ // {0, 1},
763
+ // {1, 2},
764
+ // {2, 3},
765
+ // {3, 0},
766
+ // };
767
+ // calc_line_list_from_points(point_list, point_pairs, 4, points);
768
+ // }
769
+
673
770
void calc_2d_bounding_box_bottom_line_list (
674
771
const autoware_auto_perception_msgs::msg::Shape & shape,
675
772
std::vector<geometry_msgs::msg::Point > & points)
676
773
{
677
774
const double length_half = shape.dimensions .x * 0.5 ;
678
775
const double width_half = shape.dimensions .y * 0.5 ;
679
776
const double height_half = shape.dimensions .z * 0.5 ;
680
- geometry_msgs::msg::Point point;
681
777
682
- // bounding box corner points
683
- // top surface, clockwise
684
- const double point_list[4 ][3 ] = {
685
- {length_half, width_half, -height_half},
686
- {length_half, -width_half, -height_half},
687
- {-length_half, -width_half, -height_half},
688
- {-length_half, width_half, -height_half},
689
- };
690
- const int point_pairs[4 ][2 ] = {
691
- {0 , 1 },
692
- {1 , 2 },
693
- {2 , 3 },
694
- {3 , 0 },
695
- };
696
- calc_line_list_from_points (point_list, point_pairs, 4 , points);
778
+ // Define Boost.Geometry types
779
+ using BoostPoint = boost::geometry::model::d2::point_xy<double >;
780
+ using BoostPolygon = boost::geometry::model::polygon<BoostPoint>;
781
+
782
+ // Create a rectangle polygon
783
+ BoostPolygon boost_polygon;
784
+ boost::geometry::append (boost_polygon.outer (), BoostPoint (length_half, width_half));
785
+ boost::geometry::append (boost_polygon.outer (), BoostPoint (length_half, -width_half));
786
+ boost::geometry::append (boost_polygon.outer (), BoostPoint (-length_half, -width_half));
787
+ boost::geometry::append (boost_polygon.outer (), BoostPoint (-length_half, width_half));
788
+ boost::geometry::append (boost_polygon.outer (), BoostPoint (length_half, width_half));
789
+ boost::geometry::correct (boost_polygon);
790
+
791
+ // Define buffer strategy with rounded corners
792
+ boost::geometry::strategy::buffer::distance_symmetric<double > distance_strategy (
793
+ 0.4 ); // Adjust distance as needed
794
+ boost::geometry::strategy::buffer::join_round join_strategy (
795
+ 16 ); // Adjust points per circle for roundness
796
+ boost::geometry::strategy::buffer::end_flat end_strategy;
797
+ boost::geometry::strategy::buffer::point_circle point_strategy (16 ); // Points per circle
798
+ boost::geometry::strategy::buffer::side_straight side_strategy;
799
+
800
+ // Create buffered polygon with rounded corners
801
+ std::vector<BoostPolygon> buffered_polygons;
802
+ boost::geometry::buffer (
803
+ boost_polygon, buffered_polygons, distance_strategy, side_strategy, join_strategy, end_strategy,
804
+ point_strategy);
805
+
806
+ if (buffered_polygons.empty ()) {
807
+ RCLCPP_WARN (rclcpp::get_logger (" ObjectPolygonDisplayBase" ), " Buffering produced no output." );
808
+ return ;
809
+ }
810
+
811
+ // Convert buffered polygon to RViz marker points
812
+ const auto & outer_ring = buffered_polygons.front ().outer ();
813
+ for (size_t i = 0 ; i < outer_ring.size () - 1 ; ++i) { // -1 to avoid duplicating the closing point
814
+ geometry_msgs::msg::Point point;
815
+ point.x = outer_ring[i].x ();
816
+ point.y = outer_ring[i].y ();
817
+ point.z = -height_half; // Use the bottom part of the shape
818
+ points.push_back (point);
819
+
820
+ point.x = outer_ring[i + 1 ].x ();
821
+ point.y = outer_ring[i + 1 ].y ();
822
+ point.z = -height_half; // Use the bottom part of the shape
823
+ points.push_back (point);
824
+ }
825
+
826
+ // Closing the polygon
827
+ if (!outer_ring.empty ()) {
828
+ geometry_msgs::msg::Point point;
829
+ point.x = outer_ring.back ().x ();
830
+ point.y = outer_ring.back ().y ();
831
+ point.z = -height_half;
832
+ points.push_back (point);
833
+
834
+ point.x = outer_ring.front ().x ();
835
+ point.y = outer_ring.front ().y ();
836
+ point.z = -height_half;
837
+ points.push_back (point);
838
+ }
839
+
840
+ RCLCPP_INFO (
841
+ rclcpp::get_logger (" ObjectPolygonDisplayBase" ), " Marker points size: %zu" , points.size ());
697
842
}
698
843
699
844
void calc_2d_bounding_box_bottom_direction_line_list (
0 commit comments