Skip to content

Commit

Permalink
Add inflate_to_sphere_implicit
Browse files Browse the repository at this point in the history
  • Loading branch information
jennydaman committed Jun 3, 2022
1 parent a63f59a commit 1e42441
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
23 changes: 18 additions & 5 deletions civet/extraction/surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,28 @@ class IrregularSurface(GenericSurface[_IS], Generic[_IS]):
"""
Represents a mesh (`.obj`) with irregular connectivity.
"""
def interpolate_with_sphere(self, side: Optional[Side] = None) -> RegularSurface:
def interpolate_with_sphere(
self,
side: Optional[Side] = None,
n_inflate: Optional[int] = None,
n_smooth: Optional[int] = None
) -> RegularSurface:
"""
Resample this surface to have a standard number of 81,920 triangles.
If `n_inflate` and `n_smooth` are given, use `inflate_to_sphere_implicit` instead
of `inflate_to_sphere`.
"""
options = []
if side is not None:
options += ['-' + side.value]
if (n_inflate is None) ^ (n_smooth is None):
raise ValueError('both n_inflate and n_smooth must be specified')
if n_inflate is not None and n_smooth is not None:
options += ['-inflate', str(n_inflate), str(n_smooth)]

class InterpolatedFromSphere(RegularSurface):
def command(self, output: str | PathLike
) -> Sequence[str | PathLike | AbstractDataCommand]:
side_option = []
if side is not None:
side_option = ['-' + side.value]
return 'interpolate_surface_with_sphere.pl', *side_option, self.input, output
return 'interpolate_surface_with_sphere.pl', *options, self.input, output
return InterpolatedFromSphere(self)
21 changes: 17 additions & 4 deletions scripts/interpolate_surface_with_sphere.pl
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/usr/bin/env perl
# copied from
# https://github.com/aces/surface-extraction/blob/master/scripts/marching_cubes.pl.in

# For the most part, this was adapted from
# https://github.com/aces/surface-extraction/blob/7c9c5987a2f8f5fdeb8d3fd15f2f9b636401d9a1/scripts/marching_cubes.pl.in
#
# o 2022-05-06
# Replaced `inflate_to_sphere` with `inflate_to_sphere_implicit`


use strict;
use warnings "all";
Expand All @@ -17,16 +22,18 @@
LICENSE

my $usage = <<USAGE;
Usage: $ProgramName [-left|-right] surface_unknown.obj surface_81920.obj
Usage: $ProgramName [-left|-right] [-inflate 2000 2000] surface_unknown.obj surface_81920.obj
$license
USAGE


my $side = undef;
my @inflate_args = undef;
my @options = (
['-left', 'const', "Left", \$side, "Surface is a left surface"],
['-right', 'const', "Right", \$side, "Surface is a right surface (sphere should be flipped)"],
['-inflate', 'integer', 2, \@inflate_args, "Use inflate_to_sphere_implicit instead of inflate_to_sphere, and pass the given arguments to it."]
);

GetOptions( \@options, \@ARGV ) or exit 1;
Expand All @@ -49,7 +56,13 @@
# Inflate the white surface onto a unit sphere.

my $white_sphere_sm = "${tmpdir}/white_sphere_sm.obj";
&run( 'inflate_to_sphere', $white_surface_sm, $white_sphere_sm );

if ( @inflate_args ) {
&run( 'inflate_to_sphere_implicit', $white_surface_sm, $white_sphere_sm, $inflate_args[0], $inflate_args[1] );
}
else {
&run( 'inflate_to_sphere', $white_surface_sm, $white_sphere_sm );
}

# Interpolate from sphere-to-sphere to resample the white surface
# using the 40962 vertices on the standard ICBM surface average
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setup(
name='pycivet',
version='0.0.8.post1',
version='0.0.9',
description='Object-oriented CIVET bindings for Python',
long_description=readme,
long_description_content_type='text/markdown',
Expand Down

0 comments on commit 1e42441

Please sign in to comment.