ReUseX  0.0.5
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
scene.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Povl Filip Sonne-Frederiksen
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#pragma once
6
7// The scene builder shared by `rux render` (render_view, headless) and the
8// Qt client's 3D workspace (an interactive QVTKOpenGLNativeWidget).
9//
10// render_view() used to build its VTK scene inline, so the only way for an
11// interactive viewer to show "the same thing rux render shows" was to copy
12// that code. populate_scene() is the one definition instead: it loads a
13// project's layers and adds them to a caller's vtkRenderer, and the camera and
14// cut-plane helpers below place the camera the way the presets do. Both front
15// ends call them; render_view() is now validation + populate_scene() + camera
16// + an offscreen render window.
17//
18// Header hygiene (STANDARDS §2): VTK types are forward-declared, so a consumer
19// that only needs SceneOptions/SceneInfo compiles no VTK header.
20
21#include "reusex/visualize/render_view.hpp"
22
23#include <array>
24#include <cstddef>
25#include <cstdint>
26#include <optional>
27#include <string>
28#include <string_view>
29#include <vector>
30
31class vtkActor;
32class vtkRenderer;
33
34namespace reusex::visualize {
35
38 std::array<double, 3> min{0, 0, 0};
39 std::array<double, 3> max{0, 0, 0};
40 bool valid = false;
41
42 void add(double x, double y, double z);
43 std::array<double, 3> center() const;
44 double extent(int axis) const { return max[axis] - min[axis]; }
45 double diagonal() const;
46};
47
58 std::vector<std::array<std::uint8_t, 3>> colors;
59 std::array<std::uint8_t, 3> unlabeled{0, 0, 0};
62 std::array<std::uint8_t, 3> invalid{0, 0, 0};
63};
64
67
69inline constexpr int kUnlabeledSlot = -1;
70inline constexpr int kInvalidSlot = -2;
71
77int label_palette_slot(std::uint32_t label, std::size_t size);
78
80std::array<std::uint8_t, 3> label_palette_color(const LabelPalette &palette,
81 std::uint32_t label);
82
89
90std::string_view to_string(LodMethod method);
91
101std::vector<std::uint32_t> lod_indices(std::size_t total, std::size_t budget,
102 std::string_view storage_order,
103 LodMethod *method = nullptr);
104
108 std::vector<Layer> layers{Layer::cloud};
110 std::string cloud_name = "cloud";
112 std::string mesh_name = "mesh";
114 double point_size = 2.0;
116 std::optional<InstanceHighlight> highlight;
118 std::optional<LabelPalette> palette;
119
122 std::size_t max_points = 0;
126 std::size_t coarse_points = 0;
127
129 std::size_t max_frustums = 300;
131 double frustum_depth = 0.25;
132 std::array<std::uint8_t, 3> frustum_rgb{150, 160, 176};
133 std::array<std::uint8_t, 3> panorama_rgb{255, 176, 64};
134};
135
140 std::vector<vtkActor *> actors;
143 vtkActor *coarse = nullptr;
144 std::size_t points = 0;
145 std::size_t faces = 0;
146 std::size_t items = 0;
147};
148
150struct SceneInfo {
152 std::size_t drawn_points = 0;
153 std::size_t drawn_faces = 0;
154 std::vector<SceneLayer> layers;
156 std::size_t source_points = 0;
160 std::vector<std::uint32_t> indices;
161};
162
169SceneInfo populate_scene(vtkRenderer *renderer, const ProjectDB &db,
170 const SceneOptions &opts);
171
173struct CutPlane {
174 double z = 0.0;
175 double floor_z = 0.0;
176 double height = 0.0;
177 bool from_planes = false;
178};
179
184 std::optional<double> height);
185
187void apply_cut_plane(vtkRenderer *renderer, double z);
188
190void clear_cut_planes(vtkRenderer *renderer);
191
195 int orbit_count = 8;
196 int orbit_index = 0;
197 double orbit_elevation_deg = 25.0;
198 double margin = 1.08;
199 double aspect = 4.0 / 3.0;
200};
201
204void place_preset_camera(vtkRenderer *renderer, const CameraFraming &framing,
205 const SceneBounds &bounds);
206
210void place_explicit_camera(vtkRenderer *renderer, const CameraSpec &spec,
211 int width, int height, const SceneBounds &bounds);
212
216
217} // namespace reusex::visualize
std::array< std::uint8_t, 3 > label_palette_color(const LabelPalette &palette, std::uint32_t label)
The colour of label in palette.
LodMethod
How a large cloud was thinned for drawing.
Definition scene.hpp:84
@ stride
every k-th point, evenly over the storage order
Definition scene.hpp:87
@ all
every point is drawn
Definition scene.hpp:85
@ morton_prefix
a prefix of a bit-reversed Morton cloud (stratified)
Definition scene.hpp:86
void place_explicit_camera(vtkRenderer *renderer, const CameraSpec &spec, int width, int height, const SceneBounds &bounds)
Place renderer's active camera at an explicit pose + pinhole camera, for an image of width x height p...
SceneInfo populate_scene(vtkRenderer *renderer, const ProjectDB &db, const SceneOptions &opts)
Load opts' layers from db and add them to renderer.
constexpr int kUnlabeledSlot
Sentinel slots of label_palette_slot().
Definition scene.hpp:69
void apply_cut_plane(vtkRenderer *renderer, double z)
Clip every actor of renderer to the half-space below z = z.
const LabelPalette & default_label_palette()
The tokens' scale (see LabelPalette).
std::string_view to_string(Layer layer)
The canonical name of layer (the inverse of layer_from_string).
Layer
One drawable body of content in a rendered view.
@ cloud
cloud (PointXYZRGB), stored per-point colour
void clear_cut_planes(vtkRenderer *renderer)
Remove every clipping plane from renderer's actors.
std::vector< std::uint32_t > lod_indices(std::size_t total, std::size_t budget, std::string_view storage_order, LodMethod *method=nullptr)
Which of total stored points to draw within a budget of budget.
ViewPreset
How the camera is placed.
@ top
Orthographic view looking straight down (-Z), north up.
CutPlane resolve_cut_plane(const ProjectDB &db, const SceneBounds &bounds, std::optional< double > height)
Decide where to cut bounds: height (or the default) above the floor detected by rux create planes,...
int label_palette_slot(std::uint32_t label, std::size_t size)
Palette slot of a point label: (label - 1) % size; kUnlabeledSlot for label 0 or an empty palette; kI...
void install_vtk_log_bridge()
Route VTK's diagnostics into ReUseX logging, once per process (see render_view()).
constexpr int kInvalidSlot
Definition scene.hpp:70
void place_preset_camera(vtkRenderer *renderer, const CameraFraming &framing, const SceneBounds &bounds)
Place renderer's active camera for a preset view of bounds.
How a preset camera frames the scene.
Definition scene.hpp:193
double aspect
viewport width / height
Definition scene.hpp:199
ViewPreset view
never ViewPreset::explicit_camera
Definition scene.hpp:194
An explicit camera: rigid pose plus pinhole intrinsics.
A resolved horizontal cut: where the plane sits and how that was decided.
Definition scene.hpp:173
bool from_planes
floor came from the segmentation, not the bbox
Definition scene.hpp:177
double floor_z
the reference it was measured up from
Definition scene.hpp:175
double height
metres above floor_z
Definition scene.hpp:176
double z
world z of the plane
Definition scene.hpp:174
The categorical colour scale label layers are drawn with.
Definition scene.hpp:57
std::array< std::uint8_t, 3 > invalid
An out-of-contract label (core::is_out_of_contract_label: a wrapped -1).
Definition scene.hpp:62
std::vector< std::array< std::uint8_t, 3 > > colors
labels 1..N, cyclic
Definition scene.hpp:58
std::array< std::uint8_t, 3 > unlabeled
label 0 (STANDARDS §3)
Definition scene.hpp:59
Axis-aligned bounds of the geometry a scene draws.
Definition scene.hpp:37
std::array< double, 3 > center() const
std::array< double, 3 > min
Definition scene.hpp:38
std::array< double, 3 > max
Definition scene.hpp:39
double extent(int axis) const
Definition scene.hpp:44
void add(double x, double y, double z)
What populate_scene() added.
Definition scene.hpp:150
std::size_t source_points
Points in the geometry cloud (0 when no point layer was drawn).
Definition scene.hpp:156
std::vector< std::uint32_t > indices
Storage index of each point a full point actor draws (its vtk point id -> cloud index); empty when ev...
Definition scene.hpp:160
std::vector< SceneLayer > layers
Definition scene.hpp:154
The actors one layer added, so an interactive viewer can toggle it.
Definition scene.hpp:137
std::size_t points
points drawn (per point layer)
Definition scene.hpp:144
std::size_t faces
mesh faces drawn
Definition scene.hpp:145
vtkActor * coarse
Point layers only: the hidden coarse twin (SceneOptions::coarse_points), or nullptr.
Definition scene.hpp:143
std::vector< vtkActor * > actors
Every actor of the layer (one for a point layer, one per component).
Definition scene.hpp:140
std::size_t items
frustums / panoramas / components drawn
Definition scene.hpp:146
What populate_scene() draws, and how.
Definition scene.hpp:106
std::string mesh_name
Named mesh drawn by Layer::mesh.
Definition scene.hpp:112
std::array< std::uint8_t, 3 > frustum_rgb
Definition scene.hpp:132
std::size_t coarse_points
Also build a hidden coarse actor of at most this many points per point layer (0 = none),...
Definition scene.hpp:126
std::size_t max_points
Draw at most this many points per point layer (0 = all).
Definition scene.hpp:122
std::optional< LabelPalette > palette
Colours of the label layers; std::nullopt = default_label_palette().
Definition scene.hpp:118
double frustum_depth
Depth of a drawn frustum, in metres.
Definition scene.hpp:131
std::array< std::uint8_t, 3 > panorama_rgb
Definition scene.hpp:133
std::optional< InstanceHighlight > highlight
Paint one instance and dim the rest (see render_view.hpp).
Definition scene.hpp:116
std::vector< Layer > layers
Layers in draw order. Empty is an error.
Definition scene.hpp:108
std::size_t max_frustums
Frustums drawn at most; posed frames beyond it are skipped evenly.
Definition scene.hpp:129
double point_size
Point sprite size in pixels. Must be positive.
Definition scene.hpp:114
std::string cloud_name
Named geometry cloud supplying point positions for every point layer.
Definition scene.hpp:110