re_types/blueprint/archetypes/
tensor_scalar_mapping.rs

1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/rust/api.rs
2// Based on "crates/store/re_types/definitions/rerun/blueprint/archetypes/tensor_scalar_mapping.fbs".
3
4#![allow(unused_braces)]
5#![allow(unused_imports)]
6#![allow(unused_parens)]
7#![allow(clippy::clone_on_copy)]
8#![allow(clippy::cloned_instead_of_copied)]
9#![allow(clippy::map_flatten)]
10#![allow(clippy::needless_question_mark)]
11#![allow(clippy::new_without_default)]
12#![allow(clippy::redundant_closure)]
13#![allow(clippy::too_many_arguments)]
14#![allow(clippy::too_many_lines)]
15
16use ::re_types_core::try_serialize_field;
17use ::re_types_core::SerializationResult;
18use ::re_types_core::{ComponentBatch as _, SerializedComponentBatch};
19use ::re_types_core::{ComponentDescriptor, ComponentType};
20use ::re_types_core::{DeserializationError, DeserializationResult};
21
22/// **Archetype**: Configures how tensor scalars are mapped to color.
23///
24/// ⚠️ **This type is _unstable_ and may change significantly in a way that the data won't be backwards compatible.**
25#[derive(Clone, Debug, Default)]
26pub struct TensorScalarMapping {
27    /// Filter used when zooming in on the tensor.
28    ///
29    /// Note that the filter is applied to the scalar values *before* they are mapped to color.
30    pub mag_filter: Option<SerializedComponentBatch>,
31
32    /// How scalar values map to colors.
33    pub colormap: Option<SerializedComponentBatch>,
34
35    /// Gamma exponent applied to normalized values before mapping to color.
36    ///
37    /// Raises the normalized values to the power of this value before mapping to color.
38    /// Acts like an inverse brightness. Defaults to 1.0.
39    ///
40    /// The final value for display is set as:
41    /// `colormap( ((value - data_display_range.min) / (data_display_range.max - data_display_range.min)) ** gamma )`
42    pub gamma: Option<SerializedComponentBatch>,
43}
44
45impl TensorScalarMapping {
46    /// Returns the [`ComponentDescriptor`] for [`Self::mag_filter`].
47    ///
48    /// The corresponding component is [`crate::components::MagnificationFilter`].
49    #[inline]
50    pub fn descriptor_mag_filter() -> ComponentDescriptor {
51        ComponentDescriptor {
52            archetype: Some("rerun.blueprint.archetypes.TensorScalarMapping".into()),
53            component: "TensorScalarMapping:mag_filter".into(),
54            component_type: Some("rerun.components.MagnificationFilter".into()),
55        }
56    }
57
58    /// Returns the [`ComponentDescriptor`] for [`Self::colormap`].
59    ///
60    /// The corresponding component is [`crate::components::Colormap`].
61    #[inline]
62    pub fn descriptor_colormap() -> ComponentDescriptor {
63        ComponentDescriptor {
64            archetype: Some("rerun.blueprint.archetypes.TensorScalarMapping".into()),
65            component: "TensorScalarMapping:colormap".into(),
66            component_type: Some("rerun.components.Colormap".into()),
67        }
68    }
69
70    /// Returns the [`ComponentDescriptor`] for [`Self::gamma`].
71    ///
72    /// The corresponding component is [`crate::components::GammaCorrection`].
73    #[inline]
74    pub fn descriptor_gamma() -> ComponentDescriptor {
75        ComponentDescriptor {
76            archetype: Some("rerun.blueprint.archetypes.TensorScalarMapping".into()),
77            component: "TensorScalarMapping:gamma".into(),
78            component_type: Some("rerun.components.GammaCorrection".into()),
79        }
80    }
81}
82
83static REQUIRED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 0usize]> =
84    once_cell::sync::Lazy::new(|| []);
85
86static RECOMMENDED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 0usize]> =
87    once_cell::sync::Lazy::new(|| []);
88
89static OPTIONAL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 3usize]> =
90    once_cell::sync::Lazy::new(|| {
91        [
92            TensorScalarMapping::descriptor_mag_filter(),
93            TensorScalarMapping::descriptor_colormap(),
94            TensorScalarMapping::descriptor_gamma(),
95        ]
96    });
97
98static ALL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 3usize]> =
99    once_cell::sync::Lazy::new(|| {
100        [
101            TensorScalarMapping::descriptor_mag_filter(),
102            TensorScalarMapping::descriptor_colormap(),
103            TensorScalarMapping::descriptor_gamma(),
104        ]
105    });
106
107impl TensorScalarMapping {
108    /// The total number of components in the archetype: 0 required, 0 recommended, 3 optional
109    pub const NUM_COMPONENTS: usize = 3usize;
110}
111
112impl ::re_types_core::Archetype for TensorScalarMapping {
113    #[inline]
114    fn name() -> ::re_types_core::ArchetypeName {
115        "rerun.blueprint.archetypes.TensorScalarMapping".into()
116    }
117
118    #[inline]
119    fn display_name() -> &'static str {
120        "Tensor scalar mapping"
121    }
122
123    #[inline]
124    fn required_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
125        REQUIRED_COMPONENTS.as_slice().into()
126    }
127
128    #[inline]
129    fn recommended_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
130        RECOMMENDED_COMPONENTS.as_slice().into()
131    }
132
133    #[inline]
134    fn optional_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
135        OPTIONAL_COMPONENTS.as_slice().into()
136    }
137
138    #[inline]
139    fn all_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
140        ALL_COMPONENTS.as_slice().into()
141    }
142
143    #[inline]
144    fn from_arrow_components(
145        arrow_data: impl IntoIterator<Item = (ComponentDescriptor, arrow::array::ArrayRef)>,
146    ) -> DeserializationResult<Self> {
147        re_tracing::profile_function!();
148        use ::re_types_core::{Loggable as _, ResultExt as _};
149        let arrays_by_descr: ::nohash_hasher::IntMap<_, _> = arrow_data.into_iter().collect();
150        let mag_filter = arrays_by_descr
151            .get(&Self::descriptor_mag_filter())
152            .map(|array| {
153                SerializedComponentBatch::new(array.clone(), Self::descriptor_mag_filter())
154            });
155        let colormap = arrays_by_descr
156            .get(&Self::descriptor_colormap())
157            .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_colormap()));
158        let gamma = arrays_by_descr
159            .get(&Self::descriptor_gamma())
160            .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_gamma()));
161        Ok(Self {
162            mag_filter,
163            colormap,
164            gamma,
165        })
166    }
167}
168
169impl ::re_types_core::AsComponents for TensorScalarMapping {
170    #[inline]
171    fn as_serialized_batches(&self) -> Vec<SerializedComponentBatch> {
172        use ::re_types_core::Archetype as _;
173        [
174            self.mag_filter.clone(),
175            self.colormap.clone(),
176            self.gamma.clone(),
177        ]
178        .into_iter()
179        .flatten()
180        .collect()
181    }
182}
183
184impl ::re_types_core::ArchetypeReflectionMarker for TensorScalarMapping {}
185
186impl TensorScalarMapping {
187    /// Create a new `TensorScalarMapping`.
188    #[inline]
189    pub fn new() -> Self {
190        Self {
191            mag_filter: None,
192            colormap: None,
193            gamma: None,
194        }
195    }
196
197    /// Update only some specific fields of a `TensorScalarMapping`.
198    #[inline]
199    pub fn update_fields() -> Self {
200        Self::default()
201    }
202
203    /// Clear all the fields of a `TensorScalarMapping`.
204    #[inline]
205    pub fn clear_fields() -> Self {
206        use ::re_types_core::Loggable as _;
207        Self {
208            mag_filter: Some(SerializedComponentBatch::new(
209                crate::components::MagnificationFilter::arrow_empty(),
210                Self::descriptor_mag_filter(),
211            )),
212            colormap: Some(SerializedComponentBatch::new(
213                crate::components::Colormap::arrow_empty(),
214                Self::descriptor_colormap(),
215            )),
216            gamma: Some(SerializedComponentBatch::new(
217                crate::components::GammaCorrection::arrow_empty(),
218                Self::descriptor_gamma(),
219            )),
220        }
221    }
222
223    /// Filter used when zooming in on the tensor.
224    ///
225    /// Note that the filter is applied to the scalar values *before* they are mapped to color.
226    #[inline]
227    pub fn with_mag_filter(
228        mut self,
229        mag_filter: impl Into<crate::components::MagnificationFilter>,
230    ) -> Self {
231        self.mag_filter = try_serialize_field(Self::descriptor_mag_filter(), [mag_filter]);
232        self
233    }
234
235    /// How scalar values map to colors.
236    #[inline]
237    pub fn with_colormap(mut self, colormap: impl Into<crate::components::Colormap>) -> Self {
238        self.colormap = try_serialize_field(Self::descriptor_colormap(), [colormap]);
239        self
240    }
241
242    /// Gamma exponent applied to normalized values before mapping to color.
243    ///
244    /// Raises the normalized values to the power of this value before mapping to color.
245    /// Acts like an inverse brightness. Defaults to 1.0.
246    ///
247    /// The final value for display is set as:
248    /// `colormap( ((value - data_display_range.min) / (data_display_range.max - data_display_range.min)) ** gamma )`
249    #[inline]
250    pub fn with_gamma(mut self, gamma: impl Into<crate::components::GammaCorrection>) -> Self {
251        self.gamma = try_serialize_field(Self::descriptor_gamma(), [gamma]);
252        self
253    }
254}
255
256impl ::re_byte_size::SizeBytes for TensorScalarMapping {
257    #[inline]
258    fn heap_size_bytes(&self) -> u64 {
259        self.mag_filter.heap_size_bytes()
260            + self.colormap.heap_size_bytes()
261            + self.gamma.heap_size_bytes()
262    }
263}