Search in sources :

Example 6 with RealLocalizable

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

the class DefaultBoundingBox method calculate.

@Override
public Polygon2D calculate(final Polygon2D input) {
    double min_x = Double.POSITIVE_INFINITY;
    double max_x = Double.NEGATIVE_INFINITY;
    double min_y = Double.POSITIVE_INFINITY;
    double max_y = Double.NEGATIVE_INFINITY;
    for (final RealLocalizable rl : GeomUtils.vertices(input)) {
        if (rl.getDoublePosition(0) < min_x) {
            min_x = rl.getDoublePosition(0);
        }
        if (rl.getDoublePosition(0) > max_x) {
            max_x = rl.getDoublePosition(0);
        }
        if (rl.getDoublePosition(1) < min_y) {
            min_y = rl.getDoublePosition(1);
        }
        if (rl.getDoublePosition(1) > max_y) {
            max_y = rl.getDoublePosition(1);
        }
    }
    final List<RealLocalizable> bounds = new ArrayList<>();
    bounds.add(new RealPoint(min_x, min_y));
    bounds.add(new RealPoint(min_x, max_y));
    bounds.add(new RealPoint(max_x, max_y));
    bounds.add(new RealPoint(max_x, min_y));
    return new DefaultWritablePolygon2D(bounds);
}
Also used : RealLocalizable(net.imglib2.RealLocalizable) RealPoint(net.imglib2.RealPoint) ArrayList(java.util.ArrayList) DefaultWritablePolygon2D(net.imglib2.roi.geom.real.DefaultWritablePolygon2D)

Example 7 with RealLocalizable

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

the class DefaultFeretsAngle method compute.

@Override
public void compute(final Pair<RealLocalizable, RealLocalizable> input, final DoubleType output) {
    final RealLocalizable p1 = input.getA();
    final RealLocalizable p2 = input.getB();
    final double degree = Math.atan2(p2.getDoublePosition(1) - p1.getDoublePosition(1), p2.getDoublePosition(0) - p1.getDoublePosition(0)) * (180.0 / Math.PI);
    output.set(degree % 180);
}
Also used : RealLocalizable(net.imglib2.RealLocalizable)

Example 8 with RealLocalizable

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

the class DefaultFeretsDiameter method compute.

@Override
public void compute(final Pair<RealLocalizable, RealLocalizable> input, final DoubleType output) {
    final RealLocalizable p1 = input.getA();
    final RealLocalizable p2 = input.getB();
    output.set(Math.hypot(p1.getDoublePosition(0) - p2.getDoublePosition(0), p1.getDoublePosition(1) - p2.getDoublePosition(1)));
}
Also used : RealLocalizable(net.imglib2.RealLocalizable)

Example 9 with RealLocalizable

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

the class DefaultFeretsDiameterForAngle method compute.

@Override
public void compute(Polygon2D input, DoubleType output) {
    final List<? extends RealLocalizable> points = GeomUtils.vertices(function.calculate(input));
    final double angleRad = -angle * Math.PI / 180.0;
    double minX = Double.POSITIVE_INFINITY;
    double maxX = Double.NEGATIVE_INFINITY;
    for (RealLocalizable p : points) {
        final double tmpX = p.getDoublePosition(0) * Math.cos(angleRad) - p.getDoublePosition(1) * Math.sin(angleRad);
        minX = tmpX < minX ? tmpX : minX;
        maxX = tmpX > maxX ? tmpX : maxX;
    }
    output.set(Math.abs(maxX - minX));
}
Also used : RealLocalizable(net.imglib2.RealLocalizable)

Example 10 with RealLocalizable

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

the class DefaultMaximumFeret method calculate.

@Override
public Pair<RealLocalizable, RealLocalizable> calculate(Polygon2D input) {
    final List<? extends RealLocalizable> points = GeomUtils.vertices(function.calculate(input));
    double distance = Double.NEGATIVE_INFINITY;
    RealLocalizable p0 = points.get(0);
    RealLocalizable p1 = points.get(0);
    for (int i = 0; i < points.size(); i++) {
        for (int j = i + 2; j < points.size(); j++) {
            final RealLocalizable tmpP0 = points.get(i);
            final RealLocalizable tmpP1 = points.get(j);
            final double tmp = Math.sqrt(Math.pow(tmpP0.getDoublePosition(0) - tmpP1.getDoublePosition(0), 2) + Math.pow(tmpP0.getDoublePosition(1) - tmpP1.getDoublePosition(1), 2));
            if (tmp > distance) {
                distance = tmp;
                p0 = tmpP0;
                p1 = tmpP1;
            }
        }
    }
    return new ValuePair<>(p0, p1);
}
Also used : RealLocalizable(net.imglib2.RealLocalizable) ValuePair(net.imglib2.util.ValuePair)

Aggregations

RealLocalizable (net.imglib2.RealLocalizable)21 RealPoint (net.imglib2.RealPoint)15 Test (org.junit.Test)9 LinkedHashSet (java.util.LinkedHashSet)6 DefaultMesh (net.imagej.ops.geom.geom3d.mesh.DefaultMesh)6 Vertex (net.imagej.ops.geom.geom3d.mesh.Vertex)6 Polygon2D (net.imglib2.roi.geom.real.Polygon2D)6 ArrayList (java.util.ArrayList)5 AbstractFeatureTest (net.imagej.ops.features.AbstractFeatureTest)5 AbstractOpTest (net.imagej.ops.AbstractOpTest)4 DefaultConvexHull3D (net.imagej.ops.geom.geom3d.DefaultConvexHull3D)4 TriangularFacet (net.imagej.ops.geom.geom3d.mesh.TriangularFacet)4 DefaultWritablePolygon2D (net.imglib2.roi.geom.real.DefaultWritablePolygon2D)4 ValuePair (net.imglib2.util.ValuePair)3 Facet (net.imagej.ops.geom.geom3d.mesh.Facet)2 Vector3D (org.apache.commons.math3.geometry.euclidean.threed.Vector3D)2 Random (java.util.Random)1 DefaultBoundingBox (net.imagej.ops.geom.geom2d.DefaultBoundingBox)1 DefaultContour (net.imagej.ops.geom.geom2d.DefaultContour)1 DefaultConvexHull2D (net.imagej.ops.geom.geom2d.DefaultConvexHull2D)1