re_types/components/
line_strip3d.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
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#[derive(Clone, Debug, Default, PartialEq)]
35pub struct LineStrip3D(pub Vec<crate::datatypes::Vec3D>);
36
37impl ::re_types_core::Component for LineStrip3D {
38 #[inline]
39 fn name() -> ComponentType {
40 "rerun.components.LineStrip3D".into()
41 }
42}
43
44::re_types_core::macros::impl_into_cow!(LineStrip3D);
45
46impl ::re_types_core::Loggable for LineStrip3D {
47 #[inline]
48 fn arrow_datatype() -> arrow::datatypes::DataType {
49 #![allow(clippy::wildcard_imports)]
50 use arrow::datatypes::*;
51 DataType::List(std::sync::Arc::new(Field::new(
52 "item",
53 <crate::datatypes::Vec3D>::arrow_datatype(),
54 false,
55 )))
56 }
57
58 fn to_arrow_opt<'a>(
59 data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
60 ) -> SerializationResult<arrow::array::ArrayRef>
61 where
62 Self: Clone + 'a,
63 {
64 #![allow(clippy::wildcard_imports)]
65 #![allow(clippy::manual_is_variant_and)]
66 use ::re_types_core::{arrow_helpers::as_array_ref, Loggable as _, ResultExt as _};
67 use arrow::{array::*, buffer::*, datatypes::*};
68 Ok({
69 let (somes, data0): (Vec<_>, Vec<_>) = data
70 .into_iter()
71 .map(|datum| {
72 let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
73 let datum = datum.map(|datum| datum.into_owned().0);
74 (datum.is_some(), datum)
75 })
76 .unzip();
77 let data0_validity: Option<arrow::buffer::NullBuffer> = {
78 let any_nones = somes.iter().any(|some| !*some);
79 any_nones.then(|| somes.into())
80 };
81 {
82 let offsets = arrow::buffer::OffsetBuffer::<i32>::from_lengths(
83 data0
84 .iter()
85 .map(|opt| opt.as_ref().map_or(0, |datum| datum.len())),
86 );
87 let data0_inner_data: Vec<_> = data0.into_iter().flatten().flatten().collect();
88 let data0_inner_validity: Option<arrow::buffer::NullBuffer> = None;
89 as_array_ref(ListArray::try_new(
90 std::sync::Arc::new(Field::new(
91 "item",
92 <crate::datatypes::Vec3D>::arrow_datatype(),
93 false,
94 )),
95 offsets,
96 {
97 let data0_inner_data_inner_data: Vec<_> = data0_inner_data
98 .into_iter()
99 .map(|datum| datum.0)
100 .flatten()
101 .collect();
102 let data0_inner_data_inner_validity: Option<arrow::buffer::NullBuffer> =
103 None;
104 as_array_ref(FixedSizeListArray::new(
105 std::sync::Arc::new(Field::new("item", DataType::Float32, false)),
106 3,
107 as_array_ref(PrimitiveArray::<Float32Type>::new(
108 ScalarBuffer::from(
109 data0_inner_data_inner_data.into_iter().collect::<Vec<_>>(),
110 ),
111 data0_inner_data_inner_validity,
112 )),
113 data0_inner_validity,
114 ))
115 },
116 data0_validity,
117 )?)
118 }
119 })
120 }
121
122 fn from_arrow_opt(
123 arrow_data: &dyn arrow::array::Array,
124 ) -> DeserializationResult<Vec<Option<Self>>>
125 where
126 Self: Sized,
127 {
128 #![allow(clippy::wildcard_imports)]
129 use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
130 use arrow::{array::*, buffer::*, datatypes::*};
131 Ok({
132 let arrow_data = arrow_data
133 .as_any()
134 .downcast_ref::<arrow::array::ListArray>()
135 .ok_or_else(|| {
136 let expected = Self::arrow_datatype();
137 let actual = arrow_data.data_type().clone();
138 DeserializationError::datatype_mismatch(expected, actual)
139 })
140 .with_context("rerun.components.LineStrip3D#points")?;
141 if arrow_data.is_empty() {
142 Vec::new()
143 } else {
144 let arrow_data_inner = {
145 let arrow_data_inner = &**arrow_data.values();
146 {
147 let arrow_data_inner = arrow_data_inner
148 .as_any()
149 .downcast_ref::<arrow::array::FixedSizeListArray>()
150 .ok_or_else(|| {
151 let expected = DataType::FixedSizeList(
152 std::sync::Arc::new(Field::new(
153 "item",
154 DataType::Float32,
155 false,
156 )),
157 3,
158 );
159 let actual = arrow_data_inner.data_type().clone();
160 DeserializationError::datatype_mismatch(expected, actual)
161 })
162 .with_context("rerun.components.LineStrip3D#points")?;
163 if arrow_data_inner.is_empty() {
164 Vec::new()
165 } else {
166 let offsets = (0..)
167 .step_by(3usize)
168 .zip((3usize..).step_by(3usize).take(arrow_data_inner.len()));
169 let arrow_data_inner_inner = {
170 let arrow_data_inner_inner = &**arrow_data_inner.values();
171 arrow_data_inner_inner
172 .as_any()
173 .downcast_ref::<Float32Array>()
174 .ok_or_else(|| {
175 let expected = DataType::Float32;
176 let actual = arrow_data_inner_inner.data_type().clone();
177 DeserializationError::datatype_mismatch(expected, actual)
178 })
179 .with_context("rerun.components.LineStrip3D#points")?
180 .into_iter()
181 .collect::<Vec<_>>()
182 };
183 ZipValidity::new_with_validity(offsets, arrow_data_inner.nulls())
184 .map(|elem| {
185 elem.map(|(start, end): (usize, usize)| {
186 debug_assert!(end - start == 3usize);
187 if arrow_data_inner_inner.len() < end {
188 return Err(DeserializationError::offset_slice_oob(
189 (start, end),
190 arrow_data_inner_inner.len(),
191 ));
192 }
193
194 #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
195 let data = unsafe {
196 arrow_data_inner_inner.get_unchecked(start..end)
197 };
198 let data =
199 data.iter().cloned().map(Option::unwrap_or_default);
200
201 #[allow(clippy::unwrap_used)]
203 Ok(array_init::from_iter(data).unwrap())
204 })
205 .transpose()
206 })
207 .map(|res_or_opt| {
208 res_or_opt
209 .map(|res_or_opt| res_or_opt.map(crate::datatypes::Vec3D))
210 })
211 .collect::<DeserializationResult<Vec<Option<_>>>>()?
212 }
213 .into_iter()
214 }
215 .collect::<Vec<_>>()
216 };
217 let offsets = arrow_data.offsets();
218 ZipValidity::new_with_validity(offsets.windows(2), arrow_data.nulls())
219 .map(|elem| {
220 elem.map(|window| {
221 let start = window[0] as usize;
222 let end = window[1] as usize;
223 if arrow_data_inner.len() < end {
224 return Err(DeserializationError::offset_slice_oob(
225 (start, end),
226 arrow_data_inner.len(),
227 ));
228 }
229
230 #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
231 let data = unsafe { arrow_data_inner.get_unchecked(start..end) };
232 let data = data
233 .iter()
234 .cloned()
235 .map(Option::unwrap_or_default)
236 .collect();
237 Ok(data)
238 })
239 .transpose()
240 })
241 .collect::<DeserializationResult<Vec<Option<_>>>>()?
242 }
243 .into_iter()
244 }
245 .map(|v| v.ok_or_else(DeserializationError::missing_data))
246 .map(|res| res.map(|v| Some(Self(v))))
247 .collect::<DeserializationResult<Vec<Option<_>>>>()
248 .with_context("rerun.components.LineStrip3D#points")
249 .with_context("rerun.components.LineStrip3D")?)
250 }
251}
252
253impl<I: Into<crate::datatypes::Vec3D>, T: IntoIterator<Item = I>> From<T> for LineStrip3D {
254 fn from(v: T) -> Self {
255 Self(v.into_iter().map(|v| v.into()).collect())
256 }
257}
258
259impl ::re_byte_size::SizeBytes for LineStrip3D {
260 #[inline]
261 fn heap_size_bytes(&self) -> u64 {
262 self.0.heap_size_bytes()
263 }
264
265 #[inline]
266 fn is_pod() -> bool {
267 <Vec<crate::datatypes::Vec3D>>::is_pod()
268 }
269}