6#include "reusex/core/logging.hpp"
7#include "reusex/geometry/Registry.hpp"
8#include "reusex/types.hpp"
10#include <Eigen/StdVector>
11#include <boost/graph/adjacency_list.hpp>
12#include <boost/graph/graph_traits.hpp>
13#include <boost/iterator/filter_iterator.hpp>
14#include <fmt/format.h>
15#include <pcl/pcl_base.h>
16#include <pcl/point_cloud.h>
17#include <pcl/point_types.h>
18#include <range/v3/range/concepts.hpp>
19#include <range/v3/view/zip.hpp>
47 std::variant<CellVertexData, FaceData, CellData>
data;
55 :
public boost::adjacency_list<boost::vecS,
66 boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,
70 using Vertex = boost::graph_traits<Graph>::vertex_descriptor;
71 using GraphIter = boost::graph_traits<CellComplex>::vertex_iterator;
72 using AdjacencyIter = boost::graph_traits<CellComplex>::adjacency_iterator;
75 template <CellNodeType T>
struct Is_Type {
79 bool operator()(CellComplex::vertex_descriptor vd)
const {
80 auto const &prop = (*g)[vd];
81 return prop.type == T;
92 bool operator()(CellComplex::vertex_descriptor vd)
const {
93 auto const &prop = (*g)[vd];
95 auto [begin, end] = boost::adjacent_vertices(vd, *
g);
96 for (
auto it = begin; it != end; ++it)
106 boost::filter_iterator<IsFaceBetweenCells, GraphIter>;
113 int vertex_count = 0;
123 std::vector<Eigen::Vector4d, Eigen::aligned_allocator<Eigen::Vector4d>>
125 std::vector<size_t> &verticals,
126 const std::vector<size_t> &horizontals,
127 std::vector<std::pair<size_t, size_t>> &pairs,
128 std::array<double, 2> min_xy, std::array<double, 2> max_xy,
130 std::function<
void(
size_t, std::vector<std::array<double, 3>>
const &,
131 std::vector<int>
const &)>>
132 viz_func = std::nullopt);
136 template <
typename Po
intT = pcl::Po
intXYZ>
139 std::vector<pcl::IndicesPtr> &inliers,
140 const double grid_size = 0.2) -> void;
142 template <
typename PointT = pcl::PointXYZ,
typename PointN = pcl::Normal,
143 typename PointL = pcl::Label>
145 pcl::PointCloud<PointN>::ConstPtr normals,
146 pcl::PointCloud<PointL>::ConstPtr labels,
147 const double grid_size = 0.2) -> void;
150 auto v = boost::add_vertex(*
this);
152 (*this)[v].id = vertex_count++;
153 (*this)[v].pos = pos;
158 template <
typename T>
161 auto f = boost::add_vertex(*
this);
163 (*this)[f].id = face_count++;
164 (*this)[f].pos = pos;
165 (*this)[f].data =
FaceData{plane_id};
166 for (
auto it = begin; it != end; ++it)
167 boost::add_edge(*it, f, *
this);
170 template <
typename Range>
173 return add_face(pos, std::begin(vertices), std::end(vertices), plane_id);
176 template <
typename T>
178 auto c = boost::add_vertex(*
this);
180 (*this)[c].id = cell_count++;
181 (*this)[c].pos = pos;
183 for (
auto it = begin; it != end; ++it)
184 boost::add_edge(*it, c, *
this);
187 template <
typename Range>
189 return add_cell(pos, std::begin(faces), std::end(faces));
227 template <
typename ParseContext>
constexpr auto parse(ParseContext &ctx) {
232 template <
typename FormatContext>
234 FormatContext &ctx)
const {
235 return fmt::format_to(ctx.out(),
"[{}c {}f {}v {}r {}w]", obj.
num_cells(),
242#include "reusex/geometry/CellComplexFaceCoverage.hpp"
243#include "reusex/geometry/CellComplexRoomProbabilities.hpp"
boost::graph_traits< CellComplex >::adjacency_iterator AdjacencyIter
boost::filter_iterator< IsVertex, GraphIter > VertexIterator
Is_Type< CellNodeType::vertex > IsVertex
auto get_a(Vertex f) const -> Vertex
boost::filter_iterator< IsFace, GraphIter > FaceIterator
auto compute_face_coverage(pcl::PointCloud< PointT >::ConstPtr cloud, EigenVectorContainer< double, 4 > &planes, std::vector< pcl::IndicesPtr > &inliers, const double grid_size=0.2) -> void
auto faces_between_cells_end() const -> FaceBetweenCellIterator
boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, VertexProperties, CellEdgeData > Graph
auto cells_begin() const -> CellIterator
std::ostream & operator<<(std::ostream &os) const
Vertex add_cell(Eigen::Vector3d pos, Range faces)
size_t num_vertices() const
auto vertices_end() const -> VertexIterator
CellComplex(std::vector< Eigen::Vector4d, Eigen::aligned_allocator< Eigen::Vector4d > > &planes, std::vector< size_t > &verticals, const std::vector< size_t > &horizontals, std::vector< std::pair< size_t, size_t > > &pairs, std::array< double, 2 > min_xy, std::array< double, 2 > max_xy, std::optional< std::function< void(size_t, std::vector< std::array< double, 3 > > const &, std::vector< int > const &)> > viz_func=std::nullopt)
auto faces_end() const -> FaceIterator
boost::graph_traits< CellComplex >::vertex_iterator GraphIter
boost::graph_traits< Graph >::vertex_descriptor Vertex
auto get_b(Vertex f) const -> Vertex
auto vertices_of_face_end(Vertex f) const -> VertexOnFaceIterator
boost::filter_iterator< IsFaceBetweenCells, GraphIter > FaceBetweenCellIterator
auto faces_between_cells_begin() const -> FaceBetweenCellIterator
auto faces_of_cell_end(Vertex c) const -> FaceOnCellIterator
Is_Type< CellNodeType::cell > IsCell
boost::filter_iterator< IsCell, GraphIter > CellIterator
auto faces_begin() const -> FaceIterator
Vertex add_face(Eigen::Vector3d pos, Range vertices, int plane_id=-1)
auto faces_of_cell_begin(Vertex c) const -> FaceOnCellIterator
Is_Type< CellNodeType::face > IsFace
Vertex add_cell(Eigen::Vector3d pos, T begin, T end)
auto vertices_of_face_begin(Vertex f) const -> VertexOnFaceIterator
Vertex add_face(Eigen::Vector3d pos, T begin, T end, int plane_id=-1)
auto vertices_begin() const -> VertexIterator
boost::filter_iterator< IsFace, AdjacencyIter > FaceOnCellIterator
auto compute_room_probabilities(pcl::PointCloud< PointT >::ConstPtr cloud, pcl::PointCloud< PointN >::ConstPtr normals, pcl::PointCloud< PointL >::ConstPtr labels, const double grid_size=0.2) -> void
auto cells_end() const -> CellIterator
boost::filter_iterator< IsCell, AdjacencyIter > CellOnFaceIterator
Vertex add_vertex(Eigen::Vector3d pos)
boost::filter_iterator< IsVertex, AdjacencyIter > VertexOnFaceIterator
std::vector< Eigen::Matrix< Scalar, Rows, 1 >, Eigen::aligned_allocator< Eigen::Matrix< Scalar, Rows, 1 > > > EigenVectorContainer
bool operator()(CellComplex::vertex_descriptor vd) const
IsFaceBetweenCells()=delete
IsFaceBetweenCells(const CellComplex *graph)
bool operator()(CellComplex::vertex_descriptor vd) const
Is_Type(const CellComplex *graph)
std::variant< CellVertexData, FaceData, CellData > data