8#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
9#include <CGAL/Shape_regularization/regularize_planes.h>
10#include <CGAL/property_map.h>
14#include <pcl/common/common.h>
15#include <pcl/point_cloud.h>
16#include <pcl/point_types.h>
18#include <range/v3/to_container.hpp>
19#include <range/v3/view/transform.hpp>
21#include <spdlog/spdlog.h>
24template <
typename Kernel,
typename Scalar>
struct plane_map {
27 Eigen::Matrix<Scalar, 4, 1>;
33 boost::readable_property_map_tag;
35 using FT =
typename Kernel::FT;
45 p(0) =
static_cast<Scalar
>(CGAL::to_double(val.a()));
46 p(1) =
static_cast<Scalar
>(CGAL::to_double(val.b()));
47 p(2) =
static_cast<Scalar
>(CGAL::to_double(val.c()));
48 p(3) =
static_cast<Scalar
>(CGAL::to_double(val.d()));
52template <
typename Kernel,
typename Po
intT>
struct point_map {
57 using category = boost::readable_property_map_tag;
67 pt.x =
static_cast<typename PointT::ScalarType
>(CGAL::to_double(val.x()));
68 pt.y =
static_cast<typename PointT::ScalarType
>(CGAL::to_double(val.y()));
69 pt.z =
static_cast<typename PointT::ScalarType
>(CGAL::to_double(val.z()));
74template <
typename Scalar>
using Plane = Eigen::Matrix<Scalar, 4, 1>;
76template <
typename Scalar>
78 std::vector<Plane<Scalar>, Eigen::aligned_allocator<Plane<Scalar>>>;
80template <
typename Scalar,
typename Po
intT>
82 typename pcl::PointCloud<PointT>::ConstPtr points,
83 std::vector<pcl::IndicesPtr> &inliers,
84 double angle_threshold = 25.0,
85 double distance_threshold = 0.01) {
87 "Regularizing planes with threshold: {} degrees and {} distance",
88 angle_threshold, distance_threshold);
90 using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;
91 using FT =
typename Kernel::FT;
93 std::vector<int> point_plane_index(points->size(), -1);
94 for (
size_t i = 0; i < inliers.size(); ++i) {
95 for (
const auto &idx : *(inliers[i])) {
96 point_plane_index[idx] =
static_cast<int>(i);
100 CGAL::Shape_regularization::Planes::regularize_planes(
102 CGAL::Random_access_property_map(
109 FT(distance_threshold));
std::vector< Plane< Scalar >, Eigen::aligned_allocator< Plane< Scalar > > > PlaneVector
Eigen::Matrix< Scalar, 4, 1 > Plane
auto regularizePlanes(PlaneVector< Scalar > &planes, typename pcl::PointCloud< PointT >::ConstPtr points, std::vector< pcl::IndicesPtr > &inliers, double angle_threshold=25.0, double distance_threshold=0.01)
Eigen::Matrix< Scalar, 4, 1 > key_type
typename Kernel::Plane_3 value_type
friend value_type get(const plane_map &, const key_type &p)
friend void put(const plane_map &, key_type &p, const value_type &val)
value_type operator[](const key_type &p) const
boost::readable_property_map_tag category
friend void put(const point_map &, key_type &pt, const value_type &val)
boost::readable_property_map_tag category
friend value_type get(const point_map &, const key_type &pt)
typename Kernel::Point_3 value_type
value_type operator[](const key_type &pt) const