[−][src]Struct tri_mesh::mesh::Mesh
Represents a triangle mesh. Use the Mesh builder to construct a new mesh.
Functionality:
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]
&self,
vertex_id1: VertexID,
vertex_id2: VertexID
) -> Option<HalfEdgeID>
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]
&self,
halfedge_id: HalfEdgeID
) -> (VertexID, VertexID)
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]
&self,
face_id: FaceID
) -> (VertexID, VertexID, VertexID)
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 extreme_coordinates(&self) -> (Vec3, Vec3)
[src]
Returns minimum and maximum coordinates of the axis aligned bounding box of the mesh.
pub fn axis_aligned_bounding_box_center(&self) -> Vec3
[src]
Returns the center of the smallest axis aligned box which contains the entire mesh, ie. the axis aligned bounding box.
pub fn axis_aligned_bounding_box(&self) -> Mesh
[src]
Returns the smallest axis aligned box which contains the entire mesh, ie. the axis aligned bounding box.
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]
&mut self,
halfedge_id: HalfEdgeID,
position: Vec3
) -> VertexID
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 multiplying scale
to each vertex position.
Examples
let mut mesh = MeshBuilder::new().cube().build()?; mesh.scale(2.0);
pub fn non_uniform_scale(&mut self, scale_x: f32, scale_y: f32, scale_z: f32)
[src]
Scales the entire mesh by multiplying scale_x
to the x component of each vertex position, scale_y
to the y component and scale_z
to the z component.
Examples
let mut mesh = MeshBuilder::new().cube().build()?; mesh.non_uniform_scale(2.0, 1.0, 1.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 ray_intersection(
&self,
ray_start_point: &Vec3,
ray_direction: &Vec3
) -> Option<Intersection>
[src]
&self,
ray_start_point: &Vec3,
ray_direction: &Vec3
) -> Option<Intersection>
Find the intersection between any face in the mesh and the given ray. If the ray intersects multiple faces, the face closest to the starting point in the direction of the ray is returned. If no faces are intersected, None is returned.
pub fn face_ray_intersection(
&self,
face_id: FaceID,
ray_start_point: &Vec3,
ray_direction: &Vec3
) -> Option<Intersection>
[src]
&self,
face_id: FaceID,
ray_start_point: &Vec3,
ray_direction: &Vec3
) -> Option<Intersection>
Find the intersection between the given face and ray. If the face is not intersected by the ray, None is returned.
pub fn face_line_piece_intersection(
&self,
face_id: FaceID,
point0: &Vec3,
point1: &Vec3
) -> Option<Intersection>
[src]
&self,
face_id: FaceID,
point0: &Vec3,
point1: &Vec3
) -> Option<Intersection>
Find the intersection between the given face and line piece. If the face is not intersected by the line piece, None is returned.
Note: Intersections, where the line piece is in the plane spanned by the face, are not yet fully handled.
pub fn vertex_point_intersection(
&self,
vertex_id: VertexID,
point: &Vec3
) -> Option<Intersection>
[src]
&self,
vertex_id: VertexID,
point: &Vec3
) -> Option<Intersection>
Find the intersection between the given vertex and the point. If the vertex is not close to the point, None is returned.
pub fn edge_point_intersection(
&self,
halfedge_id: HalfEdgeID,
point: &Vec3
) -> Option<Intersection>
[src]
&self,
halfedge_id: HalfEdgeID,
point: &Vec3
) -> Option<Intersection>
Find the intersection (the primitive is either a vertex or edge) between the given edge and the point. If the edge is not close to the point, None is returned.
pub fn face_point_intersection(
&self,
face_id: FaceID,
point: &Vec3
) -> Option<Intersection>
[src]
&self,
face_id: FaceID,
point: &Vec3
) -> Option<Intersection>
Find the intersection (the primitive is either a vertex, edge or face) between the given face and the point. If the face is not close to the point, None is returned.
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 other
mesh 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]
Export functionality
Methods for extracting raw mesh data which for example can be used for visualisation.
Examples
Index based arrays
// Get face indices, vertex positions and vertex normals as float arrays.. let indices = mesh.indices_buffer(); let positions = mesh.positions_buffer(); let normals = mesh.normals_buffer(); // The vertex attributes are extracted by.. for vertex in 0..positions.len()/3 { println!("The position and normal of vertex with index {} is:", vertex); println!("({}, {}, {}) and ({}, {}, {})", positions[3*vertex], positions[3*vertex+1], positions[3*vertex+2], normals[3*vertex], normals[3*vertex+1], normals[3*vertex+2]); } // .. and the face attributes are extracted by for face in 0..indices.len()/3 { let vertices = (indices[3*face] as usize, indices[3*face + 1] as usize, indices[3*face + 2] as usize); println!("The vertex positions of face with index {} is:", face); println!("({}, {}, {}), ({}, {}, {}) and ({}, {}, {})", positions[3*vertices.0], positions[3*vertices.0+1], positions[3*vertices.0+2], positions[3*vertices.1], positions[3*vertices.1+1], positions[3*vertices.1+2], positions[3*vertices.2], positions[3*vertices.2+1], positions[3*vertices.2+2]); println!("The normals of face with index {} is:", face); println!("({}, {}, {}), ({}, {}, {}) and ({}, {}, {})", normals[3*vertices.0], normals[3*vertices.0+1], normals[3*vertices.0+2], normals[3*vertices.1], normals[3*vertices.1+1], normals[3*vertices.1+2], normals[3*vertices.2], normals[3*vertices.2+1], normals[3*vertices.2+2]); }
Non-index based arrays
// Get vertex positions and vertex normals for each corner of each face as float arrays.. let positions = mesh.non_indexed_positions_buffer(); let normals = mesh.non_indexed_normals_buffer(); // .. the face attributes are extracted by for face in 0..positions.len()/9 { let vertices = (9*face, 9*face+3, 9*face+6); println!("The vertex positions of face with index {} is:", face); println!("({}, {}, {}), ({}, {}, {}) and ({}, {}, {})", positions[vertices.0], positions[vertices.0+1], positions[vertices.0+2], positions[vertices.1], positions[vertices.1+1], positions[vertices.1+2], positions[vertices.2], positions[vertices.2+1], positions[vertices.2+2]); println!("The vertex normals of face with index {} is:", face); println!("({}, {}, {}), ({}, {}, {}) and ({}, {}, {})", normals[vertices.0], normals[vertices.0+1], normals[vertices.0+2], normals[vertices.1], normals[vertices.1+1], normals[vertices.1+2], normals[vertices.2], normals[vertices.2+1], normals[vertices.2+2]); }
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])
which is meant to be used for visualisation.
Use the positions_buffer
method and normals_buffer
method to get the positions and normals of the vertices.
See this example.
pub fn positions_buffer(&self) -> Vec<f32>
[src]
Returns the positions of the vertices in an array which is meant to be used for visualisation. See this example.
Note: The connectivity of the vertices are attained by the indices_buffer
method.
pub fn normals_buffer(&self) -> Vec<f32>
[src]
Returns the normals of the vertices in an array which is meant to be used for visualisation. See this example.
Note: The connectivity of the vertices are attained by the indices_buffer
method.
Note: The normal of a vertex is computed as the average of the normals of the adjacent faces.
Note: The normals are computed from the connectivity and positions each time this method is invoked.
pub fn non_indexed_positions_buffer(&self) -> Vec<f32>
[src]
Returns the positions of the face corners in an array which is meant to be used for visualisation. See this example.
pub fn non_indexed_normals_buffer(&self) -> Vec<f32>
[src]
Returns the normals of the face corners in an array which is meant to be used for visualisation. See this example.
Note: The normal of a vertex is computed as the average of the normals of the adjacent faces.
Note: The normals are computed from the connectivity and positions each time this method is invoked.
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.
Trait Implementations
impl Clone for Mesh
[src]
fn clone(&self) -> Mesh
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Display for Mesh
[src]
impl Debug for Mesh
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,