Search in sources :

Example 1 with Object3DSurface

use of mcib3d.geom.Object3DSurface in project mcib3d-core by mcib3d.

the class Mesh method computeConvexHull3D.

public ArrayList<Point3f> computeConvexHull3D() {
    QuickHull3D hull = new QuickHull3D();
    System.out.println("Computing 3d convex hull...");
    Object3DSurface o = new Object3DSurface(vertices);
    ArrayList<Voxel3D> pointsList = o.getContours();
    Point3d[] points = new Point3d[pointsList.size()];
    for (int ve = 0; ve < points.length; ve++) {
        points[ve] = new Point3d(pointsList.get(ve).getX(), pointsList.get(ve).getY(), pointsList.get(ve).getZ());
    }
    System.out.println("done 1st for");
    hull.build(points);
    hull.triangulate();
    ArrayList<Point3f> convex = new ArrayList<Point3f>();
    int[][] faceIndices = hull.getFaces();
    Point3d[] verticesHull = hull.getVertices();
    for (int k = 0; k < faceIndices.length; k++) {
        for (int ve = 0; ve < 3; ve++) {
            Point3d point = verticesHull[faceIndices[k][ve]];
            convex.add(new Point3f((float) point.x, (float) point.y, (float) point.z));
        }
    }
    return convex;
}
Also used : Point3f(org.scijava.vecmath.Point3f) QuickHull3D(com.github.quickhull3d.QuickHull3D) Point3d(com.github.quickhull3d.Point3d) ArrayList(java.util.ArrayList) Voxel3D(mcib3d.geom.Voxel3D) Object3DSurface(mcib3d.geom.Object3DSurface)

Aggregations

Point3d (com.github.quickhull3d.Point3d)1 QuickHull3D (com.github.quickhull3d.QuickHull3D)1 ArrayList (java.util.ArrayList)1 Object3DSurface (mcib3d.geom.Object3DSurface)1 Voxel3D (mcib3d.geom.Voxel3D)1 Point3f (org.scijava.vecmath.Point3f)1