use of georegression.geometry.UtilPoint2D_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.geometry.UtilPoint2D_I32 in project BoofCV by lessthanoptimal.
the class VisualizeHogDescriptorApp method selectRegion.
private void selectRegion(int x, int y) {
int bestIndex = -1;
synchronized (hogLock) {
double bestDistance = Double.MAX_VALUE;
List<Point2D_I32> locations = hog.getLocations();
for (int i = 0; i < locations.size(); i++) {
Point2D_I32 p = locations.get(i);
double d = UtilPoint2D_I32.distance(p.x, p.y, x, y);
if (d < bestDistance) {
bestDistance = d;
bestIndex = i;
}
}
if (bestIndex >= 0) {
selectedPixel = new Point2D_I32(x, y);
selectedIndex = bestIndex;
targetDesc = hog.getDescriptions().get(bestIndex);
targetLocation = hog.getLocations().get(bestIndex);
imagePanel.repaint();
}
}
}
use of georegression.geometry.UtilPoint2D_I32 in project BoofCV by lessthanoptimal.
the class SplitMergeLineFitLoop method selectFarthest.
/**
* Computes the distance between pairs of points which are separated by 1/2 the contour list. The index of the
* first pixel in the pair with the greatest distance is returned
* @return Index of the first pixel which should be used to split the list. The other end is ret + N/2
*/
protected int selectFarthest(List<Point2D_I32> contour) {
int bestIndex = -1;
int bestDistance = 0;
int N = contour.size();
int half = N / 2;
for (int i = 0; i < half; i++) {
int end = (i + half) % N;
Point2D_I32 a = contour.get(i);
Point2D_I32 b = contour.get(end);
int dist = UtilPoint2D_I32.distanceSq(a.x, a.y, b.x, b.y);
if (bestDistance < dist) {
bestIndex = i;
bestDistance = dist;
}
}
return bestIndex;
}
Aggregations