[][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 ExactSizeIterator<Item = VertexView<&Self, G>>[src]

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

pub fn vertex_orphans(
    &mut self
) -> impl ExactSizeIterator<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 ExactSizeIterator<Item = ArcView<&Self, G>>[src]

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

pub fn arc_orphans(&mut self) -> impl ExactSizeIterator<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 ExactSizeIterator<Item = EdgeView<&Self, G>>[src]

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

pub fn edge_orphans(&mut self) -> impl ExactSizeIterator<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 ExactSizeIterator<Item = FaceView<&Self, G>>[src]

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

pub fn face_orphans(&mut self) -> impl ExactSizeIterator<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 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 ExactSizeIterator<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_buildable_by_vertex<B>(&self) -> Result<B, B::Error> where
    B: Buildable<Facet = ()>,
    B::Vertex: FromGeometry<G::Vertex>, 
[src]

Creates a Buildable from the graph.

The output is created from each unique vertex in the graph. No face geometry is used, and the Facet type is always ().

Examples

Creating a MeshBuffer from a graph used to modify a cube:

use decorum::N64;
use nalgebra::Point3;
use plexus::buffer::MeshBufferN;
use plexus::graph::MeshGraph;
use plexus::prelude::*;
use plexus::primitive::cube::Cube;
use plexus::primitive::generate::Position;

type E3 = Point3<N64>;

let mut graph = Cube::new()
    .polygons::<Position<E3>>()
    .collect::<MeshGraph<E3>>();
let key = graph.faces().nth(0).unwrap().key();
graph.face_mut(key).unwrap().extrude(1.0);

let buffer = graph
    .to_buildable_by_vertex::<MeshBufferN<usize, E3>>()
    .unwrap();

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_buildable_by_vertex_with<B, T, F>(&self, f: F) -> Result<B, B::Error> where
    B: Buildable<Vertex = T, Facet = ()>,
    F: FnMut(VertexView<&Self, G>) -> T, 
[src]

Creates a Buildable from the graph.

The output is created from each unique vertex in the graph, which is converted into the output geometry by the given function. No face geometry is used, and the Facet type is always ().

Errors

Returns an error if the vertex geometry cannot be inserted into the output, there are arity conflicts, or the output does not support topology found in the graph.

pub fn to_buildable_by_face<B>(&self) -> Result<B, B::Error> where
    B: Buildable,
    B::Vertex: FromGeometry<G::Vertex>,
    B::Facet: FromGeometry<G::Face>, 
[src]

Creates a Buildable from the graph.

The output is created from each face in the graph. For each face, the face geometry and associated vertex geometry is inserted into the buffer via FromGeometry. This means that a vertex is inserted for each of its adjacent faces.

Errors

Returns an error if the vertex geometry cannot be inserted into the output, there are arity conflicts, or the output does not support topology found in the graph.

pub fn to_buildable_by_face_with<B, T, F>(&self, f: F) -> Result<B, B::Error> where
    B: Buildable<Vertex = T>,
    B::Facet: FromGeometry<G::Face>,
    F: FnMut(FaceView<&Self, G>, VertexView<&Self, G>) -> T, 
[src]

Creates a Buildable from the graph.

The output is created from each face in the graph. The given function is called for each vertex of each face and converts the vertex geometry into the output geometry. This means that a vertex is inserted for each of its adjacent faces. The face geometry is inserted into the output via FromGeometry.

Examples

Creating a MeshBuffer from a graph loaded from PLY data and used to compute normals:

use decorum::N64;
use nalgebra::Point3;
use plexus::buffer::MeshBuffer;
use plexus::encoding::ply::{FromPly, PositionEncoding};
use plexus::graph::MeshGraph;
use plexus::prelude::*;
use plexus::primitive::Polygon;
use theon::space::Vector;

type E3 = Point3<N64>;

pub struct Vertex {
    pub position: E3,
    pub normal: Vector<E3>,
}

let ply: &[u8] = {
    // ...
};
let encoding = PositionEncoding::<E3>::default();
let (graph, _) = MeshGraph::<E3>::from_ply(encoding, ply).unwrap();

let buffer: MeshBuffer<Polygon<usize>, _> = graph
    .to_buildable_by_face_with(|face, vertex| Vertex {
        position: *vertex.position(),
        normal: face.normal().unwrap(),
    })
    .unwrap();

Errors

Returns an error if the vertex geometry cannot be inserted into the output, there are arity conflicts, or the output does not support topology found in the graph.

Trait Implementations

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

Exposes a MeshBuilder that can be used to construct a MeshGraph incrementally from surfaces and facets.

See the documentation for the builder module for more.

Examples

Creating a graph from a triangle:

use nalgebra::Point2;
use plexus::builder::Buildable;
use plexus::graph::MeshGraph;
use plexus::prelude::*;

let mut builder = MeshGraph::<Point2<f64>>::builder();
let graph = builder
    .surface_with(|builder| {
        let a = builder.insert_vertex((0.0, 0.0))?;
        let b = builder.insert_vertex((1.0, 0.0))?;
        let c = builder.insert_vertex((0.0, 1.0))?;
        builder.facets_with(|builder| builder.insert_facet(&[a, b, c], ()))
    })
    .and_then(|_| builder.build())
    .unwrap();

type Builder = GraphBuilder<G>

type Error = GraphError

type Vertex = G::Vertex

Vertex geometry. Read more

type Facet = G::Face

Facet geometry. Read more

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

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

type Dynamic = MeshArity

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<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]

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> StaticArity 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();

Auto Trait Implementations

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

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

Blanket Implementations

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

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

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

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

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

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, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> IntoGeometry<U> for T where
    U: FromGeometry<T>, 
[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<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<V, T> VZip<V> for T where
    V: MultiLane<T>,