use of net.imglib2.RealLocalizable in project imagej-ops by imagej.
the class QuickHull3DTest method randomPointSet.
/**
* Creates a random point cloud.
*
* @param n number of points
* @param seed the seed
* @return random point cloud
*/
private LinkedHashSet<RealLocalizable> randomPointSet(int n, long seed) {
LinkedHashSet<RealLocalizable> points = new LinkedHashSet<>();
Random r = new Random(seed);
for (int i = 0; i < n; i++) {
points.add(new Vertex(r.nextDouble(), r.nextDouble(), r.nextDouble()));
}
return points;
}
use of net.imglib2.RealLocalizable in project imagej-ops by imagej.
the class QuickHull3DTest method quickhull_12_Test.
@Test
public void quickhull_12_Test() {
LinkedHashSet<RealLocalizable> points = new LinkedHashSet<>();
points.add(new Vertex(-0.03621271768232132, 0.3728502838619522, 0.4947140370446388));
points.add(new Vertex(0.3210853052521919, 0.4807189479290684, 0.4433501688235907));
points.add(new Vertex(0.07214279572678994, -0.4960366976410492, 0.1112227161519441));
points.add(new Vertex(0.2229772524190855, -0.4213242506806965, -0.1966818060695024));
points.add(new Vertex(-0.3411871756810576, -0.3328629143842151, -0.4270033635450559));
points.add(new Vertex(-0.245701439441835, 0.495905311308713, -0.3194406286994373));
points.add(new Vertex(0.458374538420117, -0.09914027349943322, -0.2505798421339875));
points.add(new Vertex(-0.4954086979808367, -0.3339869997780649, -0.3195065691317492));
points.add(new Vertex(-0.3392973838740004, 0.4288679723896719, -0.01599531622230571));
points.add(new Vertex(0.2724846394476338, -0.3506708492996831, 0.2750346518820475));
points.add(new Vertex(0.3544683273457627, -0.450828987127942, -0.0827870439577727));
points.add(new Vertex(0.1667164640191164, 0.003605551555385444, -0.4014989499947977));
DefaultMesh df = new DefaultMesh(points);
DefaultMesh convexHull = (DefaultMesh) ops.run(DefaultConvexHull3D.class, df);
assertTrue(isConvex(convexHull.getFacets(), convexHull.getEpsilon()));
assertEquals(12, convexHull.getVertices().size());
}
use of net.imglib2.RealLocalizable in project imagej-ops by imagej.
the class DefaultSizePolygon method compute.
@Override
public void compute(Polygon2D input, DoubleType output) {
double sum = 0;
final int numVertices = input.numVertices();
for (int i = 0; i < numVertices; i++) {
final RealLocalizable p0 = input.vertex(i);
final RealLocalizable p1 = input.vertex((i + 1) % numVertices);
final double p0_x = p0.getDoublePosition(0);
final double p0_y = p0.getDoublePosition(1);
final double p1_x = p1.getDoublePosition(0);
final double p1_y = p1.getDoublePosition(1);
sum += p0_x * p1_y - p0_y * p1_x;
}
output.set(Math.abs(sum) / 2d);
}
use of net.imglib2.RealLocalizable in project imagej-ops by imagej.
the class DefaultSmallestEnclosingRectangle method calculate.
@Override
public Polygon2D calculate(final Polygon2D input) {
Polygon2D ch = convexHullFunc.calculate(input);
RealLocalizable cog = centroidFunc.calculate(ch);
Polygon2D minBounds = input;
double minArea = Double.POSITIVE_INFINITY;
// for each edge (i.e. line from P(i-1) to P(i)
for (int i = 1; i < ch.numVertices() - 1; i++) {
final double angle = Math.atan2(ch.vertex(i).getDoublePosition(1) - ch.vertex(i - 1).getDoublePosition(1), ch.vertex(i).getDoublePosition(0) - ch.vertex(i - 1).getDoublePosition(0));
// rotate the polygon in such a manner that the line has an angle of 0
final Polygon2D rotatedPoly = rotate(ch, -angle, cog);
// get the bounds
final Polygon2D bounds = boundingBoxFunc.calculate(rotatedPoly);
// calculate the area of the bounds
final double area = areaFunc.calculate(bounds).get();
// original polygon and save it.
if (area < minArea) {
minArea = area;
minBounds = rotate(bounds, angle, cog);
}
}
// edge (n-1) to 0
final double angle = Math.atan2(ch.vertex(0).getDoublePosition(1) - ch.vertex(ch.numVertices() - 1).getDoublePosition(1), ch.vertex(0).getDoublePosition(0) - ch.vertex(ch.numVertices() - 1).getDoublePosition(0));
// rotate the polygon in such a manner that the line has an angle of 0
final Polygon2D rotatedPoly = rotate(ch, -angle, cog);
// get the bounds
final Polygon2D bounds = boundingBoxFunc.calculate(rotatedPoly);
// calculate the area of the bounds
final double area = areaFunc.calculate(bounds).get();
// original polygon and save it.
if (area < minArea) {
minArea = area;
minBounds = rotate(bounds, angle, cog);
}
return minBounds;
}
use of net.imglib2.RealLocalizable in project imagej-ops by imagej.
the class DefaultDetectJunctions method parallelRoutine.
private <L extends RealLocalizable & RealPositionable> void parallelRoutine(RealLocalizableRealPositionable p1, RealLocalizableRealPositionable p2, RealLocalizableRealPositionable q1, RealLocalizableRealPositionable q2, List<RealPoint> junctions, boolean areVertical) {
// find out whether or not they are on the same line
boolean sameLine = false;
if (areVertical && Math.round(p1.getDoublePosition(0)) == Math.round(q1.getDoublePosition(0)))
sameLine = true;
else {
double m = (q2.getDoublePosition(1) - q1.getDoublePosition(1)) / (q2.getDoublePosition(0) - q1.getDoublePosition(0));
double bp = (p2.getDoublePosition(1) - m * p2.getDoublePosition(0));
double bq = (q2.getDoublePosition(1) - m * q2.getDoublePosition(0));
if (bp == bq)
sameLine = true;
}
// there is no junction
if (!sameLine && Math.min(Math.min(getDistance(p1, q1), getDistance(p2, q1)), Math.min(getDistance(p1, q2), getDistance(p2, q2))) > threshold)
return;
int foundJunctions = 0;
double lengthp = getDistance(p1, p2);
double lengthq = getDistance(q1, q2);
// check p1 to be a junction
if ((getDistance(p1, q1) < lengthq && getDistance(p1, q2) < lengthq && sameLine) || Math.min(getDistance(p1, q1), getDistance(p1, q2)) < threshold) {
junctions.add(makeRealPoint(p1));
foundJunctions++;
}
// check p2 to be a junction
if ((getDistance(p2, q1) < lengthq && getDistance(p2, q2) < lengthq && sameLine) || Math.min(getDistance(p2, q1), getDistance(p2, q2)) < threshold) {
junctions.add(makeRealPoint(p2));
foundJunctions++;
}
// check q1 to be a junction
if (((getDistance(q1, p1) < lengthp && getDistance(q1, p2) < lengthp && sameLine) || (Math.min(getDistance(q1, p1), getDistance(q1, p2)) < threshold)) && foundJunctions < 2) {
junctions.add(makeRealPoint(q1));
foundJunctions++;
}
// check q2 to be a junction
if (((getDistance(q2, p1) < lengthp && getDistance(q2, p2) < lengthp && sameLine) || (Math.min(getDistance(q2, p1), getDistance(q2, p2)) < threshold)) && foundJunctions < 2) {
junctions.add(makeRealPoint(q2));
foundJunctions++;
}
}
Aggregations