Search in sources :

Example 11 with LineGeneral2D_F64

use of georegression.struct.line.LineGeneral2D_F64 in project BoofCV by lessthanoptimal.

the class TestRefinePolyLineCorner method distanceSum.

@Test
public void distanceSum() {
    RefinePolyLineCorner alg = new RefinePolyLineCorner(true);
    List<Point2D_I32> contour = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        contour.add(new Point2D_I32(i, 2));
    }
    LineGeneral2D_F64 line = UtilLine2D_F64.convert(new LineParametric2D_F64(0, 0, 1, 0), (LineGeneral2D_F64) null);
    // normal case
    assertEquals(2 * 16, alg.distanceSum(line, 2, 17, contour), 1e-8);
    // boundary case
    assertEquals(2 * 15, alg.distanceSum(line, 10, 4, contour), 1e-8);
}
Also used : LineGeneral2D_F64(georegression.struct.line.LineGeneral2D_F64) ArrayList(java.util.ArrayList) LineParametric2D_F64(georegression.struct.line.LineParametric2D_F64) Point2D_I32(georegression.struct.point.Point2D_I32) Test(org.junit.Test)

Example 12 with LineGeneral2D_F64

use of georegression.struct.line.LineGeneral2D_F64 in project BoofCV by lessthanoptimal.

the class FitLinesToContour method linesIntoCorners.

/**
 * finds the intersection of a line and update the corner index
 */
boolean linesIntoCorners(int numLines, GrowQueue_I32 contourCorners) {
    skippedCorners.reset();
    // this is the index in the contour of the previous corner.  When a new corner is found this is used
    // to see if the newly fit lines point to the same corner.  If that happens a corner is "skipped"
    int contourIndexPrevious = contourCorners.get(anchor0);
    for (int i = 1; i < numLines; i++) {
        LineGeneral2D_F64 line0 = lines.get(i - 1);
        LineGeneral2D_F64 line1 = lines.get(i);
        int cornerIndex = CircularIndex.addOffset(anchor0, i, contourCorners.size);
        boolean skipped = false;
        if (null == Intersection2D_F64.intersection(line0, line1, intersection)) {
            if (verbose)
                System.out.println("  SKIPPING no intersection");
            // the two lines are parallel (or a bug earlier inserted NaN), so skip and remove one of them
            skipped = true;
        } else {
            int contourIndex = closestPoint(intersection);
            if (contourIndex != contourIndexPrevious) {
                Point2D_I32 a = contour.get(contourIndexPrevious);
                Point2D_I32 b = contour.get(contourIndex);
                if (a.x == b.x && a.y == b.y) {
                    if (verbose)
                        System.out.println("  SKIPPING duplicate coordinate");
                    // System.out.println("  duplicate "+a+" "+b);
                    skipped = true;
                } else {
                    // System.out.println("contourCorners[ "+cornerIndex+" ] = "+contourIndex);
                    contourCorners.set(cornerIndex, contourIndex);
                    contourIndexPrevious = contourIndex;
                }
            } else {
                if (verbose)
                    System.out.println("  SKIPPING duplicate corner index");
                skipped = true;
            }
        }
        if (skipped) {
            skippedCorners.add(cornerIndex);
        }
    }
    // check the last anchor to see if there's a duplicate
    int cornerIndex = CircularIndex.addOffset(anchor0, numLines, contourCorners.size);
    Point2D_I32 a = contour.get(contourIndexPrevious);
    Point2D_I32 b = contour.get(contourCorners.get(cornerIndex));
    if (a.x == b.x && a.y == b.y) {
        skippedCorners.add(cornerIndex);
    }
    // now handle all the skipped corners
    Arrays.sort(skippedCorners.data, 0, skippedCorners.size);
    for (int i = skippedCorners.size - 1; i >= 0; i--) {
        int index = skippedCorners.get(i);
        contourCorners.remove(index);
        if (anchor0 >= index) {
            anchor0--;
        }
        if (anchor1 >= index) {
            anchor1--;
        }
    }
    // cornerIndexes.size -= skippedCorners.size();
    numLines -= skippedCorners.size;
    for (int i = 0; i < numLines; i++) {
        int c0 = CircularIndex.addOffset(anchor0, i, contourCorners.size);
        int c1 = CircularIndex.addOffset(anchor0, i + 1, contourCorners.size);
        a = contour.get(contourCorners.get(c0));
        b = contour.get(contourCorners.get(c1));
        if (a.x == b.x && a.y == b.y) {
            throw new RuntimeException("Well I screwed up");
        }
    }
    return contourCorners.size() >= 3;
}
Also used : LineGeneral2D_F64(georegression.struct.line.LineGeneral2D_F64) Point2D_I32(georegression.struct.point.Point2D_I32)

Aggregations

LineGeneral2D_F64 (georegression.struct.line.LineGeneral2D_F64)12 Test (org.junit.Test)5 LineSegment2D_F64 (georegression.struct.line.LineSegment2D_F64)3 Point2D_I32 (georegression.struct.point.Point2D_I32)3 Point2D_F64 (georegression.struct.point.Point2D_F64)2 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)2 GrowQueue_I32 (org.ddogleg.struct.GrowQueue_I32)2 ClosestPoint2D_F64 (georegression.metric.ClosestPoint2D_F64)1 LineParametric2D_F64 (georegression.struct.line.LineParametric2D_F64)1 Vector2D_F64 (georegression.struct.point.Vector2D_F64)1 Quadrilateral_F64 (georegression.struct.shapes.Quadrilateral_F64)1 ArrayList (java.util.ArrayList)1