Python mayavi.mlab.animate() Examples
The following are 5
code examples of mayavi.mlab.animate().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
mayavi.mlab
, or try the search function
.
Example #1
Source File: 3d_elev_animations.py From LSDMappingTools with MIT License | 6 votes |
def run_plots(DataDirectory,Base_file): root = DataDirectory+Base_file filenames = get_filenames(root) counter = 0 # create the plot for the initial raster initial_file = filenames[0] # read in the raster raster = IO.ReadRasterArrayBlocks(initial_file) f = mlab.figure(size=(1000,1000), bgcolor=(0.5,0.5,0.5)) s = mlab.surf(raster, warp_scale=0.4, colormap='gist_earth', vmax=100) #mlab.outline(color=(0,0,0)) #mlab.axes(s, color=(1,1,1), z_axis_visibility=True, y_axis_visibility=False, xlabel='', ylabel='', zlabel='', ranges=[0,500,0,1000,0,0]) #@mlab.animate(delay=10) #def anim(): # now loop through each file and update the z values for fname in filenames: this_rast = IO.ReadRasterArrayBlocks(fname) s.mlab_source.scalars = this_rast #f.scene.render() # mlab.savefig(fname[:-4]+'_3d.png') #mlab.clf() # for (x, y, z) in zip(xs, ys, zs): # print('Updating scene...') # plt.mlab_source.set(x=x, y=y, z=z) # yield
Example #2
Source File: 3d_elev_animations.py From LSDMappingTools with MIT License | 6 votes |
def animate_plots(base_directory, fname_prefix): """ This function creates a movie of the plots using ffmpeg Args: base_directory (str): the directory with the plots. fname_prefix (str): the filename for the model run Returns: none but creates mp4 from pngs in base directory Author: FJC """ import subprocess # animate the pngs using ffmpeg system_call = "ffmpeg -framerate 5 -pattern_type glob -i '"+base_directory+"*.png' -vcodec libx264 -s 1000x1000 -pix_fmt yuv420p "+base_directory+fname_prefix+"_movie.mp4" print(system_call) subprocess.call(system_call, shell=True) #============================================================================= # This is just a welcome screen that is displayed if no arguments are provided. #=============================================================================
Example #3
Source File: 3d_elev_animations.py From LSDMappingTools with MIT License | 5 votes |
def main(argv): """ This is just a few lines for keeping track of how long the program is taking. You can ignore it. """ import time tic = time.clock() # If there are no arguments, send to the welcome screen if not len(sys.argv) > 1: full_paramfile = print_welcome() sys.exit() # Get the arguments import argparse parser = argparse.ArgumentParser() # The location of the data files parser.add_argument("-dir", "--base_directory", type=str, help="The base directory with the hillshades. If this isn't defined I'll assume it's the same as the current directory.") parser.add_argument("-fname", "--fname_prefix", type=str, help="The base file name of the hillshades.") parser.add_argument("-animate", "--animate", type=bool, default=False, help="If this is true I'll create a movie of the model run.") parser.add_argument("-zmax", "--maximum_elevation_for_plotting", type=float, default = 400, help="This is the maximum elevation in the colourbar of the landscape plot.") args = parser.parse_args() run_plots(args.base_directory,args.fname_prefix) if (args.animate): animate_plots(args.base_directory, args.fname_prefix) toc = time.clock() print("This took: "+str(toc - tic)+" units of time") #=============================================================================
Example #4
Source File: soma.py From rivuletpy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def evolve_visual3d(msnake, levelset=None, num_iters=20): """ Visual evolution of a three-dimensional morphological snake. Parameters ---------- msnake : MorphGAC or MorphACWE instance The morphological snake solver. levelset : array-like, optional If given, the levelset of the solver is initialized to this. If not given, the evolution will use the levelset already set in msnake. num_iters : int, optional The number of iterations. """ from mayavi import mlab # import matplotlib.pyplot as ppl if levelset is not None: msnake.levelset = levelset fig = mlab.gcf() mlab.clf() src = mlab.pipeline.scalar_field(msnake.data) mlab.pipeline.image_plane_widget( src, plane_orientation='x_axes', colormap='gray') cnt = mlab.contour3d(msnake.levelset, contours=[0.5]) @mlab.animate(ui=True) def anim(): for i in range(num_iters): msnake.step() cnt.mlab_source.scalars = msnake.levelset yield anim() mlab.show() # Return the last levelset. return msnake.levelset
Example #5
Source File: regions.py From diluvian with MIT License | 4 votes |
def fill_render(self, model, save_movie=True, **kwargs): from mayavi import mlab body = self.to_body() mask = body.mask fig = mlab.figure(size=(1280, 720)) if self.target is not None: target_grid = mlab.pipeline.scalar_field(np.transpose(self.target)) target_grid.spacing = np.flipud(CONFIG.volume.resolution) target_grid = mlab.pipeline.iso_surface(target_grid, contours=[0.5], color=(1, 0, 0), opacity=0.1) grid = mlab.pipeline.scalar_field(np.transpose(mask.astype(np.int32))) grid.spacing = np.flipud(CONFIG.volume.resolution) contour = mlab.pipeline.iso_surface(grid, color=(0, 1, 0), contours=[0.5], opacity=0.6) contour.actor.property.backface_culling = True grid = contour.mlab_source mlab.orientation_axes(figure=fig) mlab.view(azimuth=45, elevation=60, focalpoint='auto', figure=fig) fill_generator = self.fill(model, generator=True, **kwargs) FRAMES_PER_MOVE = 2 FPS = 60.0 ORBIT_RATE = 0.125 @mlab.animate(delay=int(1000.0/FPS), ui=True) def animate(): try: for _, _ in fill_generator: body = self.to_body() mask = body.mask grid.set(scalars=np.transpose(mask.astype(np.int32))) for _ in range(FRAMES_PER_MOVE): view = list(mlab.view(figure=fig)) view[0] = (view[0] + ORBIT_RATE * 360.0 / FPS) % 360.0 mlab.view(azimuth=view[0], elevation=view[1], focalpoint='auto') fig.scene.render() # fig.scene.movie_maker.animation_step() yield except Region.EarlyFillTermination: pass fig.scene.movie_maker.record = False fig.scene.movie_maker.animation_stop() if save_movie: fig.scene.movie_maker.record = True a = animate() # noqa mlab.show()