/** * Returns the current mouse position in the coordinates of the image * and is determined by the scaling factors and the position of the * image within the viewport. If the mouse is no longer in the viewport, * the last known mouse position will be returned. * * @return The position in image coordinates. */ public Point2d getCurrentMouseImagePosition() { return new Point2dImpl(this.pixelX, this.pixelY); }
@Override public Polygon asPolygon() { final Polygon e = new Polygon(); final Matrix transformMatrix = this.transformMatrix(); final Point2dImpl circlePoint = new Point2dImpl(0, 0); for (double t = -Math.PI; t < Math.PI; t += Math.PI / 360) { circlePoint.x = (float) Math.cos(t); circlePoint.y = (float) Math.sin(t); e.points.add(circlePoint.transform(transformMatrix)); } return e; }
@Override public SpatialLocation clone() { final SpatialLocation c = (SpatialLocation) super.clone(); return c; } }
/** * {@inheritDoc} * @see org.openimaj.vis.DataUnitsTransformer#calculatePosition(java.lang.Object) */ @Override public int[] calculatePosition( final double[] units ) { Point2dImpl p = new Point2dImpl( (float)units[0], (float)units[1] ); p = p.transform( this.dataTransformMatrix ); return new int[] { Math.round(p.getX()), Math.round(p.getY()) }; // final double[] dx = this.xAxisRenderer.calculatePosition( units[0] ); // final double[] dy = this.yAxisRenderer.calculatePosition( units[1] ); // // System.out.println( "units[0] = "+units[0]+" --> "+Arrays.toString( dx ) ); // System.out.println( "units[1] = "+units[1]+" --> "+Arrays.toString( dy ) ); // // return new int[] { (int) dx[0], (int)dy[1] }; // //(int)(dx[0]+dy[0]), (int)(dx[1]+dy[1]) }; }
@Override public void mouseReleased(MouseEvent e) { if (e.isAltDown()) { releaseClick = new Point2dImpl(e.getX(), e.getY()); this.areaSelected = true; float px = pressClick.getX(); float py = pressClick.getY(); float rx = releaseClick.getX(); float ry = releaseClick.getY(); selectArea(new Rectangle(Math.min(px, rx), Math.min(py, ry), Math.abs(px - rx), Math.abs(py - ry))); } }
boolean calcAffineAdaptation(final FImage fimage, EllipticInterestPointData kpt, AbstractStructureTensorIPD ipd) { Point2dImpl c = new Point2dImpl(); // Transformed point final Point2dImpl p = new Point2dImpl(); // Image point c = p.transform(U); cx = (int) (c.x - minx); cy = (int) (c.y - miny); p.translate(c.transform(U.inverse())); px = (int) p.x; py = (int) p.y;
@Override public void doTutorial(MBFImage toDraw) { List<KEDetectedFace> faces = this.detector.detectFaces(toDraw.flatten()); for (KEDetectedFace detectedFace : faces) { Rectangle b = detectedFace.getBounds(); Point2dImpl bp = new Point2dImpl(b.x,b.y); toDraw.drawShape(b, RGBColour.RED); FacialKeypoint[] kpts = detectedFace.getKeypoints(); List<Point2d> fpts = new ArrayList<Point2d>(); for(FacialKeypoint kpt : kpts){ Point2dImpl p = kpt.position; p.translate(bp); fpts.add(p); } toDraw.drawPoints(fpts, RGBColour.GREEN, 3); } } }
protected void updatePosition(Matrix transform) { position = position.transform(transform); }
@Override public void drawDetectedFace(MBFImage image, int thickness, KEDetectedFace f) { Rectangle bounds = f.getBounds(); image.drawShape(bounds,thickness, boundingBoxColour); FacialKeypoint[] kp = f.getKeypoints(); for (FacialKeypoint facialKeypoint : kp) { Point2dImpl position = facialKeypoint.position.clone(); position.translate(bounds.x, bounds.y); image.drawPoint(position,pointColour,thickness); } }
/** * Rotate the {@link Rectangle} about the given pivot with the given angle * (in radians) * * @param p * the pivot of the rotation * @param angle * the angle in radians * @return the rotated rectangle */ public RotatedRectangle rotate(Point2d p, double angle) { final Point2dImpl c = (Point2dImpl) this.calculateCentroid(); final float sin = (float) Math.sin(angle); final float cos = (float) Math.cos(angle); c.translate(-p.getX(), -p.getY()); final float xnew = c.x * cos - c.y * sin; final float ynew = c.x * sin + c.y * cos; c.x = xnew; c.y = ynew; c.translate(p); return new RotatedRectangle(c.x, c.y, width, height, angle); }
@Override public void mouseReleased(MouseEvent e) { if (e.isAltDown()) { releaseClick = new Point2dImpl(e.getX(), e.getY()); this.areaSelected = true; float px = pressClick.getX(); float py = pressClick.getY(); float rx = releaseClick.getX(); float ry = releaseClick.getY(); selectArea(new Rectangle(Math.min(px, rx), Math.min(py, ry), Math.abs(px - rx), Math.abs(py - ry))); } }
boolean calcAffineAdaptation(final FImage fimage, EllipticInterestPointData kpt, AbstractStructureTensorIPD ipd) { Point2dImpl c = new Point2dImpl(); // Transformed point final Point2dImpl p = new Point2dImpl(); // Image point c = p.transform(U); cx = (int) (c.x - minx); cy = (int) (c.y - miny); p.translate(c.transform(U.inverse())); px = (int) p.x; py = (int) p.y;
private void updateEllipse() { ipd.findInterestPoints(Transforms.calculateIntensityNTSC(this.image)); final Point2dImpl np = this.point.transform(transform); final Matrix sm = ipd.getSecondMomentsAt((int) np.x, (int) np.y); ellipseToDraw = EllipseUtilities.ellipseFromSecondMoments(np.x, np.y, sm, 5 * 2); }
@Override public void renderOrtho(Matrix transform, int tx, int ty, MBFImage image) { final Point2dImpl p1 = projectOrtho(transform.times(pt1)); p1.translate(tx, ty); p1.y = image.getHeight() - p1.y; final Point2dImpl p2 = projectOrtho(transform.times(pt2)); p2.translate(tx, ty); p2.y = image.getHeight() - p2.y; image.drawLine(p1, p2, thickness, colour); }
private static Point2dImpl[] getPowerPoints() { return new Point2dImpl[] { new Point2dImpl(1 / 3f, 1 / 3f), new Point2dImpl(2 / 3f, 1 / 3f), new Point2dImpl(1 / 3f, 2 / 3f), new Point2dImpl(2 / 3f, 2 / 3f) }; } }
private Point2dImpl findActualPoint(PixelSet c) { final double[] centroidDouble = c.calculateCentroid(); final Point2dImpl centroid = new Point2dImpl((float) centroidDouble[0], (float) centroidDouble[1]); final Point2dImpl actualPoint = centroid.transform(this.homography.getTransform()); return actualPoint; }
@Override public Point2dImpl transform(Matrix transform) { if (transform.getRowDimension() == 3) { float xt = (float) transform.get(0, 0) * getX() + (float) transform.get(0, 1) * getY() + (float) transform.get(0, 2); float yt = (float) transform.get(1, 0) * getX() + (float) transform.get(1, 1) * getY() + (float) transform.get(1, 2); final float zt = (float) transform.get(2, 0) * getX() + (float) transform.get(2, 1) * getY() + (float) transform.get(2, 2); xt /= zt; yt /= zt; return new Point2dImpl(xt, yt); } else if (transform.getRowDimension() == 2 && transform.getColumnDimension() == 2) { final float xt = (float) transform.get(0, 0) * getX() + (float) transform.get(0, 1) * getY(); final float yt = (float) transform.get(1, 0) * getX() + (float) transform.get(1, 1) * getY(); return new Point2dImpl(xt, yt); } else if (transform.getRowDimension() == 2 && transform.getColumnDimension() == 3) { final float xt = (float) transform.get(0, 0) * getX() + (float) transform.get(0, 1) * getY() + (float) transform.get(0, 2); final float yt = (float) transform.get(1, 0) * getX() + (float) transform.get(1, 1) * getY() + (float) transform.get(1, 2); return new Point2dImpl(xt, yt); } throw new IllegalArgumentException("Transform matrix has unexpected size"); }
private void updateEllipse() { ipd.findInterestPoints(Transforms.calculateIntensityNTSC(this.image)); final Point2dImpl np = this.point.transform(transform); final Matrix sm = ipd.getSecondMomentsAt((int) np.x, (int) np.y); ellipseToDraw = EllipseUtilities.ellipseFromSecondMoments(np.x, np.y, sm, 5 * 2); }
@Override public SpatialLocation clone() { final SpatialLocation c = (SpatialLocation) super.clone(); return c; } }
@Override public void renderOrtho(Matrix transform, int tx, int ty, MBFImage image) { final Point2dImpl p1 = projectOrtho(transform.times(pt1)); p1.translate(tx, ty); p1.y = image.getHeight() - p1.y; final Point2dImpl p2 = projectOrtho(transform.times(pt2)); p2.translate(tx, ty); p2.y = image.getHeight() - p2.y; image.drawLine(p1, p2, thickness, colour); }