How to use the mayavi.mlab.triangular_mesh function in mayavi

To help you get started, we’ve selected a few mayavi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github justachetan / DiffGeoOps / DiffGeoOps.py View on Github external
from mayavi import mlab

        if args.i[0].split(".")[1] != "npy":
            raise RunTimeError("Plotting requires .npy files!")

        f = np.load(args.i[0])
        if args.mesh is None:
            parser.error("Plotting requires --mesh")
        mlab.figure(args.title, size=(600, 600))
        mesh_file = open(args.mesh)
        vertices, triangles = read_off(mesh_file)

        x, y, z = vertices[:, 0], vertices[:, 1], vertices[:, 2]

        mesh = mlab.triangular_mesh(x, y, z, triangles,
                                    representation='wireframe', opacity=0)

        mesh.mlab_source.dataset.point_data.scalars = f
        mesh.mlab_source.dataset.point_data.scalars.name = 'Point data'

        mesh.mlab_source.update()
        mesh.parent.update()

        mesh2 = mlab.pipeline.set_active_attribute(mesh,
                                                   point_scalars='Point data')
        s2 = mlab.pipeline.surface(mesh2)
        s2.actor.mapper.interpolate_scalars_before_mapping = True
        mlab.colorbar(s2, title='Curvature\n', orientation='vertical')

        if args.save:
            mlab.savefig(args.i[0].split(".")[0] + ".png")
github leon-nn / face-fitting / bin / speech-video-hmm.py View on Github external
def animate(v, f, saveDir, t = None, alpha = 1):
    
    # Create the save directory for the images if it doesn't exist
    if not saveDir.endswith('/'):
        saveDir += '/'
    if not os.path.exists(saveDir):
        os.makedirs(saveDir)
    
    # Render the mesh
    if t is None:
        tmesh = mlab.triangular_mesh(v[0, 0, :], v[0, 1, :], v[0, 2, :], f-1, scalars = np.arange(v.shape[2]), color = (1, 1, 1))
    
    # Add texture if given
    else:
        tmesh = mlab.triangular_mesh(v[0, 0, :], v[0, 1, :], v[0, 2, :], f-1, scalars = np.arange(v.shape[2]))
        if t.shape[1] is not 3:
            t = t.T
        tmesh.module_manager.scalar_lut_manager.lut.table = np.c_[(t * 255), alpha * 255 * np.ones(v.shape[2])].astype(np.uint8)
#        tmesh.actor.pro2perty.lighting = False
        
    # Change viewport to x-y plane and enforce orthographic projection
    mlab.view(0, 0, 'auto', 'auto')
    
    mlab.gcf().scene.parallel_projection = True
    
    # Save the first frame, then loop through the rest and save them
    mlab.savefig(saveDir + '00001.png', figure = mlab.gcf())
    tms = tmesh.mlab_source
    for i in range(1, v.shape[0]):
        fName = '{:0>5}'.format(i + 1)
        tms.set(x = v[i, 0, :], y = v[i, 1, :], z = v[i, 2, :])
github jeffmahler / GPIS / src / grasp_selection / temp_jacky.py View on Github external
def mv_plot_table(T_table_world, d=0.5):
        """ Plots a table in pose T """
        table_vertices = np.array([[d, d, 0],
                                   [d, -d, 0],
                                   [-d, d, 0],
                                   [-d, -d, 0]])
        table_vertices_tf = T_table_world.apply(table_vertices.T).T
        table_tris = np.array([[0, 1, 2], [1, 2, 3]])
        mv.triangular_mesh(table_vertices[:,0], table_vertices[:,1], table_vertices[:,2], table_tris, representation='surface', color=(0,0,0))
github aestrivex / cvu / fscoords.py View on Github external
edges=edges[zi[0],:]

nr_edges = len(edges)
print nr_edges

#print adjdat
#TODO  ensure the data points are correctly

#print nr_edges
#print len(vecs)
#print len(starts)
#print len(adjdat)

fig = mlab.figure()

syrf_lh = mlab.triangular_mesh(surfpos_lh[:,0],surfpos_lh[:,1],surfpos_lh[:,2],
	surffaces_lh,opacity=.2,color=(.4,.75,.0))
syrf_rh = mlab.triangular_mesh(surfpos_rh[:,0],surfpos_rh[:,1],surfpos_rh[:,2],
	surffaces_rh,opacity=.2,color=(.4,.75,0))

nodesource = mlab.pipeline.scalar_scatter(x,y,z,name='noddy')
nodes = mlab.pipeline.glyph(nodesource,scale_mode='none',scale_factor=3.0,name='noddynod',mode='sphere',color=(0,.6,1))
#nodes.glyph.color_mode='color_by_scalar'
#nodes.mlab_source.dataset.point_data.scalars=np.tile(.1,nr_labels)

vectorsrc = mlab.pipeline.vector_scatter(starts[:,0],starts[:,1],
			starts[:,2],vecs[:,0],vecs[:,1],vecs[:,2],name='connsrc')
vectorsrc.mlab_source.dataset.point_data.scalars = adjdat 
vectorsrc.mlab_source.dataset.point_data.scalars.name='edgekey'
vectorsrc.outputs[0].update()
thres = mlab.pipeline.threshold(vectorsrc,name='thresh',)
thres.auto_reset_lower=False
github openmeeg / openmeeg / examples / mesh.py View on Github external
def plot(self,**kwarg):
        '''Plot mesh with Mayavi
        '''
        from mayavi import mlab
        f = mlab.triangular_mesh(self.points[:,0],self.points[:,1],self.points[:,2],self.faces, **kwarg)
        return f
github GUDHI / gudhi-devel / src / python / example / plot_simplex_tree_dim012.py View on Github external
from mpl_toolkits.mplot3d.art3d import Line3DCollection
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca(projection='3d')
# Plot triangles
ax.plot_trisurf(points[:,0], points[:,1], points[:,2], triangles=triangles)
# Plot points
ax.scatter3D(points[:,0], points[:,1], points[:,2])
# Plot edges
ax.add_collection3d(Line3DCollection(segments=edges))
plt.show()

## With mayavi
from mayavi import mlab
# Plot triangles
mlab.triangular_mesh(points[:,0], points[:,1], points[:,2], triangles);
# Plot points
mlab.points3d(points[:,0], points[:,1], points[:,2])
# Plot edges
for pts in edges:
    mlab.plot3d(pts[:,0],pts[:,1],pts[:,2],tube_radius=None)
mlab.show()
github jiangzhongshi / SurfaceNetworks / src / utils / mesh.py View on Github external
F = np.array(F)

    return V, F

def centroids(V, F):
    C = np.zeros(F.shape)
    for i in range(F.shape[0]):
        C[i] = (V[F[i, 0]] + V[F[i, 1]] + V[F[i, 2]]) / 3
    return C

if __name__ == "__main__":
    from mayavi import mlab
    
    V, F = load_obj("bunny.obj")

    mlab.triangular_mesh(V[:, 0], V[:, 1], V[:, 2], F)

    dists = dist(V, F)

    areas = area(F, dists)

    W, _ = cotangent_weights(F, areas, dists)
    L = graph.laplacian(W, symmetric=False)
    C = centroids(V, F)

    D, DA = dirac(V, F)
    D = D.todense()
    DA = DA.todense()


    L = np.asarray(L.todense())
    P = np.asarray(np.matmul(L, V))
github arthurmensch / cogspaces / exps / analyse / plot_mayavi.py View on Github external
def plot_on_surf(data, sides=['left', 'right'], selected=False,
                 threshold=None, inflate=1.001, **kwargs):
    """ Plot a numpy array of data on the corresponding fsaverage
        surface.

        The kwargs are passed to mlab.triangular_mesh
    """
    actors = dict()
    for side in sides:
        actors[side] = list()
        mesh = surface.load_surf_mesh(fsaverage['infl_%s' % side])
        shift = -42 if side == 'left' else 42
        surf = mlab.triangular_mesh(inflate * mesh[0][:, 0] + shift,
                                    inflate * mesh[0][:, 1],
                                    inflate * mesh[0][:, 2],
                                    mesh[1],
                                    scalars=data,
                                    **kwargs,
                                    )
        surf.module_manager.source.filter.splitting = False
        # Avoid openGL bugs with backfaces
        surf.actor.property.backface_culling = True
        actors[side].append(surf)

        if threshold is not None:
            surf.enable_contours = True
            surf.contour.auto_contours = False
            surf.contour.contours = [threshold, data.max()]
            surf.contour.filled_contours = True
github aestrivex / cvu / cvu / dataview.py View on Github external
def surfs_gen(self):
        self.syrf_lh = mlab.triangular_mesh(
            self.ds.srf.lh_verts[:,0],self.ds.srf.lh_verts[:,1],
            self.ds.srf.lh_verts[:,2],self.ds.srf.lh_tris,
            opacity=self.ds.opts.surface_visibility,
            color=self.ds.default_glass_brain_color,)
        self.syrf_rh = mlab.triangular_mesh(
            self.ds.srf.rh_verts[:,0],self.ds.srf.rh_verts[:,1],
            self.ds.srf.rh_verts[:,2],self.ds.srf.rh_tris,
            opacity=self.ds.opts.surface_visibility,
            color=self.ds.default_glass_brain_color,)
        #some colors
        #(.4,.75,0) #DARKISH GREEN
        #(.82,1,.82) #LIGHTER GREEN
        #(.82,.82,.82) #GRAY

        self.surfs_cracked=False
        for syrf in (self.syrf_lh,self.syrf_rh):