Skip to content

Commit

Permalink
update for new Meshing API
Browse files Browse the repository at this point in the history
  • Loading branch information
sjkelly committed Jul 7, 2024
1 parent a778400 commit 073d7e2
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[compat]
Aqua = "0.8"
CoordinateTransformations = "0.6"
Combinatorics = "1"
CoordinateTransformations = "0.6"
FileIO = "1"
ForwardDiff = "0.10"
GeometryBasics = "0.4"
LinearAlgebra = "1"
Meshing = "0.6, 0.7"
MeshIO = "0.4"
Meshing = "0.7"
Revise = "3"
Rotations = "1"
StaticArrays = "1"
Expand Down
12 changes: 3 additions & 9 deletions examples/gyroid.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
using Revise
using Descartes: Gyroid, Cuboid, PolarWarp, Cylinder, FRep
using GeometryBasics: GeometryBasics, mesh, HyperRectangle
using Meshing
using StaticArrays

holes = [[0,0,0], [15, 0, 0], [7.5, 7.5, 0]]

using GeometryBasics: GeometryBasics, mesh
using Meshing: MarchingTetrahedra

p = intersect(PolarWarp(Gyroid(0.5), 200), Cuboid([50,50,50]))

h = HyperRectangle(p)

@time m = mesh(p; samples=(200,200,200))
@time m = mesh(p; samples=(100,100,100), algorithm=MarchingTetrahedra());

using WGLMakie
WGLMakie.activate!(resize_to=:body)
Expand Down
4 changes: 2 additions & 2 deletions examples/piping.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using Descartes: Piping
using GeometryBasics: Mesh
using GeometryBasics: mesh

p = Piping(1.0, [[0,0,0],
[10,0,0],
[10,10,0],
[10,10,10],
[5,5,5]])

m = Mesh(p)
m = mesh(p)

using WGLMakie
mesh(m)
Expand Down
2 changes: 1 addition & 1 deletion examples/triangle_wave.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Revise
using Descartes: Descartes, TriangleWave, FRep, Grid, PolarWarp, Cuboid, union
using Descartes: Descartes, TriangleWave, FRep, PolarWarp, Cuboid, union
using WGLMakie
using CoordinateTransformations
using StaticArrays
Expand Down
2 changes: 1 addition & 1 deletion src/Descartes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using GeometryBasics: GeometryBasics
import GeometryBasics: AbstractMesh,
HyperRectangle,
Vec,
Mesh
mesh


using StaticArrays,
Expand Down
32 changes: 25 additions & 7 deletions src/meshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,35 @@ function GeometryBasics.mesh(primitives::AbstractPrimitive...;
algorithm=MarchingCubes())

f(x) = FRep(primitives[1], x)
meshes = Vector{Mesh}(undef, length(primitives))
meshes = Vector{GeometryBasics.Mesh}(undef, length(primitives))
sdf_arr = Array{Float64}(undef, samples)

for i = 1:length(primitives)
b = HyperRectangle(primitives[i])
rng = range.(b.origin, b.origin.+ b.widths)
@show rng

@info "Sampling SDF"
xp = LinRange(first(rng[1]), last(rng[1]), samples[1])
yp = LinRange(first(rng[2]), last(rng[2]), samples[2])
zp = LinRange(first(rng[3]), last(rng[3]), samples[3])
sdf(v) = FRep(primitives[i], SVector(v...))
vts, fcs = isosurface(sdf, algorithm, rng[1], rng[2], rng[3]; samples)
_points = map(GeometryBasics.Point, vts)
_faces = map(v -> GeometryBasics.TriangleFace{GeometryBasics.OneIndex}(v), fcs)
normals = map(v -> GeometryBasics.Vec3f(gradient(sdf, SVector(v...))...), vts)
meshes[i] = GeometryBasics.Mesh(GeometryBasics.meta(_points; normals=normals), _faces)
sdf_normal(v) = gradient(sdf, SVector(v...))

@time Threads.@threads for x in eachindex(xp)
for y in eachindex(yp), z in eachindex(zp)
sdf_arr[x,y,z] = sdf((xp[x],yp[y],zp[z]))
end
end

@info "generating mesh"
@time vts, fcs = isosurface(sdf_arr, algorithm, rng[1], rng[2], rng[3])
@info "remapping data types"
@time _points = map(GeometryBasics.Point, vts)
@time _faces = map(v -> GeometryBasics.TriangleFace{GeometryBasics.OneIndex}(v), fcs)
@info "evaluating normals"
@time normals = map(v -> GeometryBasics.Vec3f(sdf_normal(v)), vts)
@info "remapping mesh"
@time meshes[i] = GeometryBasics.Mesh(GeometryBasics.meta(_points; normals=normals), _faces)
end
return merge(meshes)
end
Expand Down
8 changes: 4 additions & 4 deletions test/meshes.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

@testset "Meshing" begin
c = mesh(translate([4,5,6])Cuboid([1,2,3]))
@test_broken length(c.vertices) == 7638
@test_broken length(c.faces) == 15272
#@test_broken length(c.vertices) == 7638
#@test_broken length(c.faces) == 15272


@testset "Radiused Shelled Box" begin
Expand All @@ -13,7 +13,7 @@
u2 = CSGDiff(u, Cuboid([2,2,2]))

m = mesh(u2)
@test_broken length(m.vertices) == 86406
@test_broken length(m.faces) == 172678
#@test_broken length(m.vertices) == 86406
#@test_broken length(m.faces) == 172678
end
end

0 comments on commit 073d7e2

Please sign in to comment.