Search in sources :

Example 11 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class TestSquareCrossClustersIntoGrids method findSeedNode.

@Test
public void findSeedNode() {
    List<SquareNode> cluster = new ArrayList<>();
    cluster.add(new SquareNode());
    cluster.add(new SquareNode());
    cluster.add(new SquareNode());
    for (SquareNode n : cluster) {
        n.square = new Polygon2D_F64(4);
    }
    cluster.get(1).edges[2] = new SquareEdge();
    cluster.get(2).edges[0] = new SquareEdge();
    cluster.get(2).edges[1] = new SquareEdge();
    assertTrue(cluster.get(1) == SquareCrossClustersIntoGrids.findSeedNode(cluster));
    cluster.get(1).edges[3] = new SquareEdge();
    assertTrue(cluster.get(1) == SquareCrossClustersIntoGrids.findSeedNode(cluster));
    cluster.get(1).edges[0] = new SquareEdge();
    assertTrue(cluster.get(2) == SquareCrossClustersIntoGrids.findSeedNode(cluster));
}
Also used : ArrayList(java.util.ArrayList) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.Test)

Example 12 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class TestSquareGraph method almostParallel.

private void almostParallel(boolean changeClock) {
    SquareNode a = new SquareNode();
    a.square = new Polygon2D_F64(-1, 1, 1, 1, 1, -1, -1, -1);
    SquareNode b = new SquareNode();
    b.square = new Polygon2D_F64(1, 1, 3, 1, 3, -1, 1, -1);
    int adj = 1;
    if (changeClock) {
        UtilPolygons2D_F64.flip(a.square);
        UtilPolygons2D_F64.flip(b.square);
        adj = 3;
    }
    SquareGraph alg = new SquareGraph();
    for (int i = 0; i < 4; i++) {
        assertTrue(alg.almostParallel(a, i, b, i));
        assertTrue(alg.almostParallel(a, i, b, (i + 2) % 4));
        assertFalse(alg.almostParallel(a, i, b, (i + 1) % 4));
    }
    // give it some slant
    double angle0 = 0.1;
    double angle1 = Math.PI / 4;
    double cos0 = Math.cos(angle0);
    double sin0 = Math.sin(angle0);
    double cos1 = Math.cos(angle1);
    double sin1 = Math.sin(angle1);
    a.square.get(adj).set(-1 + 2 * cos0, 1 + 2 * sin0);
    assertTrue(alg.almostParallel(a, 0, b, 0));
    assertFalse(alg.almostParallel(a, 1, b, 0));
    a.square.get(adj).set(-1 + 2 * cos1, 1 + 2 * sin1);
    assertTrue(alg.almostParallel(a, 0, b, 0));
    assertFalse(alg.almostParallel(a, 1, b, 0));
}
Also used : Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Example 13 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class TestSquareGraph method computeNodeInfo.

@Test
public void computeNodeInfo() {
    SquareNode a = new SquareNode();
    a.square = new Polygon2D_F64(-1, 1, 2, 1, 2, -1, -1, -1);
    SquareGraph alg = new SquareGraph();
    alg.computeNodeInfo(a);
    assertEquals(3, a.sideLengths[0], UtilEjml.TEST_F64);
    assertEquals(2, a.sideLengths[1], UtilEjml.TEST_F64);
    assertEquals(3, a.sideLengths[2], UtilEjml.TEST_F64);
    assertEquals(2, a.sideLengths[3], UtilEjml.TEST_F64);
    assertEquals(3, a.largestSide, UtilEjml.TEST_F64);
    assertEquals(2, a.smallestSide, UtilEjml.TEST_F64);
    assertTrue(a.center.distance(0.5, 0) < UtilEjml.TEST_F64);
}
Also used : Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.Test)

Example 14 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class TestSquareGridTools method orderNode.

@Test
public void orderNode() {
    SquareNode target = new SquareNode();
    target.square = new Polygon2D_F64(4);
    target.square.get(0).set(-1, -1);
    target.square.get(1).set(1, -1);
    target.square.get(2).set(1, 1);
    target.square.get(3).set(-1, 1);
    SquareNode up = new SquareNode();
    up.center.set(0, 5);
    SquareNode down = new SquareNode();
    down.center.set(0, -5);
    SquareNode left = new SquareNode();
    left.center.set(-5, 0);
    SquareNode right = new SquareNode();
    right.center.set(5, 0);
    SquareGridTools alg = new SquareGridTools();
    // try different orders and clockwiseness
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 4; j++) {
            // System.out.println("i = " + i + " j = " + j);
            alg.orderNode(target, right, true);
            checkOrder(alg.ordered, -1, -1, 1, -1, 1, 1, -1, 1);
            alg.orderNode(target, left, true);
            checkOrder(alg.ordered, 1, 1, -1, 1, -1, -1, 1, -1);
            alg.orderNode(target, up, false);
            checkOrder(alg.ordered, -1, -1, 1, -1, 1, 1, -1, 1);
            alg.orderNode(target, down, false);
            checkOrder(alg.ordered, 1, 1, -1, 1, -1, -1, 1, -1);
            UtilPolygons2D_F64.shiftDown(target.square);
        }
        UtilPolygons2D_F64.flip(target.square);
    }
}
Also used : Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.Test)

Example 15 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class TestSquareGridTools method boundingPolygonCCW_column.

@Test
public void boundingPolygonCCW_column() {
    SquareGridTools alg = new SquareGridTools();
    SquareGrid grid = createGrid(3, 1);
    Polygon2D_F64 poly = new Polygon2D_F64(4);
    alg.boundingPolygonCCW(grid, poly);
    double w = TestSquareRegularClustersIntoGrids.DEFAULT_WIDTH;
    assertTrue(poly.get(0).distance(-w / 2, -w / 2) <= 1e-8);
    assertTrue(poly.get(1).distance(w / 2, -w / 2) <= 1e-8);
    assertTrue(poly.get(2).distance(w / 2, w * 4 + w / 2) <= 1e-8);
    assertTrue(poly.get(3).distance(-w / 2, w * 4 + w / 2) <= 1e-8);
}
Also used : Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.Test)

Aggregations

Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)79 Test (org.junit.Test)40 Point2D_F64 (georegression.struct.point.Point2D_F64)13 ArrayList (java.util.ArrayList)9 GrayU8 (boofcv.struct.image.GrayU8)6 Rectangle2D_I32 (georegression.struct.shapes.Rectangle2D_I32)6 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)5 BufferedImage (java.awt.image.BufferedImage)5 GrowQueue_B (org.ddogleg.struct.GrowQueue_B)5 Point2D_I32 (georegression.struct.point.Point2D_I32)4 PixelTransformAffine_F32 (boofcv.alg.distort.PixelTransformAffine_F32)3 DetectPolygonFromContour (boofcv.alg.shapes.polygon.DetectPolygonFromContour)3 GrayF32 (boofcv.struct.image.GrayF32)3 Affine2D_F32 (georegression.struct.affine.Affine2D_F32)3 Se3_F64 (georegression.struct.se.Se3_F64)3 Rectangle2D_F64 (georegression.struct.shapes.Rectangle2D_F64)3 File (java.io.File)3 LensDistortionNarrowFOV (boofcv.alg.distort.LensDistortionNarrowFOV)2 LensDistortionRadialTangential (boofcv.alg.distort.radtan.LensDistortionRadialTangential)2 SquareNode (boofcv.alg.fiducial.calib.squares.SquareNode)2