Example #1
0
def test_regularize():
    vertices = _generate_vertices(5)
    mesh = triangle_mesh.TriangleMesh(vertices, POST_SPLIT_FACES)

    mesh.regularize()

    assert np.all(mesh._valences <= 6)
Example #2
0
def test_missing_halfedges():

    k3_vertices = _generate_vertices(3)
    mesh = triangle_mesh.TriangleMesh(k3_vertices, K3_FACES)

    assert _test_topology(mesh, K3_H_VERTEX, K3_H_FACE, K3_H_TWIN, K3_H_NEXT,
                          K3_H_PREV)
Example #3
0
def test_resize():

    k4_vertices = _generate_vertices(4)
    mesh = triangle_mesh.TriangleMesh(k4_vertices, K4_FACES)

    # Test a vector
    size = 10
    test_vec = np.zeros(size)
    test_vec = mesh._resize(test_vec)
    test_vec_true = np.all(test_vec[:size] == 0) & np.all(
        test_vec[size:] == -1)

    test_vec = np.zeros(size)
    test_vec[7:9] = -1
    test_vec_2 = mesh._resize(test_vec)
    test_vec_true_2 = np.all(test_vec_2[:size] == test_vec) & np.all(
        test_vec[size:] == -1)

    # Test a 2D array along axis 0
    _vertices = mesh._vertices['position']
    _vertices = mesh._resize(_vertices)
    ax0_true = np.all(_vertices[0:4] == mesh.vertices) & np.all(
        _vertices[4:] == -1)

    _vertices = mesh._vertices['position']
    _vertices = mesh._resize(_vertices, axis=1)
    ax1_true = np.all(_vertices[:, 0:3] == mesh.vertices) & np.all(
        _vertices[:, 3:] == -1)

    assert (test_vec_true & test_vec_true_2 & ax0_true & ax1_true)
Example #4
0
def test_double_edge_flip_topology():
    vertices = _generate_vertices(4)
    mesh = triangle_mesh.TriangleMesh(vertices, PRE_FLIP_FACES)

    flip_idx = np.where((mesh._h_vertex == 3) & (mesh._h_face == 0))[0][0]

    mesh.edge_flip(flip_idx)

    flip_idx = np.where((mesh._h_vertex == 2) & (mesh._h_face == 1))[0][0]

    mesh.edge_flip(flip_idx)

    # flip_idx = np.where((mesh._h_vertex == 0) & (mesh._h_face == 0))[0][0]

    # mesh.edge_flip(flip_idx)

    # flip_idx = np.where((mesh._h_vertex == 1) & (mesh._h_face == 0))[0][0]

    # mesh.edge_flip(flip_idx)

    # flip_idx = np.where((mesh._h_vertex == 2) & (mesh._h_face == 0))[0][0]

    # mesh.edge_flip(flip_idx)

    assert _test_topology(mesh, PRE_FLIP_H_VERTEX, PRE_FLIP_H_FACE,
                          PRE_FLIP_H_TWIN, PRE_FLIP_H_NEXT, PRE_FLIP_H_PREV)
Example #5
0
def test_get_halfedges():

    k4_vertices = _generate_vertices(4)
    mesh = triangle_mesh.TriangleMesh(k4_vertices, K4_FACES)

    assert _test_topology(mesh, K4_H_VERTEX, K4_H_FACE, K4_H_TWIN, K4_H_NEXT,
                          K4_H_PREV)
Example #6
0
def test_euler_characteristic():

    k4_vertices = _generate_vertices(4)
    mesh = triangle_mesh.TriangleMesh(k4_vertices, K4_FACES)

    assert ((len(mesh.vertices) - len(mesh._halfedges['vertex']) / 2. +
             len(mesh._faces)) == 2)
Example #7
0
def test_edge_split_normals():
    vertices = _generate_vertices(4)
    mesh = triangle_mesh.TriangleMesh(vertices, PRE_SPLIT_FACES)

    split_idx = np.where((mesh._h_vertex == 3) & (mesh._h_face == 0))[0][0]

    mesh.edge_split(split_idx)

    assert _test_normals(mesh)
Example #8
0
def test_edge_collapse_normals():
    vertices = _generate_vertices(4)
    mesh = triangle_mesh.TriangleMesh(vertices, K4_FACES)

    collapse_idx = np.where((mesh._h_vertex == 2) & (mesh._h_face == 1))[0][0]

    mesh.edge_collapse(collapse_idx)

    assert _test_normals(mesh)
Example #9
0
def test_vertex_neighbors():

    k4_vertices = _generate_vertices(4)
    mesh = triangle_mesh.TriangleMesh(k4_vertices, K4_FACES, 6)

    assert np.all(
        np.sort(mesh._h_vertex[
            mesh.vertex_neighbors[:, :K4_NEIGHBORS.shape[1]]],
                axis=1) == np.sort(K4_NEIGHBORS, axis=1))
Example #10
0
def test_edge_flip_normals():

    vertices = _generate_vertices(4)
    mesh = triangle_mesh.TriangleMesh(vertices, PRE_FLIP_FACES)

    flip_idx = np.where((mesh._h_vertex == 3) & (mesh._h_face == 0))[0][0]

    mesh.edge_flip(flip_idx)

    assert _test_normals(mesh)
Example #11
0
def test_vertex_neighbors():

    k4_vertices = _generate_vertices(4)
    mesh = triangle_mesh.TriangleMesh(k4_vertices, K4_FACES)
    mesh._vertices['valence'][:] = 12  # cheat our manifold checks

    assert np.all(
        np.sort(mesh._halfedges['vertex'][
            mesh.vertex_neighbors[:, :K4_NEIGHBORS.shape[1]]],
                axis=1) == np.sort(K4_NEIGHBORS, axis=1))
Example #12
0
def test_edge_collapse_topology():
    vertices = _generate_vertices(4)
    mesh = triangle_mesh.TriangleMesh(vertices, K4_FACES)

    collapse_idx = np.where((mesh._h_vertex == 2) & (mesh._h_face == 1))[0][0]

    mesh.edge_collapse(collapse_idx)

    assert _test_topology(mesh, K4_COLLAPSED_H_VERTEX, K4_COLLAPSED_H_FACE,
                          K4_COLLAPSED_H_TWIN, K4_COLLAPSED_H_NEXT,
                          K4_COLLAPSED_H_PREV)
Example #13
0
def test_edge_split_normals():
    vertices = _generate_vertices(4)
    mesh = triangle_mesh.TriangleMesh(vertices, PRE_SPLIT_FACES)
    mesh._vertices['valence'][:] = 12  # cheat our manifold checks

    split_idx = np.where((mesh._halfedges['vertex'] == 3)
                         & (mesh._halfedges['face'] == 0))[0][0]

    mesh.edge_split(split_idx)

    assert _test_normals(mesh)
Example #14
0
def test_edge_split_topology():
    vertices = _generate_vertices(4)
    mesh = triangle_mesh.TriangleMesh(vertices, PRE_SPLIT_FACES)

    split_idx = np.where((mesh._h_vertex == 3) & (mesh._h_face == 0))[0][0]

    mesh.edge_split(split_idx)

    assert _test_topology(mesh, POST_SPLIT_H_VERTEX, POST_SPLIT_H_FACE,
                          POST_SPLIT_H_TWIN, POST_SPLIT_H_NEXT,
                          POST_SPLIT_H_PREV)
Example #15
0
def test_snap_faces():
    vertices = _generate_vertices(12)
    mesh = triangle_mesh.TriangleMesh(vertices, PRE_SNAP_FACES)

    _h0 = np.where((mesh._halfedges['vertex'] == 0)
                   & (mesh._halfedges['face'] == 0))[0][0]
    _h1 = np.where((mesh._halfedges['vertex'] == 6)
                   & (mesh._halfedges['face'] == 4))[0][0]

    mesh._snap_faces(_h0, _h1)

    assert _test_topology(mesh, POST_SNAP_H_VERTEX, POST_SNAP_H_FACE,
                          POST_SNAP_H_TWIN, POST_SNAP_H_NEXT, POST_SNAP_H_PREV)
Example #16
0
def test_edge_split_topology():
    vertices = _generate_vertices(4)
    mesh = triangle_mesh.TriangleMesh(vertices, PRE_SPLIT_FACES)
    mesh._vertices['valence'][:] = 12  # cheat our manifold checks

    split_idx = np.where((mesh._halfedges['vertex'] == 3)
                         & (mesh._halfedges['face'] == 0))[0][0]

    mesh.edge_split(split_idx)

    assert _test_topology(mesh, POST_SPLIT_H_VERTEX, POST_SPLIT_H_FACE,
                          POST_SPLIT_H_TWIN, POST_SPLIT_H_NEXT,
                          POST_SPLIT_H_PREV)
Example #17
0
def test_edge_collapse_topology():
    vertices = _generate_vertices(4)
    mesh = triangle_mesh.TriangleMesh(vertices, K4_FACES)
    mesh._vertices['valence'][:] = 12  # cheat our manifold checks

    collapse_idx = np.where((mesh._halfedges['vertex'] == 2)
                            & (mesh._halfedges['face'] == 1))[0][0]

    mesh.edge_collapse(collapse_idx)

    assert _test_topology(mesh, K4_COLLAPSED_H_VERTEX, K4_COLLAPSED_H_FACE,
                          K4_COLLAPSED_H_TWIN, K4_COLLAPSED_H_NEXT,
                          K4_COLLAPSED_H_PREV)
    def OnLoadHarmonicRepresentation(self, wx_event):
        import wx
        from PYME.IO import tabular, FileUtils
        from PYME.Analysis.points.spherical_harmonics import scaled_shell_from_hdf
        import PYME.experimental._triangle_mesh as triangle_mesh
        from PYME.LMVis.layers.mesh import TriangleRenderLayer

        fdialog = wx.FileDialog(
            None,
            'Load Spherical Harmonic Representation',
            wildcard='Harmonic shell (*.hdf)|*.hdf',
            style=wx.FD_OPEN,
            defaultDir=FileUtils.nameUtils.genShiftFieldDirectoryPath())
        succ = fdialog.ShowModal()
        if (succ == wx.ID_OK):
            path = fdialog.GetPath()
            fdialog.Destroy()
        else:
            fdialog.Destroy()
            return

        shell = scaled_shell_from_hdf(path)

        points = tabular.MappingFilter(self.pipeline.selectedDataSource)
        separations, closest_points = shell.distance_to_shell(
            (points['x'], points['y'], points['z']), d_angles=self.d_angle)

        self._shells.append(shell)
        shell_number = len(self._shells)
        points.addColumn('distance_to_loaded_shell%d' % shell_number,
                         separations)
        points.addColumn(
            'inside_shell%d' % shell_number,
            shell.check_inside(points['x'], points['y'], points['z']))

        self.pipeline.addDataSource('shell%d_mapped' % shell_number, points)
        self.pipeline.selectDataSource('shell%d_mapped' % shell_number)

        v, f = shell.get_mesh_vertices_faces(self.d_angle)
        surf = triangle_mesh.TriangleMesh(v, f)
        self.pipeline.dataSources['shell_surface'] = surf

        layer = TriangleRenderLayer(self.pipeline,
                                    dsname='shell_surface',
                                    method='shaded',
                                    cmap='C')
        self.vis_frame.add_layer(layer)

        self.vis_frame.RefreshView()
Example #19
0
def test_edge_flip_topology():

    # vertices = _generate_vertices(4)
    # There's a concavity check in edge_flip, so we just stick with fixed, convex vertices
    vertices = np.array([[0.8233384, 0.04200047, 0.9175104],
                         [0.12197538, 0.3638311, 0.20577249],
                         [0.63744223, 0.55602515, 0.61852],
                         [0.8490536, 0.721189, 0.2788919]])
    mesh = triangle_mesh.TriangleMesh(vertices, PRE_FLIP_FACES)
    mesh._vertices['valence'][:] = 12  # cheat our manifold checks

    flip_idx = np.where((mesh._halfedges['vertex'] == 3)
                        & (mesh._halfedges['face'] == 0))[0][0]

    mesh.edge_flip(flip_idx)

    assert (_test_topology(mesh, POST_FLIP_H_VERTEX, POST_FLIP_H_FACE,
                           POST_FLIP_H_TWIN, POST_FLIP_H_NEXT,
                           POST_FLIP_H_PREV))
    def OnCalcHarmonicRepresentation(self, wx_event):
        from PYME.recipes import surface_fitting
        import PYME.experimental._triangle_mesh as triangle_mesh
        from PYME.LMVis.layers.mesh import TriangleRenderLayer
        recipe = self.pipeline.recipe

        shell_maker = surface_fitting.SphericalHarmonicShell(
            recipe,
            input_name=self.pipeline.selectedDataSourceKey,
            output_name='harmonic_shell')

        if shell_maker.configure_traits(kind='modal'):
            recipe.add_modules_and_execute([
                shell_maker,
            ])

            shell = recipe.namespace['harmonic_shell']

            shell_mapped = recipe.namespace['shell_mapped']
            self._shells.append(shell)

            self.pipeline.addDataSource('shell_mapped', shell_mapped)
            self.pipeline.selectDataSource('shell_mapped')

            # Add a surface rendering
            v, f = shell.get_mesh_vertices_faces(self.d_angle)
            surf = triangle_mesh.TriangleMesh(v, f)
            self.pipeline.dataSources['shell_surface'] = surf

            layer = TriangleRenderLayer(self.pipeline,
                                        dsname='shell_surface',
                                        method='shaded',
                                        cmap='C')
            self.vis_frame.add_layer(layer)

            self.vis_frame.RefreshView()