Rerun C++ SDK
Loading...
Searching...
No Matches
pinhole.hpp
1// DO NOT EDIT! This file was auto-generated by crates/re_types_builder/src/codegen/cpp/mod.rs
2// Based on "crates/re_types/definitions/rerun/archetypes/pinhole.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../compiler_utils.hpp"
8#include "../components/pinhole_projection.hpp"
9#include "../components/resolution.hpp"
10#include "../components/view_coordinates.hpp"
11#include "../data_cell.hpp"
12#include "../indicator_component.hpp"
13#include "../result.hpp"
14
15#include <cstdint>
16#include <optional>
17#include <utility>
18#include <vector>
19
20namespace rerun::archetypes {
21 /// **Archetype**: Camera perspective projection (a.k.a. intrinsics).
22 ///
23 /// ## Example
24 ///
25 /// ### Simple Pinhole Camera
26 /// ![image](https://static.rerun.io/pinhole_simple/9af9441a94bcd9fd54e1fea44fb0c59ff381a7f2/full.png)
27 ///
28 /// ```cpp
29 /// #include <rerun.hpp>
30 ///
31 /// #include <algorithm> // std::generate
32 /// #include <cstdlib> // std::rand
33 /// #include <vector>
34 ///
35 /// int main() {
36 /// const auto rec = rerun::RecordingStream("rerun_example_line_strip3d");
37 /// rec.spawn().exit_on_failure();
38 ///
39 /// rec.log("world/image", rerun::Pinhole::from_focal_length_and_resolution(3.0f, {3.0f, 3.0f}));
40 ///
41 /// std::vector<uint8_t> random_data(3 * 3 * 3);
42 /// std::generate(random_data.begin(), random_data.end(), [] {
43 /// return static_cast<uint8_t>(std::rand());
44 /// });
45 ///
46 /// const auto tensor = rerun::datatypes::TensorData({3, 3, 3}, random_data);
47 /// rec.log("world/image", rerun::Image(tensor));
48 /// }
49 /// ```
50 struct Pinhole {
51 /// Camera projection, from image coordinates to view coordinates.
53
54 /// Pixel resolution (usually integers) of child image space. Width and height.
55 ///
56 /// Example:
57 /// ```text
58 /// [1920.0, 1440.0]
59 /// ```
60 ///
61 /// `image_from_camera` project onto the space spanned by `(0,0)` and `resolution - 1`.
62 std::optional<rerun::components::Resolution> resolution;
63
64 /// Sets the view coordinates for the camera.
65 ///
66 /// All common values are available as constants on the `components.ViewCoordinates` class.
67 ///
68 /// The default is `ViewCoordinates::RDF`, i.e. X=Right, Y=Down, Z=Forward, and this is also the recommended setting.
69 /// This means that the camera frustum will point along the positive Z axis of the parent space,
70 /// and the cameras "up" direction will be along the negative Y axis of the parent space.
71 ///
72 /// The camera frustum will point whichever axis is set to `F` (or the opposite of `B`).
73 /// When logging a depth image under this entity, this is the direction the point cloud will be projected.
74 /// With `RDF`, the default forward is +Z.
75 ///
76 /// The frustum's "up" direction will be whichever axis is set to `U` (or the opposite of `D`).
77 /// This will match the negative Y direction of pixel space (all images are assumed to have xyz=RDF).
78 /// With `RDF`, the default is up is -Y.
79 ///
80 /// The frustum's "right" direction will be whichever axis is set to `R` (or the opposite of `L`).
81 /// This will match the positive X direction of pixel space (all images are assumed to have xyz=RDF).
82 /// With `RDF`, the default right is +x.
83 ///
84 /// Other common formats are `RUB` (X=Right, Y=Up, Z=Back) and `FLU` (X=Forward, Y=Left, Z=Up).
85 ///
86 /// NOTE: setting this to something else than `RDF` (the default) will change the orientation of the camera frustum,
87 /// and make the pinhole matrix not match up with the coordinate system of the pinhole entity.
88 ///
89 /// The pinhole matrix (the `image_from_camera` argument) always project along the third (Z) axis,
90 /// but will be re-oriented to project along the forward axis of the `camera_xyz` argument.
91 std::optional<rerun::components::ViewCoordinates> camera_xyz;
92
93 public:
94 static constexpr const char IndicatorComponentName[] = "rerun.components.PinholeIndicator";
95
96 /// Indicator component, used to identify the archetype when converting to a list of components.
98
99 public:
100 // Extensions to generated type defined in 'pinhole_ext.cpp'
101
102 /// Creates a pinhole from the camera focal length and resolution, both specified in pixels.
103 ///
104 /// The focal length is the diagonal of the projection matrix.
105 /// Set the same value for x & y value for symmetric cameras, or two values for anamorphic
106 /// cameras.
107 ///
108 /// Assumes the principal point to be in the middle of the sensor.
110 const datatypes::Vec2D& focal_length, const datatypes::Vec2D& resolution
111 );
112
113 /// Creates a symmetric pinhole from the camera focal length and resolution, both specified
114 /// in pixels.
115 ///
116 /// The focal length is the diagonal of the projection matrix.
117 ///
118 /// Assumes the principal point to be in the middle of the sensor.
120 float focal_length, const datatypes::Vec2D& resolution
121 ) {
122 return from_focal_length_and_resolution({focal_length, focal_length}, resolution);
123 }
124
125 /// Pixel resolution (usually integers) of child image space. Width and height.
126 ///
127 /// `image_from_camera` project onto the space spanned by `(0,0)` and `resolution - 1`.
128 Pinhole with_resolution(float width, float height) && {
130 return std::move(*this);
131 }
132
133 /// Pixel resolution (usually integers) of child image space. Width and height.
134 ///
135 /// `image_from_camera` project onto the space spanned by `(0,0)` and `resolution - 1`.
136 Pinhole with_resolution(int width, int height) && {
138 return std::move(*this);
139 }
140
141 public:
142 Pinhole() = default;
143 Pinhole(Pinhole&& other) = default;
144
145 explicit Pinhole(rerun::components::PinholeProjection _image_from_camera)
146 : image_from_camera(std::move(_image_from_camera)) {}
147
148 /// Pixel resolution (usually integers) of child image space. Width and height.
149 ///
150 /// Example:
151 /// ```text
152 /// [1920.0, 1440.0]
153 /// ```
154 ///
155 /// `image_from_camera` project onto the space spanned by `(0,0)` and `resolution - 1`.
157 resolution = std::move(_resolution);
158 // See: https://github.com/rerun-io/rerun/issues/4027
159 RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
160 }
161
162 /// Sets the view coordinates for the camera.
163 ///
164 /// All common values are available as constants on the `components.ViewCoordinates` class.
165 ///
166 /// The default is `ViewCoordinates::RDF`, i.e. X=Right, Y=Down, Z=Forward, and this is also the recommended setting.
167 /// This means that the camera frustum will point along the positive Z axis of the parent space,
168 /// and the cameras "up" direction will be along the negative Y axis of the parent space.
169 ///
170 /// The camera frustum will point whichever axis is set to `F` (or the opposite of `B`).
171 /// When logging a depth image under this entity, this is the direction the point cloud will be projected.
172 /// With `RDF`, the default forward is +Z.
173 ///
174 /// The frustum's "up" direction will be whichever axis is set to `U` (or the opposite of `D`).
175 /// This will match the negative Y direction of pixel space (all images are assumed to have xyz=RDF).
176 /// With `RDF`, the default is up is -Y.
177 ///
178 /// The frustum's "right" direction will be whichever axis is set to `R` (or the opposite of `L`).
179 /// This will match the positive X direction of pixel space (all images are assumed to have xyz=RDF).
180 /// With `RDF`, the default right is +x.
181 ///
182 /// Other common formats are `RUB` (X=Right, Y=Up, Z=Back) and `FLU` (X=Forward, Y=Left, Z=Up).
183 ///
184 /// NOTE: setting this to something else than `RDF` (the default) will change the orientation of the camera frustum,
185 /// and make the pinhole matrix not match up with the coordinate system of the pinhole entity.
186 ///
187 /// The pinhole matrix (the `image_from_camera` argument) always project along the third (Z) axis,
188 /// but will be re-oriented to project along the forward axis of the `camera_xyz` argument.
190 camera_xyz = std::move(_camera_xyz);
191 // See: https://github.com/rerun-io/rerun/issues/4027
192 RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
193 }
194
195 /// Returns the number of primary instances of this archetype.
196 size_t num_instances() const {
197 return 1;
198 }
199 };
200
201} // namespace rerun::archetypes
202
203namespace rerun {
204 /// \private
205 template <typename T>
206 struct AsComponents;
207
208 /// \private
209 template <>
210 struct AsComponents<archetypes::Pinhole> {
211 /// Serialize all set component batches.
212 static Result<std::vector<DataCell>> serialize(const archetypes::Pinhole& archetype);
213 };
214} // namespace rerun
All built-in archetypes. See Types in the Rerun manual.
Definition rerun.hpp:66
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:20
Archetype: Camera perspective projection (a.k.a.
Definition pinhole.hpp:50
rerun::components::PinholeProjection image_from_camera
Camera projection, from image coordinates to view coordinates.
Definition pinhole.hpp:52
Pinhole with_resolution(float width, float height) &&
Pixel resolution (usually integers) of child image space.
Definition pinhole.hpp:128
size_t num_instances() const
Returns the number of primary instances of this archetype.
Definition pinhole.hpp:196
Pinhole with_resolution(int width, int height) &&
Pixel resolution (usually integers) of child image space.
Definition pinhole.hpp:136
std::optional< rerun::components::ViewCoordinates > camera_xyz
Sets the view coordinates for the camera.
Definition pinhole.hpp:91
std::optional< rerun::components::Resolution > resolution
Pixel resolution (usually integers) of child image space.
Definition pinhole.hpp:62
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_resolution(rerun::components::Resolution _resolution) &&
Pixel resolution (usually integers) of child image space.
Definition pinhole.hpp:156
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:119
Pinhole with_camera_xyz(rerun::components::ViewCoordinates _camera_xyz) &&
Sets the view coordinates for the camera.
Definition pinhole.hpp:189
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:23
Component: Camera projection, from image coordinates to view coordinates.
Definition pinhole_projection.hpp:31
Component: Pixel resolution width & height, e.g.
Definition resolution.hpp:23
Component: How we interpret the coordinate system of an entity/space.
Definition view_coordinates.hpp:35
Datatype: A vector in 2D space.
Definition vec2d.hpp:20