Go to the documentation of this file.
20 #ifndef GEOMETRY__BOUNDING_BOX__ROTATING_CALIPERS_HPP_
21 #define GEOMETRY__BOUNDING_BOX__ROTATING_CALIPERS_HPP_
37 namespace bounding_box
47 template<
typename Po
intT>
51 float32_t best_cos_th = -std::numeric_limits<float32_t>::max();
53 uint32_t advance_idx = 0U;
54 for (uint32_t idx = 0U; idx < edges.size(); ++idx) {
57 const float32_t cos_th =
dot_2d(edges[idx], directions[idx]) / edge_dir_mag;
58 if (cos_th > best_cos_th) {
60 best_edge_dir_mag = edge_dir_mag;
67 cross_2d(directions[advance_idx], edges[advance_idx]) / best_edge_dir_mag;
68 for (uint32_t idx = 0U; idx < edges.size(); ++idx) {
69 rotate_2d(directions[idx], best_cos_th, sin_th);
82 template<
typename IT,
typename Po
intT>
89 for (uint32_t idx = 0U; idx < support.size(); ++idx) {
90 auto tmp_it = support[idx];
92 const PointT & q = (tmp_it ==
end) ? *begin : *tmp_it;
93 edges[idx] =
minus_2d(q, *support[idx]);
105 template<
typename IT>
113 std::array<float32_t, 3U> metric{{
114 -std::numeric_limits<float32_t>::max(),
115 -std::numeric_limits<float32_t>::max(),
116 std::numeric_limits<float32_t>::max()
119 for (pt_it = begin; pt_it !=
end; ++pt_it) {
121 const auto & pt = *pt_it;
124 if (up > metric[0U]) {
129 if (up < metric[2U]) {
135 if (uxp > metric[1U]) {
153 template<
typename IT,
typename MetricF>
156 using PointT =
base_type<decltype(*begin)>;
159 throw std::domain_error(
"Malformed list, size = " + std::to_string(std::distance(begin,
end)));
167 auto tmp = support[0U];
169 directions[0U] =
minus_2d(*tmp, *support[0U]);
171 directions[2U] =
minus_2d(directions[0U]);
172 directions[3U] =
minus_2d(directions[1U]);
179 decltype(BoundingBox::corners) best_corners;
181 size_2d(best_corners, bbox.size);
182 bbox.value = metric_fn(bbox.size);
184 for (
auto it = begin; it !=
end; ++it) {
186 const uint32_t advance_idx =
update_angles(edges, directions);
188 decltype(BoundingBox::corners) corners;
190 decltype(BoundingBox::size) tmp_size;
192 const float32_t tmp_value = metric_fn(tmp_size);
194 if (tmp_value < bbox.value) {
196 (void)std::memcpy(&best_corners[0U], &corners[0U],
sizeof(corners));
198 bbox.size = tmp_size;
199 bbox.value = tmp_value;
204 auto next_it = support[advance_idx];
206 const auto run_it = (
end == next_it) ? begin : next_it;
207 support[advance_idx] = run_it;
211 const PointT & next = (
end == next_it) ? (*begin) : (*next_it);
212 edges[advance_idx] =
minus_2d(next, *run_it);
233 template<
typename IT>
236 const auto metric_fn = [](
const decltype(BoundingBox::size) & pt) ->
float32_t
249 template<
typename IT>
252 const auto metric_fn = [](
const decltype(BoundingBox::size) & pt) ->
float32_t
265 template<
typename Po
intT>
278 template<
typename Po
intT>
288 #endif // GEOMETRY__BOUNDING_BOX__ROTATING_CALIPERS_HPP_
autoware_auto_msgs::msg::BoundingBox BoundingBox
Definition: bounding_box_common.hpp:38
T get_normal(const T &pt)
compute q s.t. p T q, or p * q = 0 This is the equivalent of a 90 degree ccw rotation
Definition: common_2d.hpp:265
auto cross_2d(const T1 &pt, const T2 &q)
compute p x q = p1 * q2 - p2 * q1
Definition: common_2d.hpp:118
BoundingBox minimum_area_bounding_box(const IT begin, const IT end)
Compute the minimum area bounding box given a convex hull of points. This function is exposed in case...
Definition: rotating_calipers.hpp:234
void compute_corners(decltype(BoundingBox::corners) &corners, const Point4< IT > &supports, const Point4< PointT > &directions)
given support points and two orthogonal directions, compute corners of bounding box
Definition: bounding_box_common.hpp:111
This file implements the monotone chain algorithm to compute 2D convex hulls on linked lists of point...
DifferentialState u
Definition: kinematic_bicycle.snippet.hpp:29
This file includes common functionality for 2D geometry, such as dot products.
BoundingBox minimum_perimeter_bounding_box(const IT begin, const IT end)
Compute the minimum perimeter bounding box given a convex hull of points This function is exposed in ...
Definition: rotating_calipers.hpp:250
void init_edges(const IT begin, const IT end, const Point4< IT > &support, Point4< PointT > &edges)
Given support points i, find direction of edge: e = P[i+1] - P[i].
Definition: rotating_calipers.hpp:83
uint32_t update_angles(const Point4< PointT > &edges, Point4< PointT > &directions)
Find which (next) edge has smallest angle delta to directions, rotate directions.
Definition: rotating_calipers.hpp:48
void init_bbox(const IT begin, const IT end, Point4< IT > &support)
Scan through list to find support points for bounding box oriented in direction of u = P[1] - P[0].
Definition: rotating_calipers.hpp:106
auto dot_2d(const T1 &pt, const T2 &q)
compute p * q = p1 * q1 + p2 * q2
Definition: common_2d.hpp:131
This file defines the lanelet2_map_provider_node class.
Definition: quick_sort.hpp:24
BoundingBox rotating_calipers_impl(const IT begin, const IT end, const MetricF metric_fn)
Compute the minimum bounding box for a convex hull using the rotating calipers method....
Definition: rotating_calipers.hpp:154
constexpr float32_t FEPS
arbitrary small constant: 1.0E-6F
Definition: types.hpp:46
std::list< PointT >::const_iterator convex_hull(std::list< PointT > &list)
A static memory implementation of convex hull computation. Shuffles points around the deque such that...
Definition: convex_hull.hpp:185
auto norm_2d(const T &pt)
get magnitude of x and y components:
Definition: common_2d.hpp:278
Common functionality for bounding box computation algorithms.
float float32_t
Definition: types.hpp:36
T minus_2d(const T &p, const T &q)
Compute the 2d difference between two points, p - q.
Definition: common_2d.hpp:145
void rotate_2d(T &pt, const float32_t cos_th, const float32_t sin_th)
rotate point given precomputed sin and cos
Definition: common_2d.hpp:236
typename std::remove_cv< typename std::remove_reference< T >::type >::type base_type
Templated alias for getting a type without CV or reference qualification.
Definition: bounding_box_common.hpp:72
void GEOMETRY_PUBLIC size_2d(const decltype(BoundingBox::corners) &corners, geometry_msgs::msg::Point32 &ret)
Compute length, width, area of bounding box.
Definition: bounding_box.cpp:39
std::array< PointT, 4U > Point4
Templated alias for an array of 4 objects of type PointT.
Definition: bounding_box_common.hpp:76
void GEOMETRY_PUBLIC finalize_box(const decltype(BoundingBox::corners) &corners, BoundingBox &box)
Computes centroid and orientation of a box given corners.
Definition: bounding_box.cpp:47
end
Definition: scripts/get_open_port.py:23