Skip to content

Commit

Permalink
Includes changes relating to foam lattices
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin-Mattheus-Moerman committed Oct 31, 2024
1 parent 995b5ee commit 7c541dc
Show file tree
Hide file tree
Showing 25 changed files with 1,155 additions and 269 deletions.
20 changes: 20 additions & 0 deletions examples/demo_dodecahedron.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Comodo
using GLMakie
using GeometryBasics

r = 1
F,V = dodecahedron(r)

## Visualize mesh
markersize = 25
strokewidth = 2
strokecolor = :black
fig = Figure(size = (800,800))

ax1 = Axis3(fig[1, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Dodecahedron")

hp1 = poly!(ax1, GeometryBasics.Mesh(V,F), color=:white,transparency=false,strokewidth=strokewidth,strokecolor=strokecolor,shading = FastShading)
hp2 = scatter!(ax1, V,markersize=markersize,color=:red)
hp3 = normalplot(ax1,F,V; color = :green)

fig
6 changes: 1 addition & 5 deletions examples/demo_dualclad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,9 @@ elseif testCase == 6
B = [v[3]>-10 for v in V]
BF = [all(B[f]) for f in F]
F = F[BF]
F,V = remove_unused_vertices(F,V)

F,V = remove_unused_vertices(F,V)
end




s = 0.5
con_type = :face
Fs,Fq,Vs = dualclad(F,V,s; connectivity=con_type)
Expand Down
2 changes: 1 addition & 1 deletion examples/demo_filletcurve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using Random
# Set seed so demo performs the same each time
Random.seed!(1)

testCase = 6
testCase = 7

if testCase == 1
V = Point{3,Float64}[ [0.0,0.0,0.0], [10.0,0.0,0.0]]
Expand Down
9 changes: 1 addition & 8 deletions examples/demo_filletcurve_extrude.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
using Comodo
using GLMakie
using GeometryBasics
using LinearAlgebra
using Rotations
using Random


# Set seed so demo performs the same each time
Random.seed!(1)

testCase = 4

Expand All @@ -27,7 +20,7 @@ end



rMax = 0.5 #collect(range(0.5,5,length(V)))
rMax = 0.5
n = 20
h =2.0
VC = filletcurve(V; rMax=rMax, constrain_method = :max, n=n, close_loop = close_loop, eps_level = 1e-6)
Expand Down
2 changes: 1 addition & 1 deletion examples/demo_hexbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ E,V,F,Fb,CFb_type = hexbox(boxDim,boxEl)


# Visualisation
cmap = colormap = cgrad(:Spectral, 6, categorical = true)
cmap = cgrad(:Spectral, 6, categorical = true)

Fbs,Vbs = separate_vertices(Fb,V)
Cbs_V = simplex2vertexdata(Fbs,CFb_type)
Expand Down
5 changes: 2 additions & 3 deletions examples/demo_kabsch_rot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ fileName_mesh = joinpath(comododir(),"assets","stl","stanford_bunny_low.stl")
M = load(fileName_mesh)

# Obtain mesh faces and vertices
F = faces(M)
F = tofaces(faces(M))
V1 = topoints(coordinates(M))

F,V1 = mergevertices(F,V1)
F,V1,_,_ = mergevertices(F,V1)

# Define a rotation tensor using Euler angles
Q = RotXYZ(0.0,0.25*π,0.25*π)
Expand Down
28 changes: 28 additions & 0 deletions examples/demo_kelvinfoam.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Comodo
using GLMakie
using GeometryBasics
using Rotations



w = 1.0
n = (4,5,5)
E,V = kelvinfoam(w,n; merge=false)
F = element2faces(E)

## Visualize mesh
strokewidth = 2
strokecolor = :black
cmap = reverse(cgrad(:Spectral, length(E), categorical = true))

fig = Figure(size = (1200,1200))
# ax1 = Axis3(fig[1, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Rhombic dodecahedron")
ax1 = LScene(fig[1,1]); cc = Makie.Camera3D(ax1.scene, projectiontype = Makie.Perspective)

hp1 = poly!(ax1, GeometryBasics.Mesh(V,F[1]), color=:white,transparency=false,strokewidth=strokewidth,strokecolor=strokecolor,shading = FastShading)
hp2 = poly!(ax1, GeometryBasics.Mesh(V,F[2]), color=:white,transparency=false,strokewidth=strokewidth,strokecolor=strokecolor,shading = FastShading)

display(fig)

cc.near[] = 1f-3
cc.far[] = 100
4 changes: 3 additions & 1 deletion examples/demo_mergevertices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ F2 = deepcopy(F1)
V2 = deepcopy(V1)


F2,V2,ind1,ind2 = mergevertices(F2,V2; roundVertices=true)
V2,indUnique,indMap = mergevertices(V2; pointSpacing=pointspacingmean(F2,V2))
indexmap!(F2,indMap) #Update indices in F2

M2 = GeometryBasics.Mesh(V2,F2)

NV1 = vertexnormal(F1,V1)
Expand Down
41 changes: 41 additions & 0 deletions examples/demo_ntrapezohedron.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Comodo
using GLMakie
using GeometryBasics
using Printf

n = 10
r = 2.0
F,V = ntrapezohedron(n,r)

## Visualize mesh
markersize = 25
strokewidth = 2
strokecolor = :black

Fn,Vn = separate_vertices(F,V)

fig = Figure(size = (1200,1200))
ax1 = Axis3(fig[1, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "n-trapezohedron")
# ax1 = LScene(fig[1,1]); cc = Makie.Camera3D(ax1.scene, projectiontype = Makie.Orthographic)

hp1 = poly!(ax1, GeometryBasics.Mesh(Vn,Fn), color=:white,transparency=false,strokewidth=strokewidth,strokecolor=strokecolor,shading = FastShading)
hp2 = scatter!(ax1, V,markersize=markersize,color=:red)
# hp3 = normalplot(ax1,F,V; color = :green)

stepRange = 3:10
hSlider = Slider(fig[2,1], range = stepRange, startvalue = 0,linewidth=30)

on(hSlider.value) do n
F,V = ntrapezohedron(n,r)
Fn,Vn = separate_vertices(F,V)
M = GeometryBasics.Mesh(Vn,Fn)
hp1[1] = M
hp2[1] = V
ax1.title = @sprintf "n-trapezohedron n=%i" n
end
slidercontrol(hSlider,ax1)

# fileName = comododir()*"/assets/temp/ntrapezohedron.mp4"
# slider2anim(fig,hSlider,fileName; backforth=true, duration=4)

fig
51 changes: 51 additions & 0 deletions examples/demo_pyritohedron.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Comodo
using GLMakie
using GeometryBasics
using Printf

r = sqrt(3.0)
h = 0.5
F,V = dodecahedron(r;h=h)

## Visualize mesh
markersize = 25
strokewidth = 2
strokecolor = :black

fig = Figure(size = (2000,1200))
ax1 = Axis3(fig[1:3, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = @sprintf "Pyritohedron h=%0.6f" h)

Fn,Vn = separate_vertices(F,V)

hp1 = poly!(ax1, GeometryBasics.Mesh(Vn,Fn), color=:white,transparency=false,strokewidth=strokewidth,strokecolor=strokecolor,shading = FastShading)
hp2 = scatter!(ax1, V,markersize=markersize,color=:red)

ax2 = Axis3(fig[1, 2], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Cube")
Fs,Vs = cube(1.0);Fs,Vs = separate_vertices(Fs,Vs)
poly!(ax2, GeometryBasics.Mesh(Vs,Fs), color=:white,transparency=false,strokewidth=strokewidth,strokecolor=strokecolor,shading = FastShading)

ax3 = Axis3(fig[2, 2], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Dodecahedron")
Fs,Vs = dodecahedron(1.0);Fs,Vs = separate_vertices(Fs,Vs)
poly!(ax3, GeometryBasics.Mesh(Vs,Fs), color=:white,transparency=false,strokewidth=strokewidth,strokecolor=strokecolor,shading = FastShading)

ax4 = Axis3(fig[3, 2], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Rhombic dodecahedron")
Fs,Vs = rhombicdodecahedron(1.0);Fs,Vs = separate_vertices(Fs,Vs)
poly!(ax4, GeometryBasics.Mesh(Vs,Fs), color=:white,transparency=false,strokewidth=strokewidth,strokecolor=strokecolor,shading = FastShading)

stepRange = collect(range(0.00001,0.9999,100))
hSlider = Slider(fig[4, :], range = stepRange, startvalue = 0,linewidth=30)

on(hSlider.value) do h
F,V = dodecahedron(r;h=h)
Fn,Vn = separate_vertices(F,V)
M = GeometryBasics.Mesh(Vn,Fn)
hp1[1] = M
hp2[1] = V
ax1.title = @sprintf "Pyritohedron h=%0.6f" h
end
slidercontrol(hSlider,ax1)

# fileName = comododir()*"/assets/temp/pyritohedron.mp4"
# slider2anim(fig,hSlider,fileName; backforth=true, duration=4)

fig
29 changes: 19 additions & 10 deletions examples/demo_quadsphere.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,33 @@ using GLMakie
using GeometryBasics
using LinearAlgebra

r = 1.0 # Radius
n = 1 # Number of refinement steps from cube
r = 2.0 # Radius

Fn1,Vn1 = quadsphere(n,1)
n1 = 0 # Number of refinement steps from cube
Fn1,Vn1 = quadsphere(n1,1)

Fn2,Vn2 = quadsphere(2,r)
Fn3,Vn3 = quadsphere(3,r)
n2 = 1 # Number of refinement steps from cube
Fn2,Vn2 = quadsphere(n2,r)

n3 = 2 # Number of refinement steps from cube
Fn3,Vn3 = quadsphere(n3,r)

n4 = 3 # Number of refinement steps from cube
Fn4,Vn4 = quadsphere(n4,r)

## Visualization
fig = Figure(size=(1600,800))
fig = Figure(size=(800,800))

ax1 = Axis3(fig[1, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Refined n=1")
ax1 = Axis3(fig[1, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Refined n=$n1")
poly!(ax1,GeometryBasics.Mesh(Vn1,Fn1), strokewidth=3,color=:white,shading=FastShading,transparency=false)

ax2 = Axis3(fig[1, 2], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Refined n=2")
ax2 = Axis3(fig[1, 2], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Refined n=$n2")
poly!(ax2,GeometryBasics.Mesh(Vn2,Fn2), strokewidth=3,color=:white,shading=FastShading,transparency=false)

ax3 = Axis3(fig[1, 3], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Refined n=3")
hp2 = poly!(ax3,GeometryBasics.Mesh(Vn3,Fn3), strokewidth=3,color=:white,shading=FastShading,transparency=false)
ax3 = Axis3(fig[2, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Refined n=$n3")
poly!(ax3,GeometryBasics.Mesh(Vn3,Fn3), strokewidth=3,color=:white,shading=FastShading,transparency=false)

ax4 = Axis3(fig[2, 2], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Refined n=$n4")
poly!(ax4,GeometryBasics.Mesh(Vn4,Fn4), strokewidth=3,color=:white,shading=FastShading,transparency=false)

fig
15 changes: 3 additions & 12 deletions examples/demo_regiontrimesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,27 +92,18 @@ elseif testCase == 5
P = (1,0.75,0.5) # Point spacings
end


F,V,C = regiontrimesh(VT,R,P)


# Visualisation
fig = Figure(size=(1000,1000))

ax1 = Axis3(fig[1, 1],aspect = :data,title="Multi-region meshing",azimuth=-pi/2,elevation=pi/2)
# hp1 = lines!(ax1, V,linewidth=4,color=:blue)
# hp2 = scatter!(ax1, V,markersize=12,color=:black)
# hp3 = scatter!(ax1, Vg,markersize=8,color=d,colormap=:Spectral)


Fp,Vp = separate_vertices(F,V) # Give each face its own point set
Cp = simplex2vertexdata(Fp,C) # Convert face color data to vertex color data
hp4 = poly!(ax1,GeometryBasics.Mesh(Vp,Fp), strokewidth=1,color=Cp, strokecolor=:black, shading = FastShading, transparency=false,colormap=Makie.Categorical(Makie.Reverse(:Spectral)))


# hp2 = scatter!(ax1, V1[indKeep],markersize=25,color=:red)
fig = Figure(size=(1000,1000))
ax1 = Axis3(fig[1, 1],aspect = :data,title="Multi-region meshing",azimuth=-pi/2,elevation=pi/2)

# hp2 = scatter!(ax1, Vg[1:length(xRange)],markersize=15,color=:yellow)
# hp2 = scatter!(ax1, Vg[2],markersize=15,color=:orange)
hp4 = poly!(ax1,GeometryBasics.Mesh(Vp,Fp), strokewidth=1,color=Cp, strokecolor=:black, shading = FastShading, transparency=false,colormap=Makie.Categorical(Makie.Reverse(:Spectral)))

fig
2 changes: 1 addition & 1 deletion examples/demo_remove_unused_vertices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ F = [F[i] for i in findall(map(v-> v[3]>0,VC))] # Remove some faces
Fc,Vc = remove_unused_vertices(F,V)

# Visualization
markersize = 12
markersize = 20
M = GeometryBasics.Mesh(Vc,Fc)
fig = Figure(size=(1200,1200))
ax1 = Axis3(fig[1, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "A cut mesh with unused vertices removed")
Expand Down
3 changes: 2 additions & 1 deletion examples/demo_rhombicdodecahedron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ using GeometryBasics
using Rotations

# Creating faces and vertices for a rhombic dodecahedron
F,V = rhombicdodecahedron(5.0)
w = 1.0
F,V = rhombicdodecahedron(w)

## Visualize mesh
markersize = 25
Expand Down
22 changes: 22 additions & 0 deletions examples/demo_rhombicdodecahedronfoam.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Comodo
using GLMakie
using GeometryBasics

w = 1.0
n = (5,4,3)
E,V = rhombicdodecahedronfoam(w,n; merge=false, orientation=:allign)
F = element2faces(E)

## Visualize mesh
strokewidth = 2
strokecolor = :black
cmap = reverse(cgrad(:Spectral, length(E), categorical = true))

fig = Figure(size = (1200,1200))
# ax1 = Axis3(fig[1, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Rhombic dodecahedron")
ax1 = LScene(fig[1,1])
cc = Makie.Camera3D(ax1.scene, projectiontype = Makie.Orthographic)

hp1 = poly!(ax1, GeometryBasics.Mesh(V,F), color=:white,transparency=false,strokewidth=strokewidth,strokecolor=strokecolor,shading = FastShading)

fig
8 changes: 2 additions & 6 deletions examples/demo_scalesimplex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,21 @@ This demo shows the use of the `scalesimplex` function.
=#

# Loading a mesh

# fileName_mesh = joinpath(comododir(),"assets","obj","spot_control_mesh_texture.obj")
# M = load(fileName_mesh)

fileName_mesh = joinpath(comododir(),"assets","stl","stanford_bunny_low.stl")
M = load(fileName_mesh)

# Obtain mesh faces and vertices
F = tofaces(faces(M))
V = topoints(coordinates(M))
F,V = mergevertices(F,V)
V,_,indMap = mergevertices(V; pointSpacing=pointspacingmean(F,V))
indexmap!(F,indMap)

# n = 1
# F,V = subtri(F,V,n; method=:Loop)

s = 0.5
Fs,Vs = scalesimplex(F,V,s)


## Visualisation

strokewidth = 0.1
Expand Down
24 changes: 24 additions & 0 deletions examples/demo_spacing2numvertices.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Comodo
using GLMakie
using GeometryBasics
using Statistics


r = 2.0 # radius
n = 3 # Number of refinement iterations
F,V = geosphere(n,r)
pointSpacing = pointspacingmean(F,V)

n2 = n+2
pointSpacingDesired = pointSpacing/4.0

println("pointSpacingDesired ",pointSpacingDesired)
NV = spacing2numvertices(F,V,pointSpacingDesired)
println("num V ",NV)

F2,V2 = geosphere(n2,r)
println("num true ",length(V2))

pointSpacingTrue = pointspacingmean(F2,V2)

println("pointSpacingTrue ",pointSpacingTrue)
Loading

0 comments on commit 7c541dc

Please sign in to comment.