Skip to content

Commit d298705

Browse files
committed
fix hex-mesh stats computation
in `generate_stats_table` algo
1 parent 90a9474 commit d298705

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

definitions/algorithms/batch_processing.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ def process_labeling(labeling_object: DataFolder):
136136
"""
137137
assert(labeling_object.type == 'labeling')
138138
# hex-mesh extraction if not already done
139+
# but only if the labeling is valid
140+
if not labeling_object.has_valid_labeling(): # type: ignore | see ../data_folder_types/labeling.accessors.py
141+
log.debug(f"Don't call 'polycube_withHexEx' on {labeling_object.path} because the labeling is invalid")
142+
return
139143
if not (labeling_object.path / 'polycube_withHexEx_1.3').exists():
140144
if user_confirmed_or_choose_autorun(POLYCUBE_WITHHEXEX_OUTPUT_MISSING_POLICY,MISSING_OUTPUT_LINE_TEMPLATE.format(algo='polycube_withHexEx', path=collapseuser(labeling_object.path))):
141145
with CONSOLE.status(RUNNING_ALGO_LINE_TEMPLATE.format(algo='polycube_withHexEx', path=collapseuser(labeling_object.path))) as status:

definitions/algorithms/generate_stats_table.py

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python
22

33
from collections import defaultdict
4+
from shutil import rmtree
5+
from rich.prompt import Confirm
46

57
from dds import *
68

@@ -124,20 +126,22 @@ def parse_Evocube_output(dataset_id: int, tet_folder: DataFolder):
124126

125127
# if there is a hex-mesh in the labeling folder, instantiate it and retrieve mesh stats
126128
hexmesh_minSJ = None
127-
if (labeling_folder.path / 'polycube_withHexEx_1.3/global_padding/inner_smoothing_50').exists():
128-
hex_mesh_folder: DataFolder = DataFolder(labeling_folder.path / 'polycube_withHexEx_1.3/global_padding/inner_smoothing_50')
129+
post_processed_hex_mesh_path = labeling_folder.path / 'polycube_withHexEx_1.3' / 'global_padding' / 'inner_smoothing_50'
130+
if post_processed_hex_mesh_path.exists():
131+
hex_mesh_folder: DataFolder = DataFolder(post_processed_hex_mesh_path)
129132
hex_mesh_stats: dict = hex_mesh_folder.get_mesh_stats_dict() # type: ignore | see ../data_folder_types/hex-mesh.accessors.py
130133
if 'quality' in hex_mesh_stats['cells']:
131134
avg_sj_sum[dataset_id,EVOCUBE] += hex_mesh_stats['cells']['quality']['hex_SJ']['avg']
132135
hexmesh_minSJ = hex_mesh_stats['cells']['quality']['hex_SJ']['min']
133136
min_sj_sum[dataset_id,EVOCUBE] += hexmesh_minSJ
134-
else:
135-
# HexEx failed, no cells in output file
136-
avg_sj_sum[dataset_id,EVOCUBE] += -1.0 # assume worse value
137-
min_sj_sum[dataset_id,EVOCUBE] += -1.0 # assume worse value
138137

139138
# update the counters
140139
if not labeling_folder.has_valid_labeling(): # type: ignore | see ../data_folder_types/labeling.accessors.py
140+
if (labeling_folder.path / 'polycube_withHexEx_1.3').exists():
141+
if Confirm(f"There is a 'polycube_withHexEx' output inside {labeling_folder.path}, but the labeling is invalid. Remove this hex-mesh folder?"):
142+
rmtree(labeling_folder.path / 'polycube_withHexEx_1.3')
143+
assert(not post_processed_hex_mesh_path.exists())
144+
assert(hexmesh_minSJ is None)
141145
fluxes[dataset_id,EVOCUBE,TET_MESHING_SUCCESS,LABELING_INVALID] += 1
142146
elif labeling_folder.nb_turning_points() != 0: # type: ignore | see ../data_folder_types/labeling.accessors.py
143147
fluxes[dataset_id,EVOCUBE,TET_MESHING_SUCCESS,LABELING_NON_MONOTONE] += 1
@@ -150,6 +154,9 @@ def parse_Evocube_output(dataset_id: int, tet_folder: DataFolder):
150154
else:
151155
# no hex-mesh
152156
fluxes[dataset_id,EVOCUBE,LABELING_NON_MONOTONE,HEX_MESHING_FAILURE] += 1
157+
# also penalize minSJ & avgSJ sums
158+
avg_sj_sum[dataset_id,EVOCUBE] += -1.0 # assume worse value
159+
min_sj_sum[dataset_id,EVOCUBE] += -1.0 # assume worse value
153160
else:
154161
fluxes[dataset_id,EVOCUBE,TET_MESHING_SUCCESS,LABELING_SUCCESS] += 1
155162
if hexmesh_minSJ is not None:
@@ -161,6 +168,9 @@ def parse_Evocube_output(dataset_id: int, tet_folder: DataFolder):
161168
else:
162169
# no hex-mesh
163170
fluxes[dataset_id,EVOCUBE,LABELING_SUCCESS,HEX_MESHING_FAILURE] += 1
171+
# also penalize minSJ & avgSJ sums
172+
avg_sj_sum[dataset_id,EVOCUBE] += -1.0 # assume worse value
173+
min_sj_sum[dataset_id,EVOCUBE] += -1.0 # assume worse value
164174

165175
def parse_Ours_2024_03_output(dataset_id: int, tet_folder: DataFolder):
166176
labeling_subfolders_generated_by_ours: list[Path] = tet_folder.get_subfolders_generated_by('automatic_polycube')
@@ -195,6 +205,9 @@ def parse_Ours_2024_03_output(dataset_id: int, tet_folder: DataFolder):
195205

196206
# update the counters
197207
if not labeling_folder.has_valid_labeling(): # type: ignore | see ../data_folder_types/labeling.accessors.py
208+
if (labeling_folder.path / 'polycube_withHexEx_1.3').exists():
209+
if Confirm(f"There is a 'polycube_withHexEx' output inside {labeling_folder.path}, but the labeling is invalid. Remove this hex-mesh folder?"):
210+
rmtree(labeling_folder.path / 'polycube_withHexEx_1.3')
198211
fluxes[dataset_id,OURS_2024_03,TET_MESHING_SUCCESS,LABELING_INVALID] += 1
199212
elif labeling_folder.nb_turning_points() != 0: # type: ignore | see ../data_folder_types/labeling.accessors.py
200213
fluxes[dataset_id,OURS_2024_03,TET_MESHING_SUCCESS,LABELING_NON_MONOTONE] += 1
@@ -274,20 +287,22 @@ def parse_Ours_2024_09(dataset_id: int, tet_mesh: DataFolder): # with parsing of
274287

275288
# if there is a hex-mesh in the labeling folder, instantiate it and retrieve mesh stats
276289
hexmesh_minSJ = None
277-
if (labeling_ours_folder.path / 'polycube_withHexEx_1.3/global_padding/inner_smoothing_50').exists():
278-
hex_mesh_folder: DataFolder = DataFolder(labeling_ours_folder.path / 'polycube_withHexEx_1.3/global_padding/inner_smoothing_50')
290+
post_processed_hex_mesh_path = labeling_ours_folder.path / 'polycube_withHexEx_1.3' / 'global_padding' / 'inner_smoothing_50'
291+
if post_processed_hex_mesh_path.exists():
292+
hex_mesh_folder: DataFolder = DataFolder(post_processed_hex_mesh_path)
279293
hex_mesh_stats: dict = hex_mesh_folder.get_mesh_stats_dict() # type: ignore | see ../data_folder_types/hex-mesh.accessors.py
280294
if 'quality' in hex_mesh_stats['cells']:
281295
avg_sj_sum[dataset_id,OURS_2024_09] += hex_mesh_stats['cells']['quality']['hex_SJ']['avg']
282296
hexmesh_minSJ = hex_mesh_stats['cells']['quality']['hex_SJ']['min']
283297
min_sj_sum[dataset_id,OURS_2024_09] += hexmesh_minSJ
284-
else:
285-
# HexEx failed, no cells in output file
286-
avg_sj_sum[dataset_id,OURS_2024_09] += -1.0 # assume worse value
287-
min_sj_sum[dataset_id,OURS_2024_09] += -1.0 # assume worse value
288298

289299
# update the counters
290300
if not labeling_ours_folder.has_valid_labeling(): # type: ignore | see ../data_folder_types/labeling.accessors.py
301+
if (labeling_ours_folder.path / 'polycube_withHexEx_1.3').exists():
302+
if Confirm(f"There is a 'polycube_withHexEx' output inside {labeling_ours_folder.path}, but the labeling is invalid. Remove this hex-mesh folder?"):
303+
rmtree(labeling_ours_folder.path / 'polycube_withHexEx_1.3')
304+
assert(not post_processed_hex_mesh_path.exists())
305+
assert(hexmesh_minSJ is None)
291306
fluxes[dataset_id,OURS_2024_09,INIT_LABELING_SUCCESS,LABELING_INVALID] += 1
292307
elif labeling_ours_folder.nb_turning_points() != 0: # type: ignore | see ../data_folder_types/labeling.accessors.py
293308
fluxes[dataset_id,OURS_2024_09,INIT_LABELING_SUCCESS,LABELING_NON_MONOTONE] += 1
@@ -300,6 +315,9 @@ def parse_Ours_2024_09(dataset_id: int, tet_mesh: DataFolder): # with parsing of
300315
else:
301316
# no hex-mesh
302317
fluxes[dataset_id,OURS_2024_09,LABELING_NON_MONOTONE,HEX_MESHING_FAILURE] += 1
318+
# also penalize minSJ & avgSJ sums
319+
avg_sj_sum[dataset_id,OURS_2024_09] += -1.0 # assume worse value
320+
min_sj_sum[dataset_id,OURS_2024_09] += -1.0 # assume worse value
303321
else:
304322
# so we have a valid labeling with no turning-points
305323
fluxes[dataset_id,OURS_2024_09,INIT_LABELING_SUCCESS,LABELING_SUCCESS] += 1
@@ -312,6 +330,9 @@ def parse_Ours_2024_09(dataset_id: int, tet_mesh: DataFolder): # with parsing of
312330
else:
313331
# no hex-mesh
314332
fluxes[dataset_id,OURS_2024_09,LABELING_SUCCESS,HEX_MESHING_FAILURE] += 1
333+
# also penalize minSJ & avgSJ sums
334+
avg_sj_sum[dataset_id,OURS_2024_09] += -1.0 # assume worse value
335+
min_sj_sum[dataset_id,OURS_2024_09] += -1.0 # assume worse value
315336

316337
def parse_PolyCut_output(dataset_id: int, tet_folder: DataFolder):
317338
if not (tet_folder.path / 'PolyCut_3').exists() or not (tet_folder.path / 'PolyCut_3' / surface_labeling_filename).exists():
@@ -337,9 +358,12 @@ def parse_PolyCut_output(dataset_id: int, tet_folder: DataFolder):
337358
# update duration sum
338359
labeling_duration[dataset_id,POLYCUT] += polycut_durations['polycut'] # should we take into account the duration of cusy2.exe, which is the executable writing the labeling?
339360

340-
# if there is a hex-mesh in the labeling folder, instantiate it and retrieve mesh stats
341361
hexmesh_minSJ = None
342-
if (labeling_folder.path / 'optimizer_100' / 'untangler' / hex_mesh_filename).exists():
362+
if not labeling_folder.has_valid_labeling(): # type: ignore | see ../data_folder_types/labeling.accessors.py
363+
# ignore the potential hex-mesh. Same policy as Evocube & Ours : invalid labeling -> no hex-mesh generation
364+
pass
365+
# if there is a hex-mesh in the labeling folder, instantiate it and retrieve mesh stats
366+
elif (labeling_folder.path / 'optimizer_100' / 'untangler' / hex_mesh_filename).exists():
343367
hex_mesh_folder: DataFolder = DataFolder(labeling_folder.path / 'optimizer_100' / 'untangler')
344368
hex_mesh_stats: dict = dict()
345369
try:
@@ -379,6 +403,7 @@ def parse_PolyCut_output(dataset_id: int, tet_folder: DataFolder):
379403

380404
# update the counters
381405
if not labeling_folder.has_valid_labeling(): # type: ignore | see ../data_folder_types/labeling.accessors.py
406+
assert(hexmesh_minSJ is None)
382407
fluxes[dataset_id,POLYCUT,COARSER_TET_MESHING_SUCCESS,LABELING_INVALID] += 1
383408
elif labeling_folder.nb_turning_points() != 0: # type: ignore | see ../data_folder_types/labeling.accessors.py
384409
fluxes[dataset_id,POLYCUT,COARSER_TET_MESHING_SUCCESS,LABELING_NON_MONOTONE] += 1

0 commit comments

Comments
 (0)