Rerun C++ SDK
Loading...
Searching...
No Matches
pinhole.hpp
1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs
2// Based on "crates/store/re_types/definitions/rerun/archetypes/pinhole.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../compiler_utils.hpp"
8#include "../component_batch.hpp"
9#include "../components/image_plane_distance.hpp"
10#include "../components/pinhole_projection.hpp"
11#include "../components/resolution.hpp"
12#include "../components/view_coordinates.hpp"
13#include "../indicator_component.hpp"
14#include "../result.hpp"
15
16#include <cmath>
17#include <cstdint>
18#include <limits>
19#include <optional>
20#include <utility>
21#include <vector>
22
23namespace rerun::archetypes {
24 /// **Archetype**: Camera perspective projection (a.k.a. intrinsics).
25 ///
26 /// ## Examples
27 ///
28 /// ### Simple pinhole camera
29 /// ![image](https://static.rerun.io/pinhole_simple/9af9441a94bcd9fd54e1fea44fb0c59ff381a7f2/full.png)
30 ///
31 /// ```cpp
32 /// #include <rerun.hpp>
33 ///
34 /// #include <algorithm> // std::generate
35 /// #include <cstdlib> // std::rand
36 /// #include <vector>
37 ///
38 /// int main() {
39 /// const auto rec = rerun::RecordingStream("rerun_example_pinhole");
40 /// rec.spawn().exit_on_failure();
41 ///
42 /// rec.log("world/image", rerun::Pinhole::from_focal_length_and_resolution(3.0f, {3.0f, 3.0f}));
43 ///
44 /// std::vector<uint8_t> random_data(3 * 3 * 3);
45 /// std::generate(random_data.begin(), random_data.end(), [] {
46 /// return static_cast<uint8_t>(std::rand());
47 /// });
48 ///
49 /// rec.log("world/image", rerun::Image::from_rgb24(random_data, {3, 3}));
50 /// }
51 /// ```
52 ///
53 /// ### Perspective pinhole camera
54 /// ![image](https://static.rerun.io/pinhole_perspective/317e2de6d212b238dcdad5b67037e9e2a2afafa0/full.png)
55 ///
56 /// ```cpp
57 /// #include <rerun.hpp>
58 ///
59 /// int main() {
60 /// const auto rec = rerun::RecordingStream("rerun_example_pinhole_perspective");
61 /// rec.spawn().exit_on_failure();
62 ///
63 /// const float fov_y = 0.7853982f;
64 /// const float aspect_ratio = 1.7777778f;
65 /// rec.log(
66 /// "world/cam",
67 /// rerun::Pinhole::from_fov_and_aspect_ratio(fov_y, aspect_ratio)
68 /// .with_camera_xyz(rerun::components::ViewCoordinates::RUB)
69 /// .with_image_plane_distance(0.1f)
70 /// );
71 ///
72 /// rec.log(
73 /// "world/points",
74 /// rerun::Points3D({{0.0f, 0.0f, -0.5f}, {0.1f, 0.1f, -0.5f}, {-0.1f, -0.1f, -0.5f}}
75 /// ).with_radii({0.025f})
76 /// );
77 /// }
78 /// ```
79 struct Pinhole {
80 /// Camera projection, from image coordinates to view coordinates.
82
83 /// Pixel resolution (usually integers) of child image space. Width and height.
84 ///
85 /// Example:
86 /// ```text
87 /// [1920.0, 1440.0]
88 /// ```
89 ///
90 /// `image_from_camera` project onto the space spanned by `(0,0)` and `resolution - 1`.
91 std::optional<rerun::components::Resolution> resolution;
92
93 /// Sets the view coordinates for the camera.
94 ///
95 /// All common values are available as constants on the `components::ViewCoordinates` class.
96 ///
97 /// The default is `ViewCoordinates::RDF`, i.e. X=Right, Y=Down, Z=Forward, and this is also the recommended setting.
98 /// This means that the camera frustum will point along the positive Z axis of the parent space,
99 /// and the cameras "up" direction will be along the negative Y axis of the parent space.
100 ///
101 /// The camera frustum will point whichever axis is set to `F` (or the opposite of `B`).
102 /// When logging a depth image under this entity, this is the direction the point cloud will be projected.
103 /// With `RDF`, the default forward is +Z.
104 ///
105 /// The frustum's "up" direction will be whichever axis is set to `U` (or the opposite of `D`).
106 /// This will match the negative Y direction of pixel space (all images are assumed to have xyz=RDF).
107 /// With `RDF`, the default is up is -Y.
108 ///
109 /// The frustum's "right" direction will be whichever axis is set to `R` (or the opposite of `L`).
110 /// This will match the positive X direction of pixel space (all images are assumed to have xyz=RDF).
111 /// With `RDF`, the default right is +x.
112 ///
113 /// Other common formats are `RUB` (X=Right, Y=Up, Z=Back) and `FLU` (X=Forward, Y=Left, Z=Up).
114 ///
115 /// NOTE: setting this to something else than `RDF` (the default) will change the orientation of the camera frustum,
116 /// and make the pinhole matrix not match up with the coordinate system of the pinhole entity.
117 ///
118 /// The pinhole matrix (the `image_from_camera` argument) always project along the third (Z) axis,
119 /// but will be re-oriented to project along the forward axis of the `camera_xyz` argument.
120 std::optional<rerun::components::ViewCoordinates> camera_xyz;
121
122 /// The distance from the camera origin to the image plane when the projection is shown in a 3D viewer.
123 ///
124 /// This is only used for visualization purposes, and does not affect the projection itself.
125 std::optional<rerun::components::ImagePlaneDistance> image_plane_distance;
126
127 public:
128 static constexpr const char IndicatorComponentName[] = "rerun.components.PinholeIndicator";
129
130 /// Indicator component, used to identify the archetype when converting to a list of components.
132
133 public: // START of extensions from pinhole_ext.cpp:
134 /// Creates a pinhole from the camera focal length and resolution, both specified in pixels.
135 ///
136 /// The focal length is the diagonal of the projection matrix.
137 /// Set the same value for x & y value for symmetric cameras, or two values for anamorphic
138 /// cameras.
139 ///
140 /// Assumes the principal point to be in the middle of the sensor.
142 const datatypes::Vec2D& focal_length, const datatypes::Vec2D& resolution
143 );
144
145 /// Creates a symmetric pinhole from the camera focal length and resolution, both specified
146 /// in pixels.
147 ///
148 /// The focal length is the diagonal of the projection matrix.
149 ///
150 /// Assumes the principal point to be in the middle of the sensor.
152 float focal_length, const datatypes::Vec2D& resolution
153 ) {
154 return from_focal_length_and_resolution({focal_length, focal_length}, resolution);
155 }
156
157 /// Creates a pinhole from the camera vertical field of view (in radians) and aspect ratio (width/height).
158 ///
159 /// Assumes the principal point to be in the middle of the sensor.
160 static Pinhole from_fov_and_aspect_ratio(float fov_y, float aspect_ratio) {
161 const float EPSILON = std::numeric_limits<float>::epsilon();
162 // `max` has explicit template args to avoid preprocessor replacement when <windows.h> is included without NOMINMAX.
163 const float focal_length_y = 0.5f / std::tan(std::max<float>(fov_y * 0.5f, EPSILON));
165 {focal_length_y, focal_length_y},
166 {aspect_ratio, 1.0}
167 );
168 }
169
170 /// Pixel resolution (usually integers) of child image space. Width and height.
171 ///
172 /// `image_from_camera` project onto the space spanned by `(0,0)` and `resolution - 1`.
173 Pinhole with_resolution(float width, float height) && {
175 return std::move(*this);
176 }
177
178 /// Pixel resolution (usually integers) of child image space. Width and height.
179 ///
180 /// `image_from_camera` project onto the space spanned by `(0,0)` and `resolution - 1`.
181 Pinhole with_resolution(int width, int height) && {
183 return std::move(*this);
184 }
185
186 // END of extensions from pinhole_ext.cpp, start of generated code:
187
188 public:
189 Pinhole() = default;
190 Pinhole(Pinhole&& other) = default;
191
192 explicit Pinhole(rerun::components::PinholeProjection _image_from_camera)
193 : image_from_camera(std::move(_image_from_camera)) {}
194
195 /// Pixel resolution (usually integers) of child image space. Width and height.
196 ///
197 /// Example:
198 /// ```text
199 /// [1920.0, 1440.0]
200 /// ```
201 ///
202 /// `image_from_camera` project onto the space spanned by `(0,0)` and `resolution - 1`.
204 resolution = std::move(_resolution);
205 // See: https://github.com/rerun-io/rerun/issues/4027
206 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
207 }
208
209 /// Sets the view coordinates for the camera.
210 ///
211 /// All common values are available as constants on the `components::ViewCoordinates` class.
212 ///
213 /// The default is `ViewCoordinates::RDF`, i.e. X=Right, Y=Down, Z=Forward, and this is also the recommended setting.
214 /// This means that the camera frustum will point along the positive Z axis of the parent space,
215 /// and the cameras "up" direction will be along the negative Y axis of the parent space.
216 ///
217 /// The camera frustum will point whichever axis is set to `F` (or the opposite of `B`).
218 /// When logging a depth image under this entity, this is the direction the point cloud will be projected.
219 /// With `RDF`, the default forward is +Z.
220 ///
221 /// The frustum's "up" direction will be whichever axis is set to `U` (or the opposite of `D`).
222 /// This will match the negative Y direction of pixel space (all images are assumed to have xyz=RDF).
223 /// With `RDF`, the default is up is -Y.
224 ///
225 /// The frustum's "right" direction will be whichever axis is set to `R` (or the opposite of `L`).
226 /// This will match the positive X direction of pixel space (all images are assumed to have xyz=RDF).
227 /// With `RDF`, the default right is +x.
228 ///
229 /// Other common formats are `RUB` (X=Right, Y=Up, Z=Back) and `FLU` (X=Forward, Y=Left, Z=Up).
230 ///
231 /// NOTE: setting this to something else than `RDF` (the default) will change the orientation of the camera frustum,
232 /// and make the pinhole matrix not match up with the coordinate system of the pinhole entity.
233 ///
234 /// The pinhole matrix (the `image_from_camera` argument) always project along the third (Z) axis,
235 /// but will be re-oriented to project along the forward axis of the `camera_xyz` argument.
237 camera_xyz = std::move(_camera_xyz);
238 // See: https://github.com/rerun-io/rerun/issues/4027
239 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
240 }
241
242 /// The distance from the camera origin to the image plane when the projection is shown in a 3D viewer.
243 ///
244 /// This is only used for visualization purposes, and does not affect the projection itself.
246 rerun::components::ImagePlaneDistance _image_plane_distance
247 ) && {
248 image_plane_distance = std::move(_image_plane_distance);
249 // See: https://github.com/rerun-io/rerun/issues/4027
250 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
251 }
252 };
253
254} // namespace rerun::archetypes
255
256namespace rerun {
257 /// \private
258 template <typename T>
259 struct AsComponents;
260
261 /// \private
262 template <>
263 struct AsComponents<archetypes::Pinhole> {
264 /// Serialize all set component batches.
265 static Result<std::vector<ComponentBatch>> serialize(const archetypes::Pinhole& archetype);
266 };
267} // namespace rerun
All built-in archetypes. See Types in the Rerun manual.
Definition rerun.hpp:77
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
Archetype: Camera perspective projection (a.k.a.
Definition pinhole.hpp:79
rerun::components::PinholeProjection image_from_camera
Camera projection, from image coordinates to view coordinates.
Definition pinhole.hpp:81
Pinhole with_resolution(float width, float height) &&
Pixel resolution (usually integers) of child image space.
Definition pinhole.hpp:173
Pinhole with_resolution(int width, int height) &&
Pixel resolution (usually integers) of child image space.
Definition pinhole.hpp:181
std::optional< rerun::components::ViewCoordinates > camera_xyz
Sets the view coordinates for the camera.
Definition pinhole.hpp:120
std::optional< rerun::components::Resolution > resolution
Pixel resolution (usually integers) of child image space.
Definition pinhole.hpp:91
static Pinhole from_fov_and_aspect_ratio(float fov_y, float aspect_ratio)
Creates a pinhole from the camera vertical field of view (in radians) and aspect ratio (width/height)...
Definition pinhole.hpp:160
static Pinhole from_focal_length_and_resolution(const datatypes::Vec2D &focal_length, const datatypes::Vec2D &resolution)
Creates a pinhole from the camera focal length and resolution, both specified in pixels.
Pinhole with_image_plane_distance(rerun::components::ImagePlaneDistance _image_plane_distance) &&
The distance from the camera origin to the image plane when the projection is shown in a 3D viewer.
Definition pinhole.hpp:245
std::optional< rerun::components::ImagePlaneDistance > image_plane_distance
The distance from the camera origin to the image plane when the projection is shown in a 3D viewer.
Definition pinhole.hpp:125
Pinhole with_resolution(rerun::components::Resolution _resolution) &&
Pixel resolution (usually integers) of child image space.
Definition pinhole.hpp:203
static Pinhole from_focal_length_and_resolution(float focal_length, const datatypes::Vec2D &resolution)
Creates a symmetric pinhole from the camera focal length and resolution, both specified in pixels.
Definition pinhole.hpp:151
Pinhole with_camera_xyz(rerun::components::ViewCoordinates _camera_xyz) &&
Sets the view coordinates for the camera.
Definition pinhole.hpp:236
Component: The distance from the camera origin to the image plane when the projection is shown in a 3...
Definition image_plane_distance.hpp:17
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:32
Component: Camera projection, from image coordinates to view coordinates.
Definition pinhole_projection.hpp:26
Component: Pixel resolution width & height, e.g.
Definition resolution.hpp:19
Component: How we interpret the coordinate system of an entity/space.
Definition view_coordinates.hpp:33
Datatype: A vector in 2D space.
Definition vec2d.hpp:21