Search in sources :

Example 11 with TriangularFacet

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

the class CentroidMesh method calculate.

@Override
public RealLocalizable calculate(final Mesh input) {
    double c_x = 0;
    double c_y = 0;
    double c_z = 0;
    for (int i = 0; i < input.getFacets().size(); i++) {
        TriangularFacet f = (TriangularFacet) input.getFacets().get(i);
        Vector3D normal = f.getNormal();
        Vector3D a = f.getP0();
        Vector3D b = f.getP1();
        Vector3D c = f.getP2();
        c_x += (1 / 24d) * normal.getX() * (Math.pow((a.getX() + b.getX()), 2) + Math.pow((b.getX() + c.getX()), 2) + Math.pow((c.getX() + a.getX()), 2));
        c_y += (1 / 24d) * normal.getY() * (Math.pow((a.getY() + b.getY()), 2) + Math.pow((b.getY() + c.getY()), 2) + Math.pow((c.getY() + a.getY()), 2));
        c_z += (1 / 24d) * normal.getZ() * (Math.pow((a.getZ() + b.getZ()), 2) + Math.pow((b.getZ() + c.getZ()), 2) + Math.pow((c.getZ() + a.getZ()), 2));
    }
    double d = 1 / (2 * sizeFunc.calculate(input).get());
    c_x *= d;
    c_y *= d;
    c_z *= d;
    return new RealPoint(-c_x, -c_y, -c_z);
}
Also used : TriangularFacet(net.imagej.ops.geom.geom3d.mesh.TriangularFacet) Vector3D(org.apache.commons.math3.geometry.euclidean.threed.Vector3D) RealPoint(net.imglib2.RealPoint) RealPoint(net.imglib2.RealPoint)

Example 12 with TriangularFacet

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

the class MeshFeatureTests method marchingCubes.

@Test
public void marchingCubes() {
    final DefaultMesh result = (DefaultMesh) ops.run(DefaultMarchingCubes.class, ROI);
    final List<Facet> expectedFacets = mesh.getFacets();
    final List<Facet> resultFacets = result.getFacets();
    for (int i = 0; i < expectedFacets.size(); i++) {
        final TriangularFacet tmpR = (TriangularFacet) resultFacets.get(i);
        final TriangularFacet tmpE = (TriangularFacet) expectedFacets.get(i);
        for (int j = 0; j < 3; j++) {
            final Vertex resultVertex = tmpR.getVertex(j);
            final Vertex expectedVertex = tmpE.getVertex(j);
            assertEquals("Triangular Facet point " + j + " differes in x- coordinate:", expectedVertex.getDoublePosition(0), resultVertex.getDoublePosition(0), EPSILON);
            assertEquals("Triangular Facet point " + j + " differes in y- coordinate:", expectedVertex.getDoublePosition(1), resultVertex.getDoublePosition(1), EPSILON);
            assertEquals("Triangular Facet point " + j + " differes in z- coordinate:", expectedVertex.getDoublePosition(2), resultVertex.getDoublePosition(2), EPSILON);
        }
    }
}
Also used : Vertex(net.imagej.ops.geom.geom3d.mesh.Vertex) TriangularFacet(net.imagej.ops.geom.geom3d.mesh.TriangularFacet) DefaultMesh(net.imagej.ops.geom.geom3d.mesh.DefaultMesh) DefaultMarchingCubes(net.imagej.ops.geom.geom3d.DefaultMarchingCubes) Facet(net.imagej.ops.geom.geom3d.mesh.Facet) TriangularFacet(net.imagej.ops.geom.geom3d.mesh.TriangularFacet) Test(org.junit.Test) AbstractFeatureTest(net.imagej.ops.features.AbstractFeatureTest)

Example 13 with TriangularFacet

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

the class AbstractFeatureTest method getMesh.

protected static Mesh getMesh() {
    final List<Vertex> vertices = new ArrayList<>();
    try {
        Files.lines(Paths.get(AbstractFeatureTest.class.getResource("3d_geometric_features_mesh.txt").toURI())).forEach(l -> {
            String[] coord = l.split(" ");
            Vertex v = new Vertex(Double.parseDouble(coord[0]), Double.parseDouble(coord[1]), Double.parseDouble(coord[2]));
            vertices.add(v);
        });
    } catch (IOException | URISyntaxException exc) {
        exc.printStackTrace();
    }
    final DefaultMesh m = new DefaultMesh();
    for (int i = 0; i < vertices.size(); i += 3) {
        final TriangularFacet f = new TriangularFacet(vertices.get(i), vertices.get(i + 1), vertices.get(i + 2));
        m.addFace(f);
    }
    return m;
}
Also used : 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) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) RealPoint(net.imglib2.RealPoint)

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