|
7 | 7 | from pathlib import Path |
8 | 8 | from utils import get_bounding_box |
9 | 9 | import fastremap |
| 10 | +import sys |
| 11 | +import shutil |
| 12 | +import itertools |
10 | 13 |
|
11 | 14 | from pyvista.core import _vtk_core as _vtk |
12 | 15 | from pyvista.core.filters import _get_output, _update_alg |
@@ -126,19 +129,24 @@ def extract_cell_meshes( |
126 | 129 | global grid |
127 | 130 | padded = np.pad(img, 1) |
128 | 131 | grid = pv.ImageData(dimensions=padded.shape, spacing=resolution, origin=(0, 0, 0)) |
129 | | - os.system(f"rm -rf {write_dir}/*") |
130 | | - os.system(f"mkdir -p {write_dir}") |
131 | | - import multiprocessing |
132 | | - from multiprocessing import Pool |
133 | | - try: |
134 | | - multiprocessing.set_start_method("fork") # wont work on windows |
135 | | - except ValueError: pass |
136 | | - with Pool(ncpus) as pool: |
137 | | - args = [(obj_id, mesh_reduction_factor, taubin_smooth_iter, |
| 132 | + |
| 133 | + write_path = Path(write_dir) |
| 134 | + if write_path.exists(): |
| 135 | + shutil.rmtree(write_path) |
| 136 | + write_path.mkdir(parents=True, exist_ok=True) |
| 137 | + |
| 138 | + args = [(obj_id, mesh_reduction_factor, taubin_smooth_iter, |
138 | 139 | f"{write_dir}/{obj_id}.ply") for obj_id in cell_labels] |
139 | | - surfaces = pool.starmap(extract_surf_id, args) |
140 | | - pool.close() |
141 | | - pool.join() |
| 140 | + |
| 141 | + if sys.platform != "win32": |
| 142 | + import multiprocessing |
| 143 | + multiprocessing.set_start_method("fork") |
| 144 | + with multiprocessing.Pool(ncpus) as pool: |
| 145 | + surfaces = pool.starmap(extract_surf_id, args) |
| 146 | + pool.close() |
| 147 | + pool.join() |
| 148 | + else: |
| 149 | + surfaces = list(itertools.starmap(extract_surf_id, args)) |
142 | 150 | return surfaces |
143 | 151 |
|
144 | 152 | def create_balanced_csg_tree(surface_files): |
|
0 commit comments