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
7#include <ReUseX/types.hpp>
8
9#include <boost/graph/adjacency_list.hpp>
10#include <boost/graph/graph_traits.hpp>
11#include <boost/graph/graphviz.hpp> // write_graphviz, read_graphviz
12#include <boost/iterator/filter_iterator.hpp>
13#include <boost/property_map/dynamic_property_map.hpp>
14#include <boost/serialization/shared_ptr.hpp>
15#include <fstream>
16
17#include <spdlog/spdlog.h>
18
19#include <fmt/format.h>
20
21#include <set>
22#include <string>
23#include <vector>
24
25#include <Eigen/StdVector>
26
27#include <pcl/pcl_base.h>
28#include <pcl/point_cloud.h>
29#include <pcl/point_types.h>
30
31#include <range/v3/range/concepts.hpp>
32#include <range/v3/view/zip.hpp>
33
35
37 std::vector<int> point_indices;
38};
39
40struct Plane {
41 Eigen::Vector4d coefficients;
42 Eigen::Vector3d origin;
43};
44
45struct Object {
46 int label;
47};
48
49// Generic vertex bundle
50struct VertexData {
51 Eigen::Vector3d centroid;
53 std::variant<PointCluster, Plane> data;
54};
55
56struct EdgeData {
57 //
58};
59
60namespace ReUseX::geometry {
61
62// TODO: Fully implement SceneGraph as central scene representation
63// category=Geometry estimate=2w
64// SceneGraph is partially defined but needs complete implementation to become
65// the core data structure for ReUseX spatial reasoning. Required features:
66// 1. Hierarchical object relationships (rooms contain walls, walls contain windows)
67// 2. Spatial queries (find objects in bounding box, nearest neighbors)
68// 3. Attribute management via Registry (materials, labels, metadata)
69// 4. Serialization/deserialization to HDF5 format
70// 5. Integration with CellComplex for 3D reconstruction pipeline
71// 6. Visitor pattern for scene traversal and operations
72// Major architectural work but enables modular scene manipulation
74 : public boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,
75 VertexData, EdgeData>,
76 public Registry {
77 protected:
78 using Graph = boost::adjacency_list<boost::vecS, boost::vecS,
79 boost::undirectedS, VertexData, EdgeData>;
80
81 public:
82 using Vertex = boost::graph_traits<Graph>::vertex_descriptor;
83
84 protected:
85 private:
86 CloudConstPtr cloud_ = nullptr;
87 std::map<int, std::string> label_map_ = {};
88 std::filesystem::path database_path_ = "";
89
90 public:
91 SceneGraph() = default;
92 ~SceneGraph() = default;
93
101
107 std::vector<CloudConstPtr> extract(int label) const;
108
114 std::vector<CloudConstPtr> ectract(std::string const label_name) const;
115
121 std::set<int> get_labels() const;
122
128 void set_database_path(std::filesystem::path db_path);
129
134 int save(const std::filesystem::path &path) const;
135
141 int export(const std::filesystem::path &path) const;
142
147 static SceneGraph load(const std::filesystem::path &path);
148
149 private:
158 void patch_segmentation();
159
169 void planar_region_growing();
170
181 void project_labels_from_database();
182
193 void segment_rooms();
194};
195} // namespace ReUseX::geometry
196
197template <> struct fmt::formatter<ReUseX::geometry::SceneGraph> {
198 // Parse function (optional)
199 template <typename ParseContext> constexpr auto parse(ParseContext &ctx) {
200 return ctx.begin();
201 }
202
203 // Format function
204 template <typename FormatContext>
206 FormatContext &ctx) const {
207 return fmt::format_to(ctx.out(), "SceneGraph");
208 }
209};
210
211// 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:27
typename Cloud::ConstPtr CloudConstPtr
Definition types.hpp:23
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