Class CachingMeshSDF
[RMS] this is variant of MeshSignedDistanceGrid that does lazy evaluation of actual distances,
using mesh spatial data structure. This is much faster if we are doing continuation-method
marching cubes as only values on surface will be computed!
Compute discretely-sampled (ie gridded) signed distance field for a mesh
The basic approach is, first compute exact distances in a narrow band, and then
extend out to rest of grid using fast "sweeping" (ie like a distance transform).
The resulting unsigned grid is then signed using ray-intersection counting, which
is also computed on the grid, so no BVH is necessary
If you set ComputeMode to NarrowBandOnly, result is a narrow-band signed distance field.
This is quite a bit faster as the sweeping is the most computationally-intensive step.
Caveats:
- the "narrow band" is based on triangle bounding boxes, so it is not necessarily
that "narrow" if you have large triangles on a diagonal to grid axes
Potential optimizations:
- Often we have a spatial data structure that would allow faster computation of the
narrow-band distances (which become quite expensive if we want a wider band!)
Not clear how to take advantage of this though. Perhaps we could have a binary
grid that, in first pass, we set bits inside triangle bboxes to 1? Or perhaps
same as current code, but we use spatial-dist, and so for each ijk we only compute once?
(then have to test for computed value at each cell of each triangle...)
This code is based on the C++ implementation found at https://github.com/christopherbatty/SDFGen
Original license was public domain.
Permission granted by Christopher Batty to include C# port under Boost license.
Inheritance
CachingMeshSDF
Namespace: g3
Assembly: cs.temp.dll.dll
Syntax
public class CachingMeshSDF
Constructors
CachingMeshSDF(DMesh3, Double, DMeshAABBTree3)
Declaration
public CachingMeshSDF(DMesh3 mesh, double cellSize, DMeshAABBTree3 spatial)
Parameters
Fields
CancelF
if this function returns true, we should abort calculation
Declaration
public Func<bool> CancelF
Field Value
CellSize
Declaration
Field Value
ComputeSigns
Declaration
Field Value
DebugPrint
Declaration
Field Value
ExpandBounds
Declaration
public Vector3d ExpandBounds
Field Value
InsideMode
Declaration
public CachingMeshSDF.InsideModes InsideMode
Field Value
MaxOffsetDistance
Declaration
public float MaxOffsetDistance
Field Value
Mesh
Declaration
Field Value
Spatial
Declaration
public DMeshAABBTree3 Spatial
Field Value
UseParallel
Declaration
Field Value
WantClosestTriGrid
Declaration
public bool WantClosestTriGrid
Field Value
WantIntersectionsGrid
Declaration
public bool WantIntersectionsGrid
Field Value
Properties
ClosestTriGrid
Declaration
public DenseGrid3i ClosestTriGrid { get; }
Property Value
Dimensions
Declaration
public Vector3i Dimensions { get; }
Property Value
Grid
SDF grid available after calling Compute()
Declaration
public DenseGrid3f Grid { get; }
Property Value
GridOrigin
Origin of the SDF grid, in same coordinates as mesh
Declaration
public Vector3f GridOrigin { get; }
Property Value
IntersectionsGrid
Declaration
public DenseGrid3i IntersectionsGrid { get; }
Property Value
Item[Vector3i]
Declaration
public float this[Vector3i idx] { get; }
Parameters
Property Value
Item[Int32, Int32, Int32]
Declaration
public float this[int i, int j, int k] { get; }
Parameters
Property Value
Methods
CellCenter(Int32, Int32, Int32)
Declaration
public Vector3f CellCenter(int i, int j, int k)
Parameters
Returns
GetValue(Vector3i)
Declaration
public float GetValue(Vector3i idx)
Parameters
Returns
Initialize()
Declaration
orientation(Double, Double, Double, Double, out Double)
Declaration
public static int orientation(double x1, double y1, double x2, double y2, out double twice_signed_area)
Parameters
Returns
point_in_triangle_2d(Double, Double, Double, Double, Double, Double, Double, Double, out Double, out Double, out Double)
Declaration
public static bool point_in_triangle_2d(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, out double a, out double b, out double c)
Parameters
Returns