re_types/components/
colormap.rs1#![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#![allow(non_camel_case_types)]
16
17use ::re_types_core::try_serialize_field;
18use ::re_types_core::SerializationResult;
19use ::re_types_core::{ComponentBatch as _, SerializedComponentBatch};
20use ::re_types_core::{ComponentDescriptor, ComponentType};
21use ::re_types_core::{DeserializationError, DeserializationResult};
22
23#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Default)]
29#[repr(u8)]
30pub enum Colormap {
31 Grayscale = 1,
35
36 Inferno = 2,
41
42 Magma = 3,
47
48 Plasma = 4,
53
54 #[default]
61 Turbo = 5,
62
63 Viridis = 6,
68
69 CyanToYellow = 7,
75}
76
77impl ::re_types_core::Component for Colormap {
78 #[inline]
79 fn name() -> ComponentType {
80 "rerun.components.Colormap".into()
81 }
82}
83
84::re_types_core::macros::impl_into_cow!(Colormap);
85
86impl ::re_types_core::Loggable for Colormap {
87 #[inline]
88 fn arrow_datatype() -> arrow::datatypes::DataType {
89 #![allow(clippy::wildcard_imports)]
90 use arrow::datatypes::*;
91 DataType::UInt8
92 }
93
94 fn to_arrow_opt<'a>(
95 data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
96 ) -> SerializationResult<arrow::array::ArrayRef>
97 where
98 Self: Clone + 'a,
99 {
100 #![allow(clippy::wildcard_imports)]
101 #![allow(clippy::manual_is_variant_and)]
102 use ::re_types_core::{arrow_helpers::as_array_ref, Loggable as _, ResultExt as _};
103 use arrow::{array::*, buffer::*, datatypes::*};
104 Ok({
105 let (somes, data0): (Vec<_>, Vec<_>) = data
106 .into_iter()
107 .map(|datum| {
108 let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
109 let datum = datum.map(|datum| *datum as u8);
110 (datum.is_some(), datum)
111 })
112 .unzip();
113 let data0_validity: Option<arrow::buffer::NullBuffer> = {
114 let any_nones = somes.iter().any(|some| !*some);
115 any_nones.then(|| somes.into())
116 };
117 as_array_ref(PrimitiveArray::<UInt8Type>::new(
118 ScalarBuffer::from(
119 data0
120 .into_iter()
121 .map(|v| v.unwrap_or_default())
122 .collect::<Vec<_>>(),
123 ),
124 data0_validity,
125 ))
126 })
127 }
128
129 fn from_arrow_opt(
130 arrow_data: &dyn arrow::array::Array,
131 ) -> DeserializationResult<Vec<Option<Self>>>
132 where
133 Self: Sized,
134 {
135 #![allow(clippy::wildcard_imports)]
136 use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
137 use arrow::{array::*, buffer::*, datatypes::*};
138 Ok(arrow_data
139 .as_any()
140 .downcast_ref::<UInt8Array>()
141 .ok_or_else(|| {
142 let expected = Self::arrow_datatype();
143 let actual = arrow_data.data_type().clone();
144 DeserializationError::datatype_mismatch(expected, actual)
145 })
146 .with_context("rerun.components.Colormap#enum")?
147 .into_iter()
148 .map(|typ| match typ {
149 Some(1) => Ok(Some(Self::Grayscale)),
150 Some(2) => Ok(Some(Self::Inferno)),
151 Some(3) => Ok(Some(Self::Magma)),
152 Some(4) => Ok(Some(Self::Plasma)),
153 Some(5) => Ok(Some(Self::Turbo)),
154 Some(6) => Ok(Some(Self::Viridis)),
155 Some(7) => Ok(Some(Self::CyanToYellow)),
156 None => Ok(None),
157 Some(invalid) => Err(DeserializationError::missing_union_arm(
158 Self::arrow_datatype(),
159 "<invalid>",
160 invalid as _,
161 )),
162 })
163 .collect::<DeserializationResult<Vec<Option<_>>>>()
164 .with_context("rerun.components.Colormap")?)
165 }
166}
167
168impl std::fmt::Display for Colormap {
169 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
170 match self {
171 Self::Grayscale => write!(f, "Grayscale"),
172 Self::Inferno => write!(f, "Inferno"),
173 Self::Magma => write!(f, "Magma"),
174 Self::Plasma => write!(f, "Plasma"),
175 Self::Turbo => write!(f, "Turbo"),
176 Self::Viridis => write!(f, "Viridis"),
177 Self::CyanToYellow => write!(f, "CyanToYellow"),
178 }
179 }
180}
181
182impl ::re_types_core::reflection::Enum for Colormap {
183 #[inline]
184 fn variants() -> &'static [Self] {
185 &[
186 Self::Grayscale,
187 Self::Inferno,
188 Self::Magma,
189 Self::Plasma,
190 Self::Turbo,
191 Self::Viridis,
192 Self::CyanToYellow,
193 ]
194 }
195
196 #[inline]
197 fn docstring_md(self) -> &'static str {
198 match self {
199 Self::Grayscale => {
200 "A simple black to white gradient.\n\nThis is a sRGB gray gradient which is perceptually uniform."
201 }
202 Self::Inferno => {
203 "The Inferno colormap from Matplotlib.\n\nThis is a perceptually uniform colormap.\nIt interpolates from black to red to bright yellow."
204 }
205 Self::Magma => {
206 "The Magma colormap from Matplotlib.\n\nThis is a perceptually uniform colormap.\nIt interpolates from black to purple to white."
207 }
208 Self::Plasma => {
209 "The Plasma colormap from Matplotlib.\n\nThis is a perceptually uniform colormap.\nIt interpolates from dark blue to purple to yellow."
210 }
211 Self::Turbo => {
212 "Google's Turbo colormap map.\n\nThis is a perceptually non-uniform rainbow colormap addressing many issues of\nmore traditional rainbow colormaps like Jet.\nIt is more perceptually uniform without sharp transitions and is more colorblind-friendly.\nDetails: <https://research.google/blog/turbo-an-improved-rainbow-colormap-for-visualization/>"
213 }
214 Self::Viridis => {
215 "The Viridis colormap from Matplotlib\n\nThis is a perceptually uniform colormap which is robust to color blindness.\nIt interpolates from dark purple to green to yellow."
216 }
217 Self::CyanToYellow => {
218 "Rasmusgo's Cyan to Yellow colormap\n\nThis is a perceptually uniform colormap which is robust to color blindness.\nIt is especially suited for visualizing signed values.\nIt interpolates from cyan to blue to dark gray to brass to yellow."
219 }
220 }
221 }
222}
223
224impl ::re_byte_size::SizeBytes for Colormap {
225 #[inline]
226 fn heap_size_bytes(&self) -> u64 {
227 0
228 }
229
230 #[inline]
231 fn is_pod() -> bool {
232 true
233 }
234}