Search in sources :

Example 1 with Point2D_I32

use of georegression.struct.point.Point2D_I32 in project BoofCV by lessthanoptimal.

the class SelectRegionDescriptionPanel method mousePressed.

@Override
public void mousePressed(MouseEvent e) {
    int x = (int) (e.getX() / imageScale);
    int y = (int) (e.getY() / imageScale);
    // see if the mouse click was on the image
    if (x < 0 || x >= background.getWidth() || y < 0 || y >= background.getHeight()) {
        if (target != null) {
            repaint();
            if (listener != null) {
                listener.descriptionChanged(null, 0, 0);
            }
        }
        target = null;
        current = null;
    } else {
        boolean adjusted = false;
        if (target != null) {
            // if the user clicked on the center point enter drag mode
            int targetX = (int) (target.x * imageScale);
            int targetY = (int) (target.y * imageScale);
            double distance = UtilPoint2D_I32.distance(e.getX(), e.getY(), targetX, targetY);
            if (distance < clickTolerance) {
                // adjust the target to be at the cursor
                dragMode = true;
                current.x += x - target.x;
                current.y += y - target.y;
                target.set(x, y);
                adjusted = true;
            } else {
                // see if the user clicked on the circle, if so go into adjustment mode
                double radiusCircle = imageScale * UtilPoint2D_I32.distance(target, current);
                distance = Math.abs(distance - radiusCircle);
                if (distance < clickTolerance) {
                    current.set(x, y);
                    adjusted = true;
                }
            }
        }
        if (adjusted) {
            repaint();
            if (listener != null) {
                listener.descriptionChanged(target, getFeatureRadius(), getFeatureOrientation());
            }
        } else {
            dragMode = false;
            target = new Point2D_I32(x, y);
            current = target.copy();
            repaint();
        }
    }
}
Also used : UtilPoint2D_I32(georegression.geometry.UtilPoint2D_I32) Point2D_I32(georegression.struct.point.Point2D_I32)

Example 2 with Point2D_I32

use of georegression.struct.point.Point2D_I32 in project BoofCV by lessthanoptimal.

the class VisualizeBinaryData method render.

/**
 * Renders only the external contours.  Each contour is individually colored as specified by 'colors'
 *
 * @param contours List of contours
 * @param colors List of RGB colors for each element in contours.  If null then random colors will be used.
 * @param out (Optional) Storage for output
 */
public static void render(List<Contour> contours, int[] colors, BufferedImage out) {
    colors = checkColors(colors, contours.size());
    for (int i = 0; i < contours.size(); i++) {
        Contour c = contours.get(i);
        int color = colors[i];
        for (Point2D_I32 p : c.external) {
            out.setRGB(p.x, p.y, color);
        }
    }
}
Also used : EdgeContour(boofcv.alg.feature.detect.edge.EdgeContour) Contour(boofcv.alg.filter.binary.Contour) Point2D_I32(georegression.struct.point.Point2D_I32)

Example 3 with Point2D_I32

use of georegression.struct.point.Point2D_I32 in project BoofCV by lessthanoptimal.

the class VisualizeBinaryData method renderContour.

private static void renderContour(double scale, Graphics2D g2, Line2D.Double l, List<Point2D_I32> list) {
    for (int i = 0, j = list.size() - 1; i < list.size(); j = i, i++) {
        Point2D_I32 p0 = list.get(i);
        Point2D_I32 p1 = list.get(j);
        // draw it in the middle
        l.setLine((p0.x + 0.5) * scale, (p0.y + 0.5) * scale, (p1.x + 0.5) * scale, (p1.y + 0.5) * scale);
        g2.draw(l);
    }
}
Also used : Point2D_I32(georegression.struct.point.Point2D_I32)

Example 4 with Point2D_I32

use of georegression.struct.point.Point2D_I32 in project BoofCV by lessthanoptimal.

the class VisualizeBinaryData method renderContours.

/**
 * Draws contours. Internal and external contours are different user specified colors.
 *
 * @param contours List of contours
 * @param colorExternal RGB color
 * @param colorInternal RGB color
 * @param width Image width
 * @param height Image height
 * @param out (Optional) storage for output image
 * @return Rendered contours
 */
public static BufferedImage renderContours(List<Contour> contours, int colorExternal, int colorInternal, int width, int height, BufferedImage out) {
    if (out == null) {
        out = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    } else {
        Graphics2D g2 = out.createGraphics();
        g2.setColor(Color.BLACK);
        g2.fillRect(0, 0, width, height);
    }
    for (Contour c : contours) {
        for (Point2D_I32 p : c.external) {
            out.setRGB(p.x, p.y, colorExternal);
        }
        for (List<Point2D_I32> l : c.internal) {
            for (Point2D_I32 p : l) {
                out.setRGB(p.x, p.y, colorInternal);
            }
        }
    }
    return out;
}
Also used : EdgeContour(boofcv.alg.feature.detect.edge.EdgeContour) Contour(boofcv.alg.filter.binary.Contour) Point2D_I32(georegression.struct.point.Point2D_I32)

Example 5 with Point2D_I32

use of georegression.struct.point.Point2D_I32 in project BoofCV by lessthanoptimal.

the class VisualizeBinaryData method renderContours.

/**
 * Draws contours. Internal and external contours are different user specified colors.
 *
 * @param contours List of contours
 * @param colorExternal (Optional) Array of RGB colors for each external contour
 * @param colorInternal RGB color
 * @param width Image width
 * @param height Image height
 * @param out (Optional) storage for output image
 * @return Rendered contours
 */
public static BufferedImage renderContours(List<Contour> contours, int[] colorExternal, int colorInternal, int width, int height, BufferedImage out) {
    if (out == null) {
        out = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    } else {
        Graphics2D g2 = out.createGraphics();
        g2.setColor(Color.BLACK);
        g2.fillRect(0, 0, width, height);
    }
    colorExternal = checkColors(colorExternal, contours.size());
    int index = 0;
    for (Contour c : contours) {
        int color = colorExternal[index++];
        for (Point2D_I32 p : c.external) {
            out.setRGB(p.x, p.y, color);
        }
        for (List<Point2D_I32> l : c.internal) {
            for (Point2D_I32 p : l) {
                out.setRGB(p.x, p.y, colorInternal);
            }
        }
    }
    return out;
}
Also used : EdgeContour(boofcv.alg.feature.detect.edge.EdgeContour) Contour(boofcv.alg.filter.binary.Contour) Point2D_I32(georegression.struct.point.Point2D_I32)

Aggregations

Point2D_I32 (georegression.struct.point.Point2D_I32)153 Test (org.junit.Test)64 ArrayList (java.util.ArrayList)41 GrowQueue_I32 (org.ddogleg.struct.GrowQueue_I32)21 Point2D_F64 (georegression.struct.point.Point2D_F64)11 EdgeContour (boofcv.alg.feature.detect.edge.EdgeContour)8 GrayF32 (boofcv.struct.image.GrayF32)8 GrayS32 (boofcv.struct.image.GrayS32)7 Contour (boofcv.alg.filter.binary.Contour)6 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)6 GrayU8 (boofcv.struct.image.GrayU8)6 PackedSetsPoint2D_I32 (boofcv.struct.PackedSetsPoint2D_I32)5 RectangleLength2D_I32 (georegression.struct.shapes.RectangleLength2D_I32)5 UtilPoint2D_I32 (georegression.geometry.UtilPoint2D_I32)4 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)4 EdgeSegment (boofcv.alg.feature.detect.edge.EdgeSegment)3 Corner (boofcv.alg.shapes.polyline.splitmerge.PolylineSplitMerge.Corner)3 FactoryDescribeImageDense (boofcv.factory.feature.dense.FactoryDescribeImageDense)3 PointIndex_I32 (boofcv.struct.PointIndex_I32)3 LineGeneral2D_F64 (georegression.struct.line.LineGeneral2D_F64)3