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 <vector>
18
19namespace reusex::io {
20struct ExportScene;
21}
22
24
25// --- Speckle Object Model ---
26
28struct Base {
29 std::string speckle_type = "Base";
30 std::string applicationId;
31 std::string name;
34 std::map<std::string, nlohmann::json> properties;
35
37 std::vector<std::shared_ptr<Base>> elements;
38
39 virtual ~Base() = default;
40};
41
43struct Point : Base {
44 double x = 0, y = 0, z = 0;
45 std::string units = "m";
46
47 Point() { speckle_type = "Objects.Geometry.Point"; }
48 Point(double x, double y, double z) : x(x), y(y), z(z) {
49 speckle_type = "Objects.Geometry.Point";
50 }
51};
52
54struct Line : Base {
56 std::string units = "m";
57
58 Line() { speckle_type = "Objects.Geometry.Line"; }
59};
60
62struct Mesh : Base {
63 std::vector<double> vertices;
64 std::vector<int> faces;
65 std::vector<int> colors;
66 std::string units = "m";
67
68 Mesh() { speckle_type = "Objects.Geometry.Mesh"; }
69};
70
72struct Pointcloud : Base {
73 std::vector<double> points;
74 std::vector<int> colors;
75 std::vector<double> sizes;
76 std::string units = "m";
77
78 Pointcloud() { speckle_type = "Objects.Geometry.Pointcloud"; }
79};
80
87 std::string definitionAppId;
88 int maxDepth = 0;
89 std::string units = "m";
90 std::vector<std::string> objects;
91
93 speckle_type = "Speckle.Core.Models.Instances.InstanceDefinitionProxy";
94 }
95};
96
100 std::string definitionId;
101 std::array<double, 16> transform{1, 0, 0, 0, 0, 1, 0, 0,
102 0, 0, 1, 0, 0, 0, 0, 1};
103 int maxDepth = 0;
104 std::string units = "m";
105
107 speckle_type = "Speckle.Core.Models.Instances.InstanceProxy";
108 }
109};
110
115struct Collection : Base {
116 std::string collectionType;
119 int version = 0;
128 bool embed_elements = false;
129 std::vector<std::shared_ptr<InstanceDefinitionProxy>>
131
133 speckle_type = "Speckle.Core.Models.Collections.Collection";
134 }
135};
136
137// --- Client ---
138
141 public:
146 SpeckleClient(std::string server_url, std::string project_id,
147 std::string token = "");
148
151 std::string send(const Base &root);
152
155 std::string commit(const std::string &object_id,
156 const std::string &branch = "main",
157 const std::string &message = "ReUseX upload");
158
161 std::string upload(const Base &root, const std::string &branch = "main",
162 const std::string &message = "ReUseX upload");
163
165 void set_max_batch_size(std::size_t bytes);
166
167 private:
169 void ensure_branch(const std::string &branch);
170
171 std::string server_url_;
172 std::string project_id_;
173 std::string token_;
174 std::size_t max_batch_bytes_ = 25 * 1024 * 1024; // 25 MB
175};
176
177// --- Conversion Helpers ---
178
181
183Mesh to_speckle(const pcl::PolygonMesh &mesh);
184
187Mesh to_speckle(const Eigen::MatrixXd &vertices, const Eigen::MatrixXi &faces);
188
189// --- Scene Export ---
190
193 std::string model_name;
194 std::shared_ptr<Base> root;
195};
196
200 std::string project_id;
201 std::string image_url_base = "https://minio.chrk.site/files/reusex";
202};
203
206auto export_to_speckle(const ExportScene &scene, const ExportConfig &cfg)
207 -> std::vector<SpeckleModel>;
208
209} // 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).
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
Definition types.hpp:28
Intermediate representation for exporting all project data.
Base class for all Speckle objects.
Definition speckle.hpp:28
std::vector< std::shared_ptr< Base > > elements
Child objects (serialized as detached @elements).
Definition speckle.hpp:37
virtual ~Base()=default
std::string applicationId
Definition speckle.hpp:30
std::map< std::string, nlohmann::json > properties
Custom properties — serialized nested under a "properties" sub-path (Speckle v3 DataObject convention...
Definition speckle.hpp:34
int version
Speckle SDK version marker.
Definition speckle.hpp:119
std::vector< std::shared_ptr< InstanceDefinitionProxy > > instanceDefinitionProxies
Definition speckle.hpp:130
bool embed_elements
When true, child elements are serialized inline (under the key elements, no @ prefix) instead of as d...
Definition speckle.hpp:128
Configuration for building Speckle objects from an ExportScene.
Definition speckle.hpp:199
std::vector< std::string > objects
Definition speckle.hpp:90
std::array< double, 16 > transform
Definition speckle.hpp:101
Triangle/quad mesh.
Definition speckle.hpp:62
std::vector< double > vertices
Flat [x,y,z,x,y,z,...].
Definition speckle.hpp:63
std::vector< int > faces
Packed [n, i0, i1, ..., n, i0, i1, ...].
Definition speckle.hpp:64
std::vector< int > colors
ARGB integers.
Definition speckle.hpp:65
Point(double x, double y, double z)
Definition speckle.hpp:48
std::vector< double > sizes
Per-point sizes.
Definition speckle.hpp:75
std::vector< int > colors
ARGB integers.
Definition speckle.hpp:74
std::vector< double > points
Flat [x,y,z,x,y,z,...].
Definition speckle.hpp:73
One model (branch) to upload to Speckle.
Definition speckle.hpp:192
std::string model_name
branch name (e.g., "cloud", "semantic")
Definition speckle.hpp:193
std::shared_ptr< Base > root
root object for this model's version
Definition speckle.hpp:194