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 <optional>
21#include <stdexcept>
22#include <string>
23#include <string_view>
24#include <vector>
25
26namespace cv {
27class Mat;
28} // namespace cv
29
30namespace reusex {
31
32class ProjectDB;
33
34namespace visualize {
35
51
54std::optional<Layer> layer_from_string(std::string_view name);
55
57std::string_view to_string(Layer layer);
58
60const std::vector<Layer> &all_layers();
61
80
85std::string_view to_string(ViewPreset view);
86
88std::optional<ViewPreset> view_preset_from_string(std::string_view name);
89
97struct CameraSpec {
99 std::array<double, 16> pose{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
100 double fx = 0.0;
101 double fy = 0.0;
102 double cx = 0.0;
103 double cy = 0.0;
104};
105
110inline constexpr double kDefaultCutHeightM = 1.2;
111
118inline constexpr double kDefaultCutBboxFraction = 0.45;
119
123inline constexpr double kHorizontalNormalZ = 0.95;
124
134 std::vector<Layer> layers{Layer::cloud};
135
137 std::string cloud_name = "cloud";
139 std::string mesh_name = "mesh";
140
142
144 int orbit_count = 8;
146 int orbit_index = 0;
148 double orbit_elevation_deg = 25.0;
149
151 std::optional<CameraSpec> camera;
152
157 bool cut = false;
158
165 std::optional<double> cut_height;
166
167 int width = 1600;
168 int height = 1200;
169
171 std::array<double, 3> background{0.11, 0.12, 0.14};
172
174 double point_size = 2.0;
175
178 double margin = 1.08;
179};
180
188class OffscreenGlUnavailable : public std::runtime_error {
189 public:
190 using std::runtime_error::runtime_error;
191};
192
216cv::Mat render_view(const ProjectDB &db, const RenderOptions &opts);
217
230CameraSpec camera_from_sensor_frame(const ProjectDB &db, int node_id, int width,
231 int height);
232
233} // namespace visualize
234} // namespace reusex
This machine cannot create an offscreen OpenGL context (#313).
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.
@ mesh
a stored mesh from the meshes table
@ labels
labels (Label) — semantic classes
@ components
building-component outlines (windows / doors / walls)
@ instances
instances (Label) — spatial instances
@ cloud
cloud (PointXYZRGB), stored per-point colour
@ planes
planes (Label) — planar segments
@ rooms
rooms (Label) — room partition
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)
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< 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].