ReUseX  0.0.1
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
SceneGraph.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 Povl Filip Sonne-Frederiksen
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#pragma once
6#include "reusex/core/logging.hpp"
7#include "reusex/geometry/Registry.hpp"
8#include "reusex/types.hpp"
9
10#include <Eigen/StdVector>
11#include <boost/graph/adjacency_list.hpp>
12#include <boost/graph/graph_traits.hpp>
13#include <boost/graph/graphviz.hpp> // write_graphviz, read_graphviz
14#include <boost/iterator/filter_iterator.hpp>
15#include <boost/property_map/dynamic_property_map.hpp>
16#include <boost/serialization/shared_ptr.hpp>
17#include <fmt/format.h>
18#include <pcl/pcl_base.h>
19#include <pcl/point_cloud.h>
20#include <pcl/point_types.h>
21#include <range/v3/range/concepts.hpp>
22#include <range/v3/view/zip.hpp>
23
24#include <fstream>
25#include <set>
26#include <string>
27#include <vector>
28
30
32 std::vector<int> point_indices;
33};
34
35struct Plane {
36 Eigen::Vector4d coefficients;
37 Eigen::Vector3d origin;
38};
39
40struct Object {
41 int label;
42};
43
44// Generic vertex bundle
45struct VertexData {
46 Eigen::Vector3d centroid;
48 std::variant<PointCluster, Plane> data;
49};
50
51struct EdgeData {
52 //
53};
54
55namespace ReUseX::geometry {
56
57// TODO: Fully implement SceneGraph as central scene representation
58// category=Geometry estimate=2w
59// SceneGraph is partially defined but needs complete implementation to become
60// the core data structure for ReUseX spatial reasoning. Required features:
61// 1. Hierarchical object relationships (rooms contain walls, walls contain
62// windows)
63// 2. Spatial queries (find objects in bounding box, nearest neighbors)
64// 3. Attribute management via Registry (materials, labels, metadata)
65// 4. Serialization/deserialization to HDF5 format
66// 5. Integration with CellComplex for 3D reconstruction pipeline
67// 6. Visitor pattern for scene traversal and operations
68// Major architectural work but enables modular scene manipulation
70 : public boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,
71 VertexData, EdgeData>,
72 public Registry {
73 protected:
74 using Graph = boost::adjacency_list<boost::vecS, boost::vecS,
75 boost::undirectedS, VertexData, EdgeData>;
76
77 public:
78 using Vertex = boost::graph_traits<Graph>::vertex_descriptor;
79
80 protected:
81 private:
82 CloudConstPtr cloud_ = nullptr;
83 std::map<int, std::string> label_map_ = {};
84 std::filesystem::path database_path_ = "";
85
86 public:
87 SceneGraph() = default;
88 ~SceneGraph() = default;
89
97
103 std::vector<CloudConstPtr> extract(int label) const;
104
110 std::vector<CloudConstPtr> ectract(std::string const label_name) const;
111
117 std::set<int> get_labels() const;
118
124 void set_database_path(std::filesystem::path db_path);
125
130 int save(const std::filesystem::path &path) const;
131
137 int export(const std::filesystem::path &path) const;
138
143 static SceneGraph load(const std::filesystem::path &path);
144
145 private:
154 void patch_segmentation();
155
165 void planar_region_growing();
166
177 void project_labels_from_database();
178
189 void segment_rooms();
190};
191} // namespace ReUseX::geometry
192
193template <> struct fmt::formatter<ReUseX::geometry::SceneGraph> {
194 // Parse function (optional)
195 template <typename ParseContext> constexpr auto parse(ParseContext &ctx) {
196 return ctx.begin();
197 }
198
199 // Format function
200 template <typename FormatContext>
202 FormatContext &ctx) const {
203 return fmt::format_to(ctx.out(), "SceneGraph");
204 }
205};
206
207// Implementation files
NodeType
NodeType
SceneGraph(CloudConstPtr cloud, CloudNConstPtr normals)
Construct a scene graph from a point cloud and its normals.
boost::graph_traits< Graph >::vertex_descriptor Vertex
int export(const std::filesystem::path &path) const
Export the scene graph to differnet formats.
boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, VertexData, EdgeData > Graph
void set_database_path(std::filesystem::path db_path)
Set the database path.
std::set< int > get_labels() const
Get all unique labels in the scene graph.
int save(const std::filesystem::path &path) const
Save the scene graph to a file.
static SceneGraph load(const std::filesystem::path &path)
Load the scene graph from a file.
std::vector< CloudConstPtr > ectract(std::string const label_name) const
Extract point clouds corresponding to a specific label name.
std::vector< CloudConstPtr > extract(int label) const
Extract point clouds corresponding to a specific label.
typename CloudN::ConstPtr CloudNConstPtr
Definition types.hpp:30
typename Cloud::ConstPtr CloudConstPtr
Definition types.hpp:26
int label
Eigen::Vector4d coefficients
Eigen::Vector3d origin
std::vector< int > point_indices
NodeType type
Eigen::Vector3d centroid
std::variant< PointCluster, Plane > data
constexpr auto parse(ParseContext &ctx)
auto format(const ReUseX::geometry::SceneGraph &obj, FormatContext &ctx) const