Search in sources :

Example 6 with Vertex

use of net.imagej.ops.geom.geom3d.mesh.Vertex in project imagej-ops by imagej.

the class DefaultConvexHull3D method createFacets.

/**
 * Adds for each edge of the horizon and vTop a new facet.
 *
 * @param horizon facet of all facets seen from point vTop
 * @param vTop point which is added to the convex hull
 * @return new created facets
 */
private List<TriangularFacet> createFacets(final Horizon horizon, final Vertex vTop) {
    List<TriangularFacet> newFacets = new ArrayList<>();
    Vertex vLeft, vRight;
    // triangles 1 to n
    for (int i = 1; i < horizon.size(); i++) {
        vLeft = horizon.getVertex(i - 1);
        vRight = horizon.getVertex(i);
        TriangularFacet f = new TriangularFacet(vRight, vTop, vLeft);
        setNeighborZero(f, horizon.getNeighbor(i));
        newFacets.add(f);
    }
    // triangle 0, this triangle connects the n-th triangle with
    // triangle number 1
    vRight = horizon.getVertex(0);
    vLeft = horizon.getLastVertex();
    TriangularFacet f = new TriangularFacet(vRight, vTop, vLeft);
    setNeighborZero(f, horizon.getNeighbor(0));
    newFacets.add(f);
    // set neighbors 1 and 2 of each triangle
    // triangle 0 has triangle n and 1 as neighbors.
    connectTriangles(newFacets);
    return newFacets;
}
Also used : Vertex(net.imagej.ops.geom.geom3d.mesh.Vertex) TriangularFacet(net.imagej.ops.geom.geom3d.mesh.TriangularFacet) ArrayList(java.util.ArrayList)

Example 7 with Vertex

use of net.imagej.ops.geom.geom3d.mesh.Vertex in project imagej-ops by imagej.

the class DefaultConvexHull3D method computeMinMax.

/**
 * Finds for each dimension the min and max vertex.
 *
 * @return min and max vertices of each dimension
 */
private Pair<Double, Vertex[]> computeMinMax(final Set<Vertex> vertices) {
    Vertex[] minMax = new Vertex[6];
    double maxX, maxY, maxZ;
    double minX, minY, minZ;
    Iterator<Vertex> it = vertices.iterator();
    Vertex initPoint = it.next();
    for (int i = 0; i < minMax.length; i++) {
        minMax[i] = initPoint;
    }
    minX = maxX = initPoint.getX();
    minY = maxY = initPoint.getY();
    minZ = maxZ = initPoint.getZ();
    while (it.hasNext()) {
        Vertex v = it.next();
        if (v.getX() > maxX) {
            maxX = v.getX();
            minMax[3] = v;
        } else if (v.getX() < minX) {
            minX = v.getX();
            minMax[0] = v;
        }
        if (v.getY() > maxY) {
            maxY = v.getY();
            minMax[4] = v;
        } else if (v.getY() < minY) {
            minY = v.getY();
            minMax[2] = v;
        }
        if (v.getZ() > maxZ) {
            maxZ = v.getZ();
            minMax[5] = v;
        } else if (v.getZ() < minZ) {
            minZ = v.getZ();
            minMax[3] = v;
        }
    }
    // This epsilon formula comes from John Lloyd's quickhull
    // implementation http://www.cs.ubc.ca/~lloyd/java/quickhull3d.html
    final double epsilon = 3 * DOUBLE_PREC * (Math.max(Math.abs(maxX), Math.abs(minX)) + Math.max(Math.abs(maxY), Math.abs(minY)) + Math.max(Math.abs(maxZ), Math.abs(minZ)));
    return new ValuePair<>(epsilon, minMax);
}
Also used : Vertex(net.imagej.ops.geom.geom3d.mesh.Vertex) ValuePair(net.imglib2.util.ValuePair)

Example 8 with Vertex

use of net.imagej.ops.geom.geom3d.mesh.Vertex in project imagej-ops by imagej.

the class QuickHull3DTest method randomPointSet.

/**
 * Creates a random point cloud.
 *
 * @param n number of points
 * @param seed the seed
 * @return random point cloud
 */
private LinkedHashSet<RealLocalizable> randomPointSet(int n, long seed) {
    LinkedHashSet<RealLocalizable> points = new LinkedHashSet<>();
    Random r = new Random(seed);
    for (int i = 0; i < n; i++) {
        points.add(new Vertex(r.nextDouble(), r.nextDouble(), r.nextDouble()));
    }
    return points;
}
Also used : RealLocalizable(net.imglib2.RealLocalizable) LinkedHashSet(java.util.LinkedHashSet) Vertex(net.imagej.ops.geom.geom3d.mesh.Vertex) Random(java.util.Random)

Example 9 with Vertex

use of net.imagej.ops.geom.geom3d.mesh.Vertex in project imagej-ops by imagej.

the class QuickHull3DTest method quickhull_12_Test.

@Test
public void quickhull_12_Test() {
    LinkedHashSet<RealLocalizable> points = new LinkedHashSet<>();
    points.add(new Vertex(-0.03621271768232132, 0.3728502838619522, 0.4947140370446388));
    points.add(new Vertex(0.3210853052521919, 0.4807189479290684, 0.4433501688235907));
    points.add(new Vertex(0.07214279572678994, -0.4960366976410492, 0.1112227161519441));
    points.add(new Vertex(0.2229772524190855, -0.4213242506806965, -0.1966818060695024));
    points.add(new Vertex(-0.3411871756810576, -0.3328629143842151, -0.4270033635450559));
    points.add(new Vertex(-0.245701439441835, 0.495905311308713, -0.3194406286994373));
    points.add(new Vertex(0.458374538420117, -0.09914027349943322, -0.2505798421339875));
    points.add(new Vertex(-0.4954086979808367, -0.3339869997780649, -0.3195065691317492));
    points.add(new Vertex(-0.3392973838740004, 0.4288679723896719, -0.01599531622230571));
    points.add(new Vertex(0.2724846394476338, -0.3506708492996831, 0.2750346518820475));
    points.add(new Vertex(0.3544683273457627, -0.450828987127942, -0.0827870439577727));
    points.add(new Vertex(0.1667164640191164, 0.003605551555385444, -0.4014989499947977));
    DefaultMesh df = new DefaultMesh(points);
    DefaultMesh convexHull = (DefaultMesh) ops.run(DefaultConvexHull3D.class, df);
    assertTrue(isConvex(convexHull.getFacets(), convexHull.getEpsilon()));
    assertEquals(12, convexHull.getVertices().size());
}
Also used : RealLocalizable(net.imglib2.RealLocalizable) LinkedHashSet(java.util.LinkedHashSet) Vertex(net.imagej.ops.geom.geom3d.mesh.Vertex) DefaultMesh(net.imagej.ops.geom.geom3d.mesh.DefaultMesh) DefaultConvexHull3D(net.imagej.ops.geom.geom3d.DefaultConvexHull3D) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 10 with Vertex

use of net.imagej.ops.geom.geom3d.mesh.Vertex in project imagej-ops by imagej.

the class DefaultConvexHull3D method assignPointsToFacets.

/**
 * Assigns all points which are not part of the convex hull to a facet. A
 * point is assigned to a facet if the point is in front of this facet. Every
 * point is assigned to only one facet. If a facet has a point in front the
 * facet is added to {@link DefaultConvexHull3D#facetsWithPointInFront}. After
 * this call {@link DefaultConvexHull3D#vertices} is empty. Points which are
 * behind all facets are removed because they are on the inside of the convex
 * hull.
 *
 * @param newFacets which could have a point in front
 * @param facetsWithPointInFront
 */
private void assignPointsToFacets(final double epsilon, final Set<Vertex> vertices, final List<TriangularFacet> newFacets, final List<TriangularFacet> facets, final List<TriangularFacet> facetsWithPointInFront) {
    Iterator<Vertex> vertexIt = vertices.iterator();
    while (vertexIt.hasNext()) {
        Vertex v = vertexIt.next();
        Iterator<TriangularFacet> facetIt = newFacets.iterator();
        TriangularFacet maxFacet = null;
        double maxdis = epsilon;
        while (facetIt.hasNext()) {
            TriangularFacet f = facetIt.next();
            double distanceToPlane = f.distanceToPlane(v);
            // point is assigned to the facet with maximum distance
            if (distanceToPlane > maxdis) {
                maxdis = distanceToPlane;
                maxFacet = f;
            }
        }
        // therefore on the inside of the convex hull.
        if (maxFacet != null) {
            maxFacet.setVertexInFront(v, maxdis);
            if (!facetsWithPointInFront.contains(maxFacet)) {
                facetsWithPointInFront.add(maxFacet);
            }
        }
    }
    facets.addAll(newFacets);
    // All vertices are reassigned or are inside of the convex hull.
    vertices.clear();
}
Also used : Vertex(net.imagej.ops.geom.geom3d.mesh.Vertex) TriangularFacet(net.imagej.ops.geom.geom3d.mesh.TriangularFacet)

Aggregations

Vertex (net.imagej.ops.geom.geom3d.mesh.Vertex)17 DefaultMesh (net.imagej.ops.geom.geom3d.mesh.DefaultMesh)8 TriangularFacet (net.imagej.ops.geom.geom3d.mesh.TriangularFacet)8 LinkedHashSet (java.util.LinkedHashSet)6 RealLocalizable (net.imglib2.RealLocalizable)6 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 AbstractOpTest (net.imagej.ops.AbstractOpTest)4 DefaultConvexHull3D (net.imagej.ops.geom.geom3d.DefaultConvexHull3D)4 Vector3D (org.apache.commons.math3.geometry.euclidean.threed.Vector3D)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 Random (java.util.Random)1 AbstractFeatureTest (net.imagej.ops.features.AbstractFeatureTest)1 DefaultMarchingCubes (net.imagej.ops.geom.geom3d.DefaultMarchingCubes)1 Facet (net.imagej.ops.geom.geom3d.mesh.Facet)1 Horizon (net.imagej.ops.geom.geom3d.mesh.Horizon)1 FinalInterval (net.imglib2.FinalInterval)1 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)1 RealPoint (net.imglib2.RealPoint)1