pub struct SignData { /* private fields */ }Expand description
Per-mesh data that decides the sign of a distance, built by
SignData::build for one revision of a mesh and one state of its BVH.
In SignMode::Pseudonormal it holds a unit pseudonormal per vertex
slot, an edge normal per triangle corner (for the edge opposite that
corner) and, for every zero-area triangle, the non-degenerate triangles
that share a vertex with it. Face normals are recomputed from the mesh when
needed.
In SignMode::Winding it holds instead the order-1 dipole moments of
every BVH node (area-weighted normal sum, area-weighted centroid and a
bounding radius), for the fast winding number of Barill et al. 2018.
Implementations§
Source§impl SignData
impl SignData
Sourcepub fn build(mesh: &mut Mesh, bvh: &Bvh, mode: SignMode) -> Result<SignData>
pub fn build(mesh: &mut Mesh, bvh: &Bvh, mode: SignMode) -> Result<SignData>
Builds the sign data of mesh in mode, building the mesh’s adjacency
and incidence first if they are not cached. Auto is resolved here
(to Winding for a closed mesh with inconsistent orientation, to
Pseudonormal otherwise); SignData::status reports the outcome.
§Errors
FieldsError::QuerywithMeshMismatchorStaleBvhwhenbvhdoes not match the currentmesh.FieldsError::OutOfMemoryorFieldsError::Storewhen the adjacency, incidence, normals or winding moments cannot be built.
Sourcepub fn try_refit(
&mut self,
mesh: &Mesh,
bvh: &Bvh,
changes: &ChangeSet,
) -> Result<bool>
pub fn try_refit( &mut self, mesh: &Mesh, bvh: &Bvh, changes: &ChangeSet, ) -> Result<bool>
Refits pseudonormal data in place after a position-only edit,
recomputing only the vertex and edge normals around
changes’ moved vertices (plus the signed volume, in O(n)).
Returns whether the refit ran: false (a full SignData::build
is needed) when the mode is not pseudonormal, the topology changed,
vertices or triangles were added or removed, the slot counts changed,
the mesh’s adjacency or incidence is not cached, the BVH is not
current, or a dirty triangle changed its degenerate status. On true
the data is current for mesh and bvh and identical to a rebuild.
§Errors
FieldsError::OutOfMemory when the dirty sets cannot be listed.
Sourcepub fn winding_number(&self, mesh: &Mesh, bvh: &Bvh, p: [f32; 3]) -> f64
pub fn winding_number(&self, mesh: &Mesh, bvh: &Bvh, p: [f32; 3]) -> f64
The generalized winding number of mesh at p: the sum of the solid
angles of its triangles seen from p, over 4π. It is 1 inside a
closed, outward-facing mesh, 0 outside it, and in between near holes.
In SignMode::Winding this is the fast approximation of Barill et
al. 2018, order 1: a BVH node whose centroid is more than beta = 8
times its radius away from p contributes its dipole term, and nearer
leaves sum their triangles’ exact solid angles (Van Oosterom–Strackee).
It is within 1e-3 of the exact value on the closed test meshes at
points farther than 1% of the bounding-box diagonal from the surface;
on a flat terrain the error is larger (about 1.2e-3, tested against
2e-3), since the errors of a flat sheet add up. In
SignMode::Pseudonormal no moments are stored and every triangle is
summed exactly, which is slow on large meshes.
Returns NaN when this data is not current for mesh and bvh (see
SignData::is_current). Nothing is allocated.
Sourcepub fn is_boundary_hit(mesh: &Mesh, hit: &ClosestHit) -> Option<bool>
pub fn is_boundary_hit(mesh: &Mesh, hit: &ClosestHit) -> Option<bool>
Whether the closest feature of hit touches a boundary edge of
mesh: a face interior never does, an edge when it is used by one
triangle only, a vertex when any edge at it is. A point past an open
rim is signed by the plane of its boundary face, so an antagonist
vertex just beyond a scan’s margin can read as penetration; apps can
use this to detect that halo. Returns None when the mesh’s
adjacency (or, for a vertex, its incidence) is not cached, or hit
is not on an alive triangle.
Sourcepub fn status(&self) -> SignStatus
pub fn status(&self) -> SignStatus
What the build found out about the mesh, and the resolved mode.
Sourcepub fn mode(&self) -> SignMode
pub fn mode(&self) -> SignMode
The resolved mode: never SignMode::Auto.
Sourcepub fn is_current(&self, mesh: &Mesh, bvh: &Bvh) -> bool
pub fn is_current(&self, mesh: &Mesh, bvh: &Bvh) -> bool
True when this data was built for mesh at its current revision and
epoch, and for bvh at its current generation.