# [−][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 information using four entities: 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.

## Implementations

### 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>>[src]

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

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

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

#### pub fn vertices(&self) -> impl ExactSizeIterator<Item = VertexView<&Self>>[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.

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

Gets the number of arcs in the graph.

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

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

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

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

#### pub fn arcs(&self) -> impl ExactSizeIterator<Item = ArcView<&Self>>[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.

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

Gets the number of edges in the graph.

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

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

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

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

#### pub fn edges(&self) -> impl ExactSizeIterator<Item = EdgeView<&Self>>[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.

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

Gets the number of faces in the graph.

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

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

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

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

#### pub fn faces(&self) -> impl ExactSizeIterator<Item = FaceView<&Self>>[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.

#### pub fn aabb(&self) -> Aabb<VertexPosition<G>> where    G::Vertex: AsPosition,    VertexPosition<G>: EuclideanSpace,    Scalar<VertexPosition<G>>: IntrinsicOrd, [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 adjacent 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: Path<&mut Self>) -> Result<(), GraphError>[src]

Splits the graph along a path.

Splitting a graph creates boundaries along the given path and copies any necessary vertex, arc, and edge geometry.

If the path bisects the graph, then splitting will result in disjointed sub-graphs.

# Examples

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

type E2 = Point2<f64>;

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

// Find the shared edge that bisects the triangles and then construct a path
// along the edge and split the graph.
let key = graph
.edges()
.find(|edge| !edge.is_boundary_edge())
.map(|edge| edge.into_arc().key())
.unwrap();
let mut path = graph.arc_mut(key).unwrap().into_path();
MeshGraph::split_at_path(path).unwrap();

#### pub fn disjoint_subgraph_vertices(    &self) -> impl ExactSizeIterator<Item = VertexView<&Self>>[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_by_vertex<B>(&self) -> Result<B, B::Error> where    B: Buildable<Facet = ()>,    B::Vertex: FromGeometry<G::Vertex>, [src]

Creates a Buildable mesh data structure 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_with_offset(1.0);

let buffer = graph.to_mesh_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_mesh_by_vertex_with<B, T, F>(&self, f: F) -> Result<B, B::Error> where    B: Buildable<Vertex = T, Facet = ()>,    F: FnMut(VertexView<&Self>) -> T, [src]

Creates a Buildable mesh data structure 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_mesh_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 mesh data structure 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_mesh_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>, VertexView<&Self>) -> T, [src]

Creates a Buildable mesh data structure 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 used to compute normals:

use decorum::N64;
use nalgebra::Point3;
use plexus::buffer::MeshBuffer;
use plexus::graph::MeshGraph;
use plexus::prelude::*;
use plexus::primitive::cube::Cube;
use plexus::primitive::generate::Position;
use plexus::primitive::BoundedPolygon;
use theon::space::Vector;

type E3 = Point3<N64>;

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

let graph = Cube::new()
.polygons::<Position<E3>>()
.collect::<MeshGraph<E3>>();

let buffer: MeshBuffer<BoundedPolygon<usize>, _> = graph
.to_mesh_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();

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

#### 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<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<Group = 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();

## Blanket Implementations

### impl<T> Same<T> for T

#### type Output = T

Should always be Self

### 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.