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);
}
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);
}
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)));
}
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));
}
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);
}
Aggregations