[][src]Struct plexus::buffer::MeshBuffer

pub struct MeshBuffer<R, G> where
    R: Grouping
{ /* fields omitted */ }

Linear representation of a mesh.

A MeshBuffer is a linear representation of a mesh that is composed of two separate buffers: an index buffer and a vertex buffer. The index buffer contains ordered indices into the data in the vertex buffer and describes the topology of the mesh. The vertex buffer contains arbitrary geometric data.

See the module documention for more information.

Methods

impl<R, G> MeshBuffer<R, G> where
    R: Grouping,
    Vec<R::Item>: IndexBuffer<R>, 
[src]

pub fn new() -> Self[src]

Creates an empty MeshBuffer.

Examples

use plexus::buffer::MeshBuffer;
use plexus::index::Flat3;

let buffer = MeshBuffer::<Flat3<u64>, (f64, f64, f64)>::new();

pub fn arity(&self) -> Arity[src]

impl<R, G> MeshBuffer<R, G> where
    R: Grouping
[src]

pub fn into_raw_buffers(self) -> (Vec<R::Item>, Vec<G>)[src]

pub fn map_vertices_into<H, F>(self, f: F) -> MeshBuffer<R, H> where
    F: FnMut(G) -> H, 
[src]

Maps over the vertex data in a MeshBuffer.

Examples

Translating the position data in a buffer:

use decorum::N64;
use nalgebra::{Point3, Vector3};
use plexus::buffer::MeshBuffer3;
use plexus::prelude::*;
use plexus::primitive::generate::Position;
use plexus::primitive::sphere::UvSphere;

let buffer = UvSphere::new(16, 8)
    .polygons::<Position<Point3<N64>>>()
    .triangulate()
    .collect::<MeshBuffer3<usize, Point3<f64>>>();
// Translate the positions.
let translation = Vector3::<f64>::x() * 2.0;
let buffer = buffer.map_vertices_into(|position| position + translation);

pub fn as_index_slice(&self) -> &[R::Item][src]

Gets a slice of the index data.

pub fn as_vertex_slice(&self) -> &[G][src]

Gets a slice of the vertex data.

impl<A, N, G> MeshBuffer<Flat<A, N>, G> where
    A: NonZero + Unsigned,
    N: Copy + Integer + NumCast + Unsigned
[src]

pub fn append<R, H>(&mut self, buffer: &mut MeshBuffer<R, H>) where
    R: Grouping,
    R::Item: Into<<Flat<A, N> as Grouping>::Item>,
    H: IntoGeometry<G>, 
[src]

Appends the contents of a MeshBuffer into another MeshBuffer. The source buffer is drained.

impl<P, G> MeshBuffer<P, G> where
    P: Grouping + Polygonal,
    P::Vertex: Copy + Integer + NumCast + Unsigned
[src]

pub fn into_polygons(
    self
) -> impl Iterator<Item = <<P as Grouping>::Item as Map<G>>::Output> where
    G: Clone,
    <P as Grouping>::Item: Map<G> + Topological,
    <<P as Grouping>::Item as Topological>::Vertex: ToPrimitive
[src]

Converts a structured MeshBuffer into an iterator of polygons containing vertex data.

Examples

Mapping over the polygons described by a buffer:

use decorum::R64;
use nalgebra::Point3;
use plexus::buffer::MeshBufferN;
use plexus::graph::MeshGraph;
use plexus::prelude::*;
use plexus::primitive::generate::Position;
use plexus::primitive::sphere::UvSphere;

let buffer = UvSphere::new(8, 8)
    .polygons::<Position<Point3<R64>>>()
    .collect::<MeshBufferN<usize, Point3<R64>>>();
let graph = buffer
    .into_polygons()
    .map_vertices(|position| position * 2.0.into())
    .triangulate()
    .collect::<MeshGraph<Point3<R64>>>();

pub fn append<R, H>(&mut self, buffer: &mut MeshBuffer<R, H>) where
    R: Grouping,
    R::Item: Into<<P as Grouping>::Item>,
    H: IntoGeometry<G>,
    <P as Grouping>::Item: Copy + Map<P::Vertex, Output = <P as Grouping>::Item> + Topological<Vertex = P::Vertex>, 
[src]

Appends the contents of a MeshBuffer into another MeshBuffer. The source buffer is drained.

Trait Implementations

impl<A, N, G> IntoFlatIndex<A, G> for MeshBuffer<Flat<A, N>, G> where
    A: NonZero + Unsigned,
    N: Copy + Integer + NumCast + Unsigned
[src]

type Item = N

impl<N, G> IntoFlatIndex<UInt<UInt<UTerm, B1>, B1>, G> for MeshBuffer<Trigon<N>, G> where
    N: Copy + Integer + NumCast + Unsigned
[src]

type Item = N

fn into_flat_index(self) -> MeshBuffer<Flat<U3, Self::Item>, G>[src]

Converts a structured index buffer into a flat index buffer.

Examples

use nalgebra::Point3;
use plexus::buffer::MeshBuffer;
use plexus::prelude::*;
use plexus::primitive::cube::Cube;
use plexus::primitive::generate::Position;
use plexus::primitive::Trigon;

let cube = Cube::new();
let buffer = MeshBuffer::<Trigon<usize>, _>::from_raw_buffers(
    cube.indexing_polygons::<Position>().triangulate(),
    cube.vertices::<Position<Point3<f32>>>(),
)
.unwrap();
let buffer = buffer.into_flat_index();
for index in buffer.as_index_slice() {
    // ...
}

impl<N, G> IntoFlatIndex<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, G> for MeshBuffer<Tetragon<N>, G> where
    N: Copy + Integer + NumCast + Unsigned
[src]

type Item = N

fn into_flat_index(self) -> MeshBuffer<Flat<U4, Self::Item>, G>[src]

Converts a structured index buffer into a flat index buffer.

Examples

use nalgebra::Point3;
use plexus::buffer::MeshBuffer;
use plexus::prelude::*;
use plexus::primitive::cube::Cube;
use plexus::primitive::generate::Position;
use plexus::primitive::Tetragon;

let cube = Cube::new();
let buffer = MeshBuffer::<Tetragon<usize>, _>::from_raw_buffers(
    cube.indexing_polygons::<Position>(),
    cube.vertices::<Position<Point3<f64>>>(),
)
.unwrap();
let buffer = buffer.into_flat_index();
for index in buffer.as_index_slice() {
    // ...
}

impl<P, G> IntoStructuredIndex<G> for MeshBuffer<P, G> where
    P: Grouping + Polygonal,
    P::Vertex: Copy + Integer + NumCast + Unsigned
[src]

type Item = P

impl<N, G> IntoStructuredIndex<G> for MeshBuffer<Flat3<N>, G> where
    N: Copy + Integer + NumCast + Unsigned,
    Trigon<N>: Grouping<Item = Trigon<N>>, 
[src]

type Item = Trigon<N>

fn into_structured_index(self) -> MeshBuffer<Self::Item, G>[src]

Converts a flat index buffer into a structured index buffer.

Examples

use nalgebra::Point3;
use plexus::buffer::MeshBuffer3;
use plexus::prelude::*;
use plexus::primitive::cube::Cube;
use plexus::primitive::generate::Position;

let cube = Cube::new();
let buffer = MeshBuffer3::<usize, _>::from_raw_buffers(
    cube.indexing_polygons::<Position>()
        .triangulate()
        .vertices(),
    cube.vertices::<Position<Point3<f32>>>(),
)
.unwrap();
let buffer = buffer.into_structured_index();
for trigon in buffer.as_index_slice() {
    // ...
}

impl<N, G> IntoStructuredIndex<G> for MeshBuffer<Flat4<N>, G> where
    N: Copy + Integer + NumCast + Unsigned,
    Tetragon<N>: Grouping<Item = Tetragon<N>>, 
[src]

type Item = Tetragon<N>

fn into_structured_index(self) -> MeshBuffer<Self::Item, G>[src]

Converts a flat index buffer into a structured index buffer.

Examples

use nalgebra::Point3;
use plexus::buffer::MeshBuffer4;
use plexus::prelude::*;
use plexus::primitive::cube::Cube;
use plexus::primitive::generate::Position;

let cube = Cube::new();
let buffer = MeshBuffer4::<usize, _>::from_raw_buffers(
    cube.indexing_polygons::<Position>().vertices(),
    cube.vertices::<Position<Point3<f64>>>(),
)
.unwrap();
let buffer = buffer.into_structured_index();
for tetragon in buffer.as_index_slice() {
    // ...
}

impl<E, G> FromEncoding<E> for MeshBuffer<Polygon<usize>, G> where
    E: FaceDecoder<Face = (), Index = Polygon<usize>> + VertexDecoder,
    E::Vertex: IntoGeometry<G>, 
[src]

type Error = BufferError

impl<R, P, G> FromIndexer<P, P> for MeshBuffer<R, G> where
    R: Grouping,
    P: Map<<Vec<R::Item> as IndexBuffer<R>>::Index> + Topological,
    P::Output: Topological<Vertex = <Vec<R::Item> as IndexBuffer<R>>::Index>,
    P::Vertex: IntoGeometry<G>,
    Vec<R::Item>: Push<R, P::Output>,
    Self: FromRawBuffers<R::Item, G>, 
[src]

type Error = Self::Error

impl<A, N, M, G> FromRawBuffers<M, G> for MeshBuffer<Flat<A, N>, G> where
    A: NonZero + Unsigned,
    N: Copy + Integer + NumCast + Unsigned,
    M: Copy + Integer + NumCast + Unsigned,
    <Flat<A, N> as Grouping>::Item: ToPrimitive
[src]

type Error = BufferError

fn from_raw_buffers<I, J>(indices: I, vertices: J) -> Result<Self, BufferError> where
    I: IntoIterator<Item = M>,
    J: IntoIterator<Item = G>, 
[src]

Creates a flat MeshBuffer from raw index and vertex buffers.

Errors

Returns an error if the index data is out of bounds within the vertex buffer or if the number of indices disagrees with the arity of the index buffer.

Examples

use decorum::N64;
use nalgebra::Point3;
use plexus::buffer::MeshBuffer3;
use plexus::index::{Flat3, HashIndexer};
use plexus::prelude::*;
use plexus::primitive;
use plexus::primitive::cube::Cube;
use plexus::primitive::generate::{Normal, Position};

type E3 = Point3<N64>;

let cube = Cube::new();
let (indices, vertices) = primitive::zip_vertices((
    cube.polygons::<Position<E3>>(),
    cube.polygons::<Normal<E3>>()
        .map_vertices(|normal| normal.into_inner()),
))
.triangulate()
.index_vertices::<Flat3, _>(HashIndexer::default());
let buffer = MeshBuffer3::<usize, _>::from_raw_buffers(indices, vertices).unwrap();

impl<P, Q, G> FromRawBuffers<Q, G> for MeshBuffer<P, G> where
    P: Grouping + Polygonal,
    P::Vertex: Copy + Integer + NumCast + Unsigned,
    Q: Into<<P as Grouping>::Item>,
    <P as Grouping>::Item: Copy + IntoVertices + Topological<Vertex = P::Vertex>, 
[src]

type Error = BufferError

fn from_raw_buffers<I, J>(indices: I, vertices: J) -> Result<Self, BufferError> where
    I: IntoIterator<Item = Q>,
    J: IntoIterator<Item = G>, 
[src]

Creates a structured MeshBuffer from raw index and vertex buffers.

Errors

Returns an error if the index data is out of bounds within the vertex buffer.

Examples

use nalgebra::Point3;
use plexus::buffer::MeshBufferN;
use plexus::prelude::*;
use plexus::primitive::generate::Position;
use plexus::primitive::sphere::UvSphere;

let sphere = UvSphere::new(8, 8);
let buffer = MeshBufferN::<usize, _>::from_raw_buffers(
    sphere.indexing_polygons::<Position>(),
    sphere.vertices::<Position<Point3<f64>>>(),
)
.unwrap();

impl<R, G> Default for MeshBuffer<R, G> where
    R: Grouping,
    Vec<R::Item>: IndexBuffer<R>, 
[src]

impl<R: Debug, G: Debug> Debug for MeshBuffer<R, G> where
    R: Grouping,
    R::Item: Debug
[src]

impl<A, N, H, G> TryFrom<MeshBuffer<Flat<A, N>, H>> for MeshGraph<G> where
    A: NonZero + Unsigned,
    N: Copy + Integer + NumCast + Unsigned,
    H: Clone + IntoGeometry<G::Vertex>,
    G: GraphGeometry
[src]

type Error = GraphError

The type returned in the event of a conversion error.

fn try_from(buffer: MeshBuffer<Flat<A, N>, H>) -> Result<Self, Self::Error>[src]

Creates a MeshGraph from a flat MeshBuffer. The arity of the polygons in the index buffer must be known and constant.

Errors

Returns an error if a MeshGraph cannot represent the topology in the MeshBuffer.

Examples

use nalgebra::Point2;
use plexus::buffer::MeshBuffer;
use plexus::graph::MeshGraph;
use plexus::index::Flat4;
use plexus::prelude::*;
use std::convert::TryFrom;

let buffer = MeshBuffer::<Flat4, _>::from_raw_buffers(
    vec![0u64, 1, 2, 3],
    vec![(0.0f64, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)],
)
.unwrap();
let mut graph = MeshGraph::<Point2<f64>>::try_from(buffer).unwrap();

impl<P, H, G> TryFrom<MeshBuffer<P, H>> for MeshGraph<G> where
    P: Grouping<Item = P> + IntoVertices + Polygonal,
    P::Vertex: Copy + Integer + NumCast + Unsigned,
    H: Clone + IntoGeometry<G::Vertex>,
    G: GraphGeometry
[src]

type Error = GraphError

The type returned in the event of a conversion error.

fn try_from(buffer: MeshBuffer<P, H>) -> Result<Self, Self::Error>[src]

Creates a MeshGraph from a structured MeshBuffer.

Errors

Returns an error if a MeshGraph cannot represent the topology in the MeshBuffer.

Examples

use nalgebra::Point2;
use plexus::buffer::MeshBuffer;
use plexus::graph::MeshGraph;
use plexus::prelude::*;
use plexus::primitive::Tetragon;
use std::convert::TryFrom;

let buffer = MeshBuffer::<Tetragon<u64>, _>::from_raw_buffers(
    vec![Tetragon::new(0u64, 1, 2, 3)],
    vec![(0.0f64, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)],
)
.unwrap();
let mut graph = MeshGraph::<Point2<f64>>::try_from(buffer).unwrap();

impl<R, P, G> FromIterator<P> for MeshBuffer<R, G> where
    R: Grouping,
    P: Topological,
    P::Vertex: Copy + Eq + Hash + IntoGeometry<G>,
    Vec<R::Item>: IndexBuffer<R>,
    Self: FromIndexer<P, P>, 
[src]

Auto Trait Implementations

impl<R, G> Send for MeshBuffer<R, G> where
    G: Send,
    <R as Grouping>::Item: Send

impl<R, G> Sync for MeshBuffer<R, G> where
    G: Sync,
    <R as Grouping>::Item: Sync

impl<R, G> Unpin for MeshBuffer<R, G> where
    G: Unpin,
    <R as Grouping>::Item: Unpin

impl<R, G> UnwindSafe for MeshBuffer<R, G> where
    G: UnwindSafe,
    <R as Grouping>::Item: UnwindSafe

impl<R, G> RefUnwindSafe for MeshBuffer<R, G> where
    G: RefUnwindSafe,
    <R as Grouping>::Item: RefUnwindSafe

Blanket Implementations

impl<T, E> FromPly<E> for T where
    E: FaceElementDecoder + FacePropertyDecoder + VertexPropertyDecoder + VertexElementDecoder,
    T: FromEncoding<E>,
    PlyError: From<<T as FromEncoding<E>>::Error>, 
[src]

impl<T> FromGeometry<T> for T[src]

impl<T, U> IntoGeometry<U> for T where
    U: FromGeometry<T>, 
[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,