Skip to content

Commit 65d402b

Browse files
authored
Merge pull request #11 from ZenanH/main
🎉 Release new version v0.1.9
2 parents 68c40fe + e69a4bc commit 65d402b

File tree

7 files changed

+56
-31
lines changed

7 files changed

+56
-31
lines changed

CondaPkg.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
channels = ["anaconda", "conda-forge"]
2+
13
[deps]
2-
trimesh = ""
4+
trimesh = "==4.6.6"

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MaterialPointVisualizer"
22
uuid = "9ce2fbfb-c269-402f-8683-a675189e795c"
33
authors = ["ZenanH <[email protected]>"]
4-
version = "0.1.8"
4+
version = "0.1.9"
55

66
[deps]
77
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![CI](https://github.com/LandslideSIM/MaterialPointVisualizer.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/LandslideSIM/MaterialPointVisualizer.jl/actions/workflows/ci.yml)
44
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg?logo=quicklook)](https://LandslideSIM.github.io/MaterialPointVisualizer.jl/stable)
55
[![Dev](https://img.shields.io/badge/docs-dev-red.svg?logo=quicklook)](https://LandslideSIM.github.io/MaterialPointVisualizer.jl/dev)
6-
[![Version](https://img.shields.io/badge/version-v0.1.8-pink)]()
6+
[![Version](https://img.shields.io/badge/version-v0.1.9-pink)]()
77

88
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.
99

docs/src/usage/surfreconstruction.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ ply2surface(
3434
splash_dir,
3535
radius,
3636
num_threads;
37-
cube_size =0.6,
38-
surface_threshold=0.6,
39-
smoothing_length =1.2
37+
cube_size = 0.6,
38+
surface_threshold = 0.6,
39+
smoothing_length = 1.2,
40+
splashsurf::String = "nothing"
4041
)
4142
```

src/MaterialPointVisualizer.jl

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import StatsBase: sample
1818
import MaterialPointSolver: DeviceArgs2D, DeviceGrid2D, DeviceParticle2D, DeviceProperty,
1919
DeviceArgs3D, DeviceGrid3D, DeviceParticle3D
2020

21-
const trimesh = Ref{Py}()
21+
const trimesh = PythonCall.pynew()
2222

2323
include(joinpath(@__DIR__, "mpm2vtp.jl" ))
2424
include(joinpath(@__DIR__, "particle2vtp.jl" ))
@@ -27,18 +27,8 @@ include(joinpath(@__DIR__, "plot/display.jl" ))
2727

2828
function __init__()
2929
@info "checking environment..."
30-
try
31-
run(pipeline(`splashsurf -V`, stdout=devnull, stderr=devnull))
32-
catch e
33-
if isa(e, Base.IOError) # splashsurf 未安装
34-
@warn """splashsurf
35-
Cannot find splashsurf on this system. If you need surface reconstruction, please
36-
install it first, see: https://github.com/InteractiveComputerGraphics/splashsurf
37-
and make sure Julia can find it.
38-
"""
39-
end
40-
end
41-
trimesh[] = pyimport("trimesh")
30+
# import Python modules
31+
PythonCall.pycopy!(trimesh, pyimport("trimesh"))
4232
end
4333

4434
end

src/particle2surf.jl

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function particle2ply(coords::Matrix; output_file::String="coord.ply")
3131
coords = hcat(coords, zeros(size(coords, 1)))
3232
end
3333
# export .ply file by using trimesh
34-
mesh = trimesh[].Trimesh(vertices=coords)
34+
mesh = trimesh.Trimesh(vertices=coords)
3535
mesh.export(output_file)
3636
# print info
3737
@info """PLY file ($(size(coords, 1)) pts) saved at:
@@ -55,7 +55,7 @@ function particle2ply(
5555
output_file = joinpath(args.project_path, args.project_name, filename)
5656
coords = hcat(mp.ξ, zeros(mp.np))
5757
# export .ply file by using trimesh
58-
mesh = trimesh[].Trimesh(vertices=coords)
58+
mesh = trimesh.Trimesh(vertices=coords)
5959
mesh.export(output_file)
6060
# print info
6161
@info """PLY file ($(size(coords, 1)) pts) saved at:
@@ -78,7 +78,7 @@ function particle2ply(
7878
filename = args.project_name * ".ply"
7979
output_file = joinpath(args.project_path, args.project_name, filename)
8080
# export .ply file by using trimesh
81-
mesh = trimesh[].Trimesh(vertices=mp.ξ)
81+
mesh = trimesh.Trimesh(vertices=mp.ξ)
8282
mesh.export(output_file)
8383
# print info
8484
@info """PLY file ($(mp.np) pts) saved at:
@@ -114,7 +114,7 @@ function particle2ply(hdf5_file::String, ply_dir::String)
114114
end
115115
output_file = joinpath(ply_dir, "iteration_$(i).ply")
116116
# export .ply file by using trimesh
117-
mesh = trimesh[].Trimesh(vertices=obj)
117+
mesh = trimesh.Trimesh(vertices=obj)
118118
mesh.export(output_file)
119119
next!(p)
120120
end
@@ -127,7 +127,7 @@ end
127127

128128
"""
129129
ply2surface(ply_dir, splash_dir, radius, num_threads; cube_size=0.6,
130-
surface_threshold=0.6, smoothing_length=1.2)
130+
surface_threshold=0.6, smoothing_length=1.2, splashsurf="nothing")
131131
132132
Description:
133133
---
@@ -148,18 +148,49 @@ function ply2surface(
148148
splash_dir,
149149
radius,
150150
num_threads;
151-
cube_size =0.6,
152-
surface_threshold=0.6,
153-
smoothing_length =1.2
151+
cube_size = 0.6,
152+
surface_threshold = 0.6,
153+
smoothing_length = 1.2,
154+
splashsurf::String = "nothing"
154155
)
156+
if splashsurf == "nothing"
157+
try
158+
run(pipeline(`splashsurf -V`, stdout=devnull, stderr=devnull))
159+
catch e
160+
if isa(e, Base.IOError) # splashsurf 未安装
161+
@warn """splashsurf
162+
Cannot find splashsurf on this system. If you need surface reconstruction, please
163+
install it first, and make sure Julia can find it.
164+
Or you can pass the path of splashsurf to ply2surface.
165+
link: https://github.com/InteractiveComputerGraphics/splashsurf
166+
"""
167+
end
168+
end
169+
splashsurfcmd = "splashsurf"
170+
else
171+
try
172+
run(pipeline(`$(splashsurf) -V`, stdout=devnull, stderr=devnull))
173+
catch e
174+
if isa(e, Base.IOError) # splashsurf 未安装
175+
@warn """invalid splashsurf path
176+
Cannot find splashsurf on this system. If you need surface reconstruction, please
177+
install it first, and make sure Julia can find it.
178+
Or you can pass the path of splashsurf to ply2surface.
179+
link: https://github.com/InteractiveComputerGraphics/splashsurf
180+
"""
181+
end
182+
end
183+
splashsurfcmd = splashsurf
184+
end
185+
155186
num_threads = 1 num_threads Sys.CPU_THREADS ? num_threads : Sys.CPU_THREADS
156187
splash_dir ply_dir || throw(ArgumentError(
157188
"The splash output directory should be different from the ply input directory"))
158189
isdir(splash_dir) || mkpath(splash_dir)
159190
if isfile(ply_dir)
160191
inputs = ply_dir
161192
outputs = joinpath(splash_dir, "surface.vtk")
162-
run(`splashsurf reconstruct $(inputs) --output-file=$(outputs)
193+
run(`$(splashsurfcmd) reconstruct $(inputs) --output-file=$(outputs)
163194
--particle-radius=$(radius*1.5)
164195
--cube-size=$(cube_size)
165196
--surface-threshold=$(surface_threshold)
@@ -174,7 +205,7 @@ function ply2surface(
174205
elseif isdir(ply_dir)
175206
inputs = joinpath(ply_dir, "iteration_{}.ply")
176207
outputs = joinpath(splash_dir, "iteration_{}.vtk")
177-
run(`splashsurf reconstruct $(inputs) --output-file=$(outputs)
208+
run(`$(splashsurfcmd) reconstruct $(inputs) --output-file=$(outputs)
178209
--particle-radius=$(radius*1.5)
179210
--cube-size=$(cube_size)
180211
--surface-threshold=$(surface_threshold)

test/runtests.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using MaterialPointVisualizer
1+
using MaterialPointVisualizer
2+
using PythonCall
23
using Test
34

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

0 commit comments

Comments
 (0)