Skip to content

Commit

Permalink
Imporved type specifications, added batman curve, and wip for regiont…
Browse files Browse the repository at this point in the history
…rimesh
  • Loading branch information
Kevin-Mattheus-Moerman committed Apr 20, 2024
1 parent 3e470b4 commit 03610ef
Show file tree
Hide file tree
Showing 22 changed files with 692 additions and 404 deletions.
32 changes: 32 additions & 0 deletions examples/demo_batman.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Comodo
using GLMakie
using DelaunayTriangulation

#=
This demo shows the use of the `batman` function to create a Batman logo curve.
The curve is useful for testing surface meshing algorithms since it contains
sharp transitions and pointy features.
=#

n = 75
V1 = batman(n)

n = 76
V2 = batman(n; symmetric = true,dir=:cw)

# Visualisation
fig = Figure(size=(1800,600))

ax1 = Axis3(fig[1, 1],aspect = :data,title="Standard, anti-clockwise")
hp1 = lines!(ax1, V1,linewidth=3,color=:blue)
hp2 = scatter!(ax1, V1,markersize=8,color=:red)
hp2 = scatter!(ax1, V1[1],markersize=15,color=:yellow)
hp2 = scatter!(ax1, V1[2],markersize=15,color=:orange)

ax2 = Axis3(fig[1, 2],aspect = :data,title="Symmetric, clockwise")
hp1 = lines!(ax2, V2,linewidth=3,color=:blue)
hp2 = scatter!(ax2, V2,markersize=8,color=:red)
hp2 = scatter!(ax2, V2[1],markersize=15,color=:yellow)
hp2 = scatter!(ax2, V2[2],markersize=15,color=:orange)

fig
26 changes: 26 additions & 0 deletions examples/demo_dirplot.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Comodo
using GLMakie
using GeometryBasics
using FileIO
using Statistics

#=
This demo shows the use of the `dirplot` function to visualize directional data.
=#

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

M = icosahedron()
F = faces(M)
V = coordinates(M)
NV = vertexnormal(F,V; weighting=:area)

styleSet = (:to,:from,:through)

for i in eachindex(styleSet)
ax1 = Axis3(fig[1, i], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = string(styleSet[i]))
hp1 = poly!(ax1,M, strokewidth=1,shading=FastShading,color=:white, transparency=true, overdraw=false)
hpa = dirplot(ax1,V,NV.*mean(edgelengths(F,V)); color=:blue,linewidth=3,scaleval=1.0,style=styleSet[i])
end

fig
2 changes: 1 addition & 1 deletion examples/demo_edgeangles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ end
a = pi/4 # "45 degree shear"
f[1,2] = tan(a)

V2 = togeometrybasics_points([f*v for v V]) # Shear the cube
V2 = [eltype(V)(f*v) for v V] # Shear the cube

A = edgeangles(F,V)
A2 = edgeangles(F,V2)
Expand Down
14 changes: 7 additions & 7 deletions examples/demo_facearea.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@ elseif testCase==4 # Merged STL for single object
M = load(fileName_mesh)

# Obtain mesh faces and vertices
F = togeometrybasics_faces(faces(M))
V = togeometrybasics_points(coordinates(M))
F = tofaces(faces(M))
V = topoints(coordinates(M))
F,V,_ = mergevertices(F,V)
F,V = subtri(F,V,2; method = :loop)
# F,V = subtri(F,V,3; method = :Loop)
elseif testCase==5 # Merged STL for single object
# Loading a mesh
fileName_mesh = joinpath(comododir(),"assets","stl","david.stl")
M = load(fileName_mesh)

# Obtain mesh faces and vertices
F = togeometrybasics_faces(faces(M))
V = togeometrybasics_points(coordinates(M))
F = tofaces(faces(M))
V = topoints(coordinates(M))
F,V,_ = mergevertices(F,V)
elseif testCase==6
# Loading a mesh
fileName_mesh = joinpath(comododir(),"assets","obj","motherChild_5k.obj")
M = load(fileName_mesh)

# Obtain mesh faces and vertices
F = togeometrybasics_faces(faces(M))
V = togeometrybasics_points(coordinates(M))
F = tofaces(faces(M))
V = topoints(coordinates(M))
end


Expand Down
1 change: 1 addition & 0 deletions examples/demo_facenormal.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Comodo
using GLMakie
using GeometryBasics

#=
This demo shows the use of the `meshnormal` function to obtain mesh face normal
Expand Down
8 changes: 7 additions & 1 deletion examples/demo_kabsch_rot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ are visualized.
=#

# 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 = faces(M)
V1 = togeometrybasics_points(coordinates(M))
V1 = topoints(coordinates(M))
V1 = [Point{3, Float64}(v) for v in V1]

F,V1 = mergevertices(F,V1)

# Define a rotation tensor using Euler angles
Expand Down
12 changes: 3 additions & 9 deletions examples/demo_load_view_obj.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,16 @@ using FileIO
fileName_mesh = joinpath(comododir(),"assets","obj","spot_quadrangulated.obj")
# M = load(fileName_mesh; facetype = GeometryBasics.QuadFace{GeometryBasics.GLIndex})
M = load(fileName_mesh)
F = togeometrybasics_faces(faces(M))
V = togeometrybasics_points(coordinates(M))
F = tofaces(faces(M))
V = topoints(coordinates(M))
# M = GeometryBasics.Mesh(V,F)

# F,V = mergevertices(F,V)

# M=cube(1)


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

ax1 = Axis3(fig[1, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Spot the cow")
hp1 = poly!(ax1,M, color=load(joinpath(comododir(),"assets","obj","spot_texture.png")), shading = FastShading, transparency=false,strokecolor=:black,strokewidth=2)
hp1 = poly!(ax1,M, color=load(joinpath(comododir(),"assets","obj","spot_texture.png")), shading = FastShading, transparency=false,strokecolor=:black,strokewidth=1)
# hp1 = mesh!(ax1,M, color=:red, shading = FastShading, transparency=false)
# hp1 = poly!(ax1,M, color=:red, shading = FastShading, transparency=false,strokecolor=:black,strokewidth=2)
# normalplot(ax1,M)

fig
6 changes: 2 additions & 4 deletions examples/demo_mergevertices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ using FileIO
# Loading a mesh
fileName_mesh = joinpath(comododir(),"assets","stl","stanford_bunny_low.stl")
M1 = load(fileName_mesh)
F1 = faces(M1)
V1 = coordinates(M1)
F1 = togeometrybasics_faces(F1)
V1 = togeometrybasics_points(V1)
F1 = tofaces(faces(M1))
V1 = topoints(coordinates(M1))

F2 = deepcopy(F1)
V2 = deepcopy(V1)
Expand Down
12 changes: 6 additions & 6 deletions examples/demo_mesh_curvature_polynomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ elseif testCase==5 # Merged STL for single object
M = load(fileName_mesh)

# Obtain mesh faces and vertices
F = togeometrybasics_faces(faces(M))
V = togeometrybasics_points(coordinates(M))
F = tofaces(faces(M))
V = topoints(coordinates(M))
F,V,_ = mergevertices(F,V)
F,V = subtri(F,V,2; method = :loop)
elseif testCase==6 # Merged STL for single object
Expand All @@ -43,17 +43,17 @@ elseif testCase==6 # Merged STL for single object
M = load(fileName_mesh)

# Obtain mesh faces and vertices
F = togeometrybasics_faces(faces(M))
V = togeometrybasics_points(coordinates(M))
F = tofaces(faces(M))
V = topoints(coordinates(M))
F,V,_ = mergevertices(F,V)
elseif testCase==7
# Loading a mesh
fileName_mesh = joinpath(comododir(),"assets","obj","motherChild_5k.obj")
M = load(fileName_mesh)

# Obtain mesh faces and vertices
F = togeometrybasics_faces(faces(M))
V = togeometrybasics_points(coordinates(M))
F = tofaces(faces(M))
V = topoints(coordinates(M))
end

M = GeometryBasics.Mesh(V,F)
Expand Down
12 changes: 6 additions & 6 deletions examples/demo_meshgroup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ elseif testCase==5 # Unmerged STL, each triangle is seperate group
M = load(fileName_mesh)

# Obtain mesh faces and vertices
F = togeometrybasics_faces(faces(M))
V = togeometrybasics_points(coordinates(M))
F = tofaces(faces(M))
V = topoints(coordinates(M))
elseif testCase==6 # Merged STL for single object
# Loading a mesh
using FileIO
fileName_mesh = joinpath(comododir(),"assets","stl","stanford_bunny_low.stl")
M = load(fileName_mesh)

# Obtain mesh faces and vertices
F = togeometrybasics_faces(faces(M))
V = togeometrybasics_points(coordinates(M))
F = tofaces(faces(M))
V = topoints(coordinates(M))
F,V,_ = mergevertices(F,V)
elseif testCase==7 # Merged STL for single object
# Loading a mesh
Expand All @@ -85,8 +85,8 @@ elseif testCase==7 # Merged STL for single object
M = load(fileName_mesh)

# Obtain mesh faces and vertices
F = togeometrybasics_faces(faces(M))
V = togeometrybasics_points(coordinates(M))
F = tofaces(faces(M))
V = topoints(coordinates(M))
F,V,_ = mergevertices(F,V)

F2 = map(f-> f.+length(V),deepcopy(F))
Expand Down
4 changes: 2 additions & 2 deletions examples/demo_quad2tri.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ elseif testCase ==3
end
a = pi/6 # "45 degree shear"
f[1,2] = tan(a)
V = togeometrybasics_points([f*v for v V]) # Shear the cube
V = [eltype(V)(f*v) for v V] # Shear the cube

# Build deformation gradient tensor to induce shear with known angles
f = zeros(3,3)
Expand All @@ -44,7 +44,7 @@ elseif testCase ==3
a = pi/6 # "45 degree shear"
f[3,1] = tan(a)

V = togeometrybasics_points([f*v for v V]) # Shear the cube
V = [eltype(V)(f*v) for v V] # Shear the cube

end

Expand Down
69 changes: 69 additions & 0 deletions examples/demo_regiontrimesh.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using Comodo
using GLMakie
using DelaunayTriangulation

#=
This demo shows the use of `hexbox` to generate a hexahedral mesh for a 3D box
domain.
=#

n = 100
V1 = batman(n)

V2 = deepcopy(V1)
Vc = circlepoints(0.25,25; dir=:cw)
V2 = append!(V2,Vc)
V2 = [Point{2,Float64}(v[1],v[2]) for v in V2]

TR_1 = triangulate(V1)
F1 = [TriangleFace{Int64}(tr) for tr in TR_1.triangles]

constrained_segments = append!(collect(1:length(V1)),1)
TR_2 = triangulate(V1; boundary_nodes=constrained_segments)
F2 = [TriangleFace{Int64}(tr) for tr in TR_2.triangles]

constrained_segments1 = append!(collect(1:length(V1)),1)
constrained_segments2 = append!(collect(1:length(Vc)),1).+length(V1)
constrained_segments = [[constrained_segments1], [constrained_segments2]]
TR_3 = triangulate(V2; boundary_nodes=constrained_segments)
F3 = [TriangleFace{Int64}(tr) for tr in TR_3.triangles]
V3 = [Point{3,Float64}(v[1],v[2],0.0) for v in V2]

TR_4 = deepcopy(TR_3)
stats = refine!(TR_4; max_area=1e-3, min_angle=27.3)
F4 = [TriangleFace{Int64}(tr) for tr in TR_4.triangles]
V4 = TR_4.points
V4 = [Point{3,Float64}(v[1],v[2],0.0) for v in V4]

E = boundaryedges(F4)
indB = unique(reduce(vcat,E))
n = 25
λ = 0.5
V4 = smoothmesh_laplacian(F4,V4, n, λ; constrained_points=indB)

# Visualisation
fig = Figure(size=(1800,600))

ax1 = Axis3(fig[1, 1],aspect = :data,title="Unconstrained")
hp1 = lines!(ax1, V1,linewidth=4,color=:blue)
hp2 = scatter!(ax1, V1,markersize=8,color=:red)
hp3 = poly!(ax1,GeometryBasics.Mesh(V1,F1), strokewidth=0.5,color=:white, strokecolor=:black, shading = FastShading, transparency=false)

ax2 = Axis3(fig[1, 2],aspect = :data,title="Constrained")
hp1 = lines!(ax2, V1,linewidth=4,color=:blue)
hp2 = scatter!(ax2, V1,markersize=8,color=:red)
hp3 = poly!(ax2,GeometryBasics.Mesh(V1,F2), strokewidth=0.5,color=:white, strokecolor=:black, shading = FastShading, transparency=false)

ax3 = Axis3(fig[2, 1],aspect = :data,title="Constrained with hole")
hp11 = lines!(ax3, V3[constrained_segments1],linewidth=4,color=:blue)
hp12 = lines!(ax3, V3[constrained_segments2],linewidth=4,color=:blue)
hp2 = scatter!(ax3, V3,markersize=8,color=:red)
hp3 = poly!(ax3,GeometryBasics.Mesh(V3,F3), strokewidth=0.5,color=:white, strokecolor=:black, shading = FastShading, transparency=false)

ax4 = Axis3(fig[2, 2],aspect = :data,title="Constrained with hole")
hp11 = lines!(ax4, V4[constrained_segments1],linewidth=4,color=:blue)
hp12 = lines!(ax4, V4[constrained_segments2],linewidth=4,color=:blue)
hp2 = scatter!(ax4, V4,markersize=8,color=:red)
hp3 = poly!(ax4,GeometryBasics.Mesh(V4,F4), strokewidth=0.5,color=:white, strokecolor=:black, shading = FastShading, transparency=false)

fig
10 changes: 6 additions & 4 deletions examples/demo_remove_unused_vertices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ 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
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 sliced mesh")

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

hp3 = poly!(ax1,M, strokewidth=1,color=:white, strokecolor=:blue, shading = FastShading, transparency=false)
hp3 = normalplot(ax1,M)
# hp3 = normalplot(ax1,M)
scatter!(Vc,markersize=markersize,color=:red)


fig
2 changes: 1 addition & 1 deletion examples/demo_subquad_Catmull_Clark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ rs3 = mean(Rn3)
d3 = Rn3.-rs3

## 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")
wireframe!(ax1,M, linewidth=8,color=:red, overdraw=false)
Expand Down
2 changes: 1 addition & 1 deletion examples/demo_subtri_loop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ax = Axis3(fig[1, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z",
slidercontrol(hSlider,ax)

hp1=wireframe!(ax,M,linewidth=3,color=:red, overdraw=false)
hp2=poly!(ax,Mn,strokewidth=2,color=:white, shading = FastShading)
hp2=poly!(ax,Mn,strokewidth=1,color=:white, shading = FastShading)

# hp2=poly!(scene,M,strokewidth=1,color=:white, shading = FastShading)

Expand Down
5 changes: 2 additions & 3 deletions examples/demo_surface_mesh_smoothing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ if testCase == 1 # Triangle mesh bunny
fileName_mesh = joinpath(comododir(),"assets","stl","stanford_bunny_low.stl")
M = load(fileName_mesh)
F = faces(M)
V = coordinates(M)
F = togeometrybasics_faces(F)
V = togeometrybasics_points(V)
V = coordinates(M)
V = topoints(V)
F,V,ind1,ind2 = mergevertices(F,V; roundVertices=true)
elseif testCase == 2 # Quad mesh sphere
F,V = quadsphere(4,100)
Expand Down
Loading

0 comments on commit 03610ef

Please sign in to comment.