[][src]Struct tri_mesh::mesh::Mesh

pub struct Mesh { /* fields omitted */ }

Methods

impl Mesh
[src]

Traversal

Methods to construct a Walker which is used for easy and efficient traversal of the mesh. See Walker for more information and examples.

pub fn walker_from_vertex(&self, vertex_id: VertexID) -> Walker
[src]

Creates a walker at the half-edge pointed to by the given vertex.

pub fn walker_from_halfedge(&self, halfedge_id: HalfEdgeID) -> Walker
[src]

Creates a walker at the given half-edge.

pub fn walker_from_face(&self, face_id: FaceID) -> Walker
[src]

Creates a walker at the half-edge pointed to by the given face.

impl Mesh
[src]

pub fn vertex_iter(&self) -> VertexIter
[src]

Iterator over the vertex ids.

Examples

let mut sum_vertex_positions = Vec3::zero();
for vertex_id in mesh.vertex_iter() {
    sum_vertex_positions += *mesh.vertex_position(vertex_id);
}

pub fn halfedge_iter(&self) -> HalfEdgeIter
[src]

Iterator over the half-edge ids.

Note: Each edge is visited two times, one for each half-edge. If you want to visit the edges only once, then use edge_iter instead.

Examples

let mut halfedge_length_average = 0.0;
let mut i = 0;
for halfedge_id in mesh.halfedge_iter() {
    halfedge_length_average += mesh.edge_length(halfedge_id);
    i += 1;
}
halfedge_length_average /= i as f32;

Important traits for EdgeIter<'a>
pub fn edge_iter(&self) -> EdgeIter
[src]

Iterator over the edges given as a half-edge id.

Note: Each edge is visited once. If you want to visit both half-edges of an edge, then use halfedge_iter instead.

Examples

let mut edge_length_average = 0.0;
let mut i = 0;
for halfedge_id in mesh.edge_iter() {
    edge_length_average += mesh.edge_length(halfedge_id);
    i += 1;
}
edge_length_average /= i as f32;

pub fn face_iter(&self) -> FaceIter
[src]

Iterator over the face ids.

Examples

let mut sum_face_area = 0.0;
for face_id in mesh.face_iter() {
    sum_face_area += mesh.face_area(face_id);
}

Important traits for VertexHalfedgeIter<'a>
pub fn vertex_halfedge_iter(&self, vertex_id: VertexID) -> VertexHalfedgeIter
[src]

Iterator over the half-edges which starts in the given vertex, ie. the one-ring.

Note: If the given vertex is the only connection between two or more separate sets of faces, then this iterator will only iterate the half-edges in one of the sets. If the vertex is on the boundary, all half-edges are visited.

Examples

let mut one_ring_average_position = Vec3::zero();
let mut i = 0;
for halfedge_id in mesh.vertex_halfedge_iter(vertex_id) {
    let walker = mesh.walker_from_halfedge(halfedge_id);
    one_ring_average_position += *mesh.vertex_position(walker.vertex_id().unwrap());
    i = i+1;
}
one_ring_average_position /= i as f32;

Important traits for FaceHalfedgeIter<'a>
pub fn face_halfedge_iter(&self, face_id: FaceID) -> FaceHalfedgeIter
[src]

Iterator over the three half-edges connected to the given face.

Examples

let mut face_circumference = 0.0f32;
for halfedge_id in mesh.face_halfedge_iter(face_id) {
    face_circumference += mesh.edge_length(halfedge_id);
}

impl Mesh
[src]

pub fn connecting_edge(
    &self,
    vertex_id1: VertexID,
    vertex_id2: VertexID
) -> Option<HalfEdgeID>
[src]

Returns the connecting edge between the two vertices or None if no edge is found.

Note: This method assumes that the mesh is properly connected. See vertex_halfedge_iter for more information.

pub fn is_vertex_on_boundary(&self, vertex_id: VertexID) -> bool
[src]

Returns whether or not the vertex is on a boundary.

pub fn is_edge_on_boundary(&self, halfedge_id: HalfEdgeID) -> bool
[src]

Returns whether or not the edge is on a boundary.

pub fn edge_vertices(&self, halfedge_id: HalfEdgeID) -> (VertexID, VertexID)
[src]

Returns the vertex id of the two adjacent vertices to the given edge.

pub fn ordered_edge_vertices(
    &self,
    halfedge_id: HalfEdgeID
) -> (VertexID, VertexID)
[src]

Returns the vertex id of the two adjacent vertices to the given edge and ordered such that ordered_edge_vertices.0 < ordered_edge_vertices.1.

pub fn face_vertices(&self, face_id: FaceID) -> (VertexID, VertexID, VertexID)
[src]

Returns the vertex id of the three connected vertices to the given face.

pub fn ordered_face_vertices(
    &self,
    face_id: FaceID
) -> (VertexID, VertexID, VertexID)
[src]

Returns the vertex id of the three connected vertices to the given face and ordered such that ordered_face_vertices.0 < ordered_face_vertices.1 < ordered_face_vertices.2.

impl Mesh
[src]

pub fn vertex_position(&self, vertex_id: VertexID) -> &Vec3
[src]

Returns the vertex position.

pub fn vertex_normal(&self, vertex_id: VertexID) -> Vec3
[src]

Returns the normal of the vertex given as the average of the normals of the neighbouring faces.

impl Mesh
[src]

pub fn edge_positions(&self, halfedge_id: HalfEdgeID) -> (&Vec3, &Vec3)
[src]

Returns the two positions of the vertices of either end of the given halfedge.

pub fn edge_length(&self, halfedge_id: HalfEdgeID) -> f32
[src]

Returns the length of the specified edge

pub fn edge_sqr_length(&self, halfedge_id: HalfEdgeID) -> f32
[src]

Returns the squared length of the specified edge

impl Mesh
[src]

pub fn face_positions(&self, face_id: FaceID) -> (&Vec3, &Vec3, &Vec3)
[src]

Returns the positions of the face vertices.

pub fn face_normal(&self, face_id: FaceID) -> Vec3
[src]

Returns the normal of the face.

pub fn face_area(&self, face_id: FaceID) -> f32
[src]

Returns the area of the face.

pub fn face_center(&self, face_id: FaceID) -> Vec3
[src]

Returns the center of the face given as the average of its vertex positions.

impl Mesh
[src]

pub fn flip_edge(&mut self, halfedge_id: HalfEdgeID) -> Result<(), Error>
[src]

Flip the given edge such that the edge after the flip is connected to the other pair of the four vertices connected to the two adjacent faces.

  /\          /|\
 /  \        / | \
/____\  --> /  |  \
\    /      \  |  /
 \  /        \ | /
  \/          \|/

Error

Returns an error if trying to flip an edge on the boundary or the flip will connect two vertices that are already connected by another edge.

pub fn split_edge(
    &mut self,
    halfedge_id: HalfEdgeID,
    position: Vec3
) -> VertexID
[src]

Split the given edge into two. Returns the id of the new vertex positioned at the given position.

pub fn split_face(&mut self, face_id: FaceID, position: Vec3) -> VertexID
[src]

Split the given face into three new faces. Returns the id of the new vertex positioned at the given position.

pub fn collapse_edge(&mut self, halfedge_id: HalfEdgeID) -> VertexID
[src]

Collapses the given edge. Consequently, the to adjacent faces are removed and the two adjacent vertices are merged into one vertex which position is the average of the original vertex positions. Returns the merged vertex.

Note: This might make some faces degenerate.

pub fn remove_face(&mut self, face_id: FaceID)
[src]

Removes the given face and the adjacent edges if they are then not connected to any face.

impl Mesh
[src]

pub fn smooth_vertices(&mut self, factor: f32)
[src]

Moves the vertices to pos + factor * (avg_pos - pos) where pos is the current position and avg_pos is the average position of the neighbouring vertices.

pub fn collapse_small_faces(&mut self, area_threshold: f32)
[src]

Collapse an edge of faces which has an area smaller than area_threshold.

pub fn remove_lonely_primitives(&mut self)
[src]

Removes edges and vertices that are not connected to a face.

pub fn flip_edges(&mut self, flatness_threshold: f32)
[src]

Flip all edges in the mesh

  • which is not on the boundary
  • where the flip will improve the sum of the quality of the two faces adjacent to the edge (The face quality is given as the circumscribed radius divided by the inscribed radius)
  • where the dot product between the normals of the adjacent faces is smaller than flattness_threshold (1: Completely flat, 0: 90 degrees angle between normals)
  • where the flip will not result in inverted triangles

impl Mesh
[src]

pub fn flip_orientation(&mut self)
[src]

Flip the orientation of all faces in the mesh, ie. such that the normal points in the opposite direction.

pub fn fix_orientation(&mut self)
[src]

Fix the orientation of all faces in the mesh such that the orientation of each pair of neighbouring faces is aligned.

impl Mesh
[src]

pub fn move_vertex_to(&mut self, vertex_id: VertexID, value: Vec3)
[src]

Moves the vertex to the specified position.

pub fn move_vertex_by(&mut self, vertex_id: VertexID, value: Vec3)
[src]

Moves the vertex by the specified vector, i.e. the new position is mesh.vertex_position(vertex_id) + value.

pub fn scale(&mut self, scale: f32)
[src]

Scales the entire mesh by applying the scale to each vertex position.

Examples

    let mut mesh = MeshBuilder::new().cube().build()?;
    mesh.scale(2.0);

pub fn translate(&mut self, translation: Vec3)
[src]

Translates the entire mesh by applying the translation to each vertex position.

Examples

    let mut mesh = MeshBuilder::new().cube().build()?;
    mesh.translate(vec3(2.5, -1.0, 0.0));

pub fn rotate(&mut self, rotation: Mat3)
[src]

Rotates the entire mesh by applying the given rotation to each vertex position.

Examples

    let mut mesh = MeshBuilder::new().cube().build()?;
    mesh.apply_transformation(Mat4::from_angle_y(Deg(360.0)));

pub fn apply_transformation(&mut self, transformation: Mat4)
[src]

Transforms the entire mesh by applying the transformation to each vertex position.

Examples

    let mut mesh = MeshBuilder::new().cube().build()?;
    mesh.apply_transformation(Mat4::from_translation(vec3(2.5, -1.0, 0.0)));

impl Mesh
[src]

pub fn merge_with(&mut self, other: &Self) -> Result<(), Error>
[src]

Merges the mesh together with the other mesh. The other mesh primitives are copied to the current mesh (and other is therefore not changed) followed by merging of overlapping primitives.

pub fn append(&mut self, other: &Self)
[src]

Appends the other mesh to this mesh which means that all the primitivess of the other mesh are copied to the current mesh. The othermesh is therefore not changed.

pub fn clone_subset(&self, faces: &HashSet<FaceID>) -> Mesh
[src]

Returns a clone a subset of this mesh.

pub fn merge_overlapping_primitives(&mut self) -> Result<(), Error>
[src]

Merges overlapping faces, edges and vertices.

Error

Returns an error if the merging will result in a non-manifold mesh.

impl Mesh
[src]

pub fn is_valid(&self) -> Result<(), Error>
[src]

WARNING: DO NOT USE IN PRODUCTION!

This method tests if the mesh is valid, i.e. has correct connectivity and orientation and contains no degenerate triangles. Intended only to be used in development and unit tests.

Errors

If the mesh is not valid, an IsNotValid error with a description of the problem is returned.

impl Mesh
[src]

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

Returns the number of vertices in the mesh.

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

Returns the number of edges in the mesh.

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

Returns the number of half-edges in the mesh.

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

Returns the number of faces in the mesh.

pub fn indices_buffer(&self) -> Vec<u32>
[src]

Returns the face indices in an array (i0, i1, i2) = (indices[3*x], indices[3*x+1], indices[3*x+2]).

let indices = mesh.indices_buffer();
for i in 0..indices.len()/3
{
    println!("The indices of face {} is: ({}, {}, {})", i, indices[3*i], indices[3*i+1], indices[3*i+2]);
}

pub fn positions_buffer(&self) -> Vec<f32>
[src]

Returns the positions of the vertices in an array.

let positions = mesh.positions_buffer();
for i in 0..positions.len()/3
{
    println!("The position of vertex with index {} is: ({}, {}, {})", i, positions[3*i], positions[3*i+1], positions[3*i+2]);
}

pub fn normals_buffer(&self) -> Vec<f32>
[src]

Returns the normals of the vertices in an array. Note: The normals are computed from the connectivity and positions each time this method is invoked.

let normals = mesh.normals_buffer();
for i in 0..normals.len()/3
{
    println!("The normal of vertex with index {} is: ({}, {}, {})", i, normals[3*i], normals[3*i+1], normals[3*i+2]);
}

pub fn extreme_coordinates(&self) -> (Vec3, Vec3)
[src]

Returns minimum and maximum coordinates of the axis aligned bounding box of the mesh.

Trait Implementations

impl Clone for Mesh
[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for Mesh
[src]

impl Display for Mesh
[src]

Auto Trait Implementations

impl Send for Mesh

impl !Sync for Mesh

Blanket Implementations

impl<T> From for T
[src]

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> ToString for T where
    T: Display + ?Sized
[src]

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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