Working with Triangle Mesh Data

A triangle mesh data object is used to represent complex surfaces that can be described by a set of adjacent triangles.

Note: you will need to include GocadData in your Module Dependencies list

Creating a TriangleMesh data object from a file

The most common file format for triangle mesh data is the Gocad format from Paradigm. Gocad files have extension ".ts". A Gocad file can be loaded as follows:

    import com.interactive.intviewerapi.data.IData;
    import com.interactive.intviewerapi.data.tmesh.ITriangleMeshData;
    import com.interactive.intviewerapi.util.DialogManager;
    ...
        IData gcd = null;
        try {
            gcd = IData.factory.createNewInstance("/data/GOCAD/SALT.ts");
        } catch (Exception ex) {
            DialogManager.getDefault().showMessageDialog("Error loading Gocad file SALT.ts.",
                    "Error Loading Gocad File", DialogManager.ERROR);
            return;
        }

Since Gocad files can contain various types of data, you need to verify that the type of data returned is indeed a ITriangleMeshData object.

    if (gcd instanceof ITriangleMeshData) {
       ...
    }

Creating a TriangleMesh data object programmatically

        float vertices[] = {0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1};
        int indexes[] = {0, 1, 3,
                         1, 2, 3,
                         4, 5, 0,
                         5, 0, 0,
                         1, 5, 2,
                         5, 6, 2,
                         3, 2, 7,
                         2, 6, 7,
                         4, 0, 7,
                         0, 3, 7,
                         7, 6, 4};
        ITriangleMeshData cube = new TriangleMeshData("cube", vertices, indexes);

Retrieving the vertices and indexes of a TriangleMesh

    ITriangleMeshData data = ...
    int[] indexes = data.getIndexes();
    float[] vertices = data.getVertices();
    System.out.println("Number of triangles = " + (data.getIndexes().length/3));

Smoothing a TriangleMesh surface

Utility class TriangleSmoothing provides an implementation of Loop's scheme for smoothing a triangle mesh surface. Each path subdvides the triangles into four sub-triangles.

    import com.interactive.intviewerapi.data.tmesh.TriangleSmoothing;
    ...
    TriangleSmoothing ts = new TriangleSmoothing(2, cube.getVertices(), cube.getIndexes());
    ITriangleMeshData smoothCube = new TriangleMeshData("smooth cube", ts.getVertices(), ts.getIndexes());

before smoothing after smoothing (2 passes)