Skip to content

Commit 98481ea

Browse files
committed
Delay VTK import to mitigate import failure on Linux w/o X11.
1 parent 965cd4c commit 98481ea

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

genesis/utils/particle.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import igl
99
import numpy as np
1010
import trimesh
11-
import vtk
12-
from vtk.util.numpy_support import vtk_to_numpy
1311

1412
import genesis as gs
1513

@@ -117,6 +115,10 @@ def trimesh_to_particles_pbs(mesh, p_size, sampler, pos=(0, 0, 0)):
117115
mesh.export(mesh_path)
118116

119117
try:
118+
# Try importing VTK. It would fail on Linux if not graphic server is running.
119+
import vtk
120+
from vtk.util.numpy_support import vtk_to_numpy
121+
120122
# Sample particles
121123
command = (
122124
os.path.join(miu.get_src_dir(), "ext/VolumeSampling"),
@@ -147,7 +149,7 @@ def trimesh_to_particles_pbs(mesh, p_size, sampler, pos=(0, 0, 0)):
147149
reader.SetFileName(vtk_path)
148150
reader.Update()
149151
positions = vtk_to_numpy(reader.GetOutput().GetPoints().GetData())
150-
except OSError as e:
152+
except (OSError, ImportError) as e:
151153
gs.raise_exception_from("`pbs` sampler failed.", e)
152154
finally:
153155
os.remove(mesh_path)

0 commit comments

Comments
 (0)