perreal has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I'm working on a wireless sensor network routing algorithm. I had some unexpected results and decided to visualize the problem by drawing the topology as a 3D plot. Used x,y as node coordinated and z as the congestion level at the node (well in fact what I have is a 2D plot and colors for z). Anyway, this way I can see how the algorithm reacts in the course of a long simulation. Currently I'm using Image::Magick to create an animated gif using lots of frames which are actually snapshots of the network. This takes more time than the simulation itself and for long runs, I run out of RAM.

My question is, do you know an efficient solution for my problem? I'm thinking about creating avi files or flash animations... I don't have time to try them all. Thanks!

  • Comment on Fast and light-weight animation solution

Replies are listed 'Best First'.
Re: Fast and light-weight animation solution
by Corion (Patriarch) on Jun 01, 2009 at 15:35 UTC

    I have had good success with using ffmpeg to write the video. I output a raw RGB stream and tell ffmpeg the width and height of the stream and ffmpeg then encodes each count of $width*$height*RGB bytes into one frame of the video. See App::VideoMixer, respectively (the source of) App::VideoMixer::Source::FFmpeg, which implements both the video reader and writer. The core of it is the following code:

    my $in_width = 640; # this depends on your input data my $in_height = 480; # this depends on your input data my $width = 320; # this depends on what you want my $height = 200; # this depends on what you want my $file = 'test.mpg'; my $ffmpeg = 'bin/ffmpeg.exe'; my $pixel_format = 'rgb'; my $pid = open my $output, sprintf qq{| %s -y -f rawvideo -pix_fmt %s -s ${in_widt +h}x${in_height} -i "-" -f mpeg2video -s ${width}x${height} "$file"}, $ffmpeg, $pixel_format ); for my $frame (@frames) { print $writer $frame; };
Re: Fast and light-weight animation solution
by zentara (Cardinal) on Jun 01, 2009 at 16:31 UTC
    See "Rubics Cube" game for a Tk 3d example...... its 3d capabilities were pretty good. There is also a new 3d scenegraph project .... google for "gtk 3d scenegraph". PDL has some 3d Tri-graph point scatter plot examples too.

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku
      I think the ideal way to visualise a lot of x/y/z points would be points3d:
      use PDL; use PDL::Graphics::TriD; # load your data maybe as 3 same-length vectors, one each for x,y,z points3d([$x,$y,$z]);
      In perldl, try demo 3d to see more. (In current PDL you need both OpenGL and OpenGL::GLUT installed to get the OpenGL TriD stuff working; it is planned to bring this back to only needing OpenGL again)