GS511 Homework #4 - Making Movies
John Huddleston
GS 511
April 9, 1996
Dr. Zachmann's Class
- Assignment Statement
- Testing of the Movie Making Process with the CG Method
- Movie of the Pascal Limacon
Choose a numerical model or an analytical solution of some problem
in your area of study (e.g. groundwater, thermodynamics, structures...)
and use the model/solution to create a sequence of images suitable
for display as an MPEG animation. The class notes
on making MPEG movies may be helpful to you in this homework.
After you have made your MPEG movie, write a short html document that
explains your animation and references it using a tag similar to:
<a href="your_movie.mpg">text to click on to see your movie</a>
Next, use the tar command:
tar -cvf huddleston_j_mpeg.tar your_movie.mpg your_explain.html
to bundle your explanation and your movie.
Finally, put the above tar file in the CVL directory:
/net/home/backup/gs510/put_hw
The system of scripts and programs as detailed in the GS511
class notes were recreated on my local system. Here is the following
order for making a movie of the Conjugate Gradient process to ensure that
the movie can be made:
- the cg_mpg.f file was compiled on a Sparc 2. (i.e. f77 cg.f)
- an images directory was created and the program was run
(i.e. cd images;../a.out)
- the r8tohdf program was downloaded from
http://starbase.jpl.nasa.gov/cdroms/ncsa_cd/hdf/pc_hdf/src/
as well as the df.h and dfi.h files for compilation. The
program was compiled with the command:
cc -o r8tohdf -DSUN r8tohdf.c -L/usr/local/lib -lhdf
- rawtohdf was rewritten as a Unix Bourne shell script
#!/bin/sh
# for the source to r8tohdf go to the following URL:
# http://starbase.jpl.nasa.gov/cdroms/ncsa_cd/hdf/pc_hdf/src/
for i in $*
do
NAME=`echo $i|cut -d. -f1`
r8tohdf 300 300 $NAME.hdf -p /usr/local/lib/pals/demo.pal $i
done
The script was run as 'rawtohdf *.raw'
- The raw files were removed with the command 'rm *.raw'
- the imconv binary was downloaded from the FTP site at SDSC
ftp://rosebud.sdsc.edu:/pub/sdsc/graphics/imtools
- hdftogif was rewritten as a Unix Bourne shell script
#!/bin/sh
# for the binary to imconv go to the following URL:
# ftp://rosebud.sdsc.edu:/pub/sdsc/graphics/imtools
#
for i in $*
do
NAME=`echo $i | cut -d. -f1`
imconv -informat hdf -infile $i -outformat gif -outfile $NAME.gif
done
The *.hdf files were converted to gif files with the command
'hdftogif *.hdf'
- The hdf files were removed with the command 'rm *.hdf'
- The mpeg_play program was available locally but the mpeg_encode
program had to be downloaded from the URL directory:
ftp://s2k-ftp.cs.berkeley.edu/pub/multimedia/mpeg/encode
- The *.gif files were combined into a movie
makempeg -format gif -from . -o cg.mpg -name "img(\d+).gif" -temp /usr3/tmp
- Finally the movie can be played with the command
mpeg_play cg.mpg
Once the CG movie project was completed to ensure that all
parts were working correctly; new code was rewritten to display
the Pascal Limacon. A plot of the Limacon of Pascal can be produced
with the following equation:
r = 1 - 2*cos(theta)
The limacon data for plotmtv was computed with the follwing C code:
#include <stdio.h>
main(argc,argv)
int argc;
char *argv[];
{
int i;
double r;
double x,y;
printf("$DATA=CURVE3D\n");
for(j = 0; j < 10;j++)
{
printf("linecolor=%d\n",j);
dj=(double)(j+1);
for(i = 0; i < 360;i++)
{
r = 1 - 2 * cos(i);
x = r * cos(i);
y = r * sin(i);
printf("%lg %lg %lg\n", dj*x, dj*y, dj);
}
}
printf("$END\n");
}
A 2D representation from plotmtv can
be seen here as well as the 3D one.
The C source file was changed to produce raw pixel data.
and here the x and y values are used to fill the location
within a 360x360 pixel array. They are multiplied by a
factor and the value of r is stored in that u(x,y) position.
#include <stdio.h>
#include <math.h>
#define USIZ 360
#define SIZ 129600
#define ABS(a) ((a)>0?(a):-(a))
int main(argc,argv)
int argc;
char *argv[];
{
int userlevel, atoi();
int fd,i,j,k,ix,iy;
double r;
double x,y;
double cos(),sin(),di,dj;
double *pu, u[USIZ][USIZ];
int *piu, iu[SIZ];
char *pcu, cu[SIZ];
char fn[12];
if (argc < 2) userlevel=20;
else userlevel=atoi(argv[1]);
printf("%d gif files are to be created\n",userlevel);
for(k = 0; k < userlevel;k++)
{
pu=&u[0][0];
for(i = 0; i < USIZ;i++)
for(j = 0; j < USIZ;j++)
*pu++=0.0;
dj=(double)(k+1);
for(i = 0; i < 360;i++)
{
di=(double)i;
r = 1 - 2 * cos(di);
x = 300.0 * r * cos(di);
y = 300.0 * r * sin(di);
ix=(int)x+USIZ/2; /* center it */
iy=(int)y+USIZ/2; /* center it */
ix=ABS(ix)%USIZ; /* no bigger than the array */
iy=ABS(iy)%USIZ; /* no bigger than the array */
u[ix][iy]=dj*r;
}
pu=&u[0][0];
piu=&iu[0];
pcu=&cu[0];
for(i = 0; i < USIZ;i++)
{
for(j = 0; j < USIZ;j++)
{
*piu = (int)(255.0 * (*pu++ + 1.0)*.5);
if(*piu < 0) *piu=0;
if(*piu > 255) *piu = 255;
*pcu++ = (char)*piu++;
}
}
if(k < 9) sprintf(fn,"lima00%d.raw",k+1);
else if(k < 99) sprintf(fn,"lima0%2d.raw",k+1);
else return(0);
fd=creat(fn,0664);
if(fd < 0) fd=open(fn,2);
if(fd < 0) { perror(fn); continue; }
write(fd,cu,(long)SIZ);
close(fd);
printf("\015%s",fn); fflush(stdout);
}
printf("\n");
return(0);
}
The control of the operation and execution for the 360x360
pixel map GIF files is controlled by the following commands:
if [ $# -lt 1 ];then
argc=2
else
argc=$1
fi
rm -f lima*.gif
../lima $argc
for i in *.raw
do
NAME=`echo $i|cut -d. -f1`
r8tohdf 360 360 $NAME.hdf -p /usr/local/lib/pals/demo.pal $i
done
rm *.raw
hdftogif *.hdf
rm *.hdf
makempeg -format gif -from . -o lima.mpg -name "lima(\d+).gif" -temp /usr3/tmp
The Limacon movie can be played with the command
'mpeg_play lima.mpg'. The interesting "feature" about the display itself
is the way the image bounces off the wall. This is possible because of
the 'ABS' or absolute macro that is used to keep the data within the
picture area.