8 #pragma GCC diagnostic push
9 #pragma GCC diagnostic ignored "-Wpedantic"
10 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
11 #include <CGAL/convex_hull_2.h>
12 #include <CGAL/min_quadrilateral_2.h>
13 #pragma GCC diagnostic pop
15 #include <pcl/point_cloud.h>
16 #include <pcl/point_types.h>
18 #include <SimoxUtility/shapes/OrientedBox.h>
19 #include <SimoxUtility/shapes/XYConstrainedOrientedBox.h>
24 #include "../VisitPointLikeContainer.h"
35 mx.col(0) = normal.normalized();
36 const VectorT other = (mx.col(0) == VectorT::UnitZ()) ? VectorT::UnitX() : VectorT::UnitZ();
37 mx.col(1) = mx.col(0).cross(other).normalized();
38 mx.col(2) = mx.col(0).cross(mx.col(1)).normalized();
47 const Eigen::Vector3d normal = dir.normalized();
48 using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;
49 using Point_2 = Kernel::Point_2;
50 using Polygon_2 = CGAL::Polygon_2<Kernel>;
52 const Eigen::Matrix3d boxFrame = normalToRotation(normal);
55 std::vector<Point_2> allProjected;
56 double allMaxX = -std::numeric_limits<double>::infinity();
57 double allMinX = +std::numeric_limits<double>::infinity();
59 const auto& consume = [&](
auto x,
auto y,
auto z)
61 const Eigen::Vector3d t = boxFrame.transpose() * Eigen::Vector3d{x, y, z};
62 allProjected.emplace_back(t.y(), t.z());
67 const auto& resize = [&](
auto size)
69 allProjected.reserve(size);
75 std::vector<Point_2> chullAll;
76 CGAL::convex_hull_2(allProjected.begin(), allProjected.end(), std::back_inserter(chullAll));
79 CGAL::min_rectangle_2(chullAll.begin(), chullAll.end(), std::back_inserter(polyAll));
80 const auto& polyps = polyAll.container();
83 <<
'\n' <<
VAROUT(normal.transpose())
84 <<
'\n' <<
VAROUT(boxFrame)
85 <<
'\n' <<
VAROUT(allProjected.size())
86 <<
'\n' <<
VAROUT(chullAll.size())
87 <<
'\n' <<
VAROUT(polyAll.container().size());
89 const auto v0 = polyps.at(0) - polyps.at(1);
90 const auto v1 = polyps.at(2) - polyps.at(1);
93 Eigen::Vector3d{allMinX, polyps.at(1).x(), polyps.at(1).y()},
94 Eigen::Vector3d{allMaxX - allMinX, 0, 0},
95 Eigen::Vector3d{0, v0.x(), v0.y()},
96 Eigen::Vector3d{0, v1.x(), v1.y()}
97 }.transformed(boxFrame);
101 simox::XYConstrainedOrientedBox<double> calculateXYOOBB(
const T& cloud)
103 const auto oobb = calculate2dOOBB(cloud, Eigen::Vector3d::UnitZ());
105 <<
'\n' <<
VAROUT(oobb.transformation())
106 <<
'\n' <<
VAROUT(oobb.dimensions())
107 <<
'\n' <<
VAROUT(oobb.axis_x().transpose());
110 const Eigen::Vector3d e1 = oobb.extend(1);
111 const Eigen::Vector3d e2 = oobb.extend(2);
126 const auto box1 = calculate2dOOBB(cloud, Eigen::Vector3d::UnitZ());
129 <<
'\n' <<
VAROUT(box1.transformation());
131 const Eigen::Vector3d
norm =
132 (box1.axis_y().norm() < box1.axis_z().norm()) ?
133 box1.axis_y() : box1.axis_z();
135 const auto box2 = calculate2dOOBB(cloud,
norm);
137 <<
'\n' <<
VAROUT(box2.transformation())
145 inline std::vector<Eigen::Vector3f> trimXYZHistogram(
148 const float trimEachSideBy)
150 std::vector<float> valuesX;
151 std::vector<float> valuesY;
152 std::vector<float> valuesZ;
155 const auto& consume = [&](
auto x,
auto y,
auto z)
157 const Eigen::Vector3f ted =
transform * Eigen::Vector3f{x, y, z};
158 valuesX.emplace_back(ted.x());
159 valuesY.emplace_back(ted.y());
160 valuesZ.emplace_back(ted.z());
162 const auto& resize = [&](
auto size)
165 valuesX.reserve(size);
166 valuesY.reserve(size);
167 valuesZ.reserve(size);
172 std::sort(valuesX.begin(), valuesX.end());
173 std::sort(valuesY.begin(), valuesY.end());
174 std::sort(valuesZ.begin(), valuesZ.end());
176 const std::size_t idxLo = sz * trimEachSideBy;
177 const std::size_t idxHi = sz -
std::max(idxLo, 1ul);
178 const float loX = valuesX.at(idxLo);
179 const float hiX = valuesX.at(idxHi);
180 const float loY = valuesY.at(idxLo);
181 const float hiY = valuesY.at(idxHi);
182 const float loZ = valuesZ.at(idxLo);
183 const float hiZ = valuesZ.at(idxHi);
186 std::vector<Eigen::Vector3f> result;
188 const auto& consume = [&](
auto x,
auto y,
auto z)
190 const Eigen::Vector3f ted =
transform * Eigen::Vector3f{x, y, z};
192 ted.x() <= hiX && ted.x() >= loX &&
193 ted.y() <= hiY && ted.y() >= loY &&
194 ted.z() <= hiZ && ted.z() >= loZ
197 result.emplace_back(x, y, z);
200 const auto& resize = [&](
auto) {};