Search in sources :

Example 46 with Polygon2D_F64

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

the class TestSquareCrossClustersIntoGrids method lowerEdgeIndex.

@Test
public void lowerEdgeIndex() {
    for (int numCorners = 3; numCorners <= 5; numCorners++) {
        for (int first = 0; first < numCorners; first++) {
            int second = (first + 1) % numCorners;
            SquareNode node = new SquareNode();
            node.square = new Polygon2D_F64(numCorners);
            node.updateArrayLength();
            connect(node, first, new SquareNode(), 0);
            node.edges[first].b.graph = SquareNode.RESET_GRAPH;
            connect(node, second, new SquareNode(), 0);
            node.edges[second].b.graph = SquareNode.RESET_GRAPH;
            assertEquals(first, SquareCrossClustersIntoGrids.lowerEdgeIndex(node));
        }
    }
}
Also used : Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.Test)

Example 47 with Polygon2D_F64

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

the class TestSquareGraph method findSideIntersect.

@Test
public void findSideIntersect() {
    LineSegment2D_F64 line = new LineSegment2D_F64();
    LineSegment2D_F64 storage = new LineSegment2D_F64();
    SquareNode a = new SquareNode();
    a.square = new Polygon2D_F64(-1, 1, 1, 1, 1, -1, -1, -1);
    SquareGraph alg = new SquareGraph();
    Point2D_F64 intersection = new Point2D_F64();
    line.b.set(0, 2);
    assertEquals(0, alg.findSideIntersect(a, line, intersection, storage));
    line.b.set(0, -2);
    assertEquals(2, alg.findSideIntersect(a, line, intersection, storage));
    line.b.set(2, 0);
    assertEquals(1, alg.findSideIntersect(a, line, intersection, storage));
    line.b.set(-2, 0);
    assertEquals(3, alg.findSideIntersect(a, line, intersection, storage));
}
Also used : LineSegment2D_F64(georegression.struct.line.LineSegment2D_F64) Point2D_F64(georegression.struct.point.Point2D_F64) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.Test)

Example 48 with Polygon2D_F64

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

the class TestSquareGraph method acuteAngle.

private void acuteAngle(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);
    if (changeClock) {
        UtilPolygons2D_F64.flip(a.square);
        UtilPolygons2D_F64.flip(b.square);
    }
    SquareGraph alg = new SquareGraph();
    assertEquals(0, alg.acuteAngle(a, 0, b, 0), 1e-8);
    assertEquals(0, alg.acuteAngle(a, 0, b, 2), 1e-8);
    assertEquals(0, alg.acuteAngle(a, 2, b, 0), 1e-8);
    assertEquals(0, alg.acuteAngle(a, 2, b, 2), 1e-8);
    assertEquals(0, alg.acuteAngle(a, 1, b, 1), 1e-8);
    assertEquals(0, alg.acuteAngle(a, 1, b, 3), 1e-8);
    assertEquals(0, alg.acuteAngle(a, 3, b, 1), 1e-8);
    assertEquals(0, alg.acuteAngle(a, 3, b, 3), 1e-8);
    assertEquals(Math.PI / 2, alg.acuteAngle(a, 0, b, 1), 1e-8);
    assertEquals(Math.PI / 2, alg.acuteAngle(a, 0, b, 3), 1e-8);
    assertEquals(Math.PI / 2, alg.acuteAngle(a, 2, b, 1), 1e-8);
    assertEquals(Math.PI / 2, alg.acuteAngle(a, 2, b, 3), 1e-8);
    assertEquals(Math.PI / 2, alg.acuteAngle(a, 1, b, 0), 1e-8);
    assertEquals(Math.PI / 2, alg.acuteAngle(a, 3, b, 0), 1e-8);
    assertEquals(Math.PI / 2, alg.acuteAngle(a, 1, b, 2), 1e-8);
    assertEquals(Math.PI / 2, alg.acuteAngle(a, 3, b, 2), 1e-8);
}
Also used : Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Example 49 with Polygon2D_F64

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

the class TestSquareGridTools method boundingPolygonCCW_rect.

@Test
public void boundingPolygonCCW_rect() {
    SquareGridTools alg = new SquareGridTools();
    double w = TestSquareRegularClustersIntoGrids.DEFAULT_WIDTH;
    Polygon2D_F64 poly = new Polygon2D_F64(4);
    for (int rows = 2; rows <= 4; rows++) {
        for (int cols = 2; cols <= 4; cols++) {
            SquareGrid grid = createGrid(rows, cols);
            for (int i = 0; i < 2; i++) {
                if (i == 1)
                    alg.transpose(grid);
                // ensure preconditions are meet
                if (alg.checkFlip(grid)) {
                    alg.flipRows(grid);
                }
                alg.boundingPolygonCCW(grid, poly);
                double x0 = -w / 2;
                double y0 = -w / 2;
                double x1 = w * 2 * (cols - 1) + w / 2;
                double y1 = w * 2 * (rows - 1) + w / 2;
                Polygon2D_F64 expected = new Polygon2D_F64(4);
                expected.get(0).set(x0, y0);
                expected.get(1).set(x1, y0);
                expected.get(2).set(x1, y1);
                expected.get(3).set(x0, y1);
                assertTrue(UtilPolygons2D_F64.isEquivalent(expected, poly, 1e-8));
            }
        }
    }
}
Also used : Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.Test)

Example 50 with Polygon2D_F64

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

the class TestSquareRegularClustersIntoGrids method createSquare.

public static SquareNode createSquare(double x, double y, double width) {
    double r = width / 2;
    Polygon2D_F64 poly = new Polygon2D_F64(4);
    poly.get(0).set(-r, r);
    poly.get(1).set(r, r);
    poly.get(2).set(r, -r);
    poly.get(3).set(-r, -r);
    SquareNode square = new SquareNode();
    for (int i = 0; i < 4; i++) {
        poly.get(i).x += x;
        poly.get(i).y += y;
        square.sideLengths[i] = width;
    }
    square.square = poly;
    square.center.set(x, y);
    square.largestSide = width;
    return square;
}
Also used : Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

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