int MeshFecDataDecomposer::fillIndices(int id, int* buffer, int bufferLength, int logMask)
{
    double* coordinates = NULL;
    double* values = NULL;

    int numIndices = 0;
    int* piNumIndices = &numIndices;
    int numVertices = 0;
    int* piNumVertices = &numVertices;
    int nVertex = 0;
    int* piNVertex = &nVertex;

    int* triangleIndices = NULL;

    int v0 = 0;
    int v1 = 0;
    int v2 = 0;
    int bufferOffset = 0;

    getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_INDICES__, jni_int, (void**) &piNumIndices);
    getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_VERTICES__, jni_int, (void**) &piNumVertices);
    getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_VERTICES_BY_ELEM__, jni_int, (void**) &piNVertex);

    getGraphicObjectProperty(id, __GO_DATA_MODEL_COORDINATES__, jni_double_vector, (void**) &coordinates);
    getGraphicObjectProperty(id, __GO_DATA_MODEL_VALUES__, jni_double_vector, (void**) &values);

    /* 0 facets */
    if (numIndices == 0 || numVertices < 3)
    {
        return 0;
    }

    getGraphicObjectProperty(id, __GO_DATA_MODEL_INDICES__, jni_int_vector, (void**) &triangleIndices);

    for (int i = 0; i < numIndices; i++)
    {
	v0 = triangleIndices[nVertex * i];
	for (unsigned int j = 1; j < nVertex - 1; ++j)
	{
	    v1 = triangleIndices[nVertex * i + j];
	    v2 = triangleIndices[nVertex * i + j + 1];
	    
	    if (areFaceIndicesValid(numVertices, v0, v1, v2) &&
                areFaceVerticesValid(coordinates, v0, v1, v2, logMask) &&
                areFaceValuesValid(values, v0, v1, v2))
	    {
		buffer[bufferOffset] = v0;
		buffer[bufferOffset + 1] = v1;
		buffer[bufferOffset + 2] = v2;
		bufferOffset += 3;
	    }
	}
    }

    return bufferOffset;
}
/*
 * To do: output shared edges once instead of twice (once per adjacent face).
 */
int TriangleMeshFecDataDecomposer::fillWireIndices(char* id, int* buffer, int bufferLength, int logMask)
{
    double* coordinates = NULL;
    double* values = NULL;

    int numVertices = 0;
    int* piNumVertices = &numVertices;
    int numIndices = 0;
    int* piNumIndices = &numIndices;
    int* triangleIndices = NULL;

    int v0 = 0;
    int v1 = 0;
    int v2 = 0;
    int bufferOffset = 0;

    getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_INDICES__, jni_int, (void**) &piNumIndices);

    getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_VERTICES__, jni_int, (void**) &piNumVertices);
    getGraphicObjectProperty(id, __GO_DATA_MODEL_COORDINATES__, jni_double_vector, (void**) &coordinates);
    getGraphicObjectProperty(id, __GO_DATA_MODEL_VALUES__, jni_double_vector, (void**) &values);

    /* 0 segments */
    if (numIndices == 0 || numVertices < 3)
    {
        return 0;
    }

    getGraphicObjectProperty(id, __GO_DATA_MODEL_INDICES__, jni_int_vector, (void**) &triangleIndices);

    for (int i = 0; i < numIndices; i++)
    {
        v0 = triangleIndices[3 * i];
        v1 = triangleIndices[3 * i + 1];
        v2 = triangleIndices[3 * i + 2];

        if (areFaceIndicesValid(numVertices, v0, v1, v2) &&
                areFaceVerticesValid(coordinates, v0, v1, v2, logMask) &&
                areFaceValuesValid(values, v0, v1, v2))
        {
            buffer[bufferOffset] = v0;
            buffer[bufferOffset + 1] = v1;
            buffer[bufferOffset + 2] = v1;
            buffer[bufferOffset + 3] = v2;
            buffer[bufferOffset + 4] = v2;
            buffer[bufferOffset + 5] = v0;

            bufferOffset += 6;
        }

    }

    return bufferOffset;
}