Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
midpoint_generator.hpp
Go to the documentation of this file.
1#ifndef SRC_PLANNING_INCLUDE_PLANNING_DELAUNY_MIDPOINT_GENERATOR_HPP_
2#define SRC_PLANNING_INCLUDE_PLANNING_DELAUNY_MIDPOINT_GENERATOR_HPP_
3
4#include <CGAL/Delaunay_triangulation_2.h>
5#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
6
7#include <rclcpp/rclcpp.hpp>
8#include <vector>
9
14
15using K = CGAL::Exact_predicates_inexact_constructions_kernel;
16using DT = CGAL::Delaunay_triangulation_2<K>;
17using Point = K::Point_2;
18using Vertex_handle = DT::Vertex_handle;
19
23
35public:
39 MidpointGenerator() = default;
40
46 explicit MidpointGenerator(const MidpointGeneratorConfig& config) : config_(config) {}
47
58 std::vector<std::shared_ptr<Midpoint>>& generate_midpoints(const std::vector<Cone>& cone_array,
59 bool rebuild_all_midpoints);
60
66 const std::vector<std::pair<Point, Point>>& get_triangulations() const;
67
75 void set_vehicle_pose(const Pose& vehicle_pose);
76
77private:
78 // Stores Delaunay triangulation edges for visualization and debugging.
79 std::vector<std::pair<Point, Point>> triangulations_;
80
81 // Current vehicle pose.
83
84 // Vector containing all generated midpoints.
85 std::vector<std::shared_ptr<Midpoint>> midpoints_;
86
88
97 void filter_cones(const std::vector<Cone>& cone_array,
98 std::vector<std::shared_ptr<Cone>>& filtered_cones, bool rebuild_all_midpoints);
99
112 std::shared_ptr<Midpoint> process_triangle_edge(
113 const Vertex_handle& va, const Vertex_handle& vb,
114 std::vector<std::shared_ptr<Cone>>& filtered_cones,
115 std::map<std::pair<int, int>, std::shared_ptr<Midpoint>>& segment_to_midpoint);
116
123 const std::array<std::shared_ptr<Midpoint>, 3>& triangle_midpoints);
124
133 int find_cone(std::vector<std::shared_ptr<Cone>>& cones, double x, double y);
134};
135
136#endif // SRC_PLANNING_INCLUDE_PLANNING_DELAUNY_MIDPOINT_GENERATOR_HPP_
Generates midpoints between cones using Delaunay triangulation.
MidpointGenerator(const MidpointGeneratorConfig &config)
Constructs a new MidpointGenerator with a specific configuration.
int find_cone(std::vector< std::shared_ptr< Cone > > &cones, double x, double y)
Finds a cone in a vector based on its position coordinates.
void connect_triangle_midpoints(const std::array< std::shared_ptr< Midpoint >, 3 > &triangle_midpoints)
Connects midpoints that belong to the same Delaunay triangle.
void filter_cones(const std::vector< Cone > &cone_array, std::vector< std::shared_ptr< Cone > > &filtered_cones, bool rebuild_all_midpoints)
Filters input cones based on proximity to the vehicle pose.
std::shared_ptr< Midpoint > process_triangle_edge(const Vertex_handle &va, const Vertex_handle &vb, std::vector< std::shared_ptr< Cone > > &filtered_cones, std::map< std::pair< int, int >, std::shared_ptr< Midpoint > > &segment_to_midpoint)
Processes a single edge of a Delaunay triangle and creates its midpoint if valid.
void set_vehicle_pose(const Pose &vehicle_pose)
Updates the vehicle pose for dynamic filtering.
MidpointGeneratorConfig config_
std::vector< std::shared_ptr< Midpoint > > & generate_midpoints(const std::vector< Cone > &cone_array, bool rebuild_all_midpoints)
Generates midpoints from a set of cones.
MidpointGenerator()=default
Default constructor.
std::vector< std::pair< Point, Point > > triangulations_
std::vector< std::shared_ptr< Midpoint > > midpoints_
const std::vector< std::pair< Point, Point > > & get_triangulations() const
Returns the current set of Delaunay edges used for visualization.
K::Point_2 Point
Definition marker.hpp:18
CGAL::Exact_predicates_inexact_constructions_kernel K
Definition marker.hpp:17
CGAL::Delaunay_triangulation_2< K > DT
DT::Vertex_handle Vertex_handle
Configuration parameters for the Midpoint Generator class.
Definition types.hpp:66
MidPoint struct represents a potential path point with connections.
Definition midpoint.hpp:17
Struct for pose representation.
Definition pose.hpp:13