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();
}
}
}
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);
}
}
}
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);
}
}
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;
}
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;
}
Aggregations