25 std::vector<typename Kernel::Point_2>
const &points,
26 const double cell_size = 0.2) {
28 double min_x = polygon[0].x(), max_x = polygon[0].x();
29 double min_y = polygon[0].y(), max_y = polygon[0].y();
30 for (
auto &p : polygon) {
31 min_x = std::min(min_x, p.x());
32 max_x = std::max(max_x, p.x());
33 min_y = std::min(min_y, p.y());
34 max_y = std::max(max_y, p.y());
37 int nx =
static_cast<int>(std::ceil((max_x - min_x) / cell_size));
38 int ny =
static_cast<int>(std::ceil((max_y - min_y) / cell_size));
40 int covered_cells = 0;
43 for (
int i = 0; i < nx; ++i) {
44 for (
int j = 0; j < ny; ++j) {
45 const double cx = min_x + (i + 0.5) * cell_size;
46 const double cy = min_y + (j + 0.5) * cell_size;
47 typename Kernel::Point_2 cell_center(cx, cy);
48 if (polygon.bounded_side(cell_center) == CGAL::ON_UNBOUNDED_SIDE)
52 for (
auto &pt : points) {
53 if (std::abs(pt.x() - cx) <= cell_size / 2 &&
54 std::abs(pt.y() - cy) <= cell_size / 2) {
64 return static_cast<double>(covered_cells) / total_cells;
70 std::vector<pcl::IndicesPtr> &inliers,
71 const double grid_size) ->
void {
73 using EPICK = CGAL::Exact_predicates_inexact_constructions_kernel;
75 using Point_3 = EPICK::Point_3;
76 using Plane_3 = EPICK::Plane_3;
78 using Polygon_2 = CGAL::Polygon_2<EPICK>;
79 using Point_2 = Polygon_2::Point_2;
82 spdlog::trace(
"calling compute_face_coverage");
88 spdmon::LoggerProgress(
"Computing face coverage", this->
num_faces());
90 std::vector<ReUseX::geometry::CellComplex::Vertex> face_list;
93 face_list.push_back(*fit);
95#pragma omp parallel for schedule(dynamic)
96 for (
size_t face_idx = 0; face_idx < face_list.size(); ++face_idx) {
97 auto fit = face_list[face_idx];
102 const int plane_id = std::get<FaceData>((*
this)[fit].data).plane_id;
104 auto get_comverage = [&](
const int id) {
112 const auto plane_vec = planes[id];
113 const auto indices = inliers[id];
115 const Plane_3 plane(plane_vec[0], plane_vec[1], plane_vec[2],
118 if (indices->empty())
123 std::back_inserter(polygon), [&](
Vertex v) {
124 const auto pos = (*this)[v].pos;
125 return plane.to_2d(Point_3(pos[0], pos[1], pos[2]));
135 const auto inliers = *indices | ranges::views::transform([&](
int idx) {
136 const PointT &p = cloud->points[idx];
137 return plane.to_2d(Point_3(p.x, p.y, p.z));
138 }) | ranges::views::filter([&](
const Point_2 &p) {
139 return polygon.bounded_side(p) == CGAL::ON_BOUNDED_SIDE;
140 }) | ranges::to<std::vector>();
148 auto val = get_comverage(plane_id);
std::vector< Eigen::Matrix< Scalar, Rows, 1 >, Eigen::aligned_allocator< Eigen::Matrix< Scalar, Rows, 1 > > > EigenVectorContainer