diff --git a/Manifest.toml b/Manifest.toml index b04903f..c838641 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -2,7 +2,7 @@ julia_version = "1.10.1" manifest_format = "2.0" -project_hash = "d4eb882a44fc91c1fbf111dd9aa6f52b208dd65c" +project_hash = "605ab7cd5a06e8048cf84924cbec19c5085ec0ef" [[deps.AbstractFFTs]] deps = ["LinearAlgebra"] @@ -308,6 +308,17 @@ git-tree-sha1 = "23163d55f885173722d1e4cf0f6110cdbaf7e272" uuid = "b552c78f-8df3-52c6-915a-8e097449b14b" version = "1.15.1" +[[deps.Distances]] +deps = ["LinearAlgebra", "Statistics", "StatsAPI"] +git-tree-sha1 = "66c4c81f259586e8f002eacebc177e1fb06363b0" +uuid = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7" +version = "0.10.11" +weakdeps = ["ChainRulesCore", "SparseArrays"] + + [deps.Distances.extensions] + DistancesChainRulesCoreExt = "ChainRulesCore" + DistancesSparseArraysExt = "SparseArrays" + [[deps.Distributed]] deps = ["Random", "Serialization", "Sockets"] uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" diff --git a/Project.toml b/Project.toml index 0d8ea2b..180fb89 100644 --- a/Project.toml +++ b/Project.toml @@ -6,6 +6,7 @@ version = "0.1.0" [deps] BSplineKit = "093aae92-e908-43d7-9660-e50ee39d5a0a" DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7" FEBio = "c57eab10-e7d7-41f3-9039-a27761009b26" FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a" diff --git a/README.md b/README.md index 01413e5..82e788a 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,12 @@ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache-blue.svg)](https://github.com/COMODO-research/Comodo.jl/blob/main/LICENSE) [![example workflow](https://github.com/COMODO-research/Comodo.jl/actions/workflows/test.yml/badge.svg)](https://github.com/COMODO-research/Comodo.jl/blob/main/.github/workflows/test.yml) +[![Join the chat at https://gitter.im/Comodo.jl](https://badges.gitter.im/Comodo.jl.svg)](https://app.gitter.im/#/room/#comodo:gitter.im?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) ![](assets/img/COMODO.png) [![Mastodon](https://img.shields.io/badge/-MASTODON-%232B90D9?style=for-the-badge&logo=mastodon&logoColor=white)](https://fosstodon.org/@kevinmoerman) + + + # About Comodo Comodo is a [Julia](https://julialang.org/) package **computational (bio)mechanics and computational design**, and offers functionality for geometry processing, meshing, finite element analysis, automated design, topology optimisation, and image-based modelling. diff --git a/assets/img/COMODO_icon.png b/assets/img/COMODO_icon.png new file mode 100644 index 0000000..8c0ef84 Binary files /dev/null and b/assets/img/COMODO_icon.png differ diff --git a/examples/demo_dist.jl b/examples/demo_dist.jl index c9db852..4a75b54 100644 --- a/examples/demo_dist.jl +++ b/examples/demo_dist.jl @@ -11,7 +11,7 @@ the minimum distances are visualised on the mesh. # Defining icosahedron r = 1 # radius of icosahedron -n = 1 # Number of refinement steps +n = 3 # Number of refinement steps # Define an icosahedron M = platonicsolid(4,r) # GeometryBasics mesh description of icosahedron @@ -20,7 +20,7 @@ F = faces(M) # Get the mesh faces # Created refined version Fn,Vn = subtri(F,V,n) # Subdevide/refine the mesh linearly - +F,V = subtri(F,V,2) # Use distND to compute distances from all in set 1 to all in set 2 DD = dist(Vn,V) diff --git a/examples/demo_mindist.jl b/examples/demo_mindist.jl index 6296a77..e168d22 100644 --- a/examples/demo_mindist.jl +++ b/examples/demo_mindist.jl @@ -3,36 +3,42 @@ using GeometryBasics # For point and mesh format using GLMakie #= -This demo shows the use of distND to compute distances for ND points. A 3D -point set is defined on an icosahedron. Next a refined (using subtri) version is -created and the distance from the refined to the unrefined are computed. Next -the minimum distances are visualised on the mesh. +This demo shows the use of dist to compute distances for ND points. A 3D +point set is defined on an geodesic sphere. Next another, more refined version +is created, and the distance from this sphere to the coarser one is computed. +Next the minimum distances are visualised on the mesh. =# # Defining icosahedron r = 1 # radius of icosahedron -n = 3 # Number of refinement steps +n = 5 # Number of refinement steps -# Define an icosahedron -M = platonicsolid(4,r) # GeometryBasics mesh description of icosahedron -V = coordinates(M) # Get the mesh coordinates -F = faces(M) # Get the mesh faces +# Define a mesh +F,V = geosphere(1,r) -# Created refined version -Fn,Vn = subtri(F,V,n) # Subdevide/refine the mesh linearly +# Define a mesh +Fn,Vn = geosphere(n,r) # Subdevide/refine the mesh linearly # Compute nearest point distances -Dn = mindist(Vn,V; getIndex = false) +Dn,indMin = mindist(Vn,V; getIndex = true) # Visualization -fig = Figure(size = (800,800)) +fig = Figure(size = (1200,500)) -ax=Axis3(fig[1, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z") +ax1=Axis3(fig[1, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z") -hp = poly!(ax,GeometryBasics.Mesh(Vn,Fn),strokewidth=0,color=Dn, shading=FastShading, overdraw=false) -hs1 = scatter!(ax, V,markersize=35,color=:black) -hs2 = scatter!(ax, Vn,markersize=15,color=Dn,strokewidth=1) +hp1 = poly!(ax1,GeometryBasics.Mesh(Vn,Fn),strokewidth=0,color=Dn,shading=FastShading, overdraw=false) +hs1 = scatter!(ax1, V,markersize=35,color=:black) + +Colorbar(fig[1, 2], hp1,label="Distance") +Legend(fig[1, 3],[hp1,hs1],["Distances on mesh","Point set"]) + +ax2=Axis3(fig[1, 4], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z") + +hp2 = poly!(ax2,GeometryBasics.Mesh(Vn,Fn),strokewidth=0,color=indMin,shading=FastShading, overdraw=false) +hs2 = scatter!(ax2, V,markersize=35,color=:black) + +Colorbar(fig[1, 5], hp2,label="Nearest point index") +Legend(fig[1, 6],[hp2,hs2],["Point indices","Point set"]) -Colorbar(fig[1, 2], hs2,label="Distance") -Legend(fig[1, 3],[hp,hs1],["Distances on mesh","Point set"]) fig \ No newline at end of file diff --git a/src/Comodo.jl b/src/Comodo.jl index 1d61d80..f3322d5 100644 --- a/src/Comodo.jl +++ b/src/Comodo.jl @@ -11,6 +11,8 @@ import Statistics import SparseArrays import GLMakie import Rotations +import BSplineKit +import Distances include("functions.jl") diff --git a/src/functions.jl b/src/functions.jl index b77efe7..d1d5e0d 100644 --- a/src/functions.jl +++ b/src/functions.jl @@ -8,6 +8,8 @@ using Statistics # For: mean using GLMakie # For slidercontrol using SparseArrays # For meshconnectivity using Rotations +using BSplineKit +using Distances function comododir() joinpath(@__DIR__, "..") @@ -206,7 +208,7 @@ function dist(V1,V2) D = Matrix{Float64}(undef,length(V1),length(V2)) for i ∈ eachindex(V1) for j ∈ eachindex(V2) - D[i,j] = norm((V1[i].-V2[j])) + D[i,j] = euclidean(V1[i],V2[j]) # norm(V1[i]-V2[j]) end end return D @@ -223,7 +225,7 @@ function mindist(V1,V2; getIndex=false, skipSelf = false ) if skipSelf && i==j d[j] = Inf else - d[j] = sqrt(sum((V1[i].-V2[j]).^2)) + d[j] = euclidean(V1[i],V2[j]) # norm(V1[i]-V2[j]) end end if getIndex