diff --git a/CondaPkg.toml b/CondaPkg.toml index b294d04..7b798e4 100644 --- a/CondaPkg.toml +++ b/CondaPkg.toml @@ -1,2 +1,4 @@ +channels = ["anaconda", "conda-forge"] + [deps] -trimesh = "" \ No newline at end of file +trimesh = "==4.6.6" \ No newline at end of file diff --git a/Project.toml b/Project.toml index 8597fb4..637490a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MaterialPointVisualizer" uuid = "9ce2fbfb-c269-402f-8683-a675189e795c" authors = ["ZenanH "] -version = "0.1.8" +version = "0.1.9" [deps] CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab" diff --git a/README.md b/README.md index 582a244..6429550 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![CI](https://github.com/LandslideSIM/MaterialPointVisualizer.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/LandslideSIM/MaterialPointVisualizer.jl/actions/workflows/ci.yml) [![Stable](https://img.shields.io/badge/docs-stable-blue.svg?logo=quicklook)](https://LandslideSIM.github.io/MaterialPointVisualizer.jl/stable) [![Dev](https://img.shields.io/badge/docs-dev-red.svg?logo=quicklook)](https://LandslideSIM.github.io/MaterialPointVisualizer.jl/dev) -[![Version](https://img.shields.io/badge/version-v0.1.8-pink)]() +[![Version](https://img.shields.io/badge/version-v0.1.9-pink)]() With this package, we can convert the MPM simulation results (HDF5 files from ***[MaterialPointSolver.jl](https://github.com/LandslideSIM/MaterialPointSolver.jl)*** ) into `.vtp` files or create ParaView-compatible animations. Additionally, it includes some post-processing functionalities. diff --git a/docs/src/usage/surfreconstruction.md b/docs/src/usage/surfreconstruction.md index 84d3a2c..67f6271 100644 --- a/docs/src/usage/surfreconstruction.md +++ b/docs/src/usage/surfreconstruction.md @@ -34,8 +34,9 @@ ply2surface( splash_dir, radius, num_threads; - cube_size =0.6, - surface_threshold=0.6, - smoothing_length =1.2 + cube_size = 0.6, + surface_threshold = 0.6, + smoothing_length = 1.2, + splashsurf::String = "nothing" ) ``` \ No newline at end of file diff --git a/src/MaterialPointVisualizer.jl b/src/MaterialPointVisualizer.jl index bc0c72f..9fcc316 100644 --- a/src/MaterialPointVisualizer.jl +++ b/src/MaterialPointVisualizer.jl @@ -18,7 +18,7 @@ import StatsBase: sample import MaterialPointSolver: DeviceArgs2D, DeviceGrid2D, DeviceParticle2D, DeviceProperty, DeviceArgs3D, DeviceGrid3D, DeviceParticle3D -const trimesh = Ref{Py}() +const trimesh = PythonCall.pynew() include(joinpath(@__DIR__, "mpm2vtp.jl" )) include(joinpath(@__DIR__, "particle2vtp.jl" )) @@ -27,18 +27,8 @@ include(joinpath(@__DIR__, "plot/display.jl" )) function __init__() @info "checking environment..." - try - run(pipeline(`splashsurf -V`, stdout=devnull, stderr=devnull)) - catch e - if isa(e, Base.IOError) # splashsurf 未安装 - @warn """splashsurf - Cannot find splashsurf on this system. If you need surface reconstruction, please - install it first, see: https://github.com/InteractiveComputerGraphics/splashsurf - and make sure Julia can find it. - """ - end - end - trimesh[] = pyimport("trimesh") + # import Python modules + PythonCall.pycopy!(trimesh, pyimport("trimesh")) end end \ No newline at end of file diff --git a/src/particle2surf.jl b/src/particle2surf.jl index 438e72c..7555ed4 100644 --- a/src/particle2surf.jl +++ b/src/particle2surf.jl @@ -31,7 +31,7 @@ function particle2ply(coords::Matrix; output_file::String="coord.ply") coords = hcat(coords, zeros(size(coords, 1))) end # export .ply file by using trimesh - mesh = trimesh[].Trimesh(vertices=coords) + mesh = trimesh.Trimesh(vertices=coords) mesh.export(output_file) # print info @info """PLY file ($(size(coords, 1)) pts) saved at: @@ -55,7 +55,7 @@ function particle2ply( output_file = joinpath(args.project_path, args.project_name, filename) coords = hcat(mp.ξ, zeros(mp.np)) # export .ply file by using trimesh - mesh = trimesh[].Trimesh(vertices=coords) + mesh = trimesh.Trimesh(vertices=coords) mesh.export(output_file) # print info @info """PLY file ($(size(coords, 1)) pts) saved at: @@ -78,7 +78,7 @@ function particle2ply( filename = args.project_name * ".ply" output_file = joinpath(args.project_path, args.project_name, filename) # export .ply file by using trimesh - mesh = trimesh[].Trimesh(vertices=mp.ξ) + mesh = trimesh.Trimesh(vertices=mp.ξ) mesh.export(output_file) # print info @info """PLY file ($(mp.np) pts) saved at: @@ -114,7 +114,7 @@ function particle2ply(hdf5_file::String, ply_dir::String) end output_file = joinpath(ply_dir, "iteration_$(i).ply") # export .ply file by using trimesh - mesh = trimesh[].Trimesh(vertices=obj) + mesh = trimesh.Trimesh(vertices=obj) mesh.export(output_file) next!(p) end @@ -127,7 +127,7 @@ end """ ply2surface(ply_dir, splash_dir, radius, num_threads; cube_size=0.6, - surface_threshold=0.6, smoothing_length=1.2) + surface_threshold=0.6, smoothing_length=1.2, splashsurf="nothing") Description: --- @@ -148,10 +148,41 @@ function ply2surface( splash_dir, radius, num_threads; - cube_size =0.6, - surface_threshold=0.6, - smoothing_length =1.2 + cube_size = 0.6, + surface_threshold = 0.6, + smoothing_length = 1.2, + splashsurf::String = "nothing" ) + if splashsurf == "nothing" + try + run(pipeline(`splashsurf -V`, stdout=devnull, stderr=devnull)) + catch e + if isa(e, Base.IOError) # splashsurf 未安装 + @warn """splashsurf + Cannot find splashsurf on this system. If you need surface reconstruction, please + install it first, and make sure Julia can find it. + Or you can pass the path of splashsurf to ply2surface. + link: https://github.com/InteractiveComputerGraphics/splashsurf + """ + end + end + splashsurfcmd = "splashsurf" + else + try + run(pipeline(`$(splashsurf) -V`, stdout=devnull, stderr=devnull)) + catch e + if isa(e, Base.IOError) # splashsurf 未安装 + @warn """invalid splashsurf path + Cannot find splashsurf on this system. If you need surface reconstruction, please + install it first, and make sure Julia can find it. + Or you can pass the path of splashsurf to ply2surface. + link: https://github.com/InteractiveComputerGraphics/splashsurf + """ + end + end + splashsurfcmd = splashsurf + end + num_threads = 1 ≤ num_threads ≤ Sys.CPU_THREADS ? num_threads : Sys.CPU_THREADS splash_dir ≠ ply_dir || throw(ArgumentError( "The splash output directory should be different from the ply input directory")) @@ -159,7 +190,7 @@ function ply2surface( if isfile(ply_dir) inputs = ply_dir outputs = joinpath(splash_dir, "surface.vtk") - run(`splashsurf reconstruct $(inputs) --output-file=$(outputs) + run(`$(splashsurfcmd) reconstruct $(inputs) --output-file=$(outputs) --particle-radius=$(radius*1.5) --cube-size=$(cube_size) --surface-threshold=$(surface_threshold) @@ -174,7 +205,7 @@ function ply2surface( elseif isdir(ply_dir) inputs = joinpath(ply_dir, "iteration_{}.ply") outputs = joinpath(splash_dir, "iteration_{}.vtk") - run(`splashsurf reconstruct $(inputs) --output-file=$(outputs) + run(`$(splashsurfcmd) reconstruct $(inputs) --output-file=$(outputs) --particle-radius=$(radius*1.5) --cube-size=$(cube_size) --surface-threshold=$(surface_threshold) diff --git a/test/runtests.jl b/test/runtests.jl index 9e07f4e..70eebfc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,5 @@ -using MaterialPointVisualizer +using MaterialPointVisualizer +using PythonCall using Test -@test !isnothing(MaterialPointVisualizer.trimesh[]) \ No newline at end of file +@test !pyconvert(Bool, PythonCall.pyisnull(MaterialPointVisualizer.trimesh)) \ No newline at end of file