ReUseX  0.0.5
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
speckle.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/types.hpp"
7
8#include <Eigen/Core>
9#include <pcl/PolygonMesh.h>
10
11#include <nlohmann/json.hpp>
12
13#include <array>
14#include <map>
15#include <memory>
16#include <string>
17#include <utility>
18#include <vector>
19
20namespace reusex::io {
21struct ExportScene;
22}
23
25
26// --- Speckle Object Model ---
27
29struct Base {
30 std::string speckle_type = "Base";
31 std::string applicationId;
32 std::string name;
35 std::map<std::string, nlohmann::json> properties;
36
38 std::vector<std::shared_ptr<Base>> elements;
39
40 virtual ~Base() = default;
41};
42
44struct Point : Base {
45 double x = 0, y = 0, z = 0;
46 std::string units = "m";
47
48 Point() { speckle_type = "Objects.Geometry.Point"; }
49 Point(double x, double y, double z) : x(x), y(y), z(z) {
50 speckle_type = "Objects.Geometry.Point";
51 }
52};
53
55struct Line : Base {
57 std::string units = "m";
58
59 Line() { speckle_type = "Objects.Geometry.Line"; }
60};
61
63struct Mesh : Base {
64 std::vector<double> vertices;
65 std::vector<int> faces;
66 std::vector<int> colors;
67 std::string units = "m";
68
69 Mesh() { speckle_type = "Objects.Geometry.Mesh"; }
70};
71
73struct Pointcloud : Base {
74 std::vector<double> points;
75 std::vector<int> colors;
76 std::vector<double> sizes;
77 std::string units = "m";
78
79 Pointcloud() { speckle_type = "Objects.Geometry.Pointcloud"; }
80};
81
88 std::string definitionAppId;
89 int maxDepth = 0;
90 std::string units = "m";
91 std::vector<std::string> objects;
92
94 speckle_type = "Speckle.Core.Models.Instances.InstanceDefinitionProxy";
95 }
96};
97
101 std::string definitionId;
102 std::array<double, 16> transform{1, 0, 0, 0, 0, 1, 0, 0,
103 0, 0, 1, 0, 0, 0, 0, 1};
104 int maxDepth = 0;
105 std::string units = "m";
106
108 speckle_type = "Speckle.Core.Models.Instances.InstanceProxy";
109 }
110};
111
116struct Collection : Base {
117 std::string collectionType;
120 int version = 0;
129 bool embed_elements = false;
130 std::vector<std::shared_ptr<InstanceDefinitionProxy>>
132
133 Collection() { speckle_type = "Speckle.Core.Models.Collections.Collection"; }
134};
135
136// --- Serialization ---
137
148std::pair<std::string, std::vector<nlohmann::json>> flatten(const Base &root);
149
150// --- Client ---
151
154 public:
159 SpeckleClient(std::string server_url, std::string project_id,
160 std::string token = "");
161
164 std::string send(const Base &root);
165
168 std::string commit(const std::string &object_id,
169 const std::string &branch = "main",
170 const std::string &message = "ReUseX upload");
171
174 std::string upload(const Base &root, const std::string &branch = "main",
175 const std::string &message = "ReUseX upload");
176
178 void set_max_batch_size(std::size_t bytes);
179
180 private:
182 void ensure_branch(const std::string &branch);
183
184 std::string server_url_;
185 std::string project_id_;
186 std::string token_;
187 std::size_t max_batch_bytes_ = 25 * 1024 * 1024; // 25 MB
188};
189
190// --- Conversion Helpers ---
191
194
196Mesh to_speckle(const pcl::PolygonMesh &mesh);
197
200Mesh to_speckle(const Eigen::MatrixXd &vertices, const Eigen::MatrixXi &faces);
201
202// --- Scene Export ---
203
206 std::string model_name;
207 std::shared_ptr<Base> root;
208};
209
213 std::string project_id;
214 std::string image_url_base = "https://minio.chrk.site/files/reusex";
215};
216
219auto export_to_speckle(const ExportScene &scene, const ExportConfig &cfg)
220 -> std::vector<SpeckleModel>;
221
222} // namespace reusex::io::speckle
SpeckleClient(std::string server_url, std::string project_id, std::string token="")
Construct a client.
std::string send(const Base &root)
Send a root object and all its children to the server.
std::string commit(const std::string &object_id, const std::string &branch="main", const std::string &message="ReUseX upload")
Create a commit/version pointing to a root object hash.
std::string upload(const Base &root, const std::string &branch="main", const std::string &message="ReUseX upload")
Convenience: send + commit in one call.
void set_max_batch_size(std::size_t bytes)
Max HTTP batch payload size in bytes (default: 25 MB).
std::pair< std::string, std::vector< nlohmann::json > > flatten(const Base &root)
Serialize an object tree into the flat list of Speckle objects that SpeckleClient::send uploads,...
auto export_to_speckle(const ExportScene &scene, const ExportConfig &cfg) -> std::vector< SpeckleModel >
Build per-model Speckle objects from an ExportScene.
Pointcloud to_speckle(CloudConstPtr cloud)
Convert a PCL point cloud to a Speckle Pointcloud.
typename Cloud::ConstPtr CloudConstPtr
Intermediate representation for exporting all project data.
Base class for all Speckle objects.
Definition speckle.hpp:29
std::vector< std::shared_ptr< Base > > elements
Child objects (serialized as detached @elements).
Definition speckle.hpp:38
virtual ~Base()=default
std::string applicationId
Definition speckle.hpp:31
std::map< std::string, nlohmann::json > properties
Custom properties — serialized nested under a "properties" sub-path (Speckle v3 DataObject convention...
Definition speckle.hpp:35
int version
Speckle SDK version marker.
Definition speckle.hpp:120
std::vector< std::shared_ptr< InstanceDefinitionProxy > > instanceDefinitionProxies
Definition speckle.hpp:131
bool embed_elements
When true, child elements are serialized inline (under the key elements, no @ prefix) instead of as d...
Definition speckle.hpp:129
Configuration for building Speckle objects from an ExportScene.
Definition speckle.hpp:212
std::vector< std::string > objects
Definition speckle.hpp:91
std::array< double, 16 > transform
Definition speckle.hpp:102
Triangle/quad mesh.
Definition speckle.hpp:63
std::vector< double > vertices
Flat [x,y,z,x,y,z,...].
Definition speckle.hpp:64
std::vector< int > faces
Packed [n, i0, i1, ..., n, i0, i1, ...].
Definition speckle.hpp:65
std::vector< int > colors
ARGB integers.
Definition speckle.hpp:66
Point(double x, double y, double z)
Definition speckle.hpp:49
std::vector< double > sizes
Per-point sizes.
Definition speckle.hpp:76
std::vector< int > colors
ARGB integers.
Definition speckle.hpp:75
std::vector< double > points
Flat [x,y,z,x,y,z,...].
Definition speckle.hpp:74
One model (branch) to upload to Speckle.
Definition speckle.hpp:205
std::string model_name
branch name (e.g., "cloud", "semantic")
Definition speckle.hpp:206
std::shared_ptr< Base > root
root object for this model's version
Definition speckle.hpp:207