Skip to content

Commit

Permalink
Added sweeplofting and kabsch rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin-Mattheus-Moerman committed Apr 6, 2024
1 parent 41fc2e9 commit 7511208
Show file tree
Hide file tree
Showing 8 changed files with 445 additions and 38 deletions.
49 changes: 16 additions & 33 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.10.2"
manifest_format = "2.0"
project_hash = "d033fa29a644db60fc5e6aeb38e2ece2b7d0fc92"
project_hash = "3ec2d41cb347d8597a69892af02440dbe8605a8b"

[[deps.AbstractFFTs]]
deps = ["LinearAlgebra"]
Expand Down Expand Up @@ -73,9 +73,9 @@ version = "7.9.0"

[[deps.ArrayLayouts]]
deps = ["FillArrays", "LinearAlgebra"]
git-tree-sha1 = "6404a564c24a994814106c374bec893195e19bac"
git-tree-sha1 = "0330bc3e828a05d1073553fb56f9695d73077370"
uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
version = "1.8.0"
version = "1.9.1"
weakdeps = ["SparseArrays"]

[deps.ArrayLayouts.extensions]
Expand Down Expand Up @@ -177,9 +177,9 @@ version = "3.24.0"

[[deps.ColorTypes]]
deps = ["FixedPointNumbers", "Random"]
git-tree-sha1 = "eb7f0f8307f71fac7c606984ea5fb2817275d6e4"
git-tree-sha1 = "b10d0b65641d57b8b4d5e234446582de5047050d"
uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
version = "0.11.4"
version = "0.11.5"

[[deps.ColorVectorSpace]]
deps = ["ColorTypes", "FixedPointNumbers", "LinearAlgebra", "Requires", "Statistics", "TensorCore"]
Expand Down Expand Up @@ -467,9 +467,9 @@ version = "2.13.1+0"

[[deps.FreeTypeAbstraction]]
deps = ["ColorVectorSpace", "Colors", "FreeType", "GeometryBasics"]
git-tree-sha1 = "055626e1a35f6771fe99060e835b72ca61a52621"
git-tree-sha1 = "2493cdfd0740015955a8e46de4ef28f49460d8bc"
uuid = "663a7486-cb36-511b-a19d-713bb74d65c9"
version = "0.10.1"
version = "0.10.3"

[[deps.FriBidi_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
Expand All @@ -495,9 +495,9 @@ version = "3.3.9+0"

[[deps.GLMakie]]
deps = ["ColorTypes", "Colors", "FileIO", "FixedPointNumbers", "FreeTypeAbstraction", "GLFW", "GeometryBasics", "LinearAlgebra", "Makie", "Markdown", "MeshIO", "ModernGL", "Observables", "PrecompileTools", "Printf", "ShaderAbstractions", "StaticArrays"]
git-tree-sha1 = "7a411adf08375e01d864386fb1eaf384de5ac9e9"
git-tree-sha1 = "b99a999cdcc7467769c7ea8cdc0978a5f059aa7b"
uuid = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
version = "0.9.9"
version = "0.9.10"

[[deps.GeoInterface]]
deps = ["Extents"]
Expand Down Expand Up @@ -859,10 +859,10 @@ uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
version = "0.5.13"

[[deps.Makie]]
deps = ["Animations", "Base64", "CRC32c", "ColorBrewer", "ColorSchemes", "ColorTypes", "Colors", "Contour", "DelaunayTriangulation", "Distributions", "DocStringExtensions", "Downloads", "FFMPEG_jll", "FileIO", "FilePaths", "FixedPointNumbers", "Format", "FreeType", "FreeTypeAbstraction", "GeometryBasics", "GridLayoutBase", "ImageIO", "InteractiveUtils", "IntervalSets", "Isoband", "KernelDensity", "LaTeXStrings", "LinearAlgebra", "MacroTools", "MakieCore", "Markdown", "MathTeXEngine", "Observables", "OffsetArrays", "Packing", "PlotUtils", "PolygonOps", "PrecompileTools", "Printf", "REPL", "Random", "RelocatableFolders", "Scratch", "ShaderAbstractions", "Showoff", "SignedDistanceFields", "SparseArrays", "StableHashTraits", "Statistics", "StatsBase", "StatsFuns", "StructArrays", "TriplotBase", "UnicodeFun"]
git-tree-sha1 = "27af6be179c711fb916a597b6644fbb5b80becc0"
deps = ["Animations", "Base64", "CRC32c", "ColorBrewer", "ColorSchemes", "ColorTypes", "Colors", "Contour", "DelaunayTriangulation", "Distributions", "DocStringExtensions", "Downloads", "FFMPEG_jll", "FileIO", "FilePaths", "FixedPointNumbers", "Format", "FreeType", "FreeTypeAbstraction", "GeometryBasics", "GridLayoutBase", "ImageIO", "InteractiveUtils", "IntervalSets", "Isoband", "KernelDensity", "LaTeXStrings", "LinearAlgebra", "MacroTools", "MakieCore", "Markdown", "MathTeXEngine", "Observables", "OffsetArrays", "Packing", "PlotUtils", "PolygonOps", "PrecompileTools", "Printf", "REPL", "Random", "RelocatableFolders", "Scratch", "ShaderAbstractions", "Showoff", "SignedDistanceFields", "SparseArrays", "Statistics", "StatsBase", "StatsFuns", "StructArrays", "TriplotBase", "UnicodeFun"]
git-tree-sha1 = "46ca613be7a1358fb93529726ea2fc28050d3ae0"
uuid = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
version = "0.20.8"
version = "0.20.9"

[[deps.MakieCore]]
deps = ["Observables", "REPL"]
Expand Down Expand Up @@ -898,9 +898,9 @@ version = "0.4.11"

[[deps.Missings]]
deps = ["DataAPI"]
git-tree-sha1 = "f66bdc5de519e8f8ae43bdc598782d35a25b1272"
git-tree-sha1 = "ec4f7fbeab05d7747bdf98eb74d130a2a2ed298d"
uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28"
version = "1.1.0"
version = "1.2.0"

[[deps.Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
Expand Down Expand Up @@ -1077,12 +1077,6 @@ git-tree-sha1 = "eb3f9df2457819bf0a9019bd93cc451697a0751e"
uuid = "2ae35dd2-176d-5d53-8349-f30d82d94d4f"
version = "0.4.20"

[[deps.PikaParser]]
deps = ["DocStringExtensions"]
git-tree-sha1 = "d6ff87de27ff3082131f31a714d25ab6d0a88abf"
uuid = "3bbf5609-3e7b-44cd-8549-7c69f321e792"
version = "0.6.1"

[[deps.Pixman_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "LLVMOpenMP_jll", "Libdl"]
git-tree-sha1 = "64779bc4c9784fee475689a1752ef4d5747c5e87"
Expand Down Expand Up @@ -1367,12 +1361,6 @@ weakdeps = ["ChainRulesCore"]
[deps.SpecialFunctions.extensions]
SpecialFunctionsChainRulesCoreExt = "ChainRulesCore"

[[deps.StableHashTraits]]
deps = ["Compat", "PikaParser", "SHA", "Tables", "TupleTools"]
git-tree-sha1 = "10dc702932fe05a0e09b8e5955f00794ea1e8b12"
uuid = "c5dd0088-6c3f-4803-b00e-f31a60c170fa"
version = "1.1.8"

[[deps.StackViews]]
deps = ["OffsetArrays"]
git-tree-sha1 = "46e589465204cd0c08b4bd97385e4fa79a0c770c"
Expand Down Expand Up @@ -1414,9 +1402,9 @@ version = "1.7.0"

[[deps.StatsBase]]
deps = ["DataAPI", "DataStructures", "LinearAlgebra", "LogExpFunctions", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "StatsAPI"]
git-tree-sha1 = "1d77abd07f617c4868c33d4f5b9e1dbb2643c9cf"
git-tree-sha1 = "5cf7606d6cef84b543b483848d4ae08ad9832b21"
uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
version = "0.34.2"
version = "0.34.3"

[[deps.StatsFuns]]
deps = ["HypergeometricFunctions", "IrrationalConstants", "LogExpFunctions", "Reexport", "Rmath", "SpecialFunctions"]
Expand Down Expand Up @@ -1511,11 +1499,6 @@ git-tree-sha1 = "4d4ed7f294cda19382ff7de4c137d24d16adc89b"
uuid = "981d1d27-644d-49a2-9326-4793e63143c3"
version = "0.1.0"

[[deps.TupleTools]]
git-tree-sha1 = "41d61b1c545b06279871ef1a4b5fcb2cac2191cd"
uuid = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6"
version = "1.5.0"

[[deps.UUIDs]]
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
Expand Down
41 changes: 41 additions & 0 deletions examples/demo_kabsch_rot.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Comodo
using GLMakie
using GeometryBasics
using FileIO
using Rotations

#=
In this demo a mesh is loaded, in this case a triangulated surface from an STL
file. Next the coordinates are rotated, and the unrotated and rotated meshes
are visualized.
=#

# Loading a 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))
F,V1 = mergevertices(F,V1)

# Define a rotation tensor using Euler angles
Q = RotXYZ(0.0,0.25*π,0.25*π)
V2 = [GeometryBasics.Point{3, Float64}(Q*v) for v V1]

R = kabsch_rot(V2,V1)
V3 = [GeometryBasics.Point{3, Float64}(R*v) for v V2]

# Rotate the coordinates
fig = Figure(size = (800,800))
ax = Axis3(fig[1, 1], aspect = :data)

hp1 = poly!(ax, GeometryBasics.Mesh(V1,F), color=:green,transparency=false,shading = FastShading)
hp2 = poly!(ax, GeometryBasics.Mesh(V2,F), strokewidth=2,color=:red,shading = FastShading)
hp3 = wireframe!(ax, GeometryBasics.Mesh(V3,F), color=:red,linewidth=2)

Legend(fig[1, 2],[hp1,hp2,hp3],["Initial","Rotated","Back rotated"])

fig


150 changes: 150 additions & 0 deletions examples/demo_sweeploft.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
using Comodo
using GeometryBasics
using GLMakie
using Rotations
using Statistics
using LinearAlgebra

testCase = 1

if testCase == 1
# Define guide curve
nc = 51 # Number of points on guide curve
P = Vector{GeometryBasics.Point{3, Float64}}(undef,4)
P[1 ] = GeometryBasics.Point{3, Float64}( 0.0, 0.0, 0.0)
P[2 ] = GeometryBasics.Point{3, Float64}( 1.0, 0.0, 0.0)
P[3 ] = GeometryBasics.Point{3, Float64}( 1.0, 1.0, 0.0)
P[4 ] = GeometryBasics.Point{3, Float64}( 1.0, 1.0, 1.0)
Vc = nbezier(P,nc) # Get Bezier fit points
Vc = [vc.*10 for vc in Vc]
Vc,Sc = evenly_sample(Vc, nc)

# Define section curves
np = 25 # Number of section points
f(t) = 2.0 + 0.5.*sin(3*t)
V1 = circlepoints(f,np; dir=:acw)
V1,_ = evenly_sample(V1, np)
Q = RotXYZ(0.0,0.5*π,0.0) # Define a rotation tensor using Euler angles
V1 = [Q*v for v V1] # Rotate the coordinates

f(t) = 2.0 + 0.5*sin(3*t)
V2 = circlepoints(f,np; dir=:acw)
V2,_ = evenly_sample(V2, np)
V2 = [v2 .+ Vc[end] for v2 V2]
elseif testCase == 2
# Define guide curve
nc = 75 # Number of points on guide curve
P = Vector{GeometryBasics.Point{3, Float64}}(undef,4)
P[1 ] = GeometryBasics.Point{3, Float64}( 0.0, 0.0, 0.0)
P[2 ] = GeometryBasics.Point{3, Float64}( 1.0, 0.0, 0.0)
P[3 ] = GeometryBasics.Point{3, Float64}( 2.0, 0.0, 0.0)
P[4 ] = GeometryBasics.Point{3, Float64}( 3.0, 0.0, 0.0)
Vc = nbezier(P,nc) # Get Bezier fit points
Vc = [vc.*10 for vc in Vc]
Vc,Sc = evenly_sample(Vc, nc)

# Define section curves
np = 35 # Number of section points
f(t) = 2.0 + 0.5.*sin(3*t)
V1 = circlepoints(f,np; dir=:acw)
V1,_ = evenly_sample(V1, np)
Q = RotXYZ(0.0,0.5*π,0.0) # Define a rotation tensor using Euler angles
V1 = [(Q*v) .+ Vc[1] for v V1] # Rotate the coordinates

f(t) = 2.0 + 0.5*sin(3*t)
V2 = circlepoints(f,np; dir=:acw)
V2,_ = evenly_sample(V2, np)
Q = RotXYZ(0.0,0.5*π,0.0) # Define a rotation tensor using Euler angles
V2 = [(Q*v) .+ Vc[end] for v V2]
elseif testCase == 3
nc = 201 # Number of points on guide curve
r = 10.0
a = 4*π
Vc = [GeometryBasics.Point{3, Float64}(r*cos(t),r*sin(t),10.0*(t/(a/2))) for t range(0,a,nc)]

# Define section curves
np = 50 # Number of section points

# Section 1
f(t) = 1.5 + 0.5.*sin(3*t)
V1 = circlepoints(f,np; dir=:cw)
V1,_ = evenly_sample(V1, np)
Q = RotXYZ(0.5*π,0.0,0.0) # Define a rotation tensor using Euler angles
V1 = [Q*v for v V1] # Rotate the coordinates

# Ensure section is orthogonal to guide curve
n3_1 = Q*Vec3{Float64}(0.0,0.0,-1.0)
n2_1 = Q*Vec3{Float64}(1.0,0.0,0.0)
n1_1 = normalizevector(cross(n3_1,n2_1))
S11 = mapreduce(permutedims,vcat,[n1_1,n2_1,n3_1])

n3_1 = normalizevector(normalizevector(Vc[2]-Vc[1]))
n2_1 = normalizevector(cross(normalizevector(V1[1]),n3_1))
n1_1 = normalizevector(cross(n3_1,n2_1))
S12 = mapreduce(permutedims,vcat,[n1_1,n2_1,n3_1])

R = RotMatrix3{Float64}(S12\S11)
V1 = [R*v for v V1]
V1= [v .+ Vc[1] for v V1]

# Section 2
f(t) = 4 + 1.5*sin(5*t)
V2 = circlepoints(f,np; dir=:cw)
V2,_ = evenly_sample(V2, np)
Q1 = RotXYZ(0.5*π,0.0,0.0) # Define a rotation tensor using Euler angles
Q2 = RotXYZ(0.0,-0.25*π,0.0) # Define a rotation tensor using Euler angles
Q = Q2*Q1
V2 = [Q*v for v V2] # Rotate the coordinates

# Ensure section is orthogonal to guide curve
n3_2 = Q*Vec3{Float64}(0.0,0.0,-1.0)
n2_2 = Q*Vec3{Float64}(1.0,0.0,0.0)
n1_2 = normalizevector(cross(n3_2,n2_2))
S21 = RotMatrix3{Float64}(mapreduce(permutedims,vcat,[n1_2,n2_2,n3_2]))

n3_2 = normalizevector(normalizevector(Vc[2]-Vc[1]))
n2_2 = normalizevector(cross(normalizevector(V1[1]),n3_1))
n1_2 = normalizevector(cross(n3_1,n2_1))
S22 = mapreduce(permutedims,vcat,[n1_1,n2_1,n3_1])

R = RotMatrix3{Float64}(S22\S21)
V2 = [R*v for v V2] # Rotate the coordinates
V2 = [v .+ Vc[end] for v V2]
end



#########

# face_type=:quad
F,V = sweeploft(Vc,V1,V2; face_type=:quad, num_twist=0)
F = invert_faces(F)


# Visualization
fig = Figure(size = (800,800))
ax = Axis3(fig[1, 1],aspect = :data,title="Swept lofting")

stepRange1 = -4:1:4
hSlider1 = Slider(fig[2, 1], range = stepRange1, startvalue = 0,linewidth=30)

# scatter!(ax, Vc,markersize=8,color=:black)
hp1 = lines!(ax, Vc,linewidth=4,color=:black)

scatter!(ax, V1,markersize=8,color=:blue)
hp2 = lines!(ax, V1,linewidth=4,color=:blue)

scatter!(ax, V2,markersize=8,color=:red)
hp3 = lines!(ax, V2,linewidth=4,color=:red)

hp1 = poly!(ax, GeometryBasics.Mesh(V,F), strokecolor=:black, strokewidth=1,color=:white,transparency=false,shading = FastShading)
# hp1 = mesh!(ax, GeometryBasics.Mesh(V,F), color=:white,transparency=false,shading = FastShading)

on(hSlider1.value) do stepIndex1
F,V = sweeploft(Vc,V1,V2; face_type=:quad, num_twist=stepIndex1)
F = invert_faces(F)
hp1[1] = GeometryBasics.Mesh(V,F)
end

fig

2 changes: 1 addition & 1 deletion src/Comodo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export circlepoints, loftlinear, trisurfslice
export wrapindex, edgeangles, count_edge_face, boundaryedges, edges2curve
export pointspacingmean, extrudecurve, meshgroup, ray_triangle_intersect
export distmarch, mesh_curvature_polynomial, curve_length, evenly_sample
export invert_faces
export invert_faces, kabsch_rot, sweeploft

# Export functions: Visualization related
export slidercontrol
Expand Down
Loading

0 comments on commit 7511208

Please sign in to comment.