re_types/components/
magnification_filter.rs1#![allow(unused_imports)]
5#![allow(unused_parens)]
6#![allow(clippy::clone_on_copy)]
7#![allow(clippy::cloned_instead_of_copied)]
8#![allow(clippy::map_flatten)]
9#![allow(clippy::needless_question_mark)]
10#![allow(clippy::new_without_default)]
11#![allow(clippy::redundant_closure)]
12#![allow(clippy::too_many_arguments)]
13#![allow(clippy::too_many_lines)]
14#![allow(non_camel_case_types)]
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, ComponentName};
20use ::re_types_core::{DeserializationError, DeserializationResult};
21
22#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Default)]
24#[repr(u8)]
25pub enum MagnificationFilter {
26 #[default]
31 Nearest = 1,
32
33 Linear = 2,
37}
38
39impl ::re_types_core::Component for MagnificationFilter {
40 #[inline]
41 fn descriptor() -> ComponentDescriptor {
42 ComponentDescriptor::new("rerun.components.MagnificationFilter")
43 }
44}
45
46::re_types_core::macros::impl_into_cow!(MagnificationFilter);
47
48impl ::re_types_core::Loggable for MagnificationFilter {
49 #[inline]
50 fn arrow_datatype() -> arrow::datatypes::DataType {
51 #![allow(clippy::wildcard_imports)]
52 use arrow::datatypes::*;
53 DataType::UInt8
54 }
55
56 fn to_arrow_opt<'a>(
57 data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
58 ) -> SerializationResult<arrow::array::ArrayRef>
59 where
60 Self: Clone + 'a,
61 {
62 #![allow(clippy::wildcard_imports)]
63 #![allow(clippy::manual_is_variant_and)]
64 use ::re_types_core::{arrow_helpers::as_array_ref, Loggable as _, ResultExt as _};
65 use arrow::{array::*, buffer::*, datatypes::*};
66 Ok({
67 let (somes, data0): (Vec<_>, Vec<_>) = data
68 .into_iter()
69 .map(|datum| {
70 let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
71 let datum = datum.map(|datum| *datum as u8);
72 (datum.is_some(), datum)
73 })
74 .unzip();
75 let data0_validity: Option<arrow::buffer::NullBuffer> = {
76 let any_nones = somes.iter().any(|some| !*some);
77 any_nones.then(|| somes.into())
78 };
79 as_array_ref(PrimitiveArray::<UInt8Type>::new(
80 ScalarBuffer::from(
81 data0
82 .into_iter()
83 .map(|v| v.unwrap_or_default())
84 .collect::<Vec<_>>(),
85 ),
86 data0_validity,
87 ))
88 })
89 }
90
91 fn from_arrow_opt(
92 arrow_data: &dyn arrow::array::Array,
93 ) -> DeserializationResult<Vec<Option<Self>>>
94 where
95 Self: Sized,
96 {
97 #![allow(clippy::wildcard_imports)]
98 use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
99 use arrow::{array::*, buffer::*, datatypes::*};
100 Ok(arrow_data
101 .as_any()
102 .downcast_ref::<UInt8Array>()
103 .ok_or_else(|| {
104 let expected = Self::arrow_datatype();
105 let actual = arrow_data.data_type().clone();
106 DeserializationError::datatype_mismatch(expected, actual)
107 })
108 .with_context("rerun.components.MagnificationFilter#enum")?
109 .into_iter()
110 .map(|typ| match typ {
111 Some(1) => Ok(Some(Self::Nearest)),
112 Some(2) => Ok(Some(Self::Linear)),
113 None => Ok(None),
114 Some(invalid) => Err(DeserializationError::missing_union_arm(
115 Self::arrow_datatype(),
116 "<invalid>",
117 invalid as _,
118 )),
119 })
120 .collect::<DeserializationResult<Vec<Option<_>>>>()
121 .with_context("rerun.components.MagnificationFilter")?)
122 }
123}
124
125impl std::fmt::Display for MagnificationFilter {
126 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
127 match self {
128 Self::Nearest => write!(f, "Nearest"),
129 Self::Linear => write!(f, "Linear"),
130 }
131 }
132}
133
134impl ::re_types_core::reflection::Enum for MagnificationFilter {
135 #[inline]
136 fn variants() -> &'static [Self] {
137 &[Self::Nearest, Self::Linear]
138 }
139
140 #[inline]
141 fn docstring_md(self) -> &'static str {
142 match self {
143 Self::Nearest => {
144 "Show the nearest pixel value.\n\nThis will give a blocky appearance when zooming in.\nUsed as default when rendering 2D images."
145 }
146 Self::Linear => {
147 "Linearly interpolate the nearest neighbors, creating a smoother look when zooming in.\n\nUsed as default for mesh rendering."
148 }
149 }
150 }
151}
152
153impl ::re_byte_size::SizeBytes for MagnificationFilter {
154 #[inline]
155 fn heap_size_bytes(&self) -> u64 {
156 0
157 }
158
159 #[inline]
160 fn is_pod() -> bool {
161 true
162 }
163}