ReUseX
0.0.5
3D Point Cloud Processing for Building Reuse
Toggle main menu visibility
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
29
namespace
reusex::geometry
{
30
31
enum class
SceneNodeType
{
point_cluster
,
plane
,
object
};
32
33
struct
PointCluster
{
34
std::vector<int>
point_indices
;
35
};
36
37
struct
ScenePlane
{
38
Eigen::Vector4d
coefficients
;
39
Eigen::Vector3d
origin
;
40
};
41
42
struct
SceneObject
{
43
int
label
;
44
};
45
46
// Generic vertex bundle
47
struct
SceneVertexData
{
48
Eigen::Vector3d
centroid
;
49
SceneNodeType
type
;
50
std::variant<PointCluster, ScenePlane>
data
;
51
};
52
53
struct
SceneEdgeData
{
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
69
class
SceneGraph
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,
76
SceneVertexData
,
SceneEdgeData
>;
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
97
SceneGraph
(
CloudConstPtr
cloud,
CloudNConstPtr
normals);
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
194
template
<>
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>
202
auto
format
(
const
reusex::geometry::SceneGraph
&obj,
203
FormatContext &ctx)
const
{
204
return
fmt::format_to(ctx.out(),
"SceneGraph"
);
205
}
206
};
207
208
// Implementation files
reusex::geometry::Registry
Definition
Registry.hpp:17
reusex::geometry::SceneGraph
Definition
SceneGraph.hpp:72
reusex::geometry::SceneGraph::SceneGraph
SceneGraph(CloudConstPtr cloud, CloudNConstPtr normals)
Construct a scene graph from a point cloud and its normals.
reusex::geometry::SceneGraph::Vertex
boost::graph_traits< Graph >::vertex_descriptor Vertex
Definition
SceneGraph.hpp:79
reusex::geometry::SceneGraph::Graph
boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, SceneVertexData, SceneEdgeData > Graph
Definition
SceneGraph.hpp:74
reusex::geometry::SceneGraph::extract
std::vector< CloudConstPtr > extract(std::string const label_name) const
Extract point clouds corresponding to a specific label name.
reusex::geometry::SceneGraph::~SceneGraph
~SceneGraph()=default
reusex::geometry::SceneGraph::load
static SceneGraph load(const std::filesystem::path &path)
Load the scene graph from a file.
reusex::geometry::SceneGraph::save
int save(const std::filesystem::path &path) const
Save the scene graph to a file.
reusex::geometry::SceneGraph::SceneGraph
SceneGraph()=default
reusex::geometry::SceneGraph::get_labels
std::set< int > get_labels() const
Get all unique labels in the scene graph.
reusex::geometry::SceneGraph::extract
std::vector< CloudConstPtr > extract(int label) const
Extract point clouds corresponding to a specific label.
reusex::geometry::SceneGraph::set_database_path
void set_database_path(std::filesystem::path db_path)
Set the database path.
reusex::geometry::SceneGraph::export
int export(const std::filesystem::path &path) const
Export the scene graph to differnet formats.
reusex::geometry
Definition
processing_observer.hpp:19
reusex::geometry::SceneNodeType
SceneNodeType
Definition
SceneGraph.hpp:31
reusex::geometry::SceneNodeType::plane
@ plane
Definition
SceneGraph.hpp:31
reusex::geometry::SceneNodeType::point_cluster
@ point_cluster
Definition
SceneGraph.hpp:31
reusex
Definition
filter_expression.hpp:12
reusex::CloudConstPtr
typename Cloud::ConstPtr CloudConstPtr
Definition
types.hpp:28
reusex::CloudNConstPtr
typename CloudN::ConstPtr CloudNConstPtr
Definition
types.hpp:32
fmt::formatter< reusex::geometry::SceneGraph >::parse
constexpr auto parse(ParseContext &ctx)
Definition
SceneGraph.hpp:196
fmt::formatter< reusex::geometry::SceneGraph >::format
auto format(const reusex::geometry::SceneGraph &obj, FormatContext &ctx) const
Definition
SceneGraph.hpp:202
reusex::geometry::PointCluster
Definition
SceneGraph.hpp:33
reusex::geometry::PointCluster::point_indices
std::vector< int > point_indices
Definition
SceneGraph.hpp:34
reusex::geometry::SceneEdgeData
Definition
SceneGraph.hpp:53
reusex::geometry::SceneObject
Definition
SceneGraph.hpp:42
reusex::geometry::SceneObject::label
int label
Definition
SceneGraph.hpp:43
reusex::geometry::ScenePlane
Definition
SceneGraph.hpp:37
reusex::geometry::ScenePlane::origin
Eigen::Vector3d origin
Definition
SceneGraph.hpp:39
reusex::geometry::ScenePlane::coefficients
Eigen::Vector4d coefficients
Definition
SceneGraph.hpp:38
reusex::geometry::SceneVertexData
Definition
SceneGraph.hpp:47
reusex::geometry::SceneVertexData::data
std::variant< PointCluster, ScenePlane > data
Definition
SceneGraph.hpp:50
reusex::geometry::SceneVertexData::type
SceneNodeType type
Definition
SceneGraph.hpp:49
reusex::geometry::SceneVertexData::centroid
Eigen::Vector3d centroid
Definition
SceneGraph.hpp:48
libs
reusex
include
geometry
SceneGraph.hpp
Generated by
1.17.0