diff --git a/ep_surface_fit.py b/ep_surface_fit.py index 03934c9..ae1cc7c 100644 --- a/ep_surface_fit.py +++ b/ep_surface_fit.py @@ -1,5 +1,5 @@ #!/usr/bin/env python - +import itertools import os import sys from pathlib import Path @@ -34,6 +34,11 @@ formatter_class=ArgumentDefaultsHelpFormatter) parser.add_argument('--no-fail', dest='no_fail', action='store_true', help='Produce exit code 0 even if any subprocesses do not.') +parser.add_argument('--sw', type=int, default=200, help='stretch weight') +parser.add_argument('--lw', type=float, default=5e-6, help='laplacian weight') +parser.add_argument('--iter', type=int, default=600, help='iterations') + + parser.add_argument('-V', '--version', action='version', version=f'%(prog)s {__version__}') @@ -48,17 +53,26 @@ def main(options: Namespace, inputdir: Path, outputdir: Path): print(DISPLAY_TITLE, file=sys.stderr, flush=True) + params = [ + '-lw', + str(options.lw), + '-sw', + str(options.sw), + '-iter', + str(options.iter) + ] + nproc = len(os.sched_getaffinity(0)) logger.info('Using {} threads.', nproc) mapper = PathMapper.file_mapper(inputdir, outputdir, glob='**/*.obj', suffix='.obj') with ThreadPoolExecutor(max_workers=nproc) as pool: - results = pool.map(lambda t: run_surface_fit(*t), mapper) + results = pool.map(lambda t, p: run_surface_fit(*t, p), mapper, itertools.repeat(params)) if not options.no_fail and not all(results): sys.exit(1) -def run_surface_fit(surface: Path, output: Path) -> bool: +def run_surface_fit(surface: Path, output: Path, params: list[str]) -> bool: """ :return: True if successful """ @@ -67,7 +81,7 @@ def run_surface_fit(surface: Path, output: Path) -> bool: logger.error('No mask found for {}', surface) return False - cmd = ['surface_fit_script.pl', mask, surface, output] + cmd = ['surface_fit_script.pl', *params, mask, surface, output] log_file = output.with_name(output.name + '.log') logger.info('Starting: {}', ' '.join(map(str, cmd))) with log_file.open('wb') as log_handle: @@ -88,7 +102,13 @@ def locate_mask_for(surface: Path) -> Optional[Path]: mask = surface.with_name(name) if mask.exists(): return mask - return None + + glob = surface.parent.glob('*.mnc') + first = next(glob, None) + second = next(glob, None) + if second is not None: + return None + return first if __name__ == '__main__': diff --git a/setup.py b/setup.py index d441851..5b2dba9 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='ep_surface_fit', - version='0.0.1', + version='0.1.0', description='surface_fit wrapper', author='Jennings Zhang', author_email='Jennings.Zhang@childrens.harvard.edu', @@ -11,7 +11,6 @@ scripts=['surface_fit_script.pl'], install_requires=['chris_plugin'], license='MIT', - python_requires='>=3.10.5', entry_points={ 'console_scripts': [ 'ep_surface_fit = ep_surface_fit:main' diff --git a/surface_fit_script.pl b/surface_fit_script.pl index f233857..b71ac15 100755 --- a/surface_fit_script.pl +++ b/surface_fit_script.pl @@ -41,9 +41,14 @@ my $age = 0; my $no_downsize = 0; my $save_chamfer = undef; +my $given_sw = 200; +my $given_lw = 5e-6; +my $given_iter = 600; my @options = ( - # no options + ['-iter', 'integer', 1, \$given_iter, "iterations"], + ['-sw', 'integer', 1, \$given_sw, "stretch weight"], + ['-lw', 'float', 1, \$given_lw, "laplacian weight"], ); GetOptions( \@options, \@ARGV ) or exit 1; @@ -101,9 +106,9 @@ # t iterations of taubin smoothing after cycles of surface_fit my @schedule = ( -# size sw n_itr inc l_w iso si os iw self t chamfer_algo -# ----- --- ----- --- ---- --- ---- --- ---- ---- -- -------- - 81920, 30, 800, 50, 5e-6, 10, 0.20, 0.0, 1e0, 0.01, 0, $simple, +# size sw n_itr inc l_w iso si os iw self t chamfer_algo +# ----- --- ----- --- ---- --- ---- --- ---- ---- -- -------- + 81920, $given_sw, $given_iter, 50, $given_lw, 10, 0.20, 0.0, 1e0, 0.01, 0, $simple, ); # Do the fitting stages like gray surface expansion.