ReUseX  0.0.5
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
29namespace reusex::geometry {
30
31enum class SceneNodeType { point_cluster, plane, object };
32
34 std::vector<int> point_indices;
35};
36
37struct ScenePlane {
38 Eigen::Vector4d coefficients;
39 Eigen::Vector3d origin;
40};
41
43 int label;
44};
45
46// Generic vertex bundle
48 Eigen::Vector3d centroid;
50 std::variant<PointCluster, ScenePlane> data;
51};
52
54 //
55};
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 SceneVertexData, SceneEdgeData>,
72 public Registry {
73 protected:
74 using Graph =
75 boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,
77
78 public:
79 using Vertex = boost::graph_traits<Graph>::vertex_descriptor;
80
81 protected:
82 private:
83 CloudConstPtr cloud_ = nullptr;
84 std::map<int, std::string> label_map_ = {};
85 std::filesystem::path database_path_ = "";
86
87 public:
88 SceneGraph() = default;
89 ~SceneGraph() = default;
90
98
104 std::vector<CloudConstPtr> extract(int label) const;
105
111 std::vector<CloudConstPtr> extract(std::string const label_name) const;
112
118 std::set<int> get_labels() const;
119
125 void set_database_path(std::filesystem::path db_path);
126
131 int save(const std::filesystem::path &path) const;
132
138 int export(const std::filesystem::path &path) const;
139
144 static SceneGraph load(const std::filesystem::path &path);
145
146 private:
155 void patch_segmentation();
156
166 void planar_region_growing();
167
178 void project_labels_from_database();
179
190 void segment_rooms();
191};
192} // namespace reusex::geometry
193
194template <> struct fmt::formatter<reusex::geometry::SceneGraph> {
195 // Parse function (optional)
196 template <typename ParseContext> constexpr auto parse(ParseContext &ctx) {
197 return ctx.begin();
198 }
199
200 // Format function
201 template <typename FormatContext>
203 FormatContext &ctx) const {
204 return fmt::format_to(ctx.out(), "SceneGraph");
205 }
206};
207
208// Implementation files
SceneGraph(CloudConstPtr cloud, CloudNConstPtr normals)
Construct a scene graph from a point cloud and its normals.
boost::graph_traits< Graph >::vertex_descriptor Vertex
boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, SceneVertexData, SceneEdgeData > Graph
std::vector< CloudConstPtr > extract(std::string const label_name) const
Extract point clouds corresponding to a specific label name.
static SceneGraph load(const std::filesystem::path &path)
Load the scene graph from a file.
int save(const std::filesystem::path &path) const
Save the scene graph to a file.
std::set< int > get_labels() const
Get all unique labels in the scene graph.
std::vector< CloudConstPtr > extract(int label) const
Extract point clouds corresponding to a specific label.
void set_database_path(std::filesystem::path db_path)
Set the database path.
int export(const std::filesystem::path &path) const
Export the scene graph to differnet formats.
typename Cloud::ConstPtr CloudConstPtr
Definition types.hpp:28
typename CloudN::ConstPtr CloudNConstPtr
Definition types.hpp:32
constexpr auto parse(ParseContext &ctx)
auto format(const reusex::geometry::SceneGraph &obj, FormatContext &ctx) const
std::vector< int > point_indices
std::variant< PointCluster, ScenePlane > data