21 #ifndef GEOMETRY__BOUNDING_BOX__EIGENBOX_2D_HPP_ 22 #define GEOMETRY__BOUNDING_BOX__EIGENBOX_2D_HPP_ 34 namespace bounding_box
66 for (
auto it = begin; it !=
end; ++it) {
68 num_points =
static_cast<float32_t>(ret.num_points);
69 const auto & pt = *it;
75 ret.xy += (
x_(pt) - ux) * (dy);
79 ret.xx += dx * (
x_(pt) - ux);
80 ret.yy += dy * (
y_(pt) - uy);
83 if (ret.num_points > 1U) {
84 num_points = num_points - 1.0F;
100 template<
typename Po
intT>
102 const Covariance2d & cov, PointT & eigvec1, PointT & eigvec2)
107 float32_t disc = ((tr_2 * tr_2) - det) + std::numeric_limits<float32_t>::epsilon();
109 throw std::runtime_error(
110 "pca_2d: negative discriminant! Should never happen for well formed " 111 "covariance matrix");
115 const auto ret = std::make_pair(tr_2 + disc, tr_2 - disc);
122 if (fabsf(cov.
xy * cov.
xy) > std::numeric_limits<float32_t>::epsilon()) {
123 xr_(eigvec1) = cov.
xy;
124 yr_(eigvec1) = ret.first - cov.
xx;
125 xr_(eigvec2) = cov.
xy;
126 yr_(eigvec2) = ret.second - cov.
xx;
128 if (cov.
xx > cov.
yy) {
154 template<
typename IT,
typename Po
intT>
163 std::array<float32_t, 4U> metrics{{
164 -std::numeric_limits<float32_t>::max(),
165 -std::numeric_limits<float32_t>::max(),
166 std::numeric_limits<float32_t>::max(),
167 std::numeric_limits<float32_t>::max()
169 for (
auto it = begin; it !=
end; ++it) {
170 const PointT & pt = *it;
172 if (val > metrics[0U]) {
176 if (val < metrics[2U]) {
180 val =
dot_2d(ret ? eig2 : eig1, pt);
181 if (val > metrics[1U]) {
185 if (val < metrics[3U]) {
201 template<
typename IT,
typename Po
intT>
207 decltype(BoundingBox::corners) corners;
225 template<
typename IT>
242 std::swap(eig1, eig2);
245 bbox.value = eigv.first;
254 #endif // GEOMETRY__BOUNDING_BOX__EIGENBOX_2D_HPP_ 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:55
autoware_auto_msgs::msg::BoundingBox BoundingBox
Definition: bounding_box_common.hpp:38
BoundingBox eigenbox_2d(const IT begin, const IT end)
Compute oriented bounding box using PCA. This uses all points in a list, and does not modify the list...
Definition: eigenbox_2d.hpp:226
bool8_t compute_supports(const IT begin, const IT end, const PointT &eig1, const PointT &eig2, Point4< IT > &support)
Given eigenvectors, compute support (furthest) point in each direction.
Definition: eigenbox_2d.hpp:155
float float32_t
Definition: types.hpp:36
dx
Definition: catr_diff.py:38
Simplified 2d covariance matrix.
Definition: eigenbox_2d.hpp:40
Covariance2d covariance_2d(const IT begin, const IT end)
Compute 2d covariance matrix of a list of points using Welford's online algorithm.
Definition: eigenbox_2d.hpp:58
bool bool8_t
Definition: types.hpp:33
std::pair< float32_t, float32_t > eig_2d(const Covariance2d &cov, PointT &eigvec1, PointT &eigvec2)
Compute eigenvectors and eigenvalues.
Definition: eigenbox_2d.hpp:101
std::size_t num_points
Number of points.
Definition: eigenbox_2d.hpp:49
auto & xr_(PointT &pt)
Gets a reference to the x value for a point.
Definition: common_2d.hpp:74
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 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
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
float32_t xy
x-y covariance
Definition: eigenbox_2d.hpp:47
auto dot_2d(const T1 &pt, const T2 &q)
compute p * q = p1 * q1 + p2 * q2
Definition: common_2d.hpp:131
auto x_(const PointT &pt)
Gets the x value for a point.
Definition: common_2d.hpp:47
dy
Definition: catr_diff.py:39
auto y_(const PointT &pt)
Gets the y value for a point.
Definition: common_2d.hpp:56
end
Definition: scripts/get_open_port.py:23
Common functionality for bounding box computation algorithms.
T minus_2d(const T &p, const T &q)
Compute the 2d difference between two points, p - q.
Definition: common_2d.hpp:145
BoundingBox compute_bounding_box(const PointT &ax1, const PointT &ax2, const Point4< IT > &supports)
Compute bounding box given a pair of basis directions.
Definition: eigenbox_2d.hpp:202
float32_t xx
Variance in the x direction.
Definition: eigenbox_2d.hpp:43
auto & yr_(PointT &pt)
Gets a reference to the y value for a point.
Definition: common_2d.hpp:83
float32_t yy
Variance in the y direction.
Definition: eigenbox_2d.hpp:45
auto cross_2d(const T1 &pt, const T2 &q)
compute p x q = p1 * q2 - p2 * q1
Definition: common_2d.hpp:118
This file defines the lanelet2_map_provider_node class.
Definition: quick_sort.hpp:24
std::array< PointT, 4U > Point4
Templated alias for an array of 4 objects of type PointT.
Definition: bounding_box_common.hpp:76