Rerun C++ SDK
Loading...
Searching...
No Matches
tensor.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/tensor.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../compiler_utils.hpp"
8#include "../component_batch.hpp"
9#include "../components/tensor_data.hpp"
10#include "../components/value_range.hpp"
11#include "../indicator_component.hpp"
12#include "../result.hpp"
13
14#include <cstdint>
15#include <optional>
16#include <utility>
17#include <vector>
18
19namespace rerun::archetypes {
20 /// **Archetype**: An N-dimensional array of numbers.
21 ///
22 /// Since the underlying `rerun::datatypes::TensorData` uses `rerun::Collection` internally,
23 /// data can be passed in without a copy from raw pointers or by reference from `std::vector`/`std::array`/c-arrays.
24 /// If needed, this "borrow-behavior" can be extended by defining your own `rerun::CollectionAdapter`.
25 ///
26 /// ## Example
27 ///
28 /// ### Simple tensor
29 /// ![image](https://static.rerun.io/tensor_simple/baacb07712f7b706e3c80e696f70616c6c20b367/full.png)
30 ///
31 /// ```cpp
32 /// #include <rerun.hpp>
33 ///
34 /// #include <algorithm> // std::generate
35 /// #include <random>
36 /// #include <vector>
37 ///
38 /// int main() {
39 /// const auto rec = rerun::RecordingStream("rerun_example_tensor");
40 /// rec.spawn().exit_on_failure();
41 ///
42 /// std::default_random_engine gen;
43 /// // On MSVC uint8_t distributions are not supported.
44 /// std::uniform_int_distribution<int> dist(0, 255);
45 ///
46 /// std::vector<uint8_t> data(8 * 6 * 3 * 5);
47 /// std::generate(data.begin(), data.end(), [&] { return static_cast<uint8_t>(dist(gen)); });
48 ///
49 /// rec.log(
50 /// "tensor",
51 /// rerun::Tensor({8, 6, 3, 5}, data).with_dim_names({"width", "height", "channel", "batch"})
52 /// );
53 /// }
54 /// ```
55 struct Tensor {
56 /// The tensor data
58
59 /// The expected range of values.
60 ///
61 /// This is typically the expected range of valid values.
62 /// Everything outside of the range is clamped to the range for the purpose of colormpaping.
63 /// Any colormap applied for display, will map this range.
64 ///
65 /// If not specified, the range will be automatically estimated from the data.
66 /// Note that the Viewer may try to guess a wider range than the minimum/maximum of values
67 /// in the contents of the tensor.
68 /// E.g. if all values are positive, some bigger than 1.0 and all smaller than 255.0,
69 /// the Viewer will guess that the data likely came from an 8bit image, thus assuming a range of 0-255.
70 std::optional<rerun::components::ValueRange> value_range;
71
72 public:
73 static constexpr const char IndicatorComponentName[] = "rerun.components.TensorIndicator";
74
75 /// Indicator component, used to identify the archetype when converting to a list of components.
77
78 public: // START of extensions from tensor_ext.cpp:
79 /// New Tensor from dimensions and tensor buffer.
81 : Tensor(datatypes::TensorData(std::move(shape), std::move(buffer))) {}
82
83 /// New tensor from dimensions and pointer to tensor data.
84 ///
85 /// Type must be one of the types supported by `rerun::datatypes::TensorData`.
86 /// \param shape
87 /// Shape of the image. Determines the number of elements expected to be in `data`.
88 /// \param data_
89 /// Target of the pointer must outlive the archetype.
90 template <typename TElement>
91 explicit Tensor(Collection<datatypes::TensorDimension> shape, const TElement* data_)
92 : Tensor(datatypes::TensorData(std::move(shape), data_)) {}
93
94 /// Update the `names` of the contained `TensorData` dimensions.
95 ///
96 /// Any existing Dimension names will be overwritten.
97 ///
98 /// If too many, or too few names are provided, this function will call
99 /// Error::handle and then proceed to only update the subset of names that it can.
101
102 // END of extensions from tensor_ext.cpp, start of generated code:
103
104 public:
105 Tensor() = default;
106 Tensor(Tensor&& other) = default;
107
108 explicit Tensor(rerun::components::TensorData _data) : data(std::move(_data)) {}
109
110 /// The expected range of values.
111 ///
112 /// This is typically the expected range of valid values.
113 /// Everything outside of the range is clamped to the range for the purpose of colormpaping.
114 /// Any colormap applied for display, will map this range.
115 ///
116 /// If not specified, the range will be automatically estimated from the data.
117 /// Note that the Viewer may try to guess a wider range than the minimum/maximum of values
118 /// in the contents of the tensor.
119 /// E.g. if all values are positive, some bigger than 1.0 and all smaller than 255.0,
120 /// the Viewer will guess that the data likely came from an 8bit image, thus assuming a range of 0-255.
122 value_range = std::move(_value_range);
123 // See: https://github.com/rerun-io/rerun/issues/4027
124 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
125 }
126 };
127
128} // namespace rerun::archetypes
129
130namespace rerun {
131 /// \private
132 template <typename T>
133 struct AsComponents;
134
135 /// \private
136 template <>
137 struct AsComponents<archetypes::Tensor> {
138 /// Serialize all set component batches.
139 static Result<std::vector<ComponentBatch>> serialize(const archetypes::Tensor& archetype);
140 };
141} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
All built-in archetypes. See Types in the Rerun manual.
Definition rerun.hpp:76
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:22
Archetype: An N-dimensional array of numbers.
Definition tensor.hpp:55
rerun::components::TensorData data
The tensor data.
Definition tensor.hpp:57
Tensor(Collection< datatypes::TensorDimension > shape, datatypes::TensorBuffer buffer)
New Tensor from dimensions and tensor buffer.
Definition tensor.hpp:80
Tensor with_value_range(rerun::components::ValueRange _value_range) &&
The expected range of values.
Definition tensor.hpp:121
std::optional< rerun::components::ValueRange > value_range
The expected range of values.
Definition tensor.hpp:70
Tensor with_dim_names(Collection< std::string > names) &&
Update the names of the contained TensorData dimensions.
Tensor(Collection< datatypes::TensorDimension > shape, const TElement *data_)
New tensor from dimensions and pointer to tensor data.
Definition tensor.hpp:91
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:30
Component: An N-dimensional array of numbers.
Definition tensor_data.hpp:22
Component: Range of expected or valid values, specifying a lower and upper bound.
Definition value_range.hpp:15
Datatype: The underlying storage for archetypes::Tensor.
Definition tensor_buffer.hpp:98
Datatype: An N-dimensional array of numbers.
Definition tensor_data.hpp:29