Skip to content

Commit 8f6eccb

Browse files
committed
Refactored get_uniquefn
Rationale for why it is implemented like this is lost in time, lets simplify it.
1 parent 0d579dd commit 8f6eccb

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/core.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import random
12
from pathlib import Path
23

34
import PIL.Image
@@ -273,8 +274,7 @@ def core_generation_funnel(outpath, inputimages, inputdepthmaps, inputnames, inp
273274
if inp[go.GEN_SIMPLE_MESH]:
274275
print(f"\nGenerating (occluded) mesh ..")
275276
basename = 'depthmap'
276-
meshsimple_fi = get_uniquefn(outpath, basename, 'obj')
277-
meshsimple_fi = os.path.join(outpath, meshsimple_fi + '_simple.obj')
277+
meshsimple_fi = get_uniquefn(outpath, basename, 'obj', 'simple')
278278

279279
depthi = raw_prediction if raw_prediction is not None else out
280280
depthi_min, depthi_max = depthi.min(), depthi.max()
@@ -346,18 +346,17 @@ def core_generation_funnel(outpath, inputimages, inputdepthmaps, inputnames, inp
346346
print("All done.\n")
347347

348348

349-
def get_uniquefn(outpath, basename, ext):
349+
def get_uniquefn(outpath, basename, ext, suffix=''):
350350
basecount = backbone.get_next_sequence_number(outpath, basename)
351-
if basecount > 0: basecount = basecount - 1
352-
fullfn = None
351+
if basecount > 0:
352+
basecount -= 1
353+
if suffix != '':
354+
suffix = f'-{suffix}' # Dash is important for selecting unique filenames (see get_next_sequence_number)
353355
for i in range(500):
354-
fn = f"{basecount + i:05}" if basename == '' else f"{basename}-{basecount + i:04}"
355-
fullfn = os.path.join(outpath, f"{fn}.{ext}")
356+
fullfn = os.path.join(outpath, f"{basename}-{basecount + i:04}{suffix}.{ext}")
356357
if not os.path.exists(fullfn):
357-
break
358-
basename = Path(fullfn).stem
359-
360-
return basename
358+
return fullfn
359+
return f"{basename}-99999{suffix}.{ext}" # Failback, should never be executed
361360

362361

363362
def run_3dphoto(device, img_rgb, img_depth, inputnames, outpath, gen_inpainted_mesh_demos, vid_ssaa, vid_format):
@@ -428,8 +427,7 @@ def run_3dphoto(device, img_rgb, img_depth, inputnames, outpath, gen_inpainted_m
428427
p = Path(inputnames[count])
429428
basename = p.stem
430429

431-
basename = get_uniquefn(outpath, basename, 'obj')
432-
mesh_fi = os.path.join(outpath, basename + '.obj')
430+
mesh_fi = get_uniquefn(outpath, basename, 'obj')
433431

434432
print(f"\nGenerating inpainted mesh .. (go make some coffee) ..")
435433

0 commit comments

Comments
 (0)