TO-DO:  test that inv. dyn. output is reasonable....


----------------------

Very simple motion file visualization program.

You must have OpenInventor installed for this to work.

----------------------
TO COMPILE

On a linux box or other Unix system, you should be able to compile by
typing "make"

----------------------
TO RUN

  ./viz <AMCFile> <ASFFile>

for example:

  ./viz ./d/Patient1.ASF ./d/Patient1.trial3.AMC

When the window comes up, type:

	p  	to play
	l	to loop
	x	to stop

        i       to calculate inverse dynamics

(..see viewer.c++ IKViewer::processEvent for the complete list of key commands..)

To move the camera

	left mouse button	rotates camera (trackball)
	middle mouse button	pans camera
	left+middle buttons	dolly camera

----------------------
HINTS

If skeleton is too large, edit the "length" entry in the ASF file (0.07 is a good number)
Speed is controlled by the SKIP_FRAMES variable in viewer.h  (should be interactively adjustable, sorry....)


------------------------------------------------------------------------
INVERSE DYNAMICS

--------------

To run, start the visualizer, hit 'i' and wait a few seconds.

Outputs described below.

--------------

The basics of inverse dynamics is implemented, but there is ONE
IMPORTANT THING MISSING.  The results are computed assuming that there
are no external forces (except gravity) acting on the character.
Obviously this will be wrong for almost all motion you might care
about.

What I have done in the past is to figure out when the feet are near
the ground and then find forces to eliminate as much as possible the
root forces on the character, which are not real forces.  See, for
example, the calcAccel method in
/nfs/hn01/nsp/Brown/sim/tracking/motionTracker/TrackActor.java

By the way, the tracking code in the motionTracker directory has more
of what you need than the code in the present directory .. forward
dynamics etc, but its inverse dynamics has a few minor bugs, and it
doesn't read in general amc files, i think.  (Besides the fact that it
is in java) However, it is good as an additional reference, especially
for solving this particular external force problem.

--------------

You may be wondering how the physical model of the character is
created.  This is done here using annotations in the skeleton (ASF)
file.  There is an example in ./d/Patient1.ASF.  This ASF file has
been hand annotated with 'radius' and 'density' keywords, and the
radius and density information is used to build a cylindrical model of
the body part geometry.

--------------

Inverse dynamics relies on accelerations, which are really noisy,
because they involve calculating the second derivative of data that is
noisy to begin with.  To partially deal with this problem, I filter
the position data that is read in from the amc file pretty heavily.
This filtering call is in actor.c++ .. Actor::readAMCFile.  You may
not want this level of filtering .. you may want more.

--------------

Running inverse dynamics results in four output files in the plots
subdirectory:

forceIndex ....  lists each DOF and its index in the boneForces and
                      velocities files (starting w/ zero) .. position
                      indices will differ, because some of the positions 
                      are quaternions...)
                      
boneForces ....  translational forces at the root and torques at the
                      joints

velocities ....  translational velocities at the root and joint
                      angular velocities 

positions ....  translational positions at the root, joint angles,
                      quaternions for root and ball joints


The first column in each of the last three files is frame number, so
indices from the forceIndex file must be incremented by 2 to use
gnuplot.  For example, the following command in gnuplot would plot the
translational positions X, Y, and Z by frame number.

plot 'positions' using 1:2, 'positions' using 1:3, 'positions' using 1:4


Y is up.  When the camera fires up, the Z direction is toward the
camera, and the X direction is to the right.

