Navigation
API > API/Runtime > API/Runtime/GeometryCore > API/Runtime/GeometryCore/Implicit
References
| Module | GeometryCore |
| Header | /Engine/Source/Runtime/GeometryCore/Public/Implicit/SweepingMeshSDF.h |
| Include | #include "Implicit/SweepingMeshSDF.h" |
Syntax
template<class TriangleMeshType>
class TSweepingMeshSDF
Remarks
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
Variables
| Type | Name | Description | |
|---|---|---|---|
| int | ApproxMaxCellsPerDimension | If the number of cells in any dimension may exceed this, CellSize will be automatically increased to keep cell count reasonable. | |
| bool | bComputeSigns | Should we try to compute signs? if not, Grid remains unsigned | |
| bool | bUseParallel | Most of this parallelizes very well, makes a huge speed difference. | |
| bool | bWantClosestTriGrid | Implementation computes the triangle closest to each Grid cell, can return this Grid if desired (only reason not to is avoid hanging onto memory) | |
| bool | bWantIntersectionsGrid | Grid of per-cell crossing or parity counts. | |
| TFunction< bool()> | CancelF | If this function returns true, we should abort calculation | |
| float | CellSize | ||
| FDenseGrid3i | ClosestTriGrid | Grid of closest triangle indices; only available if bWantClosestTriGrid is set to true. Access via GetClosestTriGrid() | |
| EComputeModes | ComputeMode | ||
| int | ExactBandWidth | Width of the band around triangles for which exact Distances are computed (In fact this is conservative, the band is often larger locally) | |
| FVector3d | ExpandBounds | Bounds of Grid will be expanded this much in positive and negative directions. | |
| FDenseGrid3f | Grid | ||
| FVector3f | GridOrigin | ||
| EInsideModes | InsideMode | ||
| FDenseGrid3i | IntersectionsGrid | Grid of intersection counts; only available if bWantIntersectionsGrid is set to true. Access via GetIntersectionsGrid() | |
| const TriangleMeshType * | Mesh | ||
| double | NarrowBandMaxDistance | How wide of narrow band should we compute. | |
| TMeshAABBTree3< TriangleMeshType > * | Spatial |
Constructors
| Type | Name | Description | |
|---|---|---|---|
TSweepingMeshSDF
(
const TriangleMeshType* Mesh, |
Functions
| Type | Name | Description | |
|---|---|---|---|
| float | At
(
int I, |
||
| FVector3f | CellCenter
(
int I, |
||
| bool | Compute
(
FAxisAlignedBox3d Bounds |
Compute the SDF | |
| FVector3i | Dimensions () |
||
| void | Empty () |
Empty out all computed result data (leaves input data alone) | |
| const FDenseGrid3i & | |||
| const FDenseGrid3i & | |||
| float | |||
| TTriLinearGridInterpolant< TSweepingMeshSDF > | |||
| 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) | |
| 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. | |
| float | PointSegmentDistance
(
const FVector3f& x0, |
Find distance x0 is from segment x1-x2 | |
| double | PointSegmentDistance
(
const FVector3d& x0, |
Find distance x0 is from segment x1-x2 | |
| float | PointTriangleDistance
(
const FVector3f& x0, |
Find distance x0 is from triangle x1-x2-x3 | |
| double | PointTriangleDistance
(
const FVector3d& x0, |
Find distance x0 is from triangle x1-x2-x3 | |
| bool | ShouldUseSpatial
(
int ExactCells, |
Encodes heuristic for deciding whether it will be faster to use | |
| bool | Validate
(
const FAxisAlignedBox3d& Bounds |
Operators
| Type | Name | Description | |
|---|---|---|---|
| float | operator[]
(
const FVector3i& Idx |
Enums
| Type | Name | Description | |
|---|---|---|---|
| EComputeModes | The narrow band is always computed exactly, and the full Grid is always signed. | ||
| EInsideModes | What counts as "inside" the mesh. |