use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class TestEllipseClustersIntoHexagonalGrid method process_affine.
private void process_affine(int rows, int cols, Affine2D_F64 affine) {
// create a grid in the expected format
EllipseClustersIntoHexagonalGrid alg = new EllipseClustersIntoHexagonalGrid();
Tuple2<List<Node>, List<EllipseRotated_F64>> grid = createHexagonalGrid(rows, cols, 0.5, 1);
for (EllipseRotated_F64 e : grid.data1) {
AffinePointOps_F64.transform(affine, e.center, e.center);
}
List<List<Node>> nodes = new ArrayList<>();
nodes.add(grid.data0);
processAndCheck(rows, cols, alg, grid, nodes);
}
use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class TestEllipseClustersIntoHexagonalGrid method saveResults.
@Test
public void saveResults() {
// construct a dummy graph
List<List<NodeInfo>> graph = new ArrayList<>();
for (int i = 0; i < 3; i++) {
graph.add(new ArrayList<NodeInfo>());
}
for (int i = 0; i < 2; i++) {
graph.get(0).add(new NodeInfo());
graph.get(2).add(new NodeInfo());
}
graph.get(1).add(new NodeInfo());
for (List<NodeInfo> row : graph) {
for (NodeInfo n : row) {
n.ellipse = new EllipseRotated_F64();
}
}
EllipseClustersIntoHexagonalGrid alg = new EllipseClustersIntoHexagonalGrid();
alg.saveResults(graph);
Grid g = alg.getGrids().get(0);
assertEquals(3, g.columns);
assertEquals(3, g.rows);
for (int row = 0; row < 3; row++) {
for (int col = 0; col < 3; col++) {
if (row % 2 == col % 2) {
assertTrue(g.get(row, col) != null);
} else {
assertTrue(g.get(row, col) == null);
}
}
}
}
use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class TestEllipseClustersIntoHexagonalGrid method selectClosest.
@Test
public void selectClosest() {
List<EllipseRotated_F64> ellipses = new ArrayList<>();
ellipses.add(new EllipseRotated_F64(0, 0, 1, 1, 0));
ellipses.add(new EllipseRotated_F64(0.5, 0.866, 1, 1, 0));
ellipses.add(new EllipseRotated_F64(0.5, 1.2, 1, 1, 0));
ellipses.add(new EllipseRotated_F64(1, 0, 1, 1, 0));
Tuple2<List<Node>, List<EllipseRotated_F64>> input = connectEllipses(ellipses, 2);
EllipseClustersIntoHexagonalGrid alg = new EllipseClustersIntoHexagonalGrid();
alg.computeNodeInfo(input.data1, input.data0);
NodeInfo found = EllipseClustersIntoHexagonalGrid.selectClosestN(alg.listInfo.get(0), alg.listInfo.get(1));
assertTrue(found != null);
assertTrue(found.ellipse == ellipses.get(3));
// move the node out of range it nothing should be accepted
alg.listInfo.get(3).ellipse.set(0, 1, 1, 1, 0);
input = connectEllipses(ellipses, 1.1);
alg.computeNodeInfo(input.data1, input.data0);
found = EllipseClustersIntoHexagonalGrid.selectClosestN(alg.listInfo.get(0), alg.listInfo.get(1));
assertTrue(found == null);
}
use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class TestEllipsesIntoClusters method axisAdjustedDistance.
@Test
public void axisAdjustedDistance() {
EllipseRotated_F64 a = new EllipseRotated_F64(2, 3, 3, 3, 0);
EllipseRotated_F64 b = new EllipseRotated_F64(6, 3, 3, 3, 0);
// it's circular so it should be the usual euclidean distance squared
assertEquals(4 * 4, EllipsesIntoClusters.axisAdjustedDistanceSq(a, b), 1e-6);
a.phi = Math.PI / 2.0;
assertEquals(4 * 4, EllipsesIntoClusters.axisAdjustedDistanceSq(a, b), 1e-6);
// not a circle any more. First test it lies along the major axis, should still be euclidean
a.a = 6;
a.phi = 0;
assertEquals(4 * 4, EllipsesIntoClusters.axisAdjustedDistanceSq(a, b), 1e-6);
// now rotate it. Distance should double
a.phi = Math.PI / 2.0;
assertEquals(8 * 8, EllipsesIntoClusters.axisAdjustedDistanceSq(a, b), 1e-6);
// Now do a rigorous test across all angles
for (int i = 0; i < 60; i++) {
a.phi = 2.0 * Math.PI * i / 60;
double dd = Math.pow(4 * Math.cos(a.phi), 2) + Math.pow(2 * 4 * Math.sin(a.phi), 2);
assertEquals(dd, EllipsesIntoClusters.axisAdjustedDistanceSq(a, b), 1e-6);
}
}
use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class TestEllipsesIntoClusters method create.
private EllipseInfo create(double x0, double y0, double a, double b, double phi) {
EllipseInfo out = new EllipseInfo();
out.ellipse = new EllipseRotated_F64(x0, y0, a, b, phi);
out.averageInside = 10;
out.averageOutside = 200;
out.contour = new ArrayList<>();
return out;
}
Aggregations