MATES 3.0-rc2

org.mates.plugins
Class TopologyMoviePlugin

java.lang.Object
  extended byorg.mates.sim.Experiment
      extended byorg.mates.plugins.TopologyMoviePlugin

public class TopologyMoviePlugin
extends Experiment

A plugin experiment for recording a movie of the topology, by taking one screenshot per simulator iteration. Note that for an actual movie file to be created (as opposed to a directory full of individual frames), MPlayer's mencoder utility is required to be installed on the system. This utility is usually installed automatically with mplayer.

By default, this TopologyMoviePlugin renders the topology using a DefaultTopologyVisualizer. However, this may be overridden with a custom TopologyVisualizer by calling setTopologyVisualizer(TopologyVisualizer).

Also by default, all frames created by this plugin are temporary and will be deleted when the JVM exits. To make frames permanent, use setAllFramesTemporary(boolean).

Finally, note that the TopologyMoviePlugin does not automatically capture frames by default. To start capturing frames, call startCapture().

Author:
Evan Sultanik

Nested Class Summary
 class TopologyMoviePlugin.ScreenshotProvider
          Class used as a callback for Screenshot.saveScreenshot(java.lang.Object, int, int, java.io.File) to prevent the topology visualizer from double buffering.
 
Field Summary
 
Fields inherited from class org.mates.sim.Experiment
parent, simulator
 
Constructor Summary
TopologyMoviePlugin(Experiment parent, java.io.File directory, java.lang.String filePrefix)
          Creates a new TopologyMoviePlugin.
 
Method Summary
 void captureFrame()
          Manually causes the plugin to record a new frame from the TopologyVisualizer.
 void cleanup()
          Forcefully deletes all frames since either the last cleanup or experiment reset.
 java.io.File getDirectory()
          Returns the directory to which the individual frames are being stored.
 long getFrameCounter()
          Returns the current value of the frame counter.
 java.util.LinkedList getFrames()
          Returns a LinkedList of File objects pointing to the individual frames of the movie.
 java.awt.Component getGUI()
          Returns the GUI component associated with this experiment.
protected  void handleInitialize()
          Callback function for initializing the experiment.
protected  void handleIterate()
          Callback function for iterating the experiment.
protected  void handleReset()
          Callback function for resetting the experiment.
 boolean isCapturing()
          Returns true if the plugin is currently automatically capturing frames.
 void saveToMovie(java.io.File pathForMovie, int fps, java.lang.String videoCodec)
          Saves the current set of frames to a movie.
 boolean saveTopologyScreenshot(java.io.File saveFile)
          Saves a screenshot of the current topology to saveFile.
 void setAllFramesTemporary(boolean framesAreTemporary)
          Sets whether or not individual frames will be deleted once the JVM exits.
 void setFrameCounter(long numFrames)
          Sets the index of the current frame.
 void setTopologyVisualizer(TopologyVisualizer visualizer)
          Sets the topology visualizer that will be used to render the individual frames of the movie.
 void startCapture()
          Causes the plugin to start automatically capturing frames, one per iteration.
 void stopCapture()
          Causes the plugin to stop automatically capturing frames.
 
Methods inherited from class org.mates.sim.Experiment
complete, getMenuItems, getParentExperiment, getSimulator, getSubExperiments, handleMenuAction, initialize, iterate, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TopologyMoviePlugin

public TopologyMoviePlugin(Experiment parent,
                           java.io.File directory,
                           java.lang.String filePrefix)
Creates a new TopologyMoviePlugin.

Parameters:
parent - the parent experiment in the experiment tree.
directory - the directory to which to save the individual frames before they are combined into a movie. If this is null, a new temporary directory will be created in the system's default temporary directory.
filePrefix - a prefix to the frame number of an image. If null, no prefix will be used. For example, if filePrefix equals "image", the frames will be named, "image0001.png," "image0002.png," et cetera.
Method Detail

getFrames

public java.util.LinkedList getFrames()
Returns a LinkedList of File objects pointing to the individual frames of the movie.


setTopologyVisualizer

public void setTopologyVisualizer(TopologyVisualizer visualizer)
Sets the topology visualizer that will be used to render the individual frames of the movie.


saveTopologyScreenshot

public boolean saveTopologyScreenshot(java.io.File saveFile)
                               throws java.lang.ClassNotFoundException,
                                      java.io.IOException
Saves a screenshot of the current topology to saveFile.

Returns:
true on success.
Throws:
java.lang.ClassNotFoundException - when writing to an EPS file and org.jibble.epsgraphics.EpsGraphics2D cannot be found.
java.io.IOException - on error writing to saveFile.

handleIterate

protected void handleIterate()
Description copied from class: Experiment
Callback function for iterating the experiment. This function will be called after the simulator has been iterated. Sub-classes of Experiment need not re-implement this function. This function is empty by default; therefore, super.handleIterate() need not be called from re-implementations of this function.

Overrides:
handleIterate in class Experiment

handleInitialize

protected void handleInitialize()
Description copied from class: Experiment
Callback function for initializing the experiment. Sub-classes of Experiment need not re-implement this function. This function is empty by default; therefore, super.handleInitialize() need not be called from re-implementations of this function.

Overrides:
handleInitialize in class Experiment

handleReset

protected void handleReset()
Description copied from class: Experiment
Callback function for resetting the experiment. This function will be called after the simulator has been reset. Sub-classes of Experiment need not re-implement this function. This function is empty by default; therefore, super.handleReset() need not be called from re-implementations of this function.

Overrides:
handleReset in class Experiment

setAllFramesTemporary

public void setAllFramesTemporary(boolean framesAreTemporary)
Sets whether or not individual frames will be deleted once the JVM exits. By default, all individual frames are deleted once the JVM exits, regardless of whether or not a movie was made of them. To make the picture files persist even after the JVM exits, pass true to this function.


cleanup

public void cleanup()
Forcefully deletes all frames since either the last cleanup or experiment reset. This will also reset the frame counter to zero.


setFrameCounter

public void setFrameCounter(long numFrames)
Sets the index of the current frame. Note that changing the frame counter in the middle of a capture may jeapordize the continuity of the resulting movie.


getFrameCounter

public long getFrameCounter()
Returns the current value of the frame counter.


getDirectory

public java.io.File getDirectory()
Returns the directory to which the individual frames are being stored. This is useful if the directory was created automatically (i.e. the directory argument to the constructor was passed as null).


saveToMovie

public void saveToMovie(java.io.File pathForMovie,
                        int fps,
                        java.lang.String videoCodec)
                 throws java.lang.Exception
Saves the current set of frames to a movie. By "current set" we mean all frames that were captured since either the last cleanup() or the last experiment reset.

Note that this function requires that mencoder be installed and runnable on the system.

Parameters:
pathForMovie - file to which to save the movie.
fps - the number of frames per second at which the movie will play back.
videoCodec - string representing the video codec to be used. This will be passed verbatim to the mencoder "-ovc" option. Examples include "copy" and "lavc". Different mencoder installations may have different codecs available; run `mencoder -ovc help` to get a list of the available codecs. If videoCodec is null, the codec will be set to "copy".
Throws:
java.lang.Exception - if either mencoder was not found, or mencoder returned an error.

captureFrame

public void captureFrame()
                  throws java.lang.IllegalArgumentException,
                         java.lang.ClassNotFoundException,
                         java.io.IOException
Manually causes the plugin to record a new frame from the TopologyVisualizer.

Throws:
java.lang.IllegalArgumentException
java.lang.ClassNotFoundException
java.io.IOException

isCapturing

public boolean isCapturing()
Returns true if the plugin is currently automatically capturing frames.

See Also:
startCapture()

startCapture

public void startCapture()
Causes the plugin to start automatically capturing frames, one per iteration.


stopCapture

public void stopCapture()
Causes the plugin to stop automatically capturing frames.


getGUI

public java.awt.Component getGUI()
Description copied from class: Experiment
Returns the GUI component associated with this experiment. This component will then be displayed if GraphicalUserInterface is used. This function defaults to return null. getGUI() is intended for child classes that extend Experiment to re-implement this function and return a GUI object.

Overrides:
getGUI in class Experiment

MATES 3.0-rc2

Submit a bug or request a feature
http://mates.sourceforge.net/

Copyright 2004 Evan Sultanik