Search in sources :

Example 1 with TriangularFacet

use of net.imagej.ops.geom.geom3d.mesh.TriangularFacet 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 TriangularFacet

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

the class DefaultConvexHull3D method computeHorizon.

/**
 * Computes the horizon of vTop. The horizon is the merged facet of all facets
 * which are in front of the point vTop.
 *
 * @param frontFacet a face which is in front of vTop
 * @param vTop a point outside of the convex hull
 * @return facet containing all facets which are in front of vTop
 */
private Horizon computeHorizon(final double epsilon, final Set<Vertex> vertices, final List<TriangularFacet> facets, final List<TriangularFacet> facetsWithPointInFront, final TriangularFacet frontFacet, final Vertex vTop) {
    // Points which are in front have to be reassigned after all new facets
    // are constructed.
    vertices.addAll(frontFacet.getVerticesInFront());
    // frontFacet is not a result facet. Remove it from result list.
    facets.remove(frontFacet);
    Horizon h = new Horizon(frontFacet);
    TriangularFacet merge = nextFacetToMerge(epsilon, h, vTop);
    while (merge != null) {
        // This points have to be reassigned as well.
        vertices.addAll(merge.getVerticesInFront());
        // This face has some points in front and therefore is not a result
        // face.
        facets.remove(merge);
        // After this step this facet is merged with another facet.
        facetsWithPointInFront.remove(merge);
        if (h.containsAll(merge.getVertices())) {
            updateNeighbors(frontFacet, merge);
            h.complexMerge(merge);
        } else {
            updateNeighbors(frontFacet, merge);
            h.simpleMerge(merge);
        }
        merge = nextFacetToMerge(epsilon, h, vTop);
    }
    return h;
}
Also used : TriangularFacet(net.imagej.ops.geom.geom3d.mesh.TriangularFacet) Horizon(net.imagej.ops.geom.geom3d.mesh.Horizon)

Example 3 with TriangularFacet

use of net.imagej.ops.geom.geom3d.mesh.TriangularFacet 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 4 with TriangularFacet

use of net.imagej.ops.geom.geom3d.mesh.TriangularFacet 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 5 with TriangularFacet

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

the class DefaultInertiaTensor3DMesh method calculate.

@Override
public RealMatrix calculate(final Mesh input) {
    final RealLocalizable o = centroid.calculate(input);
    BlockRealMatrix tensor = new BlockRealMatrix(3, 3);
    final Iterator<Facet> c = input.getFacets().iterator();
    while (c.hasNext()) {
        final TriangularFacet tf = (TriangularFacet) c.next();
        tensor = tensor.add(tetrahedronInertiaTensor(tf.getVertex(0), tf.getVertex(1), tf.getVertex(2), o));
    }
    return tensor;
}
Also used : RealLocalizable(net.imglib2.RealLocalizable) TriangularFacet(net.imagej.ops.geom.geom3d.mesh.TriangularFacet) BlockRealMatrix(org.apache.commons.math3.linear.BlockRealMatrix) Facet(net.imagej.ops.geom.geom3d.mesh.Facet) TriangularFacet(net.imagej.ops.geom.geom3d.mesh.TriangularFacet)

Aggregations

TriangularFacet (net.imagej.ops.geom.geom3d.mesh.TriangularFacet)13 Vertex (net.imagej.ops.geom.geom3d.mesh.Vertex)8 DefaultMesh (net.imagej.ops.geom.geom3d.mesh.DefaultMesh)5 ArrayList (java.util.ArrayList)4 Facet (net.imagej.ops.geom.geom3d.mesh.Facet)4 RealLocalizable (net.imglib2.RealLocalizable)3 RealPoint (net.imglib2.RealPoint)3 FinalInterval (net.imglib2.FinalInterval)2 Vector3D (org.apache.commons.math3.geometry.euclidean.threed.Vector3D)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 LinkedHashSet (java.util.LinkedHashSet)1 AbstractFeatureTest (net.imagej.ops.features.AbstractFeatureTest)1 DefaultMarchingCubes (net.imagej.ops.geom.geom3d.DefaultMarchingCubes)1 Horizon (net.imagej.ops.geom.geom3d.mesh.Horizon)1 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)1 BitType (net.imglib2.type.logic.BitType)1 BoolType (net.imglib2.type.logic.BoolType)1 DoubleType (net.imglib2.type.numeric.real.DoubleType)1 ExtendedRandomAccessibleInterval (net.imglib2.view.ExtendedRandomAccessibleInterval)1