<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="mathml.xsl"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript" src="/scripts/lib.js"></script>
<script type="text/javascript" src="/scripts/popup.js"></script>
<script type="text/javascript" >
// redefining default features
var _POPUP_FEATURES = 'width=500,height=300,resizable=1,scrollbars=1,titlebar=1,status=1';
</script>

<link rel="StyleSheet" href="/glab.css" type="text/css" media="all" />
<link rel="StyleSheet" href="../memg.css" type="text/css" media="all" />

<title>MEMG Data Format</title>

</head>

<body>

<div id="primarycontent">

<h1>Binary data format</h1>

<p>The static scene geometry is stored in a standard .obj file.  In addition
to telling us how the scene is broken into groups (using the 
&quot;<code>g [groupname]</code>&quot; syntax), the .obj file
also provides mesh connectivity (which is constant throughout the
animation), texture coordinates, and materials.  A more complete
description of the .obj file format can be found 
<a href="http://www.royriggs.com/obj.html">here</a>.  We provide a
parser for the format with our <a href="viewer.html">viewer source code</a>.  </p>

<p>The motion data is stored in a compressed binary format, since it
would be too large uncompressed to use practically.  All data is in
little-endian (PC byte order).  All integers are 32 bits and doubles are
64 bits.  At the coarsest level, the file consists of a single block containing
all the frame animations, followed by a single block for every group in the
.obj file:  </p>
<table class="fileFormat">
<tr><td>endian indicator</td><td><code>INTEGER</code> &times; 1</td></tr>
<tr><td>framerate</td><td><code>INTEGER</code> &times; 1</td></tr>
<tr><td>frame animations</td><td>See below</td></tr>
<tr><td>group 1 animation</td><td>&quot;</td></tr>
<tr><td>group 2 animation</td><td>&quot;</td></tr>
<tr><td>...</td><td>&nbsp;</td></tr>
<tr><td>group n animation</td><td>&quot;</td></tr>
</table>

<p>We now break down each of these blocks.</p>

<h3>Endian indicator</h3>

<p>This is just the integer 1.  This is simply a check to make sure you
have the correct endian-ness; if it appears to be anything other than
1, you may have to flip the byte order.  </p>

<h3>Framerate of data</h3>

<p>This is the framerate of the data.  For the data provided here, all framerates
are either 30 fps or 120 fps.</p>

<h3>Frame animations</h3>

<p>Animation for each group is stored with respect to an animated 
local coordinate frame.  We store these frame animations at the
beginning of the file.  </p>

<table class="fileFormat">
<tr><td>number of local frames (<span class="variable">k</span>)</td><td><code>INTEGER</code> &times; 1</td></tr>
<tr><td>number of timesteps (<span class="variable">n</span>)</td><td><code>INTEGER</code> &times; 1</td></tr>
<tr><td>local frame 0, timestep 0 (see below)</td><td><code>DOUBLE</code> &times; 12</td></tr>
<tr><td>local frame 1, timestep 0</td><td><code>DOUBLE</code> &times; 12</td></tr>
<tr><td>local frame 2, timestep 0</td><td><code>DOUBLE</code> &times; 12</td></tr>
<tr><td>...</td><td>&nbsp;</td></tr>
<tr><td>local frame <span class="variable">k</span>, timestep 0</td><td><code>DOUBLE</code> &times; 12</td></tr>
<tr><td>local frame 0, timestep 1</td><td><code>DOUBLE</code> &times; 12</td></tr>
<tr><td>local frame 1, timestep 1</td><td><code>DOUBLE</code> &times; 12</td></tr>
<tr><td>...</td><td>&nbsp;</td></tr>
<tr><td>local frame <span class="variable">k</span>, timestep 1</td><td><code>DOUBLE</code> &times; 12</td></tr>
<tr><td>...</td><td>&nbsp;</td></tr>
<tr><td>local frame <span class="variable">k</span>, timestep <span class="variable">n</span></td><td><code>DOUBLE</code> &times; 12</td></tr>
</table>

<p>Each timestep for a particular local frame consists of a 3 &times; 4 affine transform
matrix, stored in row order:</p>
<p>
<math xmlns="http://www.w3.org/1998/Math/MathML">
  <matrix>
    <matrixrow><cn>T[0]</cn><cn>T[1]</cn><cn>T[2]</cn><cn>T[3]</cn></matrixrow>
    <matrixrow><cn>T[4]</cn><cn>T[5]</cn><cn>T[6]</cn><cn>T[7]</cn></matrixrow>
    <matrixrow><cn>T[8]</cn><cn>T[9]</cn><cn>T[10]</cn><cn>T[11]</cn></matrixrow>
    <matrixrow><cn>0</cn><cn>0</cn><cn>0</cn><cn>1</cn></matrixrow>
  </matrix>
</math>
</p>
<p>Here, the upper-left 3 &times; 3 block is the rotation component of 
the transform and the 4th column is the translation component.</p>

<h3>Group animations</h3>

<p>The motion data for each group is stored in the following format:</p>
<table class="fileFormat">
<tr><td>Name length (<span class="variable">l</span>)</td><td><code>INTEGER</code> &times; 1</td></tr>
<tr><td>Group name</td><td><code>CHAR</code> &times; <span class="variable">l</span></td></tr>
<tr><td>Vertex count (<span class="variable">v</span>)</td><td><code>INTEGER</code> &times; 1</td></tr>
<tr><td>.obj file mapping <span class="matrix">M</span></td><td><code>INTEGER</code> &times; <span class="variable">v</span></td></tr>
<tr><td>Mean pose (<span class="matrix">p</span>)</td><td><code>DOUBLE</code> &times; (3<span class="variable">v</span>)</td></tr>
<tr><td>Parent frame</td><td><code>INTEGER</code> &times; 1</td></tr>
<tr><td><span class="matrix">U</span> row count (<span class="variable">m</span>)</td><td><code>INTEGER</code> &times; 1</td></tr>
<tr><td><span class="matrix">U</span> column count (<span class="variable">n</span>)</td><td><code>INTEGER</code> &times; 1</td></tr>
<tr><td>Basis matrix <span class="matrix">U</span></td><td><code>DOUBLE</code> &times; (<span class="variable">mn</span>)</td></tr>
<tr><td><span class="matrix">Q</span> row count (<span class="variable">p</span>)</td><td><code>INTEGER</code> &times; 1</td></tr>
<tr><td><span class="matrix">Q</span> column count (<span class="variable">q</span>)</td><td><code>INTEGER</code> &times; 1</td></tr>
<tr><td>matrix <span class="matrix">Q</span></td><td><code>DOUBLE</code> &times; (<span class="variable">pq</span>)</td></tr>
</table>

<p>Here the group name references a group in the .obj file.  The .obj file mapping
is a mapping between vertices in the motion data (as they are ordered in 
<span class="matrix">p</span> and <span class="matrix">U</span>) and vertices in 
the .obj file.  <span class="matrix">M</span>[<span class="variable">i</span>]
is a vertex index in the .obj file.  Note that .obj vertices are <b>1-indexed</b>.</p>

<p>As described in <a href="../">our paper</a>, the motion for a particular group 
<span class="variable">k</span> is computed as</p>

<blockquote style="font-size: larger">
<span class="matrix">T</span><sub><span class="variable">Wk</span></sub> 
  (<span class="matrix">p</span><sub><span class="variable">k</span></sub> +
   <span class="matrix">U</span><sub><span class="variable">k</span></sub>
	 <span class="matrix">Q</span><sub><span class="variable">k</span></sub>)
</blockquote>

<p>where the transform <span class="matrix">T</span><sub><span
class="variable">Wk</span></sub> operates on each of the vertices
independently.  In the provided viewer, we use graphics hardware to 
do this, but otherwise you should perform the following multiplication
on 3 &times; 1 blocks of the vector
<span class="matrix">v</span> = 
  (<span class="matrix">p</span><sub><span class="variable">k</span></sub> +
   <span class="matrix">U</span><sub><span class="variable">k</span></sub>
	 <span class="matrix">Q</span><sub><span class="variable">k</span></sub>):
</p>
<math mode="display" xmlns="http://www.w3.org/1998/Math/MathML">
  <matrix>
    <matrixrow><cn>T[0]</cn><cn>T[1]</cn><cn>T[2]</cn><cn>T[3]</cn></matrixrow>
    <matrixrow><cn>T[4]</cn><cn>T[5]</cn><cn>T[6]</cn><cn>T[7]</cn></matrixrow>
    <matrixrow><cn>T[8]</cn><cn>T[9]</cn><cn>T[10]</cn><cn>T[11]</cn></matrixrow>
    <matrixrow><cn>0</cn><cn>0</cn><cn>0</cn><cn>1</cn></matrixrow>
  </matrix>
	<vector>
		<selector />
		<apply><ci type="vector">v</ci>
			<cn>
				<apply>
					<plus />
					<apply><times /><cn>3</cn><ci>i</ci></apply>
					<cn>0</cn>
				</apply>
			</cn></apply>
		<apply><ci type="vector">v</ci>
			<cn>
				<apply>
					<plus />
					<apply><times /><cn>3</cn><ci>i</ci></apply>
					<cn>1</cn>
				</apply>
			</cn></apply>
		<apply><ci type="vector">v</ci>
			<cn>
				<apply>
					<plus />
					<apply><times /><cn>3</cn><ci>i</ci></apply>
					<cn>2</cn>
				</apply>
			</cn></apply>
		<cn>1</cn>
	</vector>
</math>

<div id="footer">
<a href="/"><img alt="Carnegie Mellon Graphics" style="padding: 0;" src="/i/logoBlackXSm.png" width="300" height="34" /></a>
<p style="clear: both; margin: 0;">
Comments, questions to <a href="http://www.cs.cmu.edu/~cdtwigg/">Christopher Twigg</a>.
We support <a href="http://www.w3.org">web standards</a>; this page is valid
<a href="http://validator.w3.org/check/referer">XHTML 1.0 Transitional</a> and
<a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a>.
</p>
</div>

</div>

</body>

</html>


