DRAFT   DRAFT   DRAFT   DRAFT   DRAFT   DRAFT   DRAFT   DRAFT   DRAFT

Specific details about producing an animation of a gun tube,
using the BRL-CAD Package and various IBD simulation codes.

As things presently stand, the central part of this linkage is a program
called TUBE.C that takes two input files describing the motion of the
scene, and generates an MGED database containing a separate tree
(Directed Acyclic Graph [DAG]) for each frame. The name of combination
at the top of the tree is the letter "g" (for group) followed by the
frame number, so that the first frame of the animation is tree "g0", the
second frame is tree "g1", etc.

The current X displacement data for the gun tube center of mass points
is presently contained in the array dxtab[] compiled into the program.

The input file "pos.dat" contains the projectile position data. On each
input line, the time (in milliseconds) is listed first, followed by the
X displacement of the base of the projectile, offset from the projectile
starting position.  The time values listed in this file do not have to
correspond to the time values listed for the articulation; the proper
time will be chosen by the program. If the file "tank.out" contains the
output from a normal run of IBHVG2, the file "pos.dat" can be created by
running this Shell script:

cat tank.out |
sed -n '/    TIME   TRAV/,/ PROJECTILE EXIT/p' |
grep -v "[A-Z]"    |
cut -c2-132        |
grep -v "^[ ]*$"   |
awk '{printf "%10.2f  %10.2f\n", $1, $2 }' > pos.dat

The mass displacement file is presented to the TUBE program on standard
input, where each time step has the following format:  First a line with
the word "TIME" followed by a floating point number, in milliseconds.
Then, one input line for each of ``nmass'' (e.g., 12) mass points, in
ascending order of mass point number, starting with one, with one
integer and three floating point numbers on each line:  the mass number,
the X, Y, and Z deviations (currently expected in inches, where +X is
towards the muzzle, +Y is in the vertical direction, and +Z is to the
right of the muzzle).  There must be exactly one blank line after the
last mass point data line and before the next "TIME" line. Note that
mass point 1 corresponds to "m1" on the diagram, and mass point 12 is
"m12" on the diagram.  The position of a two additional points (0 and
13) are guessed within the program, with mass point 0 being the outer
edge of the breach block, and mass point 13 being the muzzle end, but
these two points are not specified in the input file.  E.g.,

TIME 0.02
1 0.01 0.00035 0.00000075
2 0.01 0.00040 0.00000900
   (etc.)
12 1.01 0.0784 3.129

TIME 0.04
    (etc.)

Therefore, assuming the mass displacement file is in "mass.dat",
and that the "pos.dat" file exists in the same directory,
and that the model for the projectile is in the file "projectile.g"
with main (top) combination named "ke",
the TUBE program is run as follows:

tube < mass.dat > anim.g
cat projectile.g >> anim.g

This MGED database can be examined with MGED.  To see the first
frame, say:

mged anim.g

then respond to the "attach" question appropriately for the type of
graphics device being used, and then enter the command

B g0

This will display the geometry configuration for frame zero.
The "B" command in MGED stands for "Blast screen clear, then display
named object(s)".  To view frame 42, enter the command

B g42

and so on.  The MGED control dials can be used to translate, rotate,
and zoom the current viewpoint.  When a desirable viewpoint has been
selected, it can saved in a file called "view1.sh" with the command

saveview view1.sh

This file is actually a Shell script that will render that one frame for
you, using RT, and store it in a file.  However, in this case, a text
editor is used to extract just the viewsize, eye point, and homogeneous
transform matrix (20 numbers in all) and store them in another file, say
"view1.mat".

To preview the whole animation in wireframe format, assuming that there
are 300 frames running 0 to 299, this Shell script (called, say,
"preview.sh") is used:

rm -f temp.sh
cat << END > temp.sh
 mged anim.g
 attach ir		(for SGI 3-D, or "sgi" for SGI 4-D)
 B g0
 rmats view1.mat
END
for frame in `loop 0 299`
do
	echo "B g${frame}" >> temp.sh
done
sh temp.sh
rm -f temp.sh

Assuming that this animation sequence and viewpoint are satisfactory,
and that the desired "graph paper" background file is stored in a
128x128 .pix file called "movie128bw.pix" in the current directory,
the animation can be rendered the Shell script given below (called, say,
"render.sh"):

for frame in `loop 0 299`
do
	rt -s512 -M -o out.pix.${frame}  \
		anim.g g${frame} < view1.mat >>& render.log
done

The "-s512" parameter specifies that the desired image is to be square,
and 512x512 pixels in size.  This is typically the desired resolution
for videotape.  The "-M" parameter specifies that the view matrix is to
be obtained from stdin.  The "-o out.pix.${frame}" says that the output
picture is to be stored in a file called "out.pix.123" where "123"
represents the current frame number.  (The backslash at the end of the
line continues the command to the next line).  Specifying "anim.g"
names the input MGED database, and "g${frame}" specifies the treetop
appropriate for the current frame.

Because this procedure is likely to take a significant amount of time,
the shell script should be submitted as a batch job.  On the minicomputers,
the MDQS command

batch render.sh

should be used.  On both of the UNICOS Cray systems, the NQS command

qsub render.sh

should be used.

To view one of these files, the Shell environment variable FB_FILE
should be set to indicate the appropriate framebuffer on the network
to use, and the program "pix-fb" is used to transfer the picture to
the framebuffer.  For more details on the variable FB_FILE, consult
the brlcad(1) manual page;  for more details on the program "pix-fb",
consult the pix-fb(1) manual page;  for more details on the framebuffer
library, consult libfb(3) manual page.  This can be done on BRL-IBD
with these commands:

man brlcad
man pix-fb
man libfb
