Java 类javafx.collections.ObservableIntegerArray 实例源码

项目:FX3DAndroid    文件:Validator.java   
public void validate(Mesh mesh) {
        if (!(mesh instanceof TriangleMesh)) {
            throw new AssertionError("Mesh is not TriangleMesh: " + mesh.getClass() + ", mesh = " + mesh);
        }
        TriangleMesh tMesh = (TriangleMesh) mesh;
        int numPoints = tMesh.getPoints().size() / tMesh.getPointElementSize();
        int numTexCoords = tMesh.getTexCoords().size() / tMesh.getTexCoordElementSize();
        int numFaces = tMesh.getFaces().size() / tMesh.getFaceElementSize();
        if (numPoints == 0 || numPoints * tMesh.getPointElementSize() != tMesh.getPoints().size()) {
            throw new AssertionError("Points array size is not correct: " + tMesh.getPoints().size());
        }
        if (numTexCoords == 0 || numTexCoords * tMesh.getTexCoordElementSize() != tMesh.getTexCoords().size()) {
            throw new AssertionError("TexCoords array size is not correct: " + tMesh.getPoints().size());
        }
        if (numFaces == 0 || numFaces * tMesh.getFaceElementSize() != tMesh.getFaces().size()) {
            throw new AssertionError("Faces array size is not correct: " + tMesh.getPoints().size());
        }
        if (numFaces != tMesh.getFaceSmoothingGroups().size() && tMesh.getFaceSmoothingGroups().size() > 0) {
            throw new AssertionError("FaceSmoothingGroups array size is not correct: " + tMesh.getPoints().size() + ", numFaces = " + numFaces);
        }
        ObservableIntegerArray faces = tMesh.getFaces();
        for (int i = 0; i < faces.size(); i += 2) {
            int pIndex = faces.get(i);
            if (pIndex < 0 || pIndex > numPoints) {
                throw new AssertionError("Incorrect point index: " + pIndex + ", numPoints = " + numPoints);
            }
            int tcIndex = faces.get(i + 1);
            if (tcIndex < 0 || tcIndex > numTexCoords) {
                throw new AssertionError("Incorrect texCoord index: " + tcIndex + ", numTexCoords = " + numTexCoords);
            }
        }
//        System.out.println("Validation successfull of " + mesh);
    }
项目:openjfx-8u-dev-tests    文件:MeshTestApp.java   
private boolean checkSmoothingGroups(ObservableIntegerArray sgroups) {
    return arraysEquals(sgroups.toArray(new int[sgroups.size()]), smoothingGroups);
}
项目:openjfx-8u-dev-tests    文件:MeshTestApp.java   
private boolean checkFaces(ObservableIntegerArray tfaces) {
    return arraysEquals(tfaces.toArray(new int[tfaces.size()]), faces);
}
项目:fr.xs.jtk    文件:ClothMesh.java   
public final ObservableIntegerArray getFaceSmoothingGroups() {
    return mesh.getFaceSmoothingGroups();
}
项目:FXyzLib    文件:ClothMesh.java   
public final ObservableIntegerArray getFaceSmoothingGroups() {
    return mesh.getFaceSmoothingGroups();
}
项目:FX3DAndroid    文件:Optimizer.java   
private void optimizeFaces() {
        int total = 0, sameIndexes = 0, samePoints = 0, smallArea = 0;
        ObservableIntegerArray newFaces = FXCollections.observableIntegerArray();
        ObservableIntegerArray newFaceSmoothingGroups = FXCollections.observableIntegerArray();
        for (MeshView meshView : meshViews) {
            TriangleMesh mesh = (TriangleMesh) meshView.getMesh();
            ObservableIntegerArray faces = mesh.getFaces();
            ObservableIntegerArray faceSmoothingGroups = mesh.getFaceSmoothingGroups();
            ObservableFloatArray points = mesh.getPoints();
            newFaces.clear();
            newFaces.ensureCapacity(faces.size());
            newFaceSmoothingGroups.clear();
            newFaceSmoothingGroups.ensureCapacity(faceSmoothingGroups.size());
            int pointElementSize = mesh.getPointElementSize();
            int faceElementSize = mesh.getFaceElementSize();
            for (int i = 0; i < faces.size(); i += faceElementSize) {
                total++;
                int i1 = faces.get(i) * pointElementSize;
                int i2 = faces.get(i + 2) * pointElementSize;
                int i3 = faces.get(i + 4) * pointElementSize;
                if (i1 == i2 || i1 == i3 || i2 == i3) {
                    sameIndexes++;
                    continue;
                }
                Point3D p1 = new Point3D(points.get(i1), points.get(i1 + 1), points.get(i1 + 2));
                Point3D p2 = new Point3D(points.get(i2), points.get(i2 + 1), points.get(i2 + 2));
                Point3D p3 = new Point3D(points.get(i3), points.get(i3 + 1), points.get(i3 + 2));
                if (p1.equals(p2) || p1.equals(p3) || p2.equals(p3)) {
                    samePoints++;
                    continue;
                }
                double a = p1.distance(p2);
                double b = p2.distance(p3);
                double c = p3.distance(p1);
                double p = (a + b + c) / 2;
                double sqarea = p * (p - a) * (p - b) * (p - c);

                final float DEAD_FACE = 1.f/1024/1024/1024/1024; // taken from MeshNormal code

                if (sqarea < DEAD_FACE) {
                    smallArea++;
//                    System.out.printf("a = %e, b = %e, c = %e, sqarea = %e\n"
//                            + "p1 = %s\np2 = %s\np3 = %s\n", a, b, c, sqarea, p1.toString(), p2.toString(), p3.toString());
                    continue;
                }
                newFaces.addAll(faces, i, faceElementSize);
                int fIndex = i / faceElementSize;
                if (fIndex < faceSmoothingGroups.size()) {
                    newFaceSmoothingGroups.addAll(faceSmoothingGroups.get(fIndex));
                }
            }
            faces.setAll(newFaces);
            faceSmoothingGroups.setAll(newFaceSmoothingGroups);
            faces.trimToSize();
            faceSmoothingGroups.trimToSize();
        }
        int badTotal = sameIndexes + samePoints + smallArea;
        System.out.printf("Removed %d (%.2f%%) faces with same point indexes, "
                + "%d (%.2f%%) faces with same points, "
                + "%d (%.2f%%) faces with small area. "
                + "Total %d (%.2f%%) bad faces out of %d total.\n",
                sameIndexes, 100d * sameIndexes / total,
                samePoints, 100d * samePoints / total,
                smallArea, 100d * smallArea / total,
                badTotal, 100d * badTotal / total, total);
    }
项目:FX3DAndroid    文件:Optimizer.java   
private void optimizePoints() {
        int total = 0, duplicates = 0, check = 0;

        Map<Point3D, Integer> pp = new HashMap<>();
        ObservableIntegerArray reindex = FXCollections.observableIntegerArray();
        ObservableFloatArray newPoints = FXCollections.observableFloatArray();

        for (MeshView meshView : meshViews) {
            TriangleMesh mesh = (TriangleMesh) meshView.getMesh();
            ObservableFloatArray points = mesh.getPoints();
            int pointElementSize = mesh.getPointElementSize();
            int os = points.size() / pointElementSize;

            pp.clear();
            newPoints.clear();
            newPoints.ensureCapacity(points.size());
            reindex.clear();
            reindex.resize(os);

            for (int i = 0, oi = 0, ni = 0; i < points.size(); i += pointElementSize, oi++) {
                float x = points.get(i);
                float y = points.get(i + 1);
                float z = points.get(i + 2);
                Point3D p = new Point3D(x, y, z);
                Integer index = pp.get(p);
                if (index == null) {
                    pp.put(p, ni);
                    reindex.set(oi, ni);
                    newPoints.addAll(x, y, z);
                    ni++;
                } else {
                    reindex.set(oi, index);
                }
            }

            int ns = newPoints.size() / pointElementSize;

            int d = os - ns;
            duplicates += d;
            total += os;

            points.setAll(newPoints);
            points.trimToSize();

            ObservableIntegerArray faces = mesh.getFaces();
            for (int i = 0; i < faces.size(); i += 2) {
                faces.set(i, reindex.get(faces.get(i)));
            }

//            System.out.printf("There are %d (%.2f%%) duplicate points out of %d total for mesh '%s'.\n",
//                    d, 100d * d / os, os, meshView.getId());

            check += mesh.getPoints().size() / pointElementSize;
        }
        System.out.printf("There are %d (%.2f%%) duplicate points out of %d total.\n",
                duplicates, 100d * duplicates / total, total);
        System.out.printf("Now we have %d points.\n", check);
    }
项目:FX3DAndroid    文件:Optimizer.java   
private void optimizeTexCoords() {
        int total = 0, duplicates = 0, check = 0;

        Map<Point2D, Integer> pp = new HashMap<>();
        ObservableIntegerArray reindex = FXCollections.observableIntegerArray();
        ObservableFloatArray newTexCoords = FXCollections.observableFloatArray();

        for (MeshView meshView : meshViews) {
            TriangleMesh mesh = (TriangleMesh) meshView.getMesh();
            ObservableFloatArray texcoords = mesh.getTexCoords();
            int texcoordElementSize = mesh.getTexCoordElementSize();
            int os = texcoords.size() / texcoordElementSize;

            pp.clear();
            newTexCoords.clear();
            newTexCoords.ensureCapacity(texcoords.size());
            reindex.clear();
            reindex.resize(os);

            for (int i = 0, oi = 0, ni = 0; i < texcoords.size(); i += texcoordElementSize, oi++) {
                float x = texcoords.get(i);
                float y = texcoords.get(i + 1);
                Point2D p = new Point2D(x, y);
                Integer index = pp.get(p);
                if (index == null) {
                    pp.put(p, ni);
                    reindex.set(oi, ni);
                    newTexCoords.addAll(x, y);
                    ni++;
                } else {
                    reindex.set(oi, index);
                }
            }

            int ns = newTexCoords.size() / texcoordElementSize;

            int d = os - ns;
            duplicates += d;
            total += os;

            texcoords.setAll(newTexCoords);
            texcoords.trimToSize();

            ObservableIntegerArray faces = mesh.getFaces();
            for (int i = 1; i < faces.size(); i += 2) {
                faces.set(i, reindex.get(faces.get(i)));
            }

//            System.out.printf("There are %d (%.2f%%) duplicate texcoords out of %d total for mesh '%s'.\n",
//                    d, 100d * d / os, os, meshView.getId());

            check += mesh.getTexCoords().size() / texcoordElementSize;
        }
        System.out.printf("There are %d (%.2f%%) duplicate texcoords out of %d total.\n",
                duplicates, 100d * duplicates / total, total);
        System.out.printf("Now we have %d texcoords.\n", check);
    }
项目:FX3DAndroid    文件:PolygonMesh.java   
public ObservableIntegerArray getFaceSmoothingGroups() {
    return faceSmoothingGroups;
}
项目:FX3DAndroid    文件:ClothMesh.java   
public final ObservableIntegerArray getFaceSmoothingGroups() {
    return mesh.getFaceSmoothingGroups();
}
项目:FX3DAndroid    文件:ClothMesh.java   
public final ObservableIntegerArray getFaceSmoothingGroups() {
    return mesh.getFaceSmoothingGroups();
}