ReUseX  0.0.5
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
component_persistence.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
21
22#include "reusex/core/ProjectDB.hpp"
23#include "reusex/core/component_record.hpp"
24#include "reusex/geometry/BuildingComponent.hpp"
25#include "reusex/geometry/CoplanarPolygon.hpp"
26
27#include <string>
28#include <string_view>
29#include <vector>
30
31namespace reusex::geometry {
32
38inline core::ComponentRecord
41 record.name = component.name;
42 record.guid = component.guid;
43 record.type = std::string(to_string(component.type));
44 record.vertex_data = component.boundary.serialize_vertices();
45 for (int i = 0; i < 4; ++i)
46 record.plane[static_cast<size_t>(i)] = component.boundary.plane[i];
47 record.parent_id = component.parent_id;
48 record.confidence = component.confidence;
49 record.metadata = component_data_to_json(component);
50 record.notes = component.notes;
51 return record;
52}
53
55inline BuildingComponent
57 BuildingComponent component;
58 component.name = record.name;
59 component.guid = record.guid;
60 if (!record.type.empty())
61 component.type = component_type_from_string(record.type);
62 if (!record.vertex_data.empty())
64 record.vertex_data.data(), record.vertex_data.size());
65 for (int i = 0; i < 4; ++i)
66 component.boundary.plane[i] = record.plane[static_cast<size_t>(i)];
67 component.parent_id = record.parent_id;
68 component.confidence = record.confidence;
69 component.notes = record.notes;
70 // Overwrites `type` from the JSON discriminator when present, and populates
71 // the variant payload plus `source_instance_guid`.
72 component_data_from_json(component, record.metadata);
73 return component;
74}
75
79 const BuildingComponent &component) {
81}
82
85inline void
90
93 std::string_view name) {
95}
96
98inline std::vector<std::string> list_building_components(const ProjectDB &db,
99 ComponentType type) {
100 return db.list_building_components(to_string(type));
101}
102
103} // namespace reusex::geometry
std::vector< std::string > list_building_components() const
core::ComponentRecord component_record(std::string_view name) const
Load the component row with the given name. Throws if absent.
void save_component_record(const core::ComponentRecord &record)
Insert or replace the component row identified by record.name.
void update_component_record_by_guid(const core::ComponentRecord &record)
Update an existing component's mutable fields (name, type, parent_id, confidence, metadata,...
std::string_view to_string(ComponentType type)
std::vector< std::string > list_building_components(const ProjectDB &db, ComponentType type)
Names of all stored components of the given type.
void update_building_component_by_guid(ProjectDB &db, const BuildingComponent &component)
Update an existing component's mutable fields, matched by its immutable guid.
ComponentType
Discriminator for building component types.
ComponentType component_type_from_string(std::string_view str)
BuildingComponent building_component(const ProjectDB &db, std::string_view name)
Load the component stored under name. Throws if absent.
void component_data_from_json(BuildingComponent &c, const std::string &json)
Deserialize JSON TEXT into the variant data on a BuildingComponent.
core::ComponentRecord to_component_record(const BuildingComponent &component)
Flatten a component into the persistence POD.
void save_building_component(ProjectDB &db, const BuildingComponent &component)
Insert or replace component, keyed by its name.
BuildingComponent from_component_record(const core::ComponentRecord &record)
Rebuild a component from the persistence POD.
std::string component_data_to_json(const BuildingComponent &c)
Serialize the type-specific variant data to JSON TEXT.
Core-owned persistence contract for a row of the building_components table (#227).
std::array< double, 4 > plane
plane blob — Hessian normal form [a,b,c,d] of ax+by+cz+d=0, always persisted as 4 * 8 bytes.
std::string guid
guid column (schema v8) — stable, immutable identity.
double confidence
confidence column — detection confidence, -1 if manual.
std::string name
name column — unique; the UPSERT conflict target.
int parent_id
parent_id column — optional link to a parent component, -1 if none.
std::string type
type column — component-type discriminator as stored, e.g. "window".
std::string metadata
metadata column — opaque JSON TEXT owned by the geometry layer.
std::vector< uint8_t > vertex_data
vertex_data blob — boundary vertices as packed little-endian float64 xyz triples (3 * 8 bytes per ver...
std::string notes
notes column — free-form text. Bound as NULL when empty.
A detected or manual building component (window, door, wall, ...).
std::string guid
Stable, immutable identifier.
std::vector< uint8_t > serialize_vertices() const
Serialize vertices to compact binary (N * 3 * sizeof(double) bytes).
std::vector< Eigen::Vector3d > vertices
static std::vector< Eigen::Vector3d > deserialize_vertices(const void *data, size_t size)
Deserialize vertices from compact binary.