Search in sources :

Example 21 with RealPoint

use of net.imglib2.RealPoint in project imagej-ops by imagej.

the class PolygonFeatureTests method centroid.

@Test
public void centroid() {
    // ground truth computed with matlab
    final RealPoint expected = new RealPoint(38.144483985765, 59.404175563464);
    final RealPoint result = (RealPoint) ops.run(CentroidPolygon.class, contour);
    assertEquals("Centroid X", expected.getDoublePosition(0), result.getDoublePosition(0), EPSILON);
    assertEquals("Centroid Y", expected.getDoublePosition(1), result.getDoublePosition(1), EPSILON);
}
Also used : RealPoint(net.imglib2.RealPoint) Test(org.junit.Test) AbstractFeatureTest(net.imagej.ops.features.AbstractFeatureTest)

Example 22 with RealPoint

use of net.imglib2.RealPoint in project imagej-ops by imagej.

the class AbstractFeatureTest method getPolygon.

protected static Polygon2D getPolygon() {
    final List<RealPoint> vertices = new ArrayList<>();
    try {
        Files.lines(Paths.get(AbstractFeatureTest.class.getResource("2d_geometric_features_polygon.txt").toURI())).forEach(l -> {
            String[] coord = l.split(" ");
            RealPoint v = new RealPoint(new double[] { Double.parseDouble(coord[0]), Double.parseDouble(coord[1]) });
            vertices.add(v);
        });
    } catch (IOException | URISyntaxException exc) {
        exc.printStackTrace();
    }
    return new DefaultWritablePolygon2D(vertices);
}
Also used : RealPoint(net.imglib2.RealPoint) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) DefaultWritablePolygon2D(net.imglib2.roi.geom.real.DefaultWritablePolygon2D)

Aggregations

RealPoint (net.imglib2.RealPoint)21 ArrayList (java.util.ArrayList)9 RealLocalizable (net.imglib2.RealLocalizable)6 DefaultWritablePolygon2D (net.imglib2.roi.geom.real.DefaultWritablePolygon2D)5 Test (org.junit.Test)5 AbstractFeatureTest (net.imagej.ops.features.AbstractFeatureTest)4 Polygon2D (net.imglib2.roi.geom.real.Polygon2D)3 TriangularFacet (net.imagej.ops.geom.geom3d.mesh.TriangularFacet)2 DefaultWritablePolyline (net.imglib2.roi.geom.real.DefaultWritablePolyline)2 Vector3D (org.apache.commons.math3.geometry.euclidean.threed.Vector3D)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 AbstractOpTest (net.imagej.ops.AbstractOpTest)1 DefaultBoundingBox (net.imagej.ops.geom.geom2d.DefaultBoundingBox)1 DefaultConvexHull2D (net.imagej.ops.geom.geom2d.DefaultConvexHull2D)1 DefaultSmallestEnclosingRectangle (net.imagej.ops.geom.geom2d.DefaultSmallestEnclosingRectangle)1 DefaultMesh (net.imagej.ops.geom.geom3d.mesh.DefaultMesh)1 Facet (net.imagej.ops.geom.geom3d.mesh.Facet)1 FinalInterval (net.imglib2.FinalInterval)1 Interval (net.imglib2.Interval)1