Skip to content

Commit

Permalink
remove NaiveSurfaceNets and cleanup tests (support autodiff again)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjkelly committed Jul 2, 2024
1 parent 03ceb63 commit c6bf2d2
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 365 deletions.
4 changes: 1 addition & 3 deletions src/Meshing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ include("algorithmtypes.jl")
include("common.jl")
include("marching_tetrahedra.jl")
include("marching_cubes.jl")
include("surface_nets.jl")
include("roots.jl")
include("adaptive.jl")

export isosurface,
MarchingCubes,
MarchingTetrahedra,
NaiveSurfaceNets
MarchingTetrahedra

end # module
29 changes: 3 additions & 26 deletions src/algorithmtypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,9 @@ making this algorithm useful for topological analysis.
- `iso` specifies the iso level to use for surface extraction.
- `eps` is the tolerence around a voxel corner to ensure manifold mesh generation.
"""
Base.@kwdef struct MarchingTetrahedra{T} <: AbstractMeshingAlgorithm
Base.@kwdef struct MarchingTetrahedra{T,E} <: AbstractMeshingAlgorithm
iso::T = 0.0
eps::T = 1e-3
end

"""
NaiveSurfaceNets(iso=0.0, eps=1e-3)
NaiveSurfaceNets(;iso=0.0, eps=1e-3)
NaiveSurfaceNets(iso)
NaiveSurfaceNets(iso,eps)
Specifies the use of the Naive Surface Nets algorithm for isosurface extraction.
This algorithm has a slight performance advantage in some cases over Marching Cubes.
Each vertex is guaranteed to not be repeated (useful for topological analysis),
however the algorithm does not guarantee accuracy and generates quad faces.
- `iso` specifies the iso level to use for surface extraction.
- `eps` is the tolerence around a voxel corner to ensure manifold mesh generation.
- `reduceverts` reserved for future use.
"""
struct NaiveSurfaceNets{T} <: AbstractMeshingAlgorithm
iso::T
eps::T
reduceverts::Bool
insidepositive::Bool
eps::E = 1e-3
end

"""
Expand All @@ -83,7 +61,7 @@ may be large and it will be difficult to extract topological/connectivity inform
- `eps` (default: 1e-3) is the tolerence around a voxel corner to ensure manifold mesh generation.
- `reduceverts` (default: true) if true will merge vertices within a voxel to reduce mesh size by around 30% and with slight performance improvement.
"""
struct AdaptiveMarchingCubes{T} <: AbstractAdaptiveMeshingAlgorithm
struct AdaptiveMarchingCubes{T,E} <: AbstractAdaptiveMeshingAlgorithm
iso::T
eps::T
rtol::T
Expand All @@ -104,4 +82,3 @@ end
#

default_face_length(::Union{MarchingCubes,MarchingTetrahedra}) = 3
default_face_length(::NaiveSurfaceNets) = 4
7 changes: 5 additions & 2 deletions src/marching_cubes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ include("lut/mc.jl")
function isosurface(sdf::AbstractArray{T,3}, method::MarchingCubes, X=-1:1, Y=-1:1, Z=-1:1) where {T}
nx, ny, nz = size(sdf)

vts = NTuple{3,float(T)}[]
# find widest type
FT = promote_type(eltype(first(X)), eltype(first(Y)), eltype(first(Z)), eltype(T), typeof(method.iso))

vts = NTuple{3,float(FT)}[]
fcs = NTuple{3,Int}[]

xp = LinRange(first(X), last(X), nx)
Expand Down Expand Up @@ -44,7 +47,7 @@ function isosurface(f::Function, method::MarchingCubes, X=-1:1, Y=-1:1, Z=-1:1;
nx, ny, nz = samples[1], samples[2], samples[3]

# find widest type
FT = promote_type(eltype(first(X)), eltype(first(Y)), eltype(first(Z)), eltype(T))
FT = promote_type(eltype(first(X)), eltype(first(Y)), eltype(first(Z)), eltype(T), typeof(method.iso))

vts = NTuple{3,float(FT)}[]
fcs = NTuple{3,Int}[]
Expand Down
6 changes: 4 additions & 2 deletions src/marching_tetrahedra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,11 @@ end

function isosurface(sdf::AbstractArray{T, 3}, method::MarchingTetrahedra, X=-1:1, Y=-1:1, Z=-1:1) where {T}

FT = promote_type(eltype(first(X)), eltype(first(Y)), eltype(first(Z)), eltype(T), typeof(method.iso), typeof(method.eps))

vts = Dict{Int, Int}()
fcs = NTuple{3,Int}[]
vtsAry = NTuple{3,float(T)}[]
vtsAry = NTuple{3,float(FT)}[]

# process each voxel
nx::Int, ny::Int, nz::Int = size(sdf)
Expand Down Expand Up @@ -163,7 +165,7 @@ end
function isosurface(f::F, method::MarchingTetrahedra, X=-1:1, Y=-1:1, Z=-1:1;
samples::NTuple{3,T}=_DEFAULT_SAMPLES) where {F, T}

FT = promote_type(eltype(first(X)), eltype(first(Y)), eltype(first(Z)), eltype(T))
FT = promote_type(eltype(first(X)), eltype(first(Y)), eltype(first(Z)), eltype(T), typeof(method.iso), typeof(method.eps))

vts = Dict{Int, Int}()
fcs = NTuple{3,Int}[]
Expand Down
270 changes: 0 additions & 270 deletions src/surface_nets.jl

This file was deleted.

Loading

0 comments on commit c6bf2d2

Please sign in to comment.