use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class TestEllipseClustersIntoGrid method connectEllipses.
static Tuple2<List<Node>, List<EllipseRotated_F64>> connectEllipses(List<EllipseRotated_F64> ellipses, double distance) {
List<Node> cluster = new ArrayList<>();
for (int i = 0; i < ellipses.size(); i++) {
cluster.add(new Node());
cluster.get(i).which = i;
}
for (int i = 0; i < ellipses.size(); i++) {
Node n0 = cluster.get(i);
EllipseRotated_F64 e0 = ellipses.get(i);
for (int j = i + 1; j < ellipses.size(); j++) {
Node n1 = cluster.get(j);
EllipseRotated_F64 e1 = ellipses.get(j);
if (e1.center.distance(e0.center) <= distance) {
n0.connections.add(j);
n1.connections.add(i);
}
}
}
return new Tuple2<>(cluster, ellipses);
}
use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class TestEllipseClustersIntoGrid method grid_getIndexOfHexEllipse.
private void grid_getIndexOfHexEllipse(int numRows, int numCols) {
Grid g = new Grid();
g.rows = numRows;
g.columns = numCols;
int[] index = new int[g.rows * g.columns];
int totalEllipses = 0;
for (int row = 0; row < g.rows; row++) {
for (int col = 0; col < g.columns; col++) {
if (row % 2 == 0 && col % 2 == 1) {
g.ellipses.add(null);
} else if (row % 2 == 1 && col % 2 == 0) {
g.ellipses.add(null);
} else {
index[totalEllipses++] = row * g.columns + col;
g.ellipses.add(new EllipseRotated_F64());
}
}
}
for (int i = 0; i < totalEllipses; i++) {
int row = index[i] / g.columns;
int col = index[i] % g.columns;
assertEquals(row + " " + col, i, g.getIndexOfHexEllipse(row, col));
}
}
use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class TestEllipseClustersIntoHexagonalGrid method selectClosestSide.
@Test
public void selectClosestSide() {
List<EllipseRotated_F64> ellipses = new ArrayList<>();
ellipses.add(new EllipseRotated_F64(0, 0, 1, 1, 0));
ellipses.add(new EllipseRotated_F64(1, 0, 1, 1, 0));
ellipses.add(new EllipseRotated_F64(0.5, 0.866, 1, 1, 0));
ellipses.add(new EllipseRotated_F64(0, 0.866 * 2, 1, 1, 0));
ellipses.add(new EllipseRotated_F64(1, 0.866 * 2, 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.selectClosestSide(alg.listInfo.get(2), alg.listInfo.get(0));
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 TestEllipseClustersIntoHexagonalGrid method process_multiple_grids.
/**
* Multiple grids in view at the same time
*/
@Test
public void process_multiple_grids() {
// create two grids
int rows = 4;
int cols = 3;
Tuple2<List<Node>, List<EllipseRotated_F64>> grid0 = createHexagonalGrid(rows, cols, 0.5, 1);
Tuple2<List<Node>, List<EllipseRotated_F64>> grid1 = createHexagonalGrid(rows, cols, 0.5, 1);
List<List<Node>> nodes = new ArrayList<>();
List<EllipseRotated_F64> ellipses = new ArrayList<>();
nodes.add(grid0.data0);
nodes.add(grid1.data0);
ellipses.addAll(grid0.data1);
ellipses.addAll(grid1.data1);
// adjust indexing for second grid
for (Node n : grid1.data0) {
n.cluster = 1;
n.which += grid0.data1.size();
for (int i = 0; i < n.connections.size(); i++) {
n.connections.data[i] += grid0.data1.size();
}
}
EllipseClustersIntoHexagonalGrid alg = new EllipseClustersIntoHexagonalGrid();
alg.process(ellipses, nodes);
FastQueue<Grid> found = alg.getGrids();
assertEquals(2, found.size());
checkShape(rows, cols, found.get(0));
checkShape(rows, cols, found.get(1));
}
use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class TestEllipseClustersIntoHexagonalGrid method bottomTwoColumns_case1.
/**
* The second column has only one element
*/
@Test
public void bottomTwoColumns_case1() {
List<EllipseRotated_F64> ellipses = new ArrayList<>();
for (int i = 0; i < 2; i++) {
ellipses.add(new EllipseRotated_F64(i, 0, 1, 1, 0));
ellipses.add(new EllipseRotated_F64(i, hexY * 2, 1, 1, 0));
if (i == 0) {
ellipses.add(new EllipseRotated_F64(i + 0.5, hexY, 1, 1, 0));
ellipses.add(new EllipseRotated_F64(i + 0.5, 1.732, 1, 1, 0));
}
}
Tuple2<List<Node>, List<EllipseRotated_F64>> input = connectEllipses(ellipses, 1.1);
EllipseClustersIntoHexagonalGrid alg = new EllipseClustersIntoHexagonalGrid();
alg.computeNodeInfo(input.data1, input.data0);
alg.findContour(true);
List<NodeInfo> column0 = new ArrayList<>();
List<NodeInfo> column1 = new ArrayList<>();
NodeInfo corner = alg.listInfo.get(4);
NodeInfo next = alg.listInfo.get(0);
corner.marked = next.marked = true;
alg.bottomTwoColumns(corner, next, column0, column1);
assertEquals(2, column0.size());
assertEquals(1, column1.size());
assertTrue(column0.get(0).ellipse.center.distance(1, 0) < 1e-4);
assertTrue(column0.get(1).ellipse.center.distance(0, 0) < 1e-4);
assertTrue(column1.get(0).ellipse.center.distance(0.5, hexY) < 1e-4);
}
Aggregations