int getHeadVertex(GridPoint04 gp)
    {
        if (gp.isHeadVertex())
        {
            return gp.headVertexID;
        }

        bool seekingSilhouette = true;
        if (gp.IsVertex()) seekingSilhouette = false;

        int startingIndex = gp.DepthIndex;

        for (int i = 0; i <= gridStep; i++)
        {
            // WE ARE MOVING UP THE DEPTH IMAGE, SO OUR INDEX JUMPS A ROW EACH TIME
            bool isInBody = (bodyIndexData[startingIndex] != 255);

            if (isInBody && seekingSilhouette) {
                CameraSpacePoint csp = cameraSpacePoints[startingIndex];

                if (!float.IsInfinity(csp.X) &&
                    !float.IsInfinity(csp.Y) &&
                    !float.IsInfinity(csp.Z))
                {

                    gp.headVertexID = vertices.Count;
                    vertices.Add(new Vector3(csp.X, csp.Y, csp.Z));

                    uvs.Add(new Vector2(gp.DepthX / (float)depthWidth, (gp.DepthY + i) / (float)depthHeight));

                    return gp.headVertexID;
                }
            }

            if ( !isInBody && !seekingSilhouette)
            {
                // IF WE WERE IN THE BODY AND MOVING OUTWARD, AT THIS POINT WE HAVE PASSED
                // THE EDGE SO WE WANT TO MOVE BACK ONE TO THE LAST VALID VALUE.
                CameraSpacePoint csp = cameraSpacePoints[startingIndex - depthWidth];

                if (float.IsInfinity(csp.X) ||
                    float.IsInfinity(csp.Y) ||
                    float.IsInfinity(csp.Z))
                {
                    continue;
                }

                gp.headVertexID = vertices.Count;
                vertices.Add(new Vector3(csp.X, csp.Y, csp.Z));

                uvs.Add(new Vector2(gp.DepthX / (float)depthWidth, ( gp.DepthY + (i-1)) / (float)depthHeight));

                return gp.headVertexID;
            }

            startingIndex += depthWidth;

        }

        if (gp.IsVertex())
        {
            return gp.VertexID;
        }
        else
        {
            return -1;
        }
    }
    int getArmVertex(GridPoint04 gp)
    {
        // IF THE ARM HAS BEEN MARCHED BY A PREVIOUS TESTING SQUARE,
        // IT WILL ALREADY HAVE A VERTEX ID SO JUST RETURN IT.
        // OTHERWISE, WE WILL NEED TO MARCH THE ARM AND CREATE A NEW VERTEX
        if (gp.isArmVertex())
        {
            return gp.armVertexID;
        }

        // WE ASSUME THE GRID POINT IS OUTSIDE THE SILHOUETTE AND LOOKING FOR IT
        bool seekingSilhouette = true;

        // BUT WE MAY BE STARTING INSIDE THE SILHOUETTE AND LOOKING FOR THE EDGE
        // SO TEST FOR THAT BY CHECKING IF THE CORE IS A VERTEX, WHICH WOULD MEAN IT WAS VALID
        if (gp.IsVertex())
        {
            seekingSilhouette = false;
        }

        int startingIndex = gp.DepthIndex;

        for (int i = 0; i <= gridStep; i++)
        {
            bool isInBody = (bodyIndexData[startingIndex + i] != 255);

            if (isInBody && seekingSilhouette)
            {
                // IF WE WERE IN THE BODY AND MOVING OUTWARD, AT THIS POINT WE HAVE PASSED
                // THE EDGE SO WE WANT TO MOVE BACK ONE TO THE LAST VALID VALUE.
                CameraSpacePoint csp = cameraSpacePoints[startingIndex + i];

                if (float.IsInfinity(csp.X) ||
                    float.IsInfinity(csp.Y) ||
                    float.IsInfinity(csp.Z))
                {
                    continue;
                }

                gp.armVertexID = vertices.Count;
                vertices.Add(new Vector3(csp.X, csp.Y, csp.Z));

                uvs.Add(new Vector2((gp.DepthX + i) / (float)depthWidth, gp.DepthY / (float)depthHeight));

                return gp.armVertexID;

            }
            if (!isInBody && !seekingSilhouette)
            {
                // IF WE WERE IN THE BODY AND MOVING OUTWARD, AT THIS POINT WE HAVE PASSED
                // THE EDGE SO WE WANT TO MOVE BACK ONE TO THE LAST VALID VALUE.
                CameraSpacePoint csp = cameraSpacePoints[startingIndex + (i-1)];

                if (float.IsInfinity(csp.X) ||
                    float.IsInfinity(csp.Y) ||
                    float.IsInfinity(csp.Z))
                {
                    continue;
                }

                gp.armVertexID = vertices.Count;
                vertices.Add(new Vector3(csp.X, csp.Y, csp.Z));

                uvs.Add(new Vector2( (gp.DepthX + (i-1)) / (float)depthWidth, gp.DepthY / (float)depthHeight));

                return gp.armVertexID;
            }
        }

        if ( gp.IsVertex() )
        {
            return gp.VertexID;
        } else
        {
            return -1;
        }
    }