swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FAQ: making movies


From: Sven N. Thommesen
Subject: FAQ: making movies
Date: Fri, 11 Sep 1998 17:24:27 -0500

Paul and Marcus: the following text is offered for inclusion in the docs
and/or the FAQ. Hope it's of use to someone!

-Sven

// ==========================================================================

USING THE SWARM WIDGET SNAPSHOT ('MOVIE-MAKING') FACILITY:

Swarm version 1.3 has a new 'movie-making' capability, which allows us to 
save to disk bitmap snapshots of either the whole screen or of individual 
on-screen widgets. 

While the 1.3 version of Heatbugs demonstrates how to take a snapshot of 
the whole screen (the "root window"), it does not show how to snapshot 
individual widgets. (And there's an error in the Heatbugs code.) 

Here follows a more extensive demonstration of how to take snapshots.

A basic method to snapshot the root window looks like this:

-takeSnapshotOfRoot
{
  char filename[40];
  unsigned timeNow;
  id pixId;

  timeNow = getCurrentTime();

  // Create a file name that contains the simulation time:
  sprintf(filename,"zmovie.rootwindow.%04d.png", timeNow);

  // Write the bitmap snapshot to disk:
  pixId = [ [[[Pixmap createBegin: graphicZone] 
                setWidget: nil] // ('nil'=>root window)
                createEnd] 
                save: filename];

  // Release the memory used by the Pixmap object:
  [pixId drop];

  return self;
}

If we want to take snapshots of a specific widget, we replace
'nil' in the example above with the id of the widget. 

a) Some object classes (Graph, Histogram, Raster, ZoomRaster) are 
subclassed directly from Widget (or they obey the <Widget> protocol),
so we can use their id directly in the snapshot method.

For other objects, we need to extract a pointer to the graphical widget:

b) for EZGraph: 

        theWidget = [theEZGraph getGraph];

c) for EZBin:

        theWidget = [theEZBin getHistogram];

d) for the control panel:

        theWidget = [actionCache getPanel];

e) for a probe:

        // When creating the probe display, save the reference:
        tempID = CREATE_ARCHIVED_PROBE_DISPLAY(modelSwarm);
        // Then get the widget pointer:
        theWidget = [tempID getTopLevel];

Then use theWidget instead of 'nil' in the pixmap call:

-takeSnapshotOfSomeWidget: (id <Widget>) theWidget
{
  char filename[40];
  unsigned timeNow;
  id pixId;

  timeNow = getCurrentTime();

  // Create a file name that contains the simulation time:
  sprintf(filename,"zmovie.nameofmywidget.%04d.png", timeNow);

  // Write the bitmap snapshot to disk:
  pixId = [ [[[Pixmap createBegin: graphicZone] 
                setWidget: theWidget]
                createEnd] 
                save: filename];

  // Release the memory used by the Pixmap object:
  [pixId drop];

  return self;
}

KNOWN LIMITATIONS under X-windows:

1. The pixmap saved does not include the border around the widget,
which is supplied by the window manager. Thus the saved pixmap will
not show the widget's title as seen on screen.

2. If you are using a multiple-virtual-window window manager, the
program likely will abort if you try to take a snapshot of a widget
that resides outside the window that currently has the focus (most
often, the window where the ControlPanel resides).

Partial solution: move the widgets you need to take snapshots of
to the window that will have focus before starting the simulation
run. Other possibility: have the -takeSnapshot method do nothing
for, say, t < 5, then after you start the sim quickly shift focus
to the window where your widget of choice is located.

3. Problem with simtime=0: if you try to take a snapshot of a 
widget that hasn't been instantiated yet, the program will abort.
Solution: schedule the call to -takeSnapshot *after* the call to
-doTkEvents (see -buildActions in the ObserverSwarm). Other
solution: make the -takeSnapshot method do nothing for t=0.

4. Overlapping windows: if widgets overlap on your screen, taking
a snapshot of a widget that's partially under another widget may
or may not raise the desired widget so as to snapshot only that
widget. Solution: move widgets so they don't overlap.

5. You cannot create .png pixmaps while running in batch mode; the
widgets have to be showing on the screen running in visual mode 
(under the ObserverSwarm).


KNOWN LIMITATIONS under Win-32 (95/98/NT):

        (to be filled in later)


MAKING MOVIES OUT OF THE COLLECTED .png FILES:

This is quoted verbatim from a swarm-support message by Marcus Daniels on
9/11/1998:

Here's the script I use (adapted slightly from a script from Nelson Minar).
You need the netpbm utilities, the fuzzy bitmap utilities, and pngtopnm.
Note the first argument is for fbm2fli.  The typical use of this is to
specify the display area for the FLI movie.

#!/bin/bash
# make a .fli file from the given list of .png files
# requires pngtopnm, pnmtorast, fboctree, fbm2fli
# usage: png2fli "fbm2fli arguments" 0.png 1.png ...

fbm2fliparams="$1"
shift
list="$@"
output=output.fli
octdata=/tmp/octree.$$
giflist=/tmp/fbm2fli.$$

if [ -e $output ]; then
  echo "$output already exists, you need to remove it."
  exit 1;
fi

echo -n 'Building the octree data.  '
for f in $list; do
        base=${f%.png}
        echo -n "$base "
        pngtopnm $f | ppmtotga | tga2fbm | fboctree -a $octdata
done # 2> /dev/null
echo

echo -n 'Converting PNG files to 8 bit GIFs.  '
for f in $list; do
        base=${f%.png}
        tmpbase=/tmp/$base
        nf=${tmpbase}.$$.gif
        echo -n "${base} "
        pngtopnm $f | ppmtotga | tga2fbm | fboctree -G $octdata > $nf
        echo $nf >> $giflist
done # 2> /dev/null
echo

echo "Creating $output from the GIFs"
fbm2fli $fbm2fliparams $giflist $output > /dev/null 2> /dev/null

echo "Cleaning up"
echo giflist: $giflist
rm `cat $giflist`
rm $giflist $octdata

exit 0;

// (end quote)

1998-09-11 Sven Thommesen <address@hidden>

// ======================================================================


                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.
                  ==================================


reply via email to

[Prev in Thread] Current Thread [Next in Thread]