Navigation
API > API/Runtime > API/Runtime/GeometryCore
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.
You can optionally provide a spatial data structure to allow faster computation of narrow-band Distances; this is most beneficial if we want a wider band
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
TODO: a number of utility function could & should be shared between this and CachingMeshSDF!
This code is based on the implementation found at https://github.com/christopherbatty/SDFGen
| Name | TSweepingMeshSDF |
| Type | class |
| Header File | /Engine/Source/Runtime/GeometryCore/Public/Implicit/SweepingMeshSDF.h |
| Include Path | #include "Implicit/SweepingMeshSDF.h" |
Syntax
template<class TriangleMeshType, bool bScalarCellSize>
class TSweepingMeshSDF
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
TSweepingMeshSDF
(
const TriangleMeshType* Mesh, |
Implicit/SweepingMeshSDF.h |
Enums
Public
| Name | Remarks |
|---|---|
| EComputeModes | The narrow band is always computed exactly, and the full Grid is always signed. |
| EInsideModes | What counts as "inside" the mesh. |
Typedefs
| Name | Type | Remarks | Include Path |
|---|---|---|---|
| CellSizeType | std::conditional_t< bScalarCellSize, float, FVector3f > | Type to use for CellSize. | Implicit/SweepingMeshSDF.h |
| CellSizeTyped | std::conditional_t< bScalarCellSize, double, FVector3d > | Type to use for CellSize, but in double precision. | Implicit/SweepingMeshSDF.h |
Variables
Public
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| ApproxMaxCellsPerDimension | int | If the number of cells in any dimension may exceed this, CellSize will be automatically increased to keep cell count reasonable. | Implicit/SweepingMeshSDF.h | |
| bComputeSigns | bool | Should we try to compute signs? if not, Grid remains unsigned | Implicit/SweepingMeshSDF.h | |
| bUseParallel | bool | Most of this parallelizes very well, makes a huge speed difference. | Implicit/SweepingMeshSDF.h | |
| bWantClosestTriGrid | bool | Implementation computes the triangle closest to each Grid cell, can return this Grid if desired (only reason not to is avoid hanging onto memory) | Implicit/SweepingMeshSDF.h | |
| bWantIntersectionsGrid | bool | Grid of per-cell crossing or parity counts. | Implicit/SweepingMeshSDF.h | |
| CancelF | TFunction< bool()> | If this function returns true, we should abort calculation | Implicit/SweepingMeshSDF.h | |
| CellSize | CellSizeType | Implicit/SweepingMeshSDF.h | ||
| ComputeMode | EComputeModes | Implicit/SweepingMeshSDF.h | ||
| ExactBandWidth | int | Width of the band around triangles for which exact Distances are computed (In fact this is conservative, the band is often larger locally) | Implicit/SweepingMeshSDF.h | |
| ExpandBounds | FVector3d | Bounds of Grid will be expanded this much in positive and negative directions. | Implicit/SweepingMeshSDF.h | |
| Grid | FDenseGrid3f | Implicit/SweepingMeshSDF.h | ||
| GridOrigin | FVector3f | Implicit/SweepingMeshSDF.h | ||
| InsideMode | EInsideModes | Implicit/SweepingMeshSDF.h | ||
| Mesh | const TriangleMeshType * | Implicit/SweepingMeshSDF.h | ||
| NarrowBandMaxDistance | double | How wide of narrow band should we compute. | Implicit/SweepingMeshSDF.h | |
| Spatial | TMeshAABBTree3< TriangleMeshType > * | Implicit/SweepingMeshSDF.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
float At
(
int I, |
Implicit/SweepingMeshSDF.h | ||
FVector3f CellCenter
(
int I, |
Implicit/SweepingMeshSDF.h | ||
| Compute the SDF with exactly specified grid origin and dimensions | Implicit/SweepingMeshSDF.h | ||
bool Compute
(
FAxisAlignedBox3d Bounds |
Compute the SDF enclosing the given bounds, with a 'safe' buffer zone | Implicit/SweepingMeshSDF.h | |
FVector3i Dimensions() |
Implicit/SweepingMeshSDF.h | ||
void Empty() |
Empty out all computed result data (leaves input data alone) | Implicit/SweepingMeshSDF.h | |
const FDenseGrid3i & GetClosestTriGrid() |
Implicit/SweepingMeshSDF.h | ||
const FDenseGrid3i & GetIntersectionsGrid() |
Implicit/SweepingMeshSDF.h | ||
float GetValue
(
FVector3i Idx |
Implicit/SweepingMeshSDF.h | ||
TTriLinearGridInterpolant< FDenseGrid3f, InterpolantRealType, bScalarCellSize > MakeInterpolant() |
Make an interpolating sampler of the sdf data. Note the lifetime is dependent on this class. | Implicit/SweepingMeshSDF.h | |
void SetCellSize
(
float InCellSize |
Implicit/SweepingMeshSDF.h | ||
bool Validate
(
const FAxisAlignedBox3d& Bounds |
Implicit/SweepingMeshSDF.h |
Static
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
static float GetDiagLength
(
CellSizeType CellSize |
Implicit/SweepingMeshSDF.h | ||
static float GetDim
(
CellSizeType CellSize, |
Implicit/SweepingMeshSDF.h | ||
static double GetDim
(
CellSizeTyped CellSize, |
Helper methods to access CellSize in either scalar or vector mode. | Implicit/SweepingMeshSDF.h | |
static bool IsValid
(
CellSizeType CellSize |
Implicit/SweepingMeshSDF.h | ||
static int Orientation
(
double X1, |
Calculate twice signed area of triangle (0,0)-(X1,Y1)-(X2,Y2) return an SOS-determined sign (-1, +1, or 0 only if it's a truly degenerate triangle) | Implicit/SweepingMeshSDF.h | |
static bool PointInTriangle2d
(
double X0, |
Robust test of (X0,Y0) in the triangle (X1,Y1)-(X2,Y2)-(X3,Y3) if true is returned, the barycentric coordinates are set in A,B,C. | Implicit/SweepingMeshSDF.h | |
static float PointSegmentDistance
(
const FVector3f& x0, |
Find distance x0 is from segment x1-x2 | Implicit/SweepingMeshSDF.h | |
static double PointSegmentDistance
(
const FVector3d& x0, |
Find distance x0 is from segment x1-x2 | Implicit/SweepingMeshSDF.h | |
static float PointTriangleDistance
(
const FVector3f& x0, |
Find distance x0 is from triangle x1-x2-x3 | Implicit/SweepingMeshSDF.h | |
static double PointTriangleDistance
(
const FVector3d& x0, |
Find distance x0 is from triangle x1-x2-x3 | Implicit/SweepingMeshSDF.h | |
static bool ShouldUseSpatial
(
int ExactCells, |
Encodes heuristic for deciding whether it will be faster to use | Implicit/SweepingMeshSDF.h | |
static CellSizeType UnitCellSize() |
Unit cube, in CellSizeType. | Implicit/SweepingMeshSDF.h |
Operators
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
float operator[]
(
const FVector3i& Idx |
Implicit/SweepingMeshSDF.h |