Skip to content

Commit

Permalink
simplify modes
Browse files Browse the repository at this point in the history
  • Loading branch information
sjkelly committed Jun 25, 2024
1 parent c828798 commit ab5c918
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 14 deletions.
2 changes: 0 additions & 2 deletions src/adaptive.jl
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,6 @@ function isosurface(f::Function, method::AdaptiveMarchingTetrahedra, ::Type{Vert

val_store = Dict{NTuple{3,ET},ET}();
vertex_store = Dict{NTuple{3,ET},ET}();
sizehint!(val_store, trunc(Int, maximum(widths)*12/max(method.atol,method.rtol)))
sizehint!(vertex_store, trunc(Int, maximum(widths)*12/max(method.atol,method.rtol)))

@inbounds while true

Expand Down
8 changes: 2 additions & 6 deletions src/marching_cubes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ function isosurface(sdf::AbstractArray{T, 3}, method::MarchingCubes, ::Type{Vert
points = mc_vert_points(xi,yi,zi,s,origin,VertType)

# Create the triangle
method.reduceverts && _mc_unique_triangles!(method, points, iso_vals, vts, fcs, cubeindex, FaceType)
!method.reduceverts && _mc_create_triangles!(method, points, iso_vals, vts, fcs, cubeindex, FaceType)
_mc_unique_triangles!(method, points, iso_vals, vts, fcs, cubeindex, FaceType)
end
vts,fcs
end
Expand Down Expand Up @@ -70,7 +69,6 @@ function isosurface(f::Function, method::MarchingCubes, ::Type{VertType}=SVector
f(points[7]),
f(points[8]))
# TODO: Cache points


#Determine the index into the edge table which
#tells us which vertices are inside of the surface
Expand All @@ -80,9 +78,7 @@ function isosurface(f::Function, method::MarchingCubes, ::Type{VertType}=SVector
_no_triangles(cubeindex) && continue

# Create the triangle
method.reduceverts && _mc_unique_triangles!(method, points, iso_vals, vts, fcs, cubeindex, FaceType)
!method.reduceverts && _mc_create_triangles!(method, points, iso_vals, vts, fcs, cubeindex, FaceType)

_mc_unique_triangles!(method, points, iso_vals, vts, fcs, cubeindex, FaceType)
end
vts,fcs
end
Expand Down
4 changes: 2 additions & 2 deletions src/surface_nets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function isosurface(sdf::AbstractArray{T, 3}, method::NaiveSurfaceNets, ::Type{V
sdf[xi+1,yi+2,zi+2],
sdf[xi+2,yi+2,zi+2])

mask = method.insidepositive ? _get_cubeindex_pos(grid, method.iso) : _get_cubeindex(grid, method.iso)
mask = _get_cubeindex(grid, method.iso)

# Check for early termination if cell does not intersect boundary
if _no_triangles(mask)
Expand Down Expand Up @@ -155,7 +155,7 @@ function isosurface(f::Function, method::NaiveSurfaceNets,
end

# Also calculate 8-bit mask, like in marching cubes, so we can speed up sign checks later
mask = method.insidepositive ? _get_cubeindex_pos(grid, method.iso) : _get_cubeindex(grid, method.iso)
mask = _get_cubeindex(grid, method.iso)

# Check for early termination if cell does not intersect boundary
if _no_triangles(mask)
Expand Down
4 changes: 0 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,13 @@ end

@testset "marching cubes" begin
algo = MarchingCubes()
algo_no_reduce_verts = MarchingCubes(reduceverts=false)

# Extract isosurfaces using MarchingCubes
points_mf, faces_mf = isosurface(sphere_function, algo, origin=SVector(-1, -1, -1), widths=SVector(2, 2, 2), samples=(21, 21, 21))
points_mfrv, faces_mfrv = isosurface(sphere_function, algo_no_reduce_verts, origin=SVector(-1, -1, -1), widths=SVector(2, 2, 2), samples=(21, 21, 21))

# Test the number of vertices and faces
@test length(points_mfrv) == 10968
@test length(points_mf) == 7320
@test length(faces_mf) == 3656
@test length(faces_mf) == length(faces_mfrv)
end
@testset "marching tetrahedra" begin
a1 = MarchingTetrahedra()
Expand Down

0 comments on commit ab5c918

Please sign in to comment.