private void transcribeVerticesAndTriangles(HashMap<Integer, MarchingCubes.Node3f> vertexMap, ArrayList<MarchingCubes.Triangle> triangleList)
    {
        int idIter = 0;

        Iterator<Entry<Integer, MarchingCubes.Node3f>> mapIterator = vertexMap.entrySet().iterator();
        Entry<Integer, MarchingCubes.Node3f> currentEntry;
        Iterator<MarchingCubes.Triangle> vecIterator = triangleList.iterator();
        MarchingCubes.Triangle currentTri;

        // Rename vertices.
        while(mapIterator.hasNext())
        {
            currentEntry = mapIterator.next();
            currentEntry.getValue().id = idIter;
            idIter++;
        }

        // Now rename triangles.
        while(vecIterator.hasNext())
        {
            currentTri = vecIterator.next();
            currentTri.n0 = vertexMap.get(currentTri.n0).id;
            currentTri.n1 = vertexMap.get(currentTri.n1).id;
            currentTri.n2 = vertexMap.get(currentTri.n2).id;
        }

        // Copy all the vertices and triangles into two arrays so that they
        // can be efficiently accessed.
        // Copy vertices.
        mapIterator = vertexMap.entrySet().iterator();
        vertices = new Point3f[vertexMap.size()];
        for(int i = 0; i < vertices.length; i++)
        {
            currentEntry = mapIterator.next();
            vertices[i] = new Point3f(  currentEntry.getValue().x + offs[0],
                                        currentEntry.getValue().y + offs[1],
                                        currentEntry.getValue().z + offs[2]);
        }
        // Copy vertex indices which make triangles.
        vecIterator = triangleList.iterator();
        triangles = new int[triangleList.size() * 3];
        for(int i = 0; i < triangles.length; i += 3)
        {
            currentTri = vecIterator.next();
            currentTri.copyTo(i, triangles);
        }


        // Calculate normals.
        Vector3f vec1 = new Vector3f();
        Vector3f vec2 = new Vector3f();
        Vector3f normal = new Vector3f();

        int id0;
        int id1;
        int id2;

        normals = new Vector3f[vertices.length];

        // Set all normals to 0.
        for(int i = 0; i < normals.length; i++)
        {
            normals[i] = new Vector3f(0, 0, 0);
        }

        // Calculate normals.
        for(int i = 0; i < triangles.length; i += 3)
        {
            id0 = triangles[i];
            id1 = triangles[i + 1];
            id2 = triangles[i + 2];

            vec1.sub(vertices[id1], vertices[id0]);
            vec2.sub(vertices[id2], vertices[id0]);
            normal.cross(vec2, vec1);

            normals[id0].add(normal);
            normals[id1].add(normal);
            normals[id2].add(normal);
        }

        // Normalize normals.
        for(int i = 0; i < normals.length; i++)
        {
            normals[i].normalize();
        }

    }