Search in sources :

Example 1 with Vertex

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

the class DefaultConvexHull3D method calculate.

@Override
public Mesh calculate(final Mesh input) {
    DefaultMesh output = new DefaultMesh();
    Set<Vertex> vertices = new LinkedHashSet<>();
    for (final RealLocalizable v : input.getVertices()) {
        vertices.add(new Vertex(v.getDoublePosition(0), v.getDoublePosition(1), v.getDoublePosition(2)));
    }
    List<TriangularFacet> facets = new ArrayList<>();
    List<TriangularFacet> facetsWithPointInFront = new ArrayList<>();
    final double epsilon = computeHull(vertices, facets, facetsWithPointInFront);
    for (TriangularFacet f : facets) {
        output.addFace(f);
    }
    output.setEpsilon(epsilon);
    return output;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RealLocalizable(net.imglib2.RealLocalizable) Vertex(net.imagej.ops.geom.geom3d.mesh.Vertex) TriangularFacet(net.imagej.ops.geom.geom3d.mesh.TriangularFacet) DefaultMesh(net.imagej.ops.geom.geom3d.mesh.DefaultMesh) ArrayList(java.util.ArrayList)

Example 2 with Vertex

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

the class DefaultConvexHull3D method getV3.

/**
 * Finds the point with the largest distance to the plane described by v0, v1,
 * v2.
 *
 * @param v0 Vertex of the plane.
 * @param v1 Vertex of the plane.
 * @param v2 Vertex of the plane.
 * @return Vertex with the largest distance.
 */
private Vertex getV3(final double epsilon, final Set<Vertex> vertices, final Vertex v0, final Vertex v1, final Vertex v2) {
    double distPlanePoint = epsilon;
    Vertex v3 = null;
    Vector3D d0 = v1.subtract(v0);
    Vector3D d1 = v2.subtract(v0);
    Vector3D normal = d0.crossProduct(d1).normalize();
    for (final Vertex v : vertices) {
        double d = Math.abs(normal.dotProduct(v.subtract(v0)));
        if (d > distPlanePoint) {
            distPlanePoint = d;
            v3 = v;
        }
    }
    return v3;
}
Also used : Vertex(net.imagej.ops.geom.geom3d.mesh.Vertex) Vector3D(org.apache.commons.math3.geometry.euclidean.threed.Vector3D)

Example 3 with Vertex

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

the class DefaultConvexHull3D method replaceFacet.

/**
 * Replaces a facet with at least three new facets.
 *
 * @param facet the facet to replace. At least one point must be in front of
 *          next.
 */
private void replaceFacet(final double epsilon, final Set<Vertex> vertices, final List<TriangularFacet> facets, final List<TriangularFacet> facetsPointInFront, final TriangularFacet facet) {
    final Vertex v = facet.getMaximumDistanceVertex();
    final Horizon horizon = computeHorizon(epsilon, vertices, facets, facetsPointInFront, facet, v);
    assignPointsToFacets(epsilon, vertices, createFacets(horizon, v), facets, facetsPointInFront);
}
Also used : Vertex(net.imagej.ops.geom.geom3d.mesh.Vertex) Horizon(net.imagej.ops.geom.geom3d.mesh.Horizon)

Example 4 with Vertex

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

the class DefaultConvexHull3D method nextFacetToMerge.

/**
 * Returns a facet which is in front of vTop and neighbor of front.
 *
 * @param frontFacet facet in front of vTop
 * @param vTop point which is added to the convex hull
 * @return neighboring facet of front or null if no facet is in front
 */
private TriangularFacet nextFacetToMerge(final double epsilon, final Horizon frontFacet, final Vertex vTop) {
    Iterator<TriangularFacet> it = frontFacet.getNeighbors().iterator();
    while (it.hasNext()) {
        TriangularFacet f = it.next();
        if (f.distanceToPlane(vTop) > epsilon) {
            // with two edges or one edge
            if (frontFacet.containsAll(f.getVertices())) {
                Vertex v0 = f.getVertex(0);
                Vertex v1 = f.getVertex(1);
                Vertex v2 = f.getVertex(2);
                int numEdges = 0;
                if (frontFacet.hasEdge(v0, v2)) {
                    numEdges++;
                }
                if (frontFacet.hasEdge(v2, v1)) {
                    numEdges++;
                }
                if (frontFacet.hasEdge(v1, v0)) {
                    numEdges++;
                }
                if (numEdges == 1) {
                    // and will be merged.
                    continue;
                }
            }
            // not part of frontFacet.
            return f;
        }
    }
    return null;
}
Also used : Vertex(net.imagej.ops.geom.geom3d.mesh.Vertex) TriangularFacet(net.imagej.ops.geom.geom3d.mesh.TriangularFacet)

Example 5 with Vertex

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

the class DefaultConvexHull3D method getV2.

/**
 * Finds the vertex with the largest distance to the line described by v0, v1.
 *
 * @param v0 Vertex of the line.
 * @param v1 Vertex of the line.
 * @return Vertex with the largest distance.
 */
private Vertex getV2(final double epsilon, final Set<Vertex> vertices, final Vertex v0, final Vertex v1) {
    Iterator<Vertex> it = vertices.iterator();
    // v0 -------------------------------------v1
    // |
    // | d
    // |
    // * v
    // 
    // d = |(v - v0) x (v - v1)| / |(v1 - v0)|
    // We can omit the common denominator because it does not change over
    // all computations.
    double distLinePoint = epsilon;
    Vertex v2 = null;
    while (it.hasNext()) {
        Vertex v = it.next();
        Vector3D d0 = v.subtract(v1);
        Vector3D d1 = v.subtract(v0);
        double lengthSq = d0.crossProduct(d1).getNormSq();
        if (lengthSq > distLinePoint) {
            distLinePoint = lengthSq;
            v2 = v;
        }
    }
    return v2;
}
Also used : Vertex(net.imagej.ops.geom.geom3d.mesh.Vertex) Vector3D(org.apache.commons.math3.geometry.euclidean.threed.Vector3D)

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