[][src]Struct plexus::graph::MeshGraph

pub struct MeshGraph<G = (N64, N64, N64)> where
    G: GraphGeometry
{ /* fields omitted */ }

Half-edge graph representation of a mesh.

Provides topological data in the form of vertices, arcs, edges, and faces. An arc is directed from one vertex to another, with an opposing arc joining the vertices in the other direction.

MeshGraphs expose topological views, which can be used to traverse and manipulate topology and geometry in the graph.

See the module documentation for more details.

Methods

impl<G> MeshGraph<G> where
    G: GraphGeometry
[src]

pub fn new() -> Self[src]

Creates an empty MeshGraph.

Examples

use plexus::graph::MeshGraph;

let mut graph = MeshGraph::<()>::new();

pub fn vertex_count(&self) -> usize[src]

Gets the number of vertices in the graph.

pub fn vertex(&self, key: VertexKey) -> Option<VertexView<&Self, G>>[src]

Gets an immutable view of the vertex with the given key.

pub fn vertex_mut(&mut self, key: VertexKey) -> Option<VertexView<&mut Self, G>>[src]

Gets a mutable view of the vertex with the given key.

pub fn vertices(&self) -> impl Iterator<Item = VertexView<&Self, G>>[src]

Gets an iterator of immutable views over the vertices in the graph.

pub fn vertex_orphans(&mut self) -> impl Iterator<Item = VertexOrphan<G>>[src]

Gets an iterator of orphan views over the vertices in the graph.

Because this only yields orphan views, only geometry can be mutated. For topological mutations, collect the necessary keys and use vertex_mut instead.

pub fn arc_count(&self) -> usize[src]

Gets the number of arcs in the graph.

pub fn arc(&self, key: ArcKey) -> Option<ArcView<&Self, G>>[src]

Gets an immutable view of the arc with the given key.

pub fn arc_mut(&mut self, key: ArcKey) -> Option<ArcView<&mut Self, G>>[src]

Gets a mutable view of the arc with the given key.

pub fn arcs(&self) -> impl Iterator<Item = ArcView<&Self, G>>[src]

Gets an iterator of immutable views over the arcs in the graph.

pub fn arc_orphans(&mut self) -> impl Iterator<Item = ArcOrphan<G>>[src]

Gets an iterator of orphan views over the arcs in the graph.

Because this only yields orphan views, only geometry can be mutated. For topological mutations, collect the necessary keys and use arc_mut instead.

pub fn edge_count(&self) -> usize[src]

Gets the number of edges in the graph.

pub fn edge(&self, key: EdgeKey) -> Option<EdgeView<&Self, G>>[src]

Gets an immutable view of the edge with the given key.

pub fn edge_mut(&mut self, key: EdgeKey) -> Option<EdgeView<&mut Self, G>>[src]

Gets a mutable view of the edge with the given key.

pub fn edges(&self) -> impl Iterator<Item = EdgeView<&Self, G>>[src]

Gets an iterator of immutable views over the edges in the graph.

pub fn edge_orphans(&mut self) -> impl Iterator<Item = EdgeOrphan<G>>[src]

Gets an iterator of orphan views over the edges in the graph.

Because this only yields orphan views, only geometry can be mutated. For topological mutations, collect the necessary keys and use edge_mut instead.

pub fn face_count(&self) -> usize[src]

Gets the number of faces in the graph.

pub fn face(&self, key: FaceKey) -> Option<FaceView<&Self, G>>[src]

Gets an immutable view of the face with the given key.

pub fn face_mut(&mut self, key: FaceKey) -> Option<FaceView<&mut Self, G>>[src]

Gets a mutable view of the face with the given key.

pub fn faces(&self) -> impl Iterator<Item = FaceView<&Self, G>>[src]

Gets an iterator of immutable views over the faces in the graph.

pub fn face_orphans(&mut self) -> impl Iterator<Item = FaceOrphan<G>>[src]

Gets an iterator of orphan views over the faces in the graph.

Because this only yields orphan views, only geometry can be mutated. For topological mutations, collect the necessary keys and use face_mut instead.

pub fn path<I>(&self, keys: I) -> Result<PathView<&Self, G>, GraphError> where
    I: IntoIterator,
    I::Item: Borrow<VertexKey>, 
[src]

pub fn path_mut<I>(
    &mut self,
    keys: I
) -> Result<PathView<&mut Self, G>, GraphError> where
    I: IntoIterator,
    I::Item: Borrow<VertexKey>, 
[src]

pub fn aabb(&self) -> Aabb<VertexPosition<G>> where
    G::Vertex: AsPosition,
    VertexPosition<G>: EuclideanSpace
[src]

Gets an axis-aligned bounding box that encloses the graph.

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

Gets the arity of the graph.

If all faces in the graph have the same arity, then Arity::Uniform is returned with the singular arity of the graph. If the graph contains faces with differing arity, then Arity::NonUniform is returned with the minimum and maximum arity.

Arity::Uniform is returned with zero if there are no faces in the graph.

pub fn triangulate(&mut self)[src]

Triangulates the graph, tessellating all faces into triangles.

pub fn smooth<T>(&mut self, factor: T) where
    T: Into<Scalar<VertexPosition<G>>>,
    G: VertexCentroid,
    G::Vertex: AsPosition,
    VertexPosition<G>: EuclideanSpace
[src]

Smooths the positions of vertices in the graph.

Each position is translated by its offset from its centroid scaled by the given factor. The centroid of a vertex position is the mean of the positions of its neighboring vertices. That is, given a factor $k$ and a vertex with position $P$ and centroid $Q$, its position becomes $P+k(Q-P)$.

pub fn split_at_path(
    path: PathView<&mut Self, G>
) -> Result<(VertexView<&Self, G>, VertexView<&Self, G>), GraphError>
[src]

Splits the graph into two disjoint sub-graphs along a path.

The given path must either be closed or, if open, must begin and end within the same ring. Such a path subdivides the graph.

The sub-graphs are disconnected from each other, copying any vertices, arcs, and edges at their boundaries.

pub fn disjoint_subgraph_vertices(
    &self
) -> impl Iterator<Item = VertexView<&Self, G>>
[src]

Gets an iterator over a vertex within each disjoint subgraph.

Traverses the graph and returns an arbitrary vertex within each disjoint subgraph. A subgraph is disjoint if it cannot be reached from all other topology in the graph.

Examples

use nalgebra::Point2;
use plexus::graph::MeshGraph;
use plexus::prelude::*;
use plexus::primitive::Trigon;

type E2 = Point2<f64>;

// Create a graph from two disjoint triangles.
let graph = MeshGraph::<E2>::from_raw_buffers(
    vec![Trigon::new(0u32, 1, 2), Trigon::new(3, 4, 5)],
    vec![
        (-2.0, 0.0),
        (-1.0, 0.0),
        (-1.0, 1.0),
        (1.0, 0.0),
        (2.0, 0.0),
        (1.0, 1.0),
    ],
)
.unwrap();

// A vertex from each disjoint triangle is returned.
for vertex in graph.disjoint_subgraph_vertices() {
    // ...
}

pub fn into_disjoint_subgraphs(self) -> Vec<Self>[src]

Moves disjoint sub-graphs into separate graphs.

pub fn to_mesh_buffer_by_vertex<A, N, H>(
    &self
) -> Result<MeshBuffer<Flat<A, N>, H>, GraphError> where
    G::Vertex: IntoGeometry<H>,
    A: NonZero + Unsigned,
    N: Copy + Integer + NumCast + Unsigned
[src]

Creates a MeshBuffer from the graph.

The buffer is created using the vertex geometry of each unique vertex.

Errors

Returns an error if the graph does not have constant arity that is compatible with the index buffer. Typically, a graph is triangulated before being converted to a buffer.

pub fn to_mesh_buffer_by_vertex_with<A, N, H, F>(
    &self,
    f: F
) -> Result<MeshBuffer<Flat<A, N>, H>, GraphError> where
    A: NonZero + Unsigned,
    N: Copy + Integer + NumCast + Unsigned,
    F: FnMut(VertexView<&Self, G>) -> H, 
[src]

Creates a MeshBuffer from the graph.

The buffer is created using each unique vertex, which is converted into the buffer geometry by the given function.

Errors

Returns an error if the graph does not have constant arity that is compatible with the index buffer. Typically, a graph is triangulated before being converted to a buffer.

pub fn to_mesh_buffer_by_face<A, N, H>(
    &self
) -> Result<MeshBuffer<Flat<A, N>, H>, GraphError> where
    G::Vertex: IntoGeometry<H>,
    A: NonZero + Unsigned,
    N: Copy + Integer + NumCast + Unsigned
[src]

Creates a MeshBuffer from the graph.

The buffer is created using the vertex geometry of each face. Shared vertices are included for each face to which they belong.

Errors

Returns an error if the graph does not have constant arity that is compatible with the index buffer. Typically, a graph is triangulated before being converted to a buffer.

pub fn to_mesh_buffer_by_face_with<A, N, H, F>(
    &self,
    f: F
) -> Result<MeshBuffer<Flat<A, N>, H>, GraphError> where
    A: NonZero + Unsigned,
    N: Copy + Integer + NumCast + Unsigned,
    F: FnMut(FaceView<&Self, G>, VertexView<&Self, G>) -> H, 
[src]

Creates a MeshBuffer from the graph.

The buffer is created from each face, which is converted into the buffer geometry by the given function.

Errors

Returns an error if the graph does not have constant arity that is compatible with the index buffer. Typically, a graph is triangulated before being converted to a buffer.

Trait Implementations

impl<E, G> FromEncoding<E> for MeshGraph<G> where
    G: GraphGeometry,
    E: FaceDecoder + VertexDecoder,
    E::Face: IntoGeometry<G::Face>,
    E::Vertex: IntoGeometry<G::Vertex>, 
[src]

type Error = GraphError

impl<G, P> FromIndexer<P, P> for MeshGraph<G> where
    G: GraphGeometry,
    P: Map<usize> + Polygonal,
    P::Output: Grouping<Item = P::Output> + IntoVertices + Polygonal<Vertex = usize>,
    P::Vertex: IntoGeometry<G::Vertex>,
    Vec<P::Output>: IndexBuffer<P::Output, Index = usize>, 
[src]

type Error = GraphError

impl<P, G, H> FromRawBuffers<P, H> for MeshGraph<G> where
    P: IntoVertices + Polygonal,
    P::Vertex: Integer + ToPrimitive + Unsigned,
    G: GraphGeometry,
    H: IntoGeometry<G::Vertex>, 
[src]

type Error = GraphError

impl<N, G, H> FromRawBuffersWithArity<N, H> for MeshGraph<G> where
    N: Integer + ToPrimitive + Unsigned,
    G: GraphGeometry,
    H: IntoGeometry<G::Vertex>, 
[src]

type Error = GraphError

fn from_raw_buffers_with_arity<I, J>(
    indices: I,
    vertices: J,
    arity: usize
) -> Result<Self, Self::Error> where
    I: IntoIterator<Item = N>,
    J: IntoIterator<Item = H>, 
[src]

Creates a MeshGraph from raw index and vertex buffers. The arity of the polygons in the index buffer must be known and constant.

Errors

Returns an error if the arity of the index buffer is not constant, any index is out of bounds, or there is an error inserting topology into the graph.

Examples

use nalgebra::Point3;
use plexus::graph::MeshGraph;
use plexus::index::{Flat3, LruIndexer};
use plexus::prelude::*;
use plexus::primitive::generate::Position;
use plexus::primitive::sphere::UvSphere;

let (indices, positions) = UvSphere::new(16, 16)
    .polygons::<Position<Point3<f64>>>()
    .triangulate()
    .index_vertices::<Flat3, _>(LruIndexer::with_capacity(256));
let mut graph =
    MeshGraph::<Point3<f64>>::from_raw_buffers_with_arity(indices, positions, 3).unwrap();

impl<G> Default for MeshGraph<G> where
    G: GraphGeometry
[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<G, P> FromIterator<P> for MeshGraph<G> where
    G: GraphGeometry,
    P: Polygonal,
    P::Vertex: Clone + Eq + Hash + IntoGeometry<G::Vertex>,
    Self: FromIndexer<P, P>, 
[src]

Auto Trait Implementations

impl<G> Send for MeshGraph<G> where
    <G as GraphGeometry>::Arc: Send,
    <G as GraphGeometry>::Edge: Send,
    <G as GraphGeometry>::Face: Send,
    <G as GraphGeometry>::Vertex: Send

impl<G> Sync for MeshGraph<G> where
    <G as GraphGeometry>::Arc: Sync,
    <G as GraphGeometry>::Edge: Sync,
    <G as GraphGeometry>::Face: Sync,
    <G as GraphGeometry>::Vertex: Sync

impl<G> Unpin for MeshGraph<G> where
    <G as GraphGeometry>::Arc: Unpin,
    <G as GraphGeometry>::Edge: Unpin,
    <G as GraphGeometry>::Face: Unpin,
    <G as GraphGeometry>::Vertex: Unpin

impl<G> UnwindSafe for MeshGraph<G> where
    <G as GraphGeometry>::Arc: UnwindSafe,
    <G as GraphGeometry>::Edge: UnwindSafe,
    <G as GraphGeometry>::Face: UnwindSafe,
    <G as GraphGeometry>::Vertex: UnwindSafe

impl<G> RefUnwindSafe for MeshGraph<G> where
    <G as GraphGeometry>::Arc: RefUnwindSafe,
    <G as GraphGeometry>::Edge: RefUnwindSafe,
    <G as GraphGeometry>::Face: RefUnwindSafe,
    <G as GraphGeometry>::Vertex: 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>,