Trait pasture_core::containers::BorrowedBuffer
source · pub trait BorrowedBuffer<'a> {
// Required methods
fn len(&self) -> usize;
fn point_layout(&self) -> &PointLayout;
fn get_point(&self, index: usize, data: &mut [u8]);
fn get_point_range(&self, range: Range<usize>, data: &mut [u8]);
unsafe fn get_attribute_unchecked(
&self,
attribute_member: &PointAttributeMember,
index: usize,
data: &mut [u8],
);
// Provided methods
fn is_empty(&self) -> bool { ... }
fn get_attribute(
&self,
attribute: &PointAttributeDefinition,
index: usize,
data: &mut [u8],
) { ... }
fn get_attribute_range(
&self,
attribute: &PointAttributeDefinition,
point_range: Range<usize>,
data: &mut [u8],
) { ... }
fn as_interleaved(&self) -> Option<&dyn InterleavedBuffer<'a>> { ... }
fn as_columnar(&self) -> Option<&dyn ColumnarBuffer<'a>> { ... }
}
Expand description
Base trait for all point buffers in pasture. The only assumption this trait makes is that the
underlying memory can be borrowed by the buffer. Provides point and attribute accessors by
untyped value (i.e. copying into a provided &mut [u8]
)
Required Methods§
sourcefn len(&self) -> usize
fn len(&self) -> usize
Returns the length of this buffer, i.e. the number of points
§Example
use pasture_core::containers::*;
use pasture_core::layout::*;
let buffer = VectorBuffer::new_from_layout(PointLayout::default());
assert_eq!(0, buffer.len());
sourcefn point_layout(&self) -> &PointLayout
fn point_layout(&self) -> &PointLayout
Returns the PointLayout
of this buffer. The PointLayout
describes the structure of a single
point at runtime.
§Example
use pasture_core::containers::*;
use pasture_core::layout::*;
let layout = PointLayout::from_attributes(&[attributes::POSITION_3D, attributes::INTENSITY]);
let buffer = VectorBuffer::new_from_layout(layout.clone());
assert_eq!(layout, *buffer.point_layout());
sourcefn get_point(&self, index: usize, data: &mut [u8])
fn get_point(&self, index: usize, data: &mut [u8])
Writes the data for the point at index
from this buffer into data
§Panics
May panic if index
is out of bounds.
May panic if data.len()
does not equal self.point_layout().size_of_point_entry()
sourcefn get_point_range(&self, range: Range<usize>, data: &mut [u8])
fn get_point_range(&self, range: Range<usize>, data: &mut [u8])
Writes the data for the given range
of points from this buffer into data
§Panics
May panic if range
is out of bounds.
May panic if data.len()
does not equal range.len() * self.point_layout().size_of_point_entry()
sourceunsafe fn get_attribute_unchecked(
&self,
attribute_member: &PointAttributeMember,
index: usize,
data: &mut [u8],
)
unsafe fn get_attribute_unchecked( &self, attribute_member: &PointAttributeMember, index: usize, data: &mut [u8], )
Like get_attribute
, but performs no check whether the attribute actually is part of this buffers PointLayout
or not. Because of this, this function accepts a PointAttributeMember
instead of a PointAttributeDefinition
,
and this PointAttributeMember
must come from the PointLayout
of this buffer! The benefit over get_attribute
is that this function skips the include checks and thus will be faster if you repeatedly want to get data for a
single attribute
§Safety
Requires attribute_member
to be a part of this buffer’s PointLayout
Provided Methods§
sourcefn is_empty(&self) -> bool
fn is_empty(&self) -> bool
Returns true
if this buffer does not store any points
§Example
use pasture_core::containers::*;
use pasture_core::layout::*;
let buffer = VectorBuffer::new_from_layout(PointLayout::default());
assert!(buffer.is_empty());
sourcefn get_attribute(
&self,
attribute: &PointAttributeDefinition,
index: usize,
data: &mut [u8],
)
fn get_attribute( &self, attribute: &PointAttributeDefinition, index: usize, data: &mut [u8], )
Writes the data for the given attribute
of the point at index
into data
§Panics
May panic if attribute
is not part of the PointLayout
of this buffer. It is implementation-defined
whether data type conversions are supported (i.e. the buffer stores positions as Vector3<f64>
, but
get_attribute
is called with Vector3<f32>
as the attribute data type), but generally assume that
conversions are not possible!
May panic if data.len()
does not equal the size of a single value of the data type of attribute
sourcefn get_attribute_range(
&self,
attribute: &PointAttributeDefinition,
point_range: Range<usize>,
data: &mut [u8],
)
fn get_attribute_range( &self, attribute: &PointAttributeDefinition, point_range: Range<usize>, data: &mut [u8], )
Writes the data for the given attribute
of the given range of points into data
. The attribute data will
be tightly packed in data
, irregardless of the memory layout of this buffer. The attribute values might not
be correctly aligned, if the alignment requirement of attribute.datatype()
is larger than the size of the
attribute. All of the built-in attributes in pasture have alignments that are less than or equal to their size,
so for built-in attributes you can assume that the attributes in data
are correctly aligned.
§Panics
May panic if attribute
is not part of the PointLayout
of this buffer.
May panic if point_range
is out of bounds.
May panic if data.len()
does not equal attribute.size() * point_range.len()
sourcefn as_interleaved(&self) -> Option<&dyn InterleavedBuffer<'a>>
fn as_interleaved(&self) -> Option<&dyn InterleavedBuffer<'a>>
Try to get a reference to self
as an InterleavedBuffer
. Returns None
if self
does not
implement InterleavedBuffer
sourcefn as_columnar(&self) -> Option<&dyn ColumnarBuffer<'a>>
fn as_columnar(&self) -> Option<&dyn ColumnarBuffer<'a>>
Try to get a reference to self
as a ColumnarBuffer
. Returns None
if self
does not
implement ColumnarBuffer
Trait Implementations§
source§impl<'a> BorrowedBufferExt<'a> for dyn BorrowedBuffer<'a> + 'a
impl<'a> BorrowedBufferExt<'a> for dyn BorrowedBuffer<'a> + 'a
source§fn view<'b, T: PointType>(&'b self) -> PointView<'a, 'b, Self, T>where
'a: 'b,
fn view<'b, T: PointType>(&'b self) -> PointView<'a, 'b, Self, T>where
'a: 'b,
source§fn view_attribute<'b, T: PrimitiveType>(
&'b self,
attribute: &PointAttributeDefinition,
) -> AttributeView<'a, 'b, Self, T>where
'a: 'b,
fn view_attribute<'b, T: PrimitiveType>(
&'b self,
attribute: &PointAttributeDefinition,
) -> AttributeView<'a, 'b, Self, T>where
'a: 'b,
attribute
of all points in this buffer Read moresource§fn view_attribute_with_conversion<'b, T: PrimitiveType>(
&'b self,
attribute: &PointAttributeDefinition,
) -> Result<AttributeViewConverting<'a, 'b, Self, T>>where
'a: 'b,
fn view_attribute_with_conversion<'b, T: PrimitiveType>(
&'b self,
attribute: &PointAttributeDefinition,
) -> Result<AttributeViewConverting<'a, 'b, Self, T>>where
'a: 'b,
view_attribute
, but allows T::data_type()
to be different from the data type ofthe
attribute
within this buffer. Read more