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