From e9ac84b77ca80813cd22cc2017c59e13015b3223 Mon Sep 17 00:00:00 2001 From: "Josh Warner (Mac)" Date: Thu, 13 Mar 2014 23:34:46 -0500 Subject: [PATCH] TST: Add unit test for mesh orientation correction. --- skimage/measure/tests/test_marching_cubes.py | 23 +++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/skimage/measure/tests/test_marching_cubes.py b/skimage/measure/tests/test_marching_cubes.py index b3c2ddc1..60adbb0d 100644 --- a/skimage/measure/tests/test_marching_cubes.py +++ b/skimage/measure/tests/test_marching_cubes.py @@ -2,7 +2,8 @@ import numpy as np from numpy.testing import assert_raises from skimage.draw import ellipsoid, ellipsoid_stats -from skimage.measure import marching_cubes, mesh_surface_area +from skimage.measure import (marching_cubes, mesh_surface_area, + correct_mesh_orientation) def test_marching_cubes_isotropic(): @@ -36,5 +37,25 @@ def test_invalid_input(): assert_raises(ValueError, marching_cubes, np.zeros((20, 20)), 0) +def test_correct_mesh_orientation(): + sphere_small = ellipsoid(1, 1, 1, levelset=True) + verts, faces = marching_cubes(sphere_small, 0.) + + # Correct mesh orientation - descent + corrected_faces1 = correct_mesh_orientation(sphere_small, verts, faces, + gradient_direction='descent') + corrected_faces2 = correct_mesh_orientation(sphere_small, verts, faces, + gradient_direction='ascent') + + # Ensure ascent is opposite of descent for all faces + np.testing.assert_array_equal(corrected_faces1, corrected_faces2[:, ::-1]) + + # Ensure correct faces have been reversed: 1, 4, and 5 + idx = [1, 4, 5] + expected = faces.copy() + expected[idx] = expected[idx, ::-1] + np.testing.assert_array_equal(expected, corrected_faces1) + + if __name__ == '__main__': np.testing.run_module_suite()