how to make animation? (fwd)

Tom G. Smith smitty at kcc.com
Mon Mar 27 10:07:35 EST 2000


Hello Mohamed,

My colleague recently discovered a nice technique for doing
animations.  It needs ImageMagick, but it's prettly slick.
Here's a Tcl fragment -

whirl.tcl:
#!/usr/bin/tcl
#-----------------------------------------------------------------------
# Description:  This Tcl script can be sourced to define subroutine whirl,
# which can be invoked to generate a series of ppm files that later can
# be combined to produce an animation.
#-----------------------------------------------------------------------
# Changelog:
# 000323 Smitty created.
#-----------------------------------------------------------------------

proc whirl {{hsize 100} {vsize 100} {basename whirl} {nsteps 10}
	{x 0} {y 1} {z 0}} {
# ---------------------------------------------------------------
# Generates a series of ppm files, with filenames of the form
# $filename_001.ppm, $filename_002.ppm, etc.  The files contain
# progressive images of the scene, with the camera rotated about
# the z axis a specified increment for each image, for a full
# 360 degrees.  Expects renWin, a vtkRenderWindow object, and
# actor, a vtkActor object, to be predefined.
#
# Arguments -
# basename
#	Filenames will be $basename_001.ppm, $basename_002.ppm, etc.
#	If omitted, the default is "whirl".
# hsize
#	Horizontal size in pels of the images.
#	If omitted, the default is 100.
# vsize
#	Vertical size in pels of the images.
#	If omitted, the default is 100.
# nsteps
#	Number of images to be generated, i.e. 10 would produce
#	10 images, each rotated from the others by 36 degrees about
#	the z axis.
#	If omitted, the default is 10.
# x
#	Set to 1 if rotation is to occur about the x axis.
#	Default is 0.
# y
#	Set to 1 if rotation is to occur about the y axis.
#	Default is 1.
# z
#	Set to 1 if rotation is to occur about the z axis.
#	Default is 0.
# ---------------------------------------------------------------
	global dirname

	set delta [expr 360.0/$nsteps]
	set suffix ppm
	set n 0
	cmd [list\
		"renWin SetSize $hsize $vsize"\
		 "wm withdraw ."]
	while {$n < $nsteps} {
		incr n
		set filename "${basename}_[format %03d $n].$suffix"
		cmd [list\
			"renWin Render"\
			"renWin SetFileName $filename"\
			"renWin SaveImageAsPPM"]
		if {$x} { cmd [list "actor RotateX $delta"] }
		if {$y} { cmd [list "actor RotateY $delta"] }
		if {$z} { cmd [list "actor RotateZ $delta"] }
	}
	cmd [list "destroy ."]
	catch {exec $dirname/whirl.sh $basename}
} ;# End whirl.

whirl.sh:
#!/usr/bin/sh
# -----------------------------------------------------------------
# Description:
# Called by whirl.tcl.  Uses convert from ImageMagick to convert
# ppm files to gif, then invokes whirlgif to create an animation
# from the gif files.  You can see the resulting animation with -
#	animate $1.gif
# -----------------------------------------------------------------
# Changelog:
# 000324 Smitty created.
# -----------------------------------------------------------------
for i in `ls $1*.ppm | cut -d. -f1`
do
	convert $i.ppm $i.gif
	rm $i.ppm
done
whirlgif -loop 999999 -o $1.gif ${1}_[0-9][0-9][0-9].gif
rm ${1}_[0-9][0-9][0-9].gif

Forwarded message:
> From owner-vtkusers at public.kitware.com  Fri Mar 24 20:14:42 2000
> From: "Mohamed Magdi" <m_magdi1 at hotmail.com>
> To: vtkusers at public.kitware.com
> Subject: how to make animation?
> Date: Fri, 24 Mar 2000 16:28:49 PST
> 
> hello vtk user,
> 
> 
> i am using vtk espesially the example lox.cxx(fluid dynamics)
> i want to make animation
> i need code or algorithm in c++
> please i want details
> please send me urgently
>   thanks
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com
> 
> --------------------------------------------------------------------
> This is the private VTK discussion list. Please keep messages on-topic.
> Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
> To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
> <majordomo at public.kitware.com>. For help, send message body containing
> "info vtkusers" to the same address.
> --------------------------------------------------------------------
> 


-- 

------------------------------------------------------------------------------
This e-mail is intended for the use of the addressee(s) only and may contain privileged, confidential, or proprietary information that is exempt from disclosure under law.  If you have received this message in error, please inform us promptly by reply e-mail, then delete the e-mail and destroy any printed copy.   Thank you.

==============================================================================
--------------------------------------------------------------------
This is the private VTK discussion list. Please keep messages on-topic.
Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at public.kitware.com>. For help, send message body containing
"info vtkusers" to the same address.
--------------------------------------------------------------------



More information about the vtkusers mailing list