ReUseX  0.0.5
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
render_view.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
7// Headless render-to-image (#294).
8//
9// Renders the contents of a .rux project to an in-memory image without a
10// display server. The backend is VTK's offscreen render window: the flake's
11// VTK is built with VTK_OPENGL_HAS_EGL, and VTK transparently falls back from
12// vtkXOpenGLRenderWindow to vtkEGLRenderWindow when no X/Wayland session is
13// reachable, so `env -u DISPLAY rux render ...` renders on the GPU exactly as
14// it would with a session attached.
15//
16// Keep this header light (STANDARDS §2): cv::Mat and ProjectDB are
17// forward-declared, and no VTK header is exposed to consumers.
18
19#include <array>
20#include <cstdint>
21#include <optional>
22#include <stdexcept>
23#include <string>
24#include <string_view>
25#include <vector>
26
27namespace cv {
28class Mat;
29} // namespace cv
30
31namespace reusex {
32
33class ProjectDB;
34
35namespace visualize {
36
46enum class Layer {
49 planes,
50 rooms,
51 instances,
52 mesh,
56};
57
60std::optional<Layer> layer_from_string(std::string_view name);
61
63std::string_view to_string(Layer layer);
64
66const std::vector<Layer> &all_layers();
67
86
91std::string_view to_string(ViewPreset view);
92
94std::optional<ViewPreset> view_preset_from_string(std::string_view name);
95
105 std::array<double, 16> pose{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
106 double fx = 0.0;
107 double fy = 0.0;
108 double cx = 0.0;
109 double cy = 0.0;
110};
111
116inline constexpr double kDefaultCutHeightM = 1.2;
117
124inline constexpr double kDefaultCutBboxFraction = 0.45;
125
129inline constexpr double kHorizontalNormalZ = 0.95;
130
136 std::string cloud_name = "instances";
138 std::uint32_t instance_id = 0;
139};
140
150 std::vector<Layer> layers{Layer::cloud};
151
153 std::string cloud_name = "cloud";
155 std::string mesh_name = "mesh";
156
158
160 int orbit_count = 8;
162 int orbit_index = 0;
164 double orbit_elevation_deg = 25.0;
165
167 std::optional<CameraSpec> camera;
168
173 bool cut = false;
174
181 std::optional<double> cut_height;
182
183 int width = 1600;
184 int height = 1200;
185
187 std::array<double, 3> background{0.11, 0.12, 0.14};
188
190 double point_size = 2.0;
191
194 double margin = 1.08;
195
199 std::optional<InstanceHighlight> highlight;
200};
201
209class OffscreenGlUnavailable : public std::runtime_error {
210 public:
211 using std::runtime_error::runtime_error;
212};
213
237cv::Mat render_view(const ProjectDB &db, const RenderOptions &opts);
238
251CameraSpec camera_from_sensor_frame(const ProjectDB &db, int node_id, int width,
252 int height);
253
254} // namespace visualize
255} // namespace reusex
This machine cannot create an offscreen OpenGL context (#313).
Turn a 2D mask drawn on one sensor frame into a labelled 3D selection and a survey part (Segmentering...
constexpr double kHorizontalNormalZ
|n_z| above which a segmented plane counts as horizontal when looking for the floor.
cv::Mat render_view(const ProjectDB &db, const RenderOptions &opts)
Render one view of db to an image.
std::optional< Layer > layer_from_string(std::string_view name)
Parse a layer name as accepted by rux render --layers.
const std::vector< Layer > & all_layers()
Every layer, in draw order — the vocabulary --layers accepts.
std::string_view to_string(Layer layer)
The canonical name of layer (the inverse of layer_from_string).
constexpr double kDefaultCutBboxFraction
Fallback cut height when no floor plane is available, as a fraction of the scene's vertical extent.
Layer
One drawable body of content in a rendered view.
@ panoramas
a marker at each placed 360 panorama
@ labels
labels (Label) — semantic classes
@ components
building-component outlines (windows / doors / walls)
@ frustums
camera frustums of the posed sensor frames (subsampled)
@ cloud
cloud (PointXYZRGB), stored per-point colour
ViewPreset
How the camera is placed.
@ orbit
Perspective view on a ring around the scene; see RenderOptions::orbit_index / orbit_count / orbit_ele...
@ plan
A true floor plan: ViewPreset::top plus a horizontal cut (#306).
@ explicit_camera
Use RenderOptions::camera verbatim.
@ top
Orthographic view looking straight down (-Z), north up.
@ front
Orthographic elevation looking along +Y.
std::optional< ViewPreset > view_preset_from_string(std::string_view name)
Parse a bare view-preset name.
constexpr double kDefaultCutHeightM
Default height of the plan cut above the detected floor, in metres.
CameraSpec camera_from_sensor_frame(const ProjectDB &db, int node_id, int width, int height)
Build the camera that reproduces a stored sensor frame's viewpoint.
An explicit camera: rigid pose plus pinhole intrinsics.
double fx
focal length in pixels (x)
std::array< double, 16 > pose
Row-major 4x4 camera-to-world transform.
double cy
principal point in pixels (y)
double fy
focal length in pixels (y)
double cx
principal point in pixels (x)
One instance to call out in a render (Kortlægning evidence, #265 Phase 2 Task 8).
std::string cloud_name
Named Label cloud supplying the per-point instance id, index-aligned with RenderOptions::cloud_name.
std::uint32_t instance_id
The instance id to paint; every other point is dimmed.
Everything render_view() can be told to do.
std::string cloud_name
Named geometry cloud supplying point positions for every point layer.
double point_size
Point sprite size in pixels.
double margin
Framing slack around the scene bounding box: 1.0 is a tight fit, larger pulls back,...
std::optional< double > cut_height
Height of the cut plane above the floor, in metres.
std::vector< Layer > layers
Layers to draw.
bool cut
Clip away everything above a horizontal cut plane before rendering.
double orbit_elevation_deg
Height of the orbit ring above the scene centre, in degrees.
int orbit_count
Number of viewpoints on the orbit ring (--view orbit:N).
int orbit_index
Which of the orbit_count viewpoints to render, in [0, orbit_count).
std::optional< InstanceHighlight > highlight
Paint one instance in kHighlightRgb and dim the rest (Kortlægning evidence).
std::optional< CameraSpec > camera
Camera used when view == ViewPreset::explicit_camera.
std::string mesh_name
Named mesh drawn by Layer::mesh.
std::array< double, 3 > background
Background colour as linear RGB in [0, 1].