public void setFillImageKeepingAspectRatio(Rectangle rectangle, Image image, Dimension2D gamingContextDimension2D) { double imageWidth = image.getWidth(); double imageHeight = image.getHeight(); double imageHeightToWidthRatio = imageHeight / imageWidth; double initialHeight = rectangle.getHeight(); double initialWidth = initialHeight / imageHeightToWidthRatio; double positionX = (gamingContextDimension2D.getWidth() - initialWidth) / 2; double positionY = (gamingContextDimension2D.getHeight() - initialHeight) / 2; rectangle.setFill(new ImagePattern(image)); rectangle.setX(positionX); rectangle.setY(positionY); rectangle.setWidth(initialWidth); rectangle.setHeight(initialHeight); rectangle.setTranslateX(0); rectangle.setScaleX(1); rectangle.setScaleY(1); rectangle.setScaleZ(1); }
public Position newRandomPosition(double radius) { double minX = radius; double minY = radius; Dimension2D dimension2D = getDimension2D(); double maxX = dimension2D.getWidth() - radius; double maxY = dimension2D.getHeight() - radius; if (maxX > 0 && maxY > 0) { double positionX = random.nextInt((int) (maxX - minX)) + minX; double positionY = random.nextInt((int) (maxY - minY)) + minY; return new Position((int) positionX, (int) positionY); } else { return new Position((int) radius, (int) radius); } }
public static Point2D latLongToPixel(final Dimension2D MAP_DIMENSION, final Point2D UPPER_LEFT, final Point2D LOWER_RIGHT, final Point2D LOCATION) { final double LATITUDE = LOCATION.getX(); final double LONGITUDE = LOCATION.getY(); final double MAP_WIDTH = MAP_DIMENSION.getWidth(); final double MAP_HEIGHT = MAP_DIMENSION.getHeight(); final double WORLD_MAP_WIDTH = ((MAP_WIDTH / (LOWER_RIGHT.getY() - UPPER_LEFT.getY())) * 360) / (2 * Math.PI); final double MAP_OFFSET_Y = (WORLD_MAP_WIDTH / 2 * Math.log10((1 + Math.sin(Math.toRadians(LOWER_RIGHT.getX()))) / (1 - Math.sin(Math.toRadians(LOWER_RIGHT.getX()))))); final double X = (LONGITUDE - UPPER_LEFT.getY()) * (MAP_WIDTH / (LOWER_RIGHT.getY() - UPPER_LEFT.getY())); final double Y = MAP_HEIGHT - ((WORLD_MAP_WIDTH / 2 * Math.log10((1 + Math.sin(Math.toRadians(LATITUDE))) / (1 - Math.sin(Math.toRadians(LATITUDE))))) - MAP_OFFSET_Y); return new Point2D(X, Y); }
/** * Constructs new closed chain shaped bounding shape. * Note: chain shape can only be used with static objects. * Note: chain shape must have at least 2 points * * @param points points to use in a chain * @return closed chain bounding shape * @throws IllegalArgumentException if number of points is less than 2 */ public static BoundingShape chain(Point2D... points) { if (points.length < 2) throw new IllegalArgumentException("Chain shape requires at least 2 points. Given points: " + points.length); double maxX = Stream.of(points) .mapToDouble(Point2D::getX) .max() .getAsDouble(); double maxY = Stream.of(points) .mapToDouble(Point2D::getY) .max() .getAsDouble(); return new BoundingShape(ShapeType.CHAIN, points, new Dimension2D(maxX, maxY)); }
public void moveTarget() { if (maxVelocity == 0) return; final Bounds b = target.getBoundsInParent(); final Point2D p = target.getPosition(); final Dimension2D d = target.getDimension(); final CollisionType ct = checkCollision(); if (b.getMinX() <= 1 || b.getMinX() + d.getWidth() > thisSuper.getArenaWidth() || ct == CollisionType.COLLISION_X || ct == CollisionType.COLLISION_BOTH) { dx *= -1; } if (b.getMinY() <= 1 || b.getMinY() + d.getHeight() > thisSuper.getArenaHeight() || ct == CollisionType.COLLISION_X || ct == CollisionType.COLLISION_BOTH) { dy *= -1; } target.setPosition(p.getX() + dx, p.getY() + dy); }
protected void autoCalibrateSuccess(Bounds arenaBounds, Optional<Dimension2D> paperDims, long delay) { if (isAutoCalibrating.get() && cameraCalibrationListener != null) { isAutoCalibrating.set(false); logger.debug("autoCalibrateSuccess {} {} {} {} paper {}", (int) arenaBounds.getMinX(), (int) arenaBounds.getMinY(), (int) arenaBounds.getWidth(), (int) arenaBounds.getHeight(), paperDims.isPresent()); cameraAutoCalibrated = true; cameraCalibrationListener.calibrate(arenaBounds, paperDims, false, delay); if (recordCalibratedArea && !recordingCalibratedArea) startRecordingCalibratedArea(new File("calibratedArea.mp4"), (int) arenaBounds.getWidth(), (int) arenaBounds.getHeight()); } }
@Test public void testTwo() throws ConfigurationException { PerspectiveManager pm = new PerspectiveManager(new BoundingBox(0, 0, 422, 316)); pm.setCameraParameters(4, 3.125, 2.32); pm.setCameraFeedSize(640, 480); pm.setCameraDistance(3406); pm.setShooterDistance(3406); pm.setProjectorResolution(1024, 768); pm.calculateUnknown(); assertEquals(1753.0, pm.getProjectionWidth(), 1); assertEquals(1299.0, pm.getProjectionHeight(), 1); Optional<Dimension2D> dims = pm.calculateObjectSize(300, 200, 3406); assertTrue(dims.isPresent()); assertEquals(175.3, dims.get().getWidth(), 1); assertEquals(118.2, dims.get().getHeight(), 1); }
@Test public void testThree() throws ConfigurationException { PerspectiveManager pm = new PerspectiveManager(new BoundingBox(0, 0, 422, 316)); pm.setProjectionSize(1753, 1299); pm.setCameraFeedSize(640, 480); pm.setCameraDistance(3406); pm.setShooterDistance(3406); pm.setProjectorResolution(1024, 768); pm.calculateUnknown(); assertEquals(4, pm.getFocalLength(), 1); assertEquals(3.122, pm.getSensorWidth(), .01); assertEquals(2.317, pm.getSensorHeight(), .01); Optional<Dimension2D> dims = pm.calculateObjectSize(300, 200, 3406); assertTrue(dims.isPresent()); assertEquals(175.3, dims.get().getWidth(), 1); assertEquals(118.2, dims.get().getHeight(), 1); }
private void setDistance() { if (!validateDistanceData()) return; persistSettings(); final int width = Integer.parseInt(targetWidth.getText()); final int height = Integer.parseInt(targetHeight.getText()); final int distance = Integer.parseInt(targetDistance.getText()); if (logger.isTraceEnabled()) { logger.trace( "New target settings from distance settings pane: current width = {}, " + "default height = {}, default distance = {}, new distance = {}", width, height, originalTargetDistance, distance); } final Optional<Dimension2D> targetDimensions = perspectiveManager.calculateObjectSize(width, height, distance); if (targetDimensions.isPresent()) { final Dimension2D d = targetDimensions.get(); target.setDimensions(d.getWidth(), d.getHeight()); } }
public PerspectiveManager(Bounds arenaBounds, Dimension2D feedDims, Dimension2D paperBounds, Dimension2D projectorRes) { this(arenaBounds); setCameraFeedSize((int) feedDims.getWidth(), (int) feedDims.getHeight()); this.setProjectorResolution(projectorRes); setProjectionSizeFromLetterPaperPixels(paperBounds); if (cameraDistance == -1) cameraDistance = DEFAULT_SHOOTER_DISTANCE; if (shooterDistance == -1) shooterDistance = DEFAULT_SHOOTER_DISTANCE; calculateRealWorldSize(); }
public PerspectiveManager(String cameraName, Bounds arenaBounds, Dimension2D feedDims, Dimension2D paperBounds, Dimension2D projectorRes) { this(cameraName, feedDims, arenaBounds); setProjectionSizeFromLetterPaperPixels(paperBounds); this.setProjectorResolution(projectorRes); // Camera distance is unknown calculateUnknown(); if (cameraDistance == -1) cameraDistance = DEFAULT_SHOOTER_DISTANCE; if (shooterDistance == -1) shooterDistance = DEFAULT_SHOOTER_DISTANCE; calculateRealWorldSize(); }
@Test public void testPaperPixelsCalcParams() throws ConfigurationException { PerspectiveManager pm = new PerspectiveManager(new BoundingBox(0, 0, 422, 316), new Dimension2D(640, 480), new Dimension2D(67, 53), new Dimension2D(1024, 768)); pm.setCameraDistance(3498); pm.setShooterDistance(3498); pm.calculateUnknown(); assertEquals(4, pm.getFocalLength(), 1); assertEquals(3.047, pm.getSensorWidth(), .01); assertEquals(2.235, pm.getSensorHeight(), .01); Optional<Dimension2D> dims = pm.calculateObjectSize(279, 216, pm.getCameraDistance()); assertTrue(dims.isPresent()); assertEquals(162.6, dims.get().getWidth(), 1); assertEquals(128.9, dims.get().getHeight(), 1); }
public Dimension2D getSize() { return EventQueueWait.exec(new Callable<Dimension2D>() { @Override public Dimension2D call() throws Exception { return new Dimension2D(currentWindow.getWidth(), currentWindow.getHeight()); } }); }
public Dimension2D getSymbolSize(final Series<X, Y> SERIES) { if (!getData().contains(SERIES)) { return new Dimension2D(0, 0); } if (SERIES.getData().isEmpty()) { return new Dimension2D(0, 0); } for (XYChart.Data<X, Y> data : SERIES.getData()) { StackPane stackPane = (StackPane) data.getNode(); if (null == stackPane) { continue; } else { return new Dimension2D(stackPane.getLayoutBounds().getWidth(), stackPane.getLayoutBounds().getHeight()); } } return new Dimension2D(0, 0); }
private void setHiddenPicture(GameContext gameContext) { final int randomPictureIndex = (int) Math.floor(Math.random() * images.length); final Image randomPicture = images[randomPictureIndex]; Dimension2D dimension2D = gameContext.getGamePanelDimensionProvider().getDimension2D(); Rectangle imageRectangle = new Rectangle(0, 0, dimension2D.getWidth(), dimension2D.getHeight()); imageRectangle.setFill(new ImagePattern(randomPicture, 0, 0, 1, 1, true)); AspectRatioImageRectangleUtil aspectRatioImageRectangleUtil = new AspectRatioImageRectangleUtil(); aspectRatioImageRectangleUtil.setFillImageKeepingAspectRatio(imageRectangle, randomPicture, dimension2D); gameContext.getChildren().add(imageRectangle); }
@Override public void launch() { this.currentRoundDetails = new CurrentRoundDetails(initCount, nbLines, nbColomns); javafx.geometry.Dimension2D dimension2D = gameContext.getGamePanelDimensionProvider().getDimension2D(); setHiddenPicture(gameContext); double width = dimension2D.getWidth() / nbColomns; double height = dimension2D.getHeight() / nbLines; for (int i = 0; i < nbColomns; i++) for (int j = 0; j < nbLines; j++) { Bloc bloc = new Bloc(i * width, j * height, width + 1, height + 1, i, j);// width+1, height+1 to avoid // spaces between blocks for // Scratchcard if (colors) bloc.setFill(new Color(Math.random(), Math.random(), Math.random(), 1)); else bloc.setFill(Color.BLACK); gameContext.getChildren().add(bloc); currentRoundDetails.blocs[i][j] = bloc; bloc.toFront(); GazeUtils.addEventFilter(bloc); bloc.addEventFilter(MouseEvent.ANY, enterEvent); bloc.addEventFilter(GazeEvent.ANY, enterEvent); stats.start(); } }
public static Dimension2D shouldFitIn(double originalWidth, double originalHeight, double toFitWidth, double toFitHeight) { double fitRatio = toFitWidth / toFitHeight; double originalRatio = originalWidth / originalHeight; if (fitRatio > originalRatio) { double widthFactor = toFitWidth / originalWidth; return new Dimension2D(toFitWidth, originalHeight * widthFactor); } else { double heightFactor = toFitHeight / originalHeight; return new Dimension2D(originalWidth * heightFactor, toFitHeight); } }
public AffineEvent(EventType<? extends Event> eventType, Affine affine, Affine previous, Dimension2D targetDimension) { super(eventType); this.affine = affine; this.previous = previous; this.targetDimension = targetDimension; }
@Override public void translateBy(Dimension2D targetAmount) { fireAffineEvent(AffineEvent.CHANGE_STARTED); // target coordinate, so append; origin is top left so we we flip signs affine.appendTranslation(-targetAmount.getWidth(), -targetAmount.getHeight()); clampAtBound(true); fireAffineEvent(AffineEvent.CHANGE_FINISHED); }
@Override public void centreOn(Point2D pointOnTarget) { fireAffineEvent(AffineEvent.CHANGE_STARTED); // move to centre point and apply scale Point2D delta = pointOnTarget.subtract(targetPointAtViewportCentre()); translateBy(new Dimension2D(delta.getX(), delta.getY())); fireAffineEvent(AffineEvent.CHANGE_FINISHED); }
@Test public void testTranslateRelative() throws Exception { final double zoom = 2d; final double dx = 30d; final double dy = -40d; pane.setScrollBarEnabled(false); pane.zoomTo(zoom, pane.targetPointAtViewportCentre()); pane.centreOn(new Point2D(256, 256)); final Transform previous = target.captureTransform(); pane.translateBy(new Dimension2D(dx, dy)); final Transform now = target.captureTransform(); assertThat(now.getTx() - previous.getTy()).isEqualTo(-dx * zoom); assertThat(now.getTy() - previous.getTy()).isEqualTo(-dy * zoom); }
public final HeatMap build() { double width = 400; double height = 400; ColorMapping colorMapping = ColorMapping.LIME_YELLOW_RED; double eventRadius = 15.5; boolean fadeColors = false; double heatMapOpacity = 0.5; OpacityDistribution opacityDistribution = OpacityDistribution.CUSTOM; for (String key : properties.keySet()) { if ("prefSize".equals(key)) { Dimension2D dim = ((ObjectProperty<Dimension2D>) properties.get(key)).get(); width = dim.getWidth(); height = dim.getHeight(); } else if ("width".equals(key)) { width = ((DoubleProperty) properties.get(key)).get(); } else if ("height".equals(key)) { height = ((DoubleProperty) properties.get(key)).get(); } else if ("colorMapping".equals(key)) { colorMapping = ((ObjectProperty<ColorMapping>) properties.get(key)).get(); } else if ("eventRadius".equals(key)) { eventRadius = ((DoubleProperty) properties.get(key)).get(); } else if ("fadeColors".equals(key)) { fadeColors = ((BooleanProperty) properties.get(key)).get(); } else if ("heatMapOpacity".equals(key)) { heatMapOpacity = ((DoubleProperty) properties.get(key)).get(); } else if ("opacityDistribution".equals(key)) { opacityDistribution = ((ObjectProperty<OpacityDistribution>) properties.get(key)).get(); } } return new HeatMap(width, height, colorMapping, eventRadius, fadeColors, heatMapOpacity, opacityDistribution); }
public final HeatMap build() { double width = 400; double height = 400; ColorMapping colorMapping = ColorMapping.LIME_YELLOW_RED; double spotRadius = 15.5; boolean fadeColors = false; double heatMapOpacity = 0.5; OpacityDistribution opacityDistribution = OpacityDistribution.CUSTOM; for (String key : properties.keySet()) { if ("prefSize".equals(key)) { Dimension2D dim = ((ObjectProperty<Dimension2D>) properties.get(key)).get(); width = dim.getWidth(); height = dim.getHeight(); } else if ("width".equals(key)) { width = ((DoubleProperty) properties.get(key)).get(); } else if ("height".equals(key)) { height = ((DoubleProperty) properties.get(key)).get(); } else if ("colorMapping".equals(key)) { colorMapping = ((ObjectProperty<ColorMapping>) properties.get(key)).get(); } else if ("spotRadius".equals(key)) { spotRadius = ((DoubleProperty) properties.get(key)).get(); } else if ("fadeColors".equals(key)) { fadeColors = ((BooleanProperty) properties.get(key)).get(); } else if ("heatMapOpacity".equals(key)) { heatMapOpacity = ((DoubleProperty) properties.get(key)).get(); } else if ("opacityDistribution".equals(key)) { opacityDistribution = ((ObjectProperty<OpacityDistribution>) properties.get(key)).get(); } } return new HeatMap(width, height, colorMapping, spotRadius, fadeColors, heatMapOpacity, opacityDistribution); }
public final AreaHeatMap build() { final AreaHeatMap CONTROL = new AreaHeatMap(); for (String key : properties.keySet()) { if ("prefSize".equals(key)) { Dimension2D dim = ((ObjectProperty<Dimension2D>) properties.get(key)).get(); CONTROL.setPrefSize(dim.getWidth(), dim.getHeight()); } else if ("colorMapping".equals(key)) { CONTROL.setColorMapping(((ObjectProperty<ColorMapping>) properties.get(key)).get()); } else if("useColorMapping".equals(key)) { CONTROL.setUseColorMapping(((BooleanProperty) properties.get(key)).get()); } else if ("quality".equals(key)) { CONTROL.setQuality(((IntegerProperty) properties.get(key)).get()); } else if ("heatMapOpacity".equals(key)) { CONTROL.setHeatMapOpacity(((DoubleProperty) properties.get(key)).get()); } else if ("dataPointsVisible".equals(key)) { CONTROL.setDataPointsVisible(((BooleanProperty) properties.get(key)).get()); } else if ("smoothedHull".equals(key)) { CONTROL.setSmoothedHull(((BooleanProperty) properties.get(key)).get()); } else if ("discreteColors".equals(key)) { CONTROL.setDiscreteColors(((BooleanProperty) properties.get(key)).get()); } else if ("noOfCloserInfluentPoints".equals(key)) { CONTROL.setNoOfCloserInfluentPoints(((IntegerProperty) properties.get(key)).get()); } } if (properties.keySet().contains("dataPointsArray")) { CONTROL.setDataPoints(((ObjectProperty<DataPoint[]>) properties.get("dataPointsArray")).get()); } if(properties.keySet().contains("dataPointsList")) { CONTROL.setDataPoints(((ObjectProperty<List<DataPoint>>) properties.get("dataPointsList")).get()); } return CONTROL; }
private double getLabelSize() { Dimension2D dim = measureTickMarkLabelSize("-888.88E-88", getTickLabelRotation()); if (getSide().isHorizontal()) { return dim.getWidth(); } else { return dim.getHeight(); } }
public void addPaperDimensions(Dimension2D newPaperDimensions, boolean averagePatterns) { if (!paperDimensions.isPresent() || !averagePatterns) { paperDimensions = Optional.of(newPaperDimensions); logger.trace("Found paper dimensions {}", paperDimensions.get()); } else if (paperDimensions.isPresent()) { paperDimensions = Optional.of(averageDimensions(paperDimensions.get(), newPaperDimensions)); logger.trace("Averaged paper dimensions {}", paperDimensions.get()); } }
/** * Stretches the children in the other direction as the direction of the * container, if required. * * @param pLayoutSize the size of the layout. * @param pRows the rows. */ private void doStretchOtherDirection(Dimension2D pLayoutSize, List<LayoutRow> pRows) { Insets padding = getPaddingSafe(); double widthFactor = 1; double heightFactor = 1; if (orientation.get() == Orientation.HORIZONTAL && stretchVertical.get()) { double height = getHeight() - padding.getTop() - padding.getBottom(); heightFactor = height / pLayoutSize.getHeight(); } if (orientation.get() == Orientation.VERTICAL && stretchHorizontal.get()) { double width = getWidth() - padding.getLeft() - padding.getRight(); widthFactor = width / pLayoutSize.getWidth(); } for (LayoutRow row : pRows) { for (Node node : row.getNodes()) { node.resizeRelocate( node.getLayoutX() * widthFactor, node.getLayoutY() * heightFactor, node.getLayoutBounds().getWidth() * widthFactor, node.getLayoutBounds().getHeight() * heightFactor); } } }
/** * Starting with a target's real world width and height in mm, as it appears * on a projection, calculate a new width and height in pixels to resize the * target to such that it appears to be a distance of * <code>desiredDistance</code> in mm away. This calculation assumes that * the current real world dimensions are the result of the target being * <code>realDistance</code> away in mm. * * To set the initial real word size of a target, call this method with the * desired <code>realWidth</code> and <code>realHeight</code> with * <code>realDistance</code> and <code>desiredDistance</code> equal to the * target's initial real world distance. * * @param realWidth * the current width of the target on the projection in mm * @param realHeight * the current height of the target on the projection in mm * @param realDistance * the current distance of the target in mm * @param desiredDistance * the desired new distance of the target used to derive the new * target dimensions. Value must be > 0 * @return the new targets dimensions in pixels necessary to make it appear * <code>desiredDistance</code> away given its current real world * dimensions and distance */ public Optional<Dimension2D> calculateObjectSize(double realWidth, double realHeight, double desiredDistance) { if (!isInitialized()) { logger.error("projection manager has unknowns projectionWidth = {}, projectionHeight = {}, " + "shooterDistance = {}, pxPerMMhigh = {}", projectionWidth, projectionHeight, shooterDistance, pxPerMMhigh); return Optional.empty(); } if (desiredDistance == 0) { throw new IllegalArgumentException("desiredDistance cannot be 0"); } // Make it appropriate size for the desired distance // Should just cap the result dimensions at the size of the projector final double distRatio = shooterDistance / desiredDistance; final double adjWidthmm = realWidth * distRatio; final double adjHeightmm = realHeight * distRatio; final double adjWidthpx = adjWidthmm * pxPerMMwide; final double adjHeightpx = adjHeightmm * pxPerMMhigh; if (logger.isTraceEnabled()) { logger.trace("real w {} h {} d {}", realWidth, realHeight, desiredDistance); logger.trace("sD {} dR {} - adjmm {} {} adjpx {} {}", shooterDistance, distRatio, adjWidthmm, adjHeightmm, adjWidthpx, adjHeightpx); } return Optional.of(new Dimension2D(adjWidthpx, adjHeightpx)); }
public final PushButton build() { final PushButton CONTROL = new PushButton(); for (String key : properties.keySet()) { if ("prefSize".equals(key)) { Dimension2D dim = ((ObjectProperty<Dimension2D>) properties.get(key)).get(); CONTROL.setPrefSize(dim.getWidth(), dim.getHeight()); } else if("minWidth".equals(key)) { CONTROL.setMinWidth(((DoubleProperty) properties.get(key)).get()); } else if("minHeight".equals(key)) { CONTROL.setMinHeight(((DoubleProperty) properties.get(key)).get()); } else if("prefWidth".equals(key)) { CONTROL.setPrefWidth(((DoubleProperty) properties.get(key)).get()); } else if("prefHeight".equals(key)) { CONTROL.setPrefHeight(((DoubleProperty) properties.get(key)).get()); } else if("maxWidth".equals(key)) { CONTROL.setMaxWidth(((DoubleProperty) properties.get(key)).get()); } else if("maxHeight".equals(key)) { CONTROL.setMaxHeight(((DoubleProperty) properties.get(key)).get()); } else if ("layoutX".equals(key)) { CONTROL.setLayoutX(((DoubleProperty) properties.get(key)).get()); } else if ("layoutY".equals(key)) { CONTROL.setLayoutY(((DoubleProperty) properties.get(key)).get()); } else if ("translateX".equals(key)) { CONTROL.setTranslateX(((DoubleProperty) properties.get(key)).get()); } else if ("translateY".equals(key)) { CONTROL.setTranslateY(((DoubleProperty) properties.get(key)).get()); } else if ("scaleX".equals(key)) { CONTROL.setScaleX(((DoubleProperty) properties.get(key)).get()); } else if ("scaleY".equals(key)) { CONTROL.setScaleY(((DoubleProperty) properties.get(key)).get()); } } return CONTROL; }
/** * Calculates all auto-size {@link Anchor}s. * * @param pAutoSizeCount the auto size count. */ private void calculateAutoSizeAnchors(int pAutoSizeCount) { for (Node child : getChildren()) { if (child.isManaged()) { Constraints constraint = getConstraint(child); Dimension2D preferredSize = NodeUtil.getPrefSize(child); calculateAutoSize(constraint.leftAnchor, constraint.rightAnchor, preferredSize.getWidth(), pAutoSizeCount); calculateAutoSize(constraint.topAnchor, constraint.bottomAnchor, preferredSize.getHeight(), pAutoSizeCount); } } }
@Override public void process(Frame frame) { if (frame.getTimestamp() - lastFrameCheck < minimumInterval) return; lastFrameCheck = frame.getTimestamp(); Imgproc.equalizeHist(frame.getOriginalMat(), frame.getOriginalMat()); final List<MatOfPoint2f> listPatterns = findPatterns(frame.getOriginalMat(), true); if (listPatterns.isEmpty()) return; final Optional<Dimension2D> paperRes = findPaperPattern(frame.getOriginalMat(), listPatterns); if (paperRes.isPresent()) ((StepFindPaperPattern) stepFindPaperPattern).addPaperDimensions(paperRes.get(), true); if (listPatterns.isEmpty()) return; // Technically there could still be more than one pattern // or even a pattern that is much too small // But damn if we're gonna fix every problem the user gives us final Optional<Bounds> bounds = calibrateFrame(listPatterns.get(0), frame.getOriginalMat()); if (bounds.isPresent()) { boundsResult = bounds.get(); } else { boundsResult = null; } }
@Test(expected = IllegalArgumentException.class) public void testDesiredDistanceCannotBeZero() { PerspectiveManager pm = new PerspectiveManager("C270", new Dimension2D(1280, 720), new BoundingBox(0, 0, 736, 544)); pm.setCameraFeedSize(1280, 720); pm.setCameraDistance(3406); pm.setShooterDistance(3406); pm.setProjectorResolution(1024, 768); pm.calculateUnknown(); pm.calculateObjectSize(10, 10, 0); }
/** Compute the preferred size for a text * * <p>Must be called on the UI thread, * because it's using one shared text helper. * * @param font Font * @param text Text * @return Width, height */ public static Dimension2D computeTextSize(final Font font, final String text) { // com.sun.javafx.scene.control.skin.Utils contains related code, // but is private helper.setFont(font); // With default line spacing of 0.0, // height of multi-line text is too small... helper.setLineSpacing(1.0); helper.setText(text); final Bounds measure = helper.getLayoutBounds(); return new Dimension2D(measure.getWidth(), measure.getHeight()); }
/** * Performs the alignment of the children. * * @param pLayoutSize the size of the layout. * @param pRows the rows. */ private void doAlignment(Dimension2D pLayoutSize, List<LayoutRow> pRows) { doStretchSameDirection(pRows); doAlignmentInLayout(pLayoutSize, pRows); doStretchOtherDirection(pLayoutSize, pRows); doAlignmentInContainer(pLayoutSize); }
/** * The dimensions of the arena when the course was saved. * * @return Optional.empty for courses saved prior to 3.7 */ public Optional<Dimension2D> getResolution() { if (resolution.isPresent()) { return resolution; } else { return Optional.empty(); } }
public PerspectiveManager(String cameraName, Bounds arenaBounds, Dimension2D feedDims, Dimension2D projectorRes) { this(cameraName, feedDims, arenaBounds); this.setProjectorResolution(projectorRes); if (cameraDistance == -1) cameraDistance = DEFAULT_SHOOTER_DISTANCE; if (shooterDistance == -1) shooterDistance = DEFAULT_SHOOTER_DISTANCE; calculateUnknown(); }
public static boolean isCameraSupported(final String cameraName, Dimension2D desiredResolution) { for (final CameraParameters cam : cameraParameters) { if (cameraName.contains(cam.getName()) && Math.abs(cam.getValidDimensions().getWidth() - desiredResolution.getWidth()) < .001 && Math.abs(cam.getValidDimensions().getHeight() - desiredResolution.getHeight()) < .001) { return true; } } return false; }
private boolean setCameraParameters(final String cameraName, Dimension2D desiredResolution) { for (final CameraParameters cam : cameraParameters) { if (cameraName.contains(cam.getName()) && Math.abs(cam.getValidDimensions().getWidth() - desiredResolution.getWidth()) < .001 && Math.abs(cam.getValidDimensions().getHeight() - desiredResolution.getHeight()) < .001) { focalLength = cam.getFocalLength(); sensorWidth = cam.getSensorWidth(); sensorHeight = cam.getSensorHeight(); return true; } } return false; }
private void setProjectionSizeFromLetterPaperPixels(Dimension2D letterDims) { if (logger.isTraceEnabled()) logger.trace("letter w {} h {}", letterDims.getWidth(), letterDims.getHeight()); if (cameraWidth == -1 || patternWidth == -1) { logger.error("Missing cameraWidth or patternWidth for US Letter calculation"); return; } // Calculate the size of the whole camera feed using the size of the // letter final double cameraFeedWidthMM = (cameraWidth / letterDims.getWidth()) * US_LETTER_WIDTH_MM; final double cameraFeedHeightMM = (cameraHeight / letterDims.getHeight()) * US_LETTER_HEIGHT_MM; if (logger.isTraceEnabled()) { logger.trace("{} = ({} / {}) * {}", cameraFeedWidthMM, cameraWidth, letterDims.getWidth(), US_LETTER_WIDTH_MM); logger.trace("{} = ({} / {}) * {}", cameraFeedHeightMM, cameraHeight, letterDims.getHeight(), US_LETTER_HEIGHT_MM); } // Set the projection width/height in mm projectionWidth = (int) (cameraFeedWidthMM * ((double) patternWidth / (double) cameraWidth)); projectionHeight = (int) (cameraFeedHeightMM * ((double) patternHeight / (double) cameraHeight)); if (logger.isTraceEnabled()) { logger.trace("{} = ({} / {}) * {}", projectionWidth, cameraFeedWidthMM, patternWidth, cameraWidth); logger.trace("{} = ({} / {}) * {}", projectionHeight, cameraFeedHeightMM, patternHeight, cameraHeight); } }