Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CondaPkg.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
channels = ["anaconda", "conda-forge"]

[deps]
trimesh = ""
trimesh = "==4.6.6"
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MaterialPointVisualizer"
uuid = "9ce2fbfb-c269-402f-8683-a675189e795c"
authors = ["ZenanH <[email protected]>"]
version = "0.1.8"
version = "0.1.9"

[deps]
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
7 changes: 4 additions & 3 deletions docs/src/usage/surfreconstruction.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
```
16 changes: 3 additions & 13 deletions src/MaterialPointVisualizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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" ))
Expand All @@ -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
51 changes: 41 additions & 10 deletions src/particle2surf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
---
Expand All @@ -148,18 +148,49 @@ 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"))
isdir(splash_dir) || mkpath(splash_dir)
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)
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MaterialPointVisualizer
using MaterialPointVisualizer
using PythonCall
using Test

@test !isnothing(MaterialPointVisualizer.trimesh[])
@test !pyconvert(Bool, PythonCall.pyisnull(MaterialPointVisualizer.trimesh))