[MINC-users] Side-specific behaviour of subdivide_polygons
Claude LEPAGE
claude at bic.mni.mcgill.ca
Fri Nov 17 17:46:23 EST 2017
The two cases are different. When subdividing a "right" surface,
the polygons will be oriented in the opposite direction than left.
General rule: always re-orient the surface as a "left" surface
before subdividing.
Also, the sphere that comes out from create_tetra is "left" oriented.
Here is my PERL wrapper for this:
# subdivide a surface taking into account if it's a left or right hemisphere.
sub subdivide_mesh {
my $input = shift;
my $npoly = shift;
my $output = shift;
my $npoly_input = `print_n_polygons $input`;
chomp( $npoly_input );
if( !CheckFlipOrientation( $input ) ) {
&run( "subdivide_polygons", $input, $output, $npoly );
} else {
# flip right as left first before subdividing, then flip back.
&run( "param2xfm", '-clobber', '-scales', -1, 1, 1,
"${tmpdir}/flip.xfm" );
my $input_flipped = "${tmpdir}/right_flipped.obj";
&run( "transform_objects", $input,
"${tmpdir}/flip.xfm", $input_flipped );
&run( "subdivide_polygons", $input_flipped, $output, $npoly );
&run( "transform_objects", $output,
"${tmpdir}/flip.xfm", $output ); # flip.xfm is its own inverse
unlink( $input_flipped );
unlink( "${tmpdir}/flip.xfm" );
}
}
# Check if the input surface has the same side orientation (left)
# as the default template model.
sub CheckFlipOrientation {
my $obj = shift;
my $npoly = `print_n_polygons $obj`;
chomp( $npoly );
my $ret = `tail -5 $obj`;
my @verts = split( ' ', $ret );
my @last3 = ( $verts[$#verts-2], $verts[$#verts-1], $verts[$#verts] );
my $dummy_sphere = "${tmpdir}/dummy_sphere.obj";
&run('create_tetra',$dummy_sphere,0,0,0,1,1,1,$npoly);
$ret = `tail -5 $dummy_sphere`;
unlink( $dummy_sphere );
@verts = split( ' ', $ret );
my @sphere3 = ( $verts[$#verts-2], $verts[$#verts-1], $verts[$#verts] );
if( $last3[0] == $verts[$#verts-2] &&
$last3[1] == $verts[$#verts-1] &&
$last3[2] == $verts[$#verts-0] ) {
return 0;
} else {
return 1;
}
}
>
> Hi all,
>
> I was wondering if someone could explain if there are meaningful
> differences between the following two operations:
>
> $ subdivide_polygons lowres_left.obj highres_left.obj
> $ transform_objects highres_left.obj xflip.xfm highres_right_0.obj
> vs
> $ transform_objects lowres_left.obj xflip.xfm lowres_right.obj
> $ subdivide_polygons lowres_right.obj highres_right_1.obj
>
> Flipping then subdividing yields different results from subdividing then
> flipping:
>
> $ diff -q highres_right_0.obj highres_right_1.obj
> Files highres_right_0.obj and highres_right_1.obj differ
>
> I get the impression that the set of vertices is equivalent between the two
> hires surfaces, but there connectivity is somehow different.
>
> Thanks,
> Andrew
> _______________________________________________
> MINC-users at bic.mni.mcgill.ca
> http://www.bic.mni.mcgill.ca/mailman/listinfo/minc-users
>
More information about the MINC-users
mailing list