Struct ros_pointcloud2::Convert
source · pub struct Convert<T, const SIZE: usize, const DIM: usize, const METADIM: usize, C>where
T: FromBytes,
C: PointConvertible<T, SIZE, DIM, METADIM>,{ /* private fields */ }Expand description
The Convert struct is used to convert between a PointCloud2 message and a custom type. A custom type must implement the FromBytes trait and the Into trait. The Into trait is used to convert the custom type into a tuple of the coordinates and the meta data. The FromBytes trait is used to convert the bytes from the PointCloud2 message into the custom type.
§Example
use ros_pointcloud2::mem_macros::size_of;
use ros_pointcloud2::{Convert, PointMeta};
use ros_pointcloud2::ros_types::PointCloud2Msg;
const DIM : usize = 3; // how many dimensions your point has (e.g. x, y, z)
const METADIM : usize = 4; // how many meta fields you have (e.g. r, g, b, a)
type MyConverter = Convert<f32, { size_of!(f32) }, DIM, METADIM, ([f32; DIM], [PointMeta; METADIM])>;Implementations§
Trait Implementations§
source§impl<T, const SIZE: usize, const DIM: usize, const METADIM: usize, C> FallibleIterator for Convert<T, SIZE, DIM, METADIM, C>where
T: FromBytes,
C: PointConvertible<T, SIZE, DIM, METADIM>,
impl<T, const SIZE: usize, const DIM: usize, const METADIM: usize, C> FallibleIterator for Convert<T, SIZE, DIM, METADIM, C>where
T: FromBytes,
C: PointConvertible<T, SIZE, DIM, METADIM>,
source§fn next(&mut self) -> Result<Option<Self::Item>, Self::Error>
fn next(&mut self) -> Result<Option<Self::Item>, Self::Error>
Iterate over the data buffer and interpret the data as a point.
§type Error = ConversionError
type Error = ConversionError
source§fn size_hint(&self) -> (usize, Option<usize>)
fn size_hint(&self) -> (usize, Option<usize>)
source§fn count(self) -> Result<usize, Self::Error>where
Self: Sized,
fn count(self) -> Result<usize, Self::Error>where
Self: Sized,
source§fn last(self) -> Result<Option<Self::Item>, Self::Error>where
Self: Sized,
fn last(self) -> Result<Option<Self::Item>, Self::Error>where
Self: Sized,
source§fn nth(&mut self, n: usize) -> Result<Option<Self::Item>, Self::Error>
fn nth(&mut self, n: usize) -> Result<Option<Self::Item>, Self::Error>
nth element of the iterator.source§fn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
fn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
source§fn chain<I>(self, it: I) -> Chain<Self, I>
fn chain<I>(self, it: I) -> Chain<Self, I>
source§fn zip<I>(
self,
o: I
) -> Zip<Self, <I as IntoFallibleIterator>::IntoFallibleIter>
fn zip<I>( self, o: I ) -> Zip<Self, <I as IntoFallibleIterator>::IntoFallibleIter>
source§fn map<F, B>(self, f: F) -> Map<Self, F>
fn map<F, B>(self, f: F) -> Map<Self, F>
source§fn for_each<F>(self, f: F) -> Result<(), Self::Error>
fn for_each<F>(self, f: F) -> Result<(), Self::Error>
source§fn filter<F>(self, f: F) -> Filter<Self, F>
fn filter<F>(self, f: F) -> Filter<Self, F>
source§fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
source§fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
source§fn peekable(self) -> Peekable<Self>where
Self: Sized,
fn peekable(self) -> Peekable<Self>where
Self: Sized,
source§fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
source§fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
source§fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
n values of this iterator.source§fn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where
Self: Sized,
n values of this
iterator.source§fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>
fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>
source§fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>
source§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
Ok(None). Read moresource§fn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
source§fn collect<T>(self) -> Result<T, Self::Error>
fn collect<T>(self) -> Result<T, Self::Error>
source§fn partition<B, F>(self, f: F) -> Result<(B, B), Self::Error>
fn partition<B, F>(self, f: F) -> Result<(B, B), Self::Error>
source§fn fold<B, F>(self, init: B, f: F) -> Result<B, Self::Error>
fn fold<B, F>(self, init: B, f: F) -> Result<B, Self::Error>
source§fn try_fold<B, E, F>(&mut self, init: B, f: F) -> Result<B, E>
fn try_fold<B, E, F>(&mut self, init: B, f: F) -> Result<B, E>
source§fn all<F>(&mut self, f: F) -> Result<bool, Self::Error>
fn all<F>(&mut self, f: F) -> Result<bool, Self::Error>
source§fn any<F>(&mut self, f: F) -> Result<bool, Self::Error>
fn any<F>(&mut self, f: F) -> Result<bool, Self::Error>
source§fn find<F>(&mut self, f: F) -> Result<Option<Self::Item>, Self::Error>
fn find<F>(&mut self, f: F) -> Result<Option<Self::Item>, Self::Error>
source§fn find_map<B, F>(&mut self, f: F) -> Result<Option<B>, Self::Error>
fn find_map<B, F>(&mut self, f: F) -> Result<Option<B>, Self::Error>
None result.source§fn position<F>(&mut self, f: F) -> Result<Option<usize>, Self::Error>
fn position<F>(&mut self, f: F) -> Result<Option<usize>, Self::Error>
source§fn max_by_key<B, F>(self, f: F) -> Result<Option<Self::Item>, Self::Error>
fn max_by_key<B, F>(self, f: F) -> Result<Option<Self::Item>, Self::Error>
source§fn max_by<F>(self, f: F) -> Result<Option<Self::Item>, Self::Error>
fn max_by<F>(self, f: F) -> Result<Option<Self::Item>, Self::Error>
source§fn min_by_key<B, F>(self, f: F) -> Result<Option<Self::Item>, Self::Error>
fn min_by_key<B, F>(self, f: F) -> Result<Option<Self::Item>, Self::Error>
source§fn min_by<F>(self, f: F) -> Result<Option<Self::Item>, Self::Error>
fn min_by<F>(self, f: F) -> Result<Option<Self::Item>, Self::Error>
source§fn unzip<A, B, FromA, FromB>(self) -> Result<(FromA, FromB), Self::Error>
fn unzip<A, B, FromA, FromB>(self) -> Result<(FromA, FromB), Self::Error>
source§fn partial_cmp<I>(self, other: I) -> Result<Option<Ordering>, Self::Error>where
Self: Sized,
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,
fn partial_cmp<I>(self, other: I) -> Result<Option<Ordering>, Self::Error>where
Self: Sized,
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,
source§fn eq<I>(self, other: I) -> Result<bool, Self::Error>where
Self: Sized,
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialEq<<I as IntoFallibleIterator>::Item>,
fn eq<I>(self, other: I) -> Result<bool, Self::Error>where
Self: Sized,
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialEq<<I as IntoFallibleIterator>::Item>,
source§fn ne<I>(self, other: I) -> Result<bool, Self::Error>where
Self: Sized,
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialEq<<I as IntoFallibleIterator>::Item>,
fn ne<I>(self, other: I) -> Result<bool, Self::Error>where
Self: Sized,
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialEq<<I as IntoFallibleIterator>::Item>,
source§fn lt<I>(self, other: I) -> Result<bool, Self::Error>where
Self: Sized,
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,
fn lt<I>(self, other: I) -> Result<bool, Self::Error>where
Self: Sized,
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,
source§fn le<I>(self, other: I) -> Result<bool, Self::Error>where
Self: Sized,
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,
fn le<I>(self, other: I) -> Result<bool, Self::Error>where
Self: Sized,
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,
source§fn gt<I>(self, other: I) -> Result<bool, Self::Error>where
Self: Sized,
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,
fn gt<I>(self, other: I) -> Result<bool, Self::Error>where
Self: Sized,
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,
source§fn ge<I>(self, other: I) -> Result<bool, Self::Error>where
Self: Sized,
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,
fn ge<I>(self, other: I) -> Result<bool, Self::Error>where
Self: Sized,
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,
source§impl<T, const SIZE: usize, const DIM: usize, const METADIM: usize, C> TryFrom<PointCloud2Msg> for Convert<T, SIZE, DIM, METADIM, C>where
T: FromBytes,
C: PointConvertible<T, SIZE, DIM, METADIM>,
impl<T, const SIZE: usize, const DIM: usize, const METADIM: usize, C> TryFrom<PointCloud2Msg> for Convert<T, SIZE, DIM, METADIM, C>where
T: FromBytes,
C: PointConvertible<T, SIZE, DIM, METADIM>,
source§fn try_from(cloud: PointCloud2Msg) -> Result<Self, Self::Error>
fn try_from(cloud: PointCloud2Msg) -> Result<Self, Self::Error>
Converts a ROS PointCloud2 message into a Convert struct that implements the Iterator trait. Iterate over the struct to get or use the points.
§Example
Since we do not have a ROS node here, we first create a PointCloud2 message and then convert back to a Convert struct.
use ros_pointcloud2::ros_types::PointCloud2Msg;
use ros_pointcloud2::ConvertXYZ;
use ros_pointcloud2::pcl_utils::PointXYZ;
let cloud_points: Vec<PointXYZ> = vec![
PointXYZ { x: 1.0, y: 2.0, z: 3.0 },
PointXYZ { x: 4.0, y: 5.0, z: 6.0 },
];
let msg: PointCloud2Msg = ConvertXYZ::try_from(cloud_points).unwrap().try_into().unwrap();
let convert: ConvertXYZ = ConvertXYZ::try_from(msg).unwrap(); // parse message§type Error = ConversionError
type Error = ConversionError
source§impl<T, const SIZE: usize, const DIM: usize, const METADIM: usize, C> TryFrom<Vec<C>> for Convert<T, SIZE, DIM, METADIM, C>where
T: FromBytes,
C: PointConvertible<T, SIZE, DIM, METADIM>,
impl<T, const SIZE: usize, const DIM: usize, const METADIM: usize, C> TryFrom<Vec<C>> for Convert<T, SIZE, DIM, METADIM, C>where
T: FromBytes,
C: PointConvertible<T, SIZE, DIM, METADIM>,
source§fn try_from(cloud: Vec<C>) -> Result<Self, Self::Error>
fn try_from(cloud: Vec<C>) -> Result<Self, Self::Error>
Converts a vector of custom types into a Convert struct that implements the Iterator trait.
§Example
use ros_pointcloud2::{ConvertXYZ, ConversionError};
use ros_pointcloud2::pcl_utils::PointXYZ;
let cloud_points: Vec<PointXYZ> = vec![
PointXYZ { x: 1.0, y: 2.0, z: 3.0 },
PointXYZ { x: 4.0, y: 5.0, z: 6.0 },
];
let convert: Result<ConvertXYZ, ConversionError> = ConvertXYZ::try_from(cloud_points);§type Error = ConversionError
type Error = ConversionError
source§impl<T, const SIZE: usize, const DIM: usize, const METADIM: usize, C> TryInto<PointCloud2Msg> for Convert<T, SIZE, DIM, METADIM, C>where
T: FromBytes,
C: PointConvertible<T, SIZE, DIM, METADIM>,
impl<T, const SIZE: usize, const DIM: usize, const METADIM: usize, C> TryInto<PointCloud2Msg> for Convert<T, SIZE, DIM, METADIM, C>where
T: FromBytes,
C: PointConvertible<T, SIZE, DIM, METADIM>,
source§fn try_into(self) -> Result<PointCloud2Msg, Self::Error>
fn try_into(self) -> Result<PointCloud2Msg, Self::Error>
Convert the point cloud to a ROS message.
First use the try_from method for initializing the conversion and parsing meta data.
Then use the try_into method to do the actual conversion.
§Example
use ros_pointcloud2::ros_types::PointCloud2Msg;
use ros_pointcloud2::ConvertXYZ;
use ros_pointcloud2::pcl_utils::PointXYZ;
let cloud_points: Vec<PointXYZ> = vec![
PointXYZ { x: 1.0, y: 2.0, z: 3.0 },
PointXYZ { x: 4.0, y: 5.0, z: 6.0 },
];
let msg_out: PointCloud2Msg = ConvertXYZ::try_from(cloud_points).unwrap().try_into().unwrap();