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 <map>
14#include <memory>
15#include <string>
16#include <vector>
17
18namespace reusex::io {
19struct ExportScene;
20}
21
23
24// --- Speckle Object Model ---
25
27struct Base {
28 std::string speckle_type = "Base";
29 std::string applicationId;
30 std::map<std::string, nlohmann::json> properties;
31
33 std::vector<std::shared_ptr<Base>> elements;
34
35 virtual ~Base() = default;
36};
37
39struct Point : Base {
40 double x = 0, y = 0, z = 0;
41 std::string units = "m";
42
43 Point() { speckle_type = "Objects.Geometry.Point"; }
44 Point(double x, double y, double z) : x(x), y(y), z(z) {
45 speckle_type = "Objects.Geometry.Point";
46 }
47};
48
50struct Line : Base {
52 std::string units = "m";
53
54 Line() { speckle_type = "Objects.Geometry.Line"; }
55};
56
58struct Mesh : Base {
59 std::vector<double> vertices;
60 std::vector<int> faces;
61 std::vector<int> colors;
62 std::string units = "m";
63
64 Mesh() { speckle_type = "Objects.Geometry.Mesh"; }
65};
66
68struct Pointcloud : Base {
69 std::vector<double> points;
70 std::vector<int> colors;
71 std::vector<double> sizes;
72 std::string units = "m";
73
74 Pointcloud() { speckle_type = "Objects.Geometry.Pointcloud"; }
75};
76
78struct Collection : Base {
79 std::string name;
80 std::string collectionType = "Container";
81
82 Collection() { speckle_type = "Speckle.Core.Models.Collection"; }
83};
84
85// --- Client ---
86
89 public:
94 SpeckleClient(std::string server_url, std::string project_id,
95 std::string token = "");
96
99 std::string send(const Base &root);
100
103 std::string commit(const std::string &object_id,
104 const std::string &branch = "main",
105 const std::string &message = "ReUseX upload");
106
109 std::string upload(const Base &root, const std::string &branch = "main",
110 const std::string &message = "ReUseX upload");
111
113 void set_max_batch_size(std::size_t bytes);
114
115 private:
117 void ensure_branch(const std::string &branch);
118
119 std::string server_url_;
120 std::string project_id_;
121 std::string token_;
122 std::size_t max_batch_bytes_ = 25 * 1024 * 1024; // 25 MB
123};
124
125// --- Conversion Helpers ---
126
129
131Mesh to_speckle(const pcl::PolygonMesh &mesh);
132
134Mesh to_speckle(const Eigen::MatrixXd &vertices, const Eigen::MatrixXi &faces);
135
136// --- Scene Export ---
137
140 std::string model_name;
141 std::shared_ptr<Base> root;
142};
143
146auto export_to_speckle(const ExportScene &scene) -> std::vector<SpeckleModel>;
147
148} // 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) -> 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:27
std::vector< std::shared_ptr< Base > > elements
Child objects (serialized as detached @elements).
Definition speckle.hpp:33
virtual ~Base()=default
std::string applicationId
Definition speckle.hpp:29
std::map< std::string, nlohmann::json > properties
Definition speckle.hpp:30
Triangle/quad mesh.
Definition speckle.hpp:58
std::vector< double > vertices
Flat [x,y,z,x,y,z,...].
Definition speckle.hpp:59
std::vector< int > faces
Packed [n, i0, i1, ..., n, i0, i1, ...].
Definition speckle.hpp:60
std::vector< int > colors
ARGB integers.
Definition speckle.hpp:61
Point(double x, double y, double z)
Definition speckle.hpp:44
std::vector< double > sizes
Per-point sizes.
Definition speckle.hpp:71
std::vector< int > colors
ARGB integers.
Definition speckle.hpp:70
std::vector< double > points
Flat [x,y,z,x,y,z,...].
Definition speckle.hpp:69
One model (branch) to upload to Speckle.
Definition speckle.hpp:139
std::string model_name
branch name (e.g., "cloud", "semantic")
Definition speckle.hpp:140
std::shared_ptr< Base > root
root object for this model's version
Definition speckle.hpp:141