pub struct TriangleMesh {
pub vertices: Vec<Vertex>,
pub faces: Vec<Face>,
}Expand description
A triangle mesh with indexed face set representation
§Examples
use scirs2_spatial::mesh::{TriangleMesh, Vertex, Face};
let vertices = vec![
Vertex::new(0.0, 0.0, 0.0),
Vertex::new(1.0, 0.0, 0.0),
Vertex::new(0.5, 1.0, 0.0),
Vertex::new(0.5, 0.5, 1.0),
];
let faces = vec![
Face::new(0, 1, 2),
Face::new(0, 1, 3),
Face::new(1, 2, 3),
Face::new(0, 2, 3),
];
let mesh = TriangleMesh::new(vertices, faces).expect("Operation failed");
assert_eq!(mesh.num_vertices(), 4);
assert_eq!(mesh.num_faces(), 4);Fields§
§vertices: Vec<Vertex>Vertex positions
faces: Vec<Face>Triangle faces (indices into vertices)
Implementations§
Source§impl TriangleMesh
impl TriangleMesh
Sourcepub fn num_vertices(&self) -> usize
pub fn num_vertices(&self) -> usize
Number of vertices
Sourcepub fn vertex_neighbors(&self) -> HashMap<usize, HashSet<usize>>
pub fn vertex_neighbors(&self) -> HashMap<usize, HashSet<usize>>
Build vertex-to-vertex adjacency (neighbors)
Sourcepub fn face_normal_raw(&self, face_idx: usize) -> SpatialResult<[f64; 3]>
pub fn face_normal_raw(&self, face_idx: usize) -> SpatialResult<[f64; 3]>
Compute face normal for a given face index (unnormalized)
Sourcepub fn face_normal(&self, face_idx: usize) -> SpatialResult<[f64; 3]>
pub fn face_normal(&self, face_idx: usize) -> SpatialResult<[f64; 3]>
Compute normalized face normal for a given face index
Sourcepub fn compute_face_normals(&self) -> SpatialResult<Vec<[f64; 3]>>
pub fn compute_face_normals(&self) -> SpatialResult<Vec<[f64; 3]>>
Compute all face normals (normalized)
Sourcepub fn compute_vertex_normals(&self) -> SpatialResult<Vec<[f64; 3]>>
pub fn compute_vertex_normals(&self) -> SpatialResult<Vec<[f64; 3]>>
Compute vertex normals by averaging adjacent face normals weighted by face area
Sourcepub fn face_area(&self, face_idx: usize) -> SpatialResult<f64>
pub fn face_area(&self, face_idx: usize) -> SpatialResult<f64>
Compute the area of a face
Sourcepub fn surface_area(&self) -> SpatialResult<f64>
pub fn surface_area(&self) -> SpatialResult<f64>
Compute the total surface area of the mesh
Sourcepub fn bounding_box(&self) -> Option<(Vertex, Vertex)>
pub fn bounding_box(&self) -> Option<(Vertex, Vertex)>
Compute the bounding box of the mesh
Sourcepub fn to_stl_ascii(&self, name: &str) -> SpatialResult<String>
pub fn to_stl_ascii(&self, name: &str) -> SpatialResult<String>
Sourcepub fn from_stl_ascii(stl_data: &str) -> SpatialResult<Self>
pub fn from_stl_ascii(stl_data: &str) -> SpatialResult<Self>
Sourcepub fn is_manifold(&self) -> bool
pub fn is_manifold(&self) -> bool
Check if the mesh is manifold (every edge has exactly 1 or 2 adjacent faces)
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Check if the mesh is closed (every edge has exactly 2 adjacent faces)
Sourcepub fn boundary_edges(&self) -> Vec<Edge>
pub fn boundary_edges(&self) -> Vec<Edge>
Get boundary edges (edges with only 1 adjacent face)
Sourcepub fn euler_characteristic(&self) -> i64
pub fn euler_characteristic(&self) -> i64
Compute the Euler characteristic: V - E + F
Trait Implementations§
Source§impl Clone for TriangleMesh
impl Clone for TriangleMesh
Source§fn clone(&self) -> TriangleMesh
fn clone(&self) -> TriangleMesh
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for TriangleMesh
impl RefUnwindSafe for TriangleMesh
impl Send for TriangleMesh
impl Sync for TriangleMesh
impl Unpin for TriangleMesh
impl UnsafeUnpin for TriangleMesh
impl UnwindSafe for TriangleMesh
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.