From bc9d9d8acbb44352cfc37a88336691f8efc12465 Mon Sep 17 00:00:00 2001 From: Michael McAuliffe Date: Sun, 28 Aug 2016 13:44:53 -0600 Subject: [PATCH 1/4] Fix for duplicate vertices in .obj importing --- menpo3d/io/input/mesh/base.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/menpo3d/io/input/mesh/base.py b/menpo3d/io/input/mesh/base.py index 8658358..c047b1b 100644 --- a/menpo3d/io/input/mesh/base.py +++ b/menpo3d/io/input/mesh/base.py @@ -189,12 +189,15 @@ def obj_importer(filepath, asset=None, texture_resolver=None, **kwargs): import vtk from vtk.util.numpy_support import vtk_to_numpy + cleaner = vtk.vtkCleanPolyData() + obj_importer = vtk.vtkOBJReader() obj_importer.SetFileName(str(filepath)) - obj_importer.Update() + cleaner.SetInputConnection(obj_importer.GetOutputPort()) + cleaner.Update() # Get the output - polydata = obj_importer.GetOutput() + polydata = cleaner.GetOutput() # We must have point data! points = vtk_to_numpy(polydata.GetPoints().GetData()).astype(np.float) From 7d0398c653a3a28c096794c08c8058d53b630282 Mon Sep 17 00:00:00 2001 From: Michael McAuliffe Date: Sun, 28 Aug 2016 13:55:03 -0600 Subject: [PATCH 2/4] Add tests for number of mesh points during import --- menpo3d/io/test/io_input_test.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/menpo3d/io/test/io_input_test.py b/menpo3d/io/test/io_input_test.py index 48a549a..f151cf2 100644 --- a/menpo3d/io/test/io_input_test.py +++ b/menpo3d/io/test/io_input_test.py @@ -37,11 +37,14 @@ def test_import_asset_james(): mesh = mio.import_builtin_asset('james.obj') assert(isinstance(mesh, TexturedTriMesh)) assert(isinstance(mesh.points, np.ndarray)) + assert(mesh.points.shape[0] == 34913) assert(mesh.points.shape[1] == 3) assert(isinstance(mesh.trilist, np.ndarray)) + assert(mesh.trilist.shape[0] == 68486) assert(mesh.trilist.shape[1] == 3) assert(isinstance(mesh.texture, Image)) assert(isinstance(mesh.tcoords, PointCloud)) + assert(mesh.tcoords.points.shape[0] == 34913) assert(mesh.tcoords.points.shape[1] == 2) From 20983fcc1d7fcf71363ec4cb14afda3c42ddad6b Mon Sep 17 00:00:00 2001 From: Michael McAuliffe Date: Sun, 28 Aug 2016 15:45:08 -0600 Subject: [PATCH 3/4] Fix name of VTK method for triangle filter --- menpo3d/io/input/mesh/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/menpo3d/io/input/mesh/base.py b/menpo3d/io/input/mesh/base.py index c047b1b..b376a86 100644 --- a/menpo3d/io/input/mesh/base.py +++ b/menpo3d/io/input/mesh/base.py @@ -74,7 +74,7 @@ def vtk_ensure_trilist(polydata): 'connectivity is being coerced into a triangular ' 'mesh. This may have unintended consequences.') t_filter = vtk.vtkTriangleFilter() - t_filter.SetInput(polydata) + t_filter.SetInputData(polydata) t_filter.Update() trilist = vtk_to_numpy(t_filter.GetOutput().GetPolys().GetData()) From 28f3685b36b15e945e90ecbab9c6f4e6ecf8860a Mon Sep 17 00:00:00 2001 From: Michael McAuliffe Date: Mon, 29 Aug 2016 10:16:20 -0600 Subject: [PATCH 4/4] Add test for ordering of points and triangles --- menpo3d/io/test/io_input_test.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/menpo3d/io/test/io_input_test.py b/menpo3d/io/test/io_input_test.py index f151cf2..b823e09 100644 --- a/menpo3d/io/test/io_input_test.py +++ b/menpo3d/io/test/io_input_test.py @@ -32,16 +32,26 @@ def test_import_asset_bunny(): assert(isinstance(mesh.trilist, np.ndarray)) assert(mesh.trilist.shape[1] == 3) - def test_import_asset_james(): mesh = mio.import_builtin_asset('james.obj') assert(isinstance(mesh, TexturedTriMesh)) assert(isinstance(mesh.points, np.ndarray)) assert(mesh.points.shape[0] == 34913) assert(mesh.points.shape[1] == 3) + assert(np.sum(np.abs(mesh.points[0] - np.array([-26.118378, -28.308096, 22.519226]))) < 0.0001) + assert(np.sum(np.abs(mesh.points[10] - np.array([-20.797331, -118.940681, -38.822590]))) < 0.0001) + + assert(np.sum(np.abs(mesh.points[-1] - np.array([95.002327, -141.065002, -169.500397]))) < 0.0001) + assert(np.sum(np.abs(mesh.points[-10] - np.array([104.967415, -174.204849, -131.351486]))) < 0.0001) + assert(isinstance(mesh.trilist, np.ndarray)) assert(mesh.trilist.shape[0] == 68486) assert(mesh.trilist.shape[1] == 3) + assert((mesh.trilist[0] == (np.array([1, 2, 3]) - 1)).all()) # -1 to correct for 0 indexing in Python + assert((mesh.trilist[10] == (np.array([21, 22, 23]) - 1)).all()) + + assert((mesh.trilist[-1] == (np.array([33867, 33866, 32605]) - 1)).all()) + assert((mesh.trilist[-10] == (np.array([31365, 18442, 7867]) - 1)).all()) assert(isinstance(mesh.texture, Image)) assert(isinstance(mesh.tcoords, PointCloud)) assert(mesh.tcoords.points.shape[0] == 34913)