javafx.geometry.BoundingBox Java Examples

The following examples show how to use javafx.geometry.BoundingBox. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MouseUtilsTests.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
@Test
public void mouseOutsideBoundaryBoxDistanceTests() {
    final Bounds screenBounds = new BoundingBox(/* minX */ 0.0, /* minY */ 0.0, /* width */ 10.0, /* height */ 5.0);

    // mouse inside
    assertEquals(0, MouseUtils.mouseOutsideBoundaryBoxDistance(screenBounds, new Point2D(1, 1)));
    assertEquals(0, MouseUtils.mouseOutsideBoundaryBoxDistance(screenBounds, new Point2D(0, 0)));
    assertEquals(0, MouseUtils.mouseOutsideBoundaryBoxDistance(screenBounds, new Point2D(10, 5)));

    // mouse outside
    assertEquals(2, MouseUtils.mouseOutsideBoundaryBoxDistance(screenBounds, new Point2D(-2.0, 0)));
    assertEquals(2, MouseUtils.mouseOutsideBoundaryBoxDistance(screenBounds, new Point2D(12.0, 0)));
    assertEquals(2, MouseUtils.mouseOutsideBoundaryBoxDistance(screenBounds, new Point2D(0.0, -2)));
    assertEquals(2, MouseUtils.mouseOutsideBoundaryBoxDistance(screenBounds, new Point2D(0.0, 7)));

    // test Manhattan-Norm
    assertEquals(4, MouseUtils.mouseOutsideBoundaryBoxDistance(screenBounds, new Point2D(-2.0, 9)));
    assertEquals(4, MouseUtils.mouseOutsideBoundaryBoxDistance(screenBounds, new Point2D(-4.0, 7)));
}
 
Example #2
Source File: TestCameraManagerDark.java    From ShootOFF with GNU General Public License v3.0 6 votes vote down vote up
@Test
// DARK
public void testPS3EyeHardwareDefaultsBrightRoomLimitedBounds() {
	// Turn off the top sectors because they are all just noise.
	for (int x = 0; x < JavaShotDetector.SECTOR_ROWS; x++) {
		sectorStatuses[0][x] = false;
	}

	Bounds projectionBounds = new BoundingBox(109, 104, 379, 297);

	List<DisplayShot> shots = findShots("/shotsearcher/ps3eye_hardware_defaults_bright_room.mp4",
			Optional.of(projectionBounds), mockManager, config, sectorStatuses);

	List<Shot> requiredShots = new ArrayList<Shot>();
	requiredShots.add(new Shot(ShotColor.RED, 176.5, 251.3, 0, 2));

	List<Shot> optionalShots = new ArrayList<Shot>();
	optionalShots.add(new Shot(ShotColor.RED, 236.5, 169.5, 0, 2));
	optionalShots.add(new Shot(ShotColor.RED, 175, 191.5, 0, 2));
	optionalShots.add(new Shot(ShotColor.RED, 229.5, 227.5, 0, 2));

	super.checkShots(collector, shots, requiredShots, optionalShots, false);
}
 
Example #3
Source File: TestCameraManagerDark.java    From ShootOFF with GNU General Public License v3.0 6 votes vote down vote up
@Test
// DARK
public void testPS3EyeHardwareDefaultsRedLaserRoomLightOnSafariLimitedBounds() {
	Bounds projectionBounds = new BoundingBox(131, 77, 390, 265);

	List<DisplayShot> shots = findShots("/shotsearcher/ps3eye_hardware_defaults_safari_red_laser_lights_on.mp4",
			Optional.of(projectionBounds), mockManager, config, sectorStatuses);

	List<Shot> requiredShots = new ArrayList<Shot>();
	requiredShots.add(new Shot(ShotColor.RED, 473.6, 126.5, 0, 2));
	requiredShots.add(new Shot(ShotColor.RED, 349.2, 130.5, 0, 2));
	requiredShots.add(new Shot(ShotColor.RED, 207.3, 113.5, 0, 2));
	requiredShots.add(new Shot(ShotColor.RED, 183.1, 226.9, 0, 2));
	requiredShots.add(new Shot(ShotColor.RED, 310.5, 228.5, 0, 2));
	requiredShots.add(new Shot(ShotColor.RED, 468.7, 219.8, 0, 2));
	requiredShots.add(new Shot(ShotColor.RED, 469.8, 268.5, 0, 2));
	requiredShots.add(new Shot(ShotColor.RED, 339.9, 291.8, 0, 2));
	requiredShots.add(new Shot(ShotColor.RED, 201.5, 297.7, 0, 2));

	super.checkShots(collector, shots, requiredShots, new ArrayList<Shot>(), true);
}
 
Example #4
Source File: CanvasManager.java    From ShootOFF with GNU General Public License v3.0 6 votes vote down vote up
public Bounds translateCanvasToCamera(Bounds bounds) {
	if (config.getDisplayWidth() == cameraManager.getFeedWidth()
			&& config.getDisplayHeight() == cameraManager.getFeedHeight())
		return bounds;

	final double scaleX = (double) cameraManager.getFeedWidth() / (double) config.getDisplayWidth();
	final double scaleY = (double) cameraManager.getFeedHeight() / (double) config.getDisplayHeight();

	final double minX = (bounds.getMinX() * scaleX);
	final double minY = (bounds.getMinY() * scaleY);
	final double width = (bounds.getWidth() * scaleX);
	final double height = (bounds.getHeight() * scaleY);

	logger.trace("translateCanvasToCamera {} {} {} {} - {} {} {} {}", bounds.getMinX(), bounds.getMinY(),
			bounds.getWidth(), bounds.getHeight(), minX, minY, width, height);

	return new BoundingBox(minX, minY, width, height);
}
 
Example #5
Source File: TestPerspectiveManager.java    From ShootOFF with GNU General Public License v3.0 6 votes vote down vote up
@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);
}
 
Example #6
Source File: TestPerspectiveManager.java    From ShootOFF with GNU General Public License v3.0 6 votes vote down vote up
@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);
}
 
Example #7
Source File: TestPerspectiveManager.java    From ShootOFF with GNU General Public License v3.0 6 votes vote down vote up
@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);
}
 
Example #8
Source File: CanvasManager.java    From ShootOFF with GNU General Public License v3.0 6 votes vote down vote up
public Bounds translateCameraToCanvas(Bounds bounds) {
	if (config.getDisplayWidth() == cameraManager.getFeedWidth()
			&& config.getDisplayHeight() == cameraManager.getFeedHeight())
		return bounds;

	final double scaleX = (double) config.getDisplayWidth() / (double) cameraManager.getFeedWidth();
	final double scaleY = (double) config.getDisplayHeight() / (double) cameraManager.getFeedHeight();

	final double minX = (bounds.getMinX() * scaleX);
	final double minY = (bounds.getMinY() * scaleY);
	final double width = (bounds.getWidth() * scaleX);
	final double height = (bounds.getHeight() * scaleY);

	logger.trace("translateCameraToCanvas {} {} {} {} - {} {} {} {}", bounds.getMinX(), bounds.getMinY(),
			bounds.getWidth(), bounds.getHeight(), minX, minY, width, height);

	return new BoundingBox(minX, minY, width, height);
}
 
Example #9
Source File: JFXMasonryPane.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
protected boolean validHeight(BoundingBox box, Region region, double cellH, double gutterX, double gutterY) {
    boolean valid = false;
    if (region.getMinHeight() != -1 && box.getHeight() * cellH + (box.getHeight() - 1) * 2 * gutterY < region.getMinHeight()) {
        return false;
    }

    if (region.getPrefHeight() == USE_COMPUTED_SIZE && box.getHeight() * cellH + (box.getHeight() - 1) * 2 * gutterY >= region
        .prefHeight(region.prefWidth(-1))) {
        valid = true;
    }
    if (region.getPrefHeight() != USE_COMPUTED_SIZE && box.getHeight() * cellH + (box.getHeight() - 1) * 2 * gutterY >= region
        .getPrefHeight()) {
        valid = true;
    }
    return valid;
}
 
Example #10
Source File: JFXMasonryPane.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
protected boolean validWidth(BoundingBox box, Region region, double cellW, double gutterX, double gutterY) {
    boolean valid = false;
    if (region.getMinWidth() != -1 && box.getWidth() * cellW + (box.getWidth() - 1) * 2 * gutterX < region.getMinWidth()) {
        return false;
    }

    if (region.getPrefWidth() == USE_COMPUTED_SIZE && box.getWidth() * cellW + (box.getWidth() - 1) * 2 * gutterX >= region
        .prefWidth(-1)) {
        valid = true;
    }
    if (region.getPrefWidth() != USE_COMPUTED_SIZE && box.getWidth() * cellW + (box.getWidth() - 1) * 2 * gutterX >= region
        .getPrefWidth()) {
        valid = true;
    }
    return valid;
}
 
Example #11
Source File: MouseUtilsTests.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
@Test
public void mouseInsideBoundaryBoxDistanceTests() {
    final Bounds screenBounds = new BoundingBox(/* minX */ 0.0, /* minY */ 0.0, /* width */ 10.0, /* height */ 5.0);

    // mouse outside
    assertEquals(0, MouseUtils.mouseInsideBoundaryBoxDistance(screenBounds, new Point2D(-2, 0)));
    assertEquals(0, MouseUtils.mouseInsideBoundaryBoxDistance(screenBounds, new Point2D(12, 0)));
    assertEquals(0, MouseUtils.mouseInsideBoundaryBoxDistance(screenBounds, new Point2D(0, -2)));
    assertEquals(0, MouseUtils.mouseInsideBoundaryBoxDistance(screenBounds, new Point2D(0, 7)));

    // mouse inside
    assertEquals(2, MouseUtils.mouseInsideBoundaryBoxDistance(screenBounds, new Point2D(2.0, 2.5)));
    assertEquals(2, MouseUtils.mouseInsideBoundaryBoxDistance(screenBounds, new Point2D(8.0, 2.5)));
    assertEquals(2, MouseUtils.mouseInsideBoundaryBoxDistance(screenBounds, new Point2D(5, 2)));
    assertEquals(2, MouseUtils.mouseInsideBoundaryBoxDistance(screenBounds, new Point2D(5, 3)));

    // mouse on boundary
    assertEquals(0, MouseUtils.mouseInsideBoundaryBoxDistance(screenBounds, new Point2D(0, 3)));
    assertEquals(0, MouseUtils.mouseInsideBoundaryBoxDistance(screenBounds, new Point2D(3, 0)));
    assertEquals(0, MouseUtils.mouseInsideBoundaryBoxDistance(screenBounds, new Point2D(10, 3)));
    assertEquals(0, MouseUtils.mouseInsideBoundaryBoxDistance(screenBounds, new Point2D(3, 5)));

    // test Manhattan-Norm
    assertEquals(1, MouseUtils.mouseInsideBoundaryBoxDistance(screenBounds, new Point2D(1, 3)));
    assertEquals(1, MouseUtils.mouseInsideBoundaryBoxDistance(screenBounds, new Point2D(5, 1)));
}
 
Example #12
Source File: YRangeIndicator.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
@Override
public void layoutChildren() {
    if (getChart() == null) {
        return;
    }

    final Bounds plotAreaBounds = getChart().getCanvas().getBoundsInLocal();
    final double minX = plotAreaBounds.getMinX();
    final double maxX = plotAreaBounds.getMaxX();
    final double minY = plotAreaBounds.getMinY();
    final double maxY = plotAreaBounds.getMaxY();

    final Axis yAxis = getNumericAxis();
    final double value1 = yAxis.getDisplayPosition(getLowerBound());
    final double value2 = yAxis.getDisplayPosition(getUpperBound());

    final double startY = Math.max(minY, minY + Math.min(value1, value2));
    final double endY = Math.min(maxY, minY + Math.max(value1, value2));

    layout(new BoundingBox(minX, startY, maxX - minX, endY - startY));
}
 
Example #13
Source File: XValueIndicator.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
@Override
public void layoutChildren() {
    if (getChart() == null) {
        return;
    }

    final Bounds plotAreaBounds = getChart().getCanvas().getBoundsInLocal();
    final double minX = plotAreaBounds.getMinX();
    final double maxX = plotAreaBounds.getMaxX();
    final double minY = plotAreaBounds.getMinY();
    final double maxY = plotAreaBounds.getMaxY();
    final double xPos = minX + getChart().getFirstAxis(Orientation.HORIZONTAL).getDisplayPosition(getValue());

    if (xPos < minX || xPos > maxX) {
        getChartChildren().clear();
    } else {
        layoutLine(xPos, minY, xPos, maxY);
        layoutMarker(xPos, minY + 1.5 * AbstractSingleValueIndicator.triangleHalfWidth, xPos, maxY);
        layoutLabel(new BoundingBox(xPos, minY, 0, maxY - minY), AbstractSingleValueIndicator.MIDDLE_POSITION,
                getLabelPosition());
    }
}
 
Example #14
Source File: YValueIndicator.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
@Override
public void layoutChildren() {
    if (getChart() == null) {
        return;
    }
    final Bounds plotAreaBounds = getChart().getCanvas().getBoundsInLocal();
    final double minX = plotAreaBounds.getMinX();
    final double maxX = plotAreaBounds.getMaxX();
    final double minY = plotAreaBounds.getMinY();
    final double maxY = plotAreaBounds.getMaxY();

    final double yPos = minY + getNumericAxis().getDisplayPosition(getValue());

    if (yPos < minY || yPos > maxY) {
        getChartChildren().clear();
    } else {
        layoutLine(minX, yPos, maxX, yPos);
        layoutMarker(maxX - 1.5 * AbstractSingleValueIndicator.triangleHalfWidth, yPos, minX, yPos); // +
                // 1.5*TRIANGLE_HALF_WIDTH
        layoutLabel(new BoundingBox(minX, yPos, maxX - minX, 0), getLabelPosition(),
                AbstractSingleValueIndicator.MIDDLE_POSITION);
    }
}
 
Example #15
Source File: XRangeIndicator.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
@Override
public void layoutChildren() {
    if (getChart() == null) {
        return;
    }
    final Bounds plotAreaBounds = getChart().getCanvas().getBoundsInLocal();
    final double minX = plotAreaBounds.getMinX();
    final double maxX = plotAreaBounds.getMaxX();
    final double minY = plotAreaBounds.getMinY();
    final double maxY = plotAreaBounds.getMaxY();

    final Axis xAxis = getNumericAxis();
    final double value1 = xAxis.getDisplayPosition(getLowerBound());
    final double value2 = xAxis.getDisplayPosition(getUpperBound());

    final double startX = Math.max(minX, minX + Math.min(value1, value2));
    final double endX = Math.min(maxX, minX + Math.max(value1, value2));

    layout(new BoundingBox(startX, minY, endX - startX, maxY - minY));
}
 
Example #16
Source File: GenericStyledArea.java    From RichTextFX with BSD 2-Clause "Simplified" License 6 votes vote down vote up
final Optional<Bounds> getSelectionBoundsOnScreen(Selection<PS, SEG, S> selection) {
    if (selection.getLength() == 0) {
        return Optional.empty();
    }

    List<Bounds> bounds = new ArrayList<>(selection.getParagraphSpan());
    for (int i = selection.getStartParagraphIndex(); i <= selection.getEndParagraphIndex(); i++) {
        virtualFlow.getCellIfVisible(i)
                .ifPresent(c -> c.getNode()
                        .getSelectionBoundsOnScreen(selection)
                        .ifPresent(bounds::add)
                );
    }

    if(bounds.size() == 0) {
        return Optional.empty();
    }
    double minX = bounds.stream().mapToDouble(Bounds::getMinX).min().getAsDouble();
    double maxX = bounds.stream().mapToDouble(Bounds::getMaxX).max().getAsDouble();
    double minY = bounds.stream().mapToDouble(Bounds::getMinY).min().getAsDouble();
    double maxY = bounds.stream().mapToDouble(Bounds::getMaxY).max().getAsDouble();
    return Optional.of(new BoundingBox(minX, minY, maxX-minX, maxY-minY));
}
 
Example #17
Source File: SmartGraphPanel.java    From JavaFXSmartGraph with MIT License 6 votes vote down vote up
/**
 * Computes the bounding box from all displayed vertices.
 *
 * @return bounding box
 */
private Bounds getPlotBounds() {
    double minX = Double.MAX_VALUE, minY = Double.MAX_VALUE,
            maxX = Double.MIN_VALUE, maxY = Double.MIN_VALUE;
    
    if(vertexNodes.size() == 0) return new BoundingBox(0, 0, getWidth(), getHeight());
    
    for (SmartGraphVertexNode<V> v : vertexNodes.values()) {
        minX = Math.min(minX, v.getCenterX());
        minY = Math.min(minY, v.getCenterY());
        maxX = Math.max(maxX, v.getCenterX());
        maxY = Math.max(maxY, v.getCenterY());
    }

    return new BoundingBox(minX, minY, maxX - minX, maxY - minY);
}
 
Example #18
Source File: GenericStyledArea.java    From RichTextFX with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Bounds getParagraphBoundsOnScreen(Cell<Paragraph<PS, SEG, S>, ParagraphBox<PS, SEG, S>> cell) {
    Bounds nodeLocal = cell.getNode().getBoundsInLocal();
    Bounds nodeScreen = cell.getNode().localToScreen(nodeLocal);
    Bounds areaLocal = getBoundsInLocal();
    Bounds areaScreen = localToScreen(areaLocal);

    // use area's minX if scrolled right and paragraph's left is not visible
    double minX = nodeScreen.getMinX() < areaScreen.getMinX()
            ? areaScreen.getMinX()
            : nodeScreen.getMinX();
    // use area's minY if scrolled down vertically and paragraph's top is not visible
    double minY = nodeScreen.getMinY() < areaScreen.getMinY()
            ? areaScreen.getMinY()
            : nodeScreen.getMinY();
    // use area's width whether paragraph spans outside of it or not
    // so that short or long paragraph takes up the entire space
    double width = areaScreen.getWidth();
    // use area's maxY if scrolled up vertically and paragraph's bottom is not visible
    double maxY = nodeScreen.getMaxY() < areaScreen.getMaxY()
            ? nodeScreen.getMaxY()
            : areaScreen.getMaxY();
    return new BoundingBox(minX, minY, width, maxY - minY);
}
 
Example #19
Source File: TestTargetCommands.java    From ShootOFF with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void setUp() throws ConfigurationException {
	System.setProperty("shootoff.home", System.getProperty("user.dir"));

	TextToSpeech.silence(true);
	TrainingExerciseBase.silence(true);
	
	config = new Configuration(new String[0]);
	canvasManager = new MockCanvasManager(config);
	cameraManager = new MockCameraManager();
	
	bounds = new BoundingBox(100, 100, 540, 260);
	
	cameraManager.setProjectionBounds(bounds);
	canvasManager.setCameraManager(cameraManager);
	
	ProjectorArenaPane projectorArenaPane = new MockProjectorArenaController(config, canvasManager);
	
	canvasManager.setProjectorArena(projectorArenaPane, bounds);
	canvasManager.getCanvasGroup().getChildren().clear();

	targets = new ArrayList<Target>();
	TargetComponents poiComponents = TargetIO.loadTarget(new File("targets/POI_Offset_Adjustment.target")).get();
	poiTarget = (TargetView) canvasManager.addTarget(
			new TargetView(poiComponents.getTargetGroup(), poiComponents.getTargetTags(), targets));
	targets.add(poiTarget);
	
	canvasManager.addTarget(new File("targets/POI_Offset_Adjustment.target"));
	
	canvasManager.getTargets().get(0).setDimensions(640, 360);
	canvasManager.getTargets().get(0).setPosition(0, 0);
}
 
Example #20
Source File: JFXMasonryPane.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
/**
 * returns the available box at the cell (x,y) of the grid that fits the block if existed
 *
 * @param x
 * @param y
 * @param block
 * @return
 */
protected BoundingBox getFreeArea(int[][] matrix, int x, int y, Region block, double cellWidth, double cellHeight, int limitRow, int limitCol, double gutterX, double gutterY) {
    double blockHeight = getBLockHeight(block);
    double blockWidth = getBLockWidth(block);

    int rowsNeeded = (int) Math.ceil(blockHeight / (cellHeight + gutterY));
    if (cellHeight * rowsNeeded + (rowsNeeded - 1) * 2 * gutterY < blockHeight) {
        rowsNeeded++;
    }
    int maxRow = Math.min(x + rowsNeeded, limitRow);

    int colsNeeded = (int) Math.ceil(blockWidth / (cellWidth + gutterX));
    if (cellWidth * colsNeeded + (colsNeeded - 1) * 2 * gutterX < blockWidth) {
        colsNeeded++;
    }
    int maxCol = Math.min(y + colsNeeded, limitCol);

    int minRow = maxRow;
    int minCol = maxCol;
    for (int i = x; i < minRow; i++) {
        for (int j = y; j < maxCol; j++) {
            if (matrix[i][j] != 0) {
                if (y < j && j < minCol) {
                    minCol = j;
                }
            }
        }
    }
    for (int i = x; i < maxRow; i++) {
        for (int j = y; j < minCol; j++) {
            if (matrix[i][j] != 0) {
                if (x < i && i < minRow) {
                    minRow = i;
                }
            }
        }
    }
    return new BoundingBox(x, y, minCol - y, minRow - x);
}
 
Example #21
Source File: TestPerspectiveManager.java    From ShootOFF with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testOne() throws ConfigurationException {
	assertTrue(PerspectiveManager.isCameraSupported("C270", new Dimension2D(1280, 720)));
	
	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();

	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);

	dims = pm.calculateObjectSize(300, 200, 3406*2);
	assertTrue(dims.isPresent());
	assertEquals(87.7, dims.get().getWidth(), 1);
	assertEquals(59.1, dims.get().getHeight(), 1);

	dims = pm.calculateObjectSize(300, 200, 3406 / 2);
	assertTrue(dims.isPresent());
	assertEquals(350.7, dims.get().getWidth(), 1);
	assertEquals(236.5, dims.get().getHeight(), 1);

	pm.setShooterDistance(3406 * 2);
	dims = pm.calculateObjectSize(300, 200, 3406);
	assertTrue(dims.isPresent());
	assertEquals(350.7, dims.get().getWidth(), 1);
	assertEquals(236.5, dims.get().getHeight(), 1);

}
 
Example #22
Source File: TestPerspectiveManager.java    From ShootOFF with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #23
Source File: BreakingNewsDemo.java    From htm.java-examples with GNU Affero General Public License v3.0 5 votes vote down vote up
public void configureView() {
    view = new BreakingNewsDemoView();
    view.autoModeProperty().addListener((v, o, n) -> { this.mode = n; });
    this.mode = view.autoModeProperty().get();
    view.startActionProperty().addListener((v, o, n) -> {
        if(n) {
            if(mode == Mode.AUTO) cursor++;
            start();
        }else{
            stop();
        }
    });
    view.runOneProperty().addListener((v, o, n) -> {
        this.cursor += n.intValue();
        runOne(jsonList.get(cursor), cursor);
    });
    view.flipStateProperty().addListener((v, o, n) -> {
        view.flipPaneProperty().get().flip();
    });

    view.setPrefSize(1370, 1160);
    view.setMinSize(1370, 1160);

    mainViewScroll  = new ScrollPane();
    mainViewScroll.setViewportBounds(new BoundingBox(0, 0, 1370, 1160));

    mainViewScroll.setHbarPolicy(ScrollBarPolicy.NEVER);
    mainViewScroll.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
    mainViewScroll.setContent(view);
    mainViewScroll.viewportBoundsProperty().addListener((v, o, n) -> {
        view.setPrefSize(Math.max(1370, n.getMaxX()), Math.max(1160, n.getMaxY()));//1370, 1160);
    });

    createDataStream();
    createAlgorithm();
}
 
Example #24
Source File: ImageMosaicStep.java    From TweetwallFX with MIT License 5 votes vote down vote up
private Transition createMosaicTransition(final List<ImageStore> imageStores) {
    final SequentialTransition fadeIn = new SequentialTransition();
    final List<FadeTransition> allFadeIns = new ArrayList<>();
    final double width = pane.getWidth() / 6.0 - 10;
    final double height = pane.getHeight() / 5.0 - 8;
    final List<ImageStore> distillingList = new ArrayList<>(imageStores);

    for (int i = 0; i < 6; i++) {
        for (int j = 0; j < 5; j++) {
            int index = RANDOM.nextInt(distillingList.size());
            ImageStore selectedImage = distillingList.remove(index);
            ImageView imageView = new ImageView(selectedImage.getImage());
            imageView.setCache(true);
            imageView.setCacheHint(CacheHint.SPEED);
            imageView.setFitWidth(width);
            imageView.setFitHeight(height);
            imageView.setEffect(new GaussianBlur(0));
            rects[i][j] = imageView;
            bounds[i][j] = new BoundingBox(i * (width + 10) + 5, j * (height + 8) + 4, width, height);
            rects[i][j].setOpacity(0);
            rects[i][j].setLayoutX(bounds[i][j].getMinX());
            rects[i][j].setLayoutY(bounds[i][j].getMinY());
            pane.getChildren().add(rects[i][j]);
            FadeTransition ft = new FadeTransition(Duration.seconds(0.3), imageView);
            ft.setToValue(1);
            allFadeIns.add(ft);
        }
    }
    Collections.shuffle(allFadeIns);
    fadeIn.getChildren().addAll(allFadeIns);
    return fadeIn;
}
 
Example #25
Source File: GenericStyledArea.java    From RichTextFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static Bounds extendLeft(Bounds b, double w) {
    if(w == 0) {
        return b;
    } else {
        return new BoundingBox(
                b.getMinX() - w, b.getMinY(),
                b.getWidth() + w, b.getHeight());
    }
}
 
Example #26
Source File: AppUtils.java    From OpenLabeler with Apache License 2.0 5 votes vote down vote up
public static Bounds getBounds(Point2D... points) {
   double minX = Double.MAX_VALUE;
   double maxX = -Double.MAX_VALUE;
   double minY = Double.MAX_VALUE;
   double maxY = -Double.MAX_VALUE;
   for (Point2D pt : points) {
      minX = Math.min(minX, pt.getX());
      maxX = Math.max(maxX, pt.getX());
      minY = Math.min(minY, pt.getY());
      maxY = Math.max(maxY, pt.getY());
   };
   return new BoundingBox(minX, minY, maxX - minX, maxY - minY);
}
 
Example #27
Source File: AppUtils.java    From OpenLabeler with Apache License 2.0 5 votes vote down vote up
public static Bounds insetBounds(Bounds bounds, double amount) {
   return new BoundingBox(
         bounds.getMinX() + amount,
         bounds.getMinY() + amount,
         bounds.getMaxX() - amount,
         bounds.getMaxY() - amount);
}
 
Example #28
Source File: DropOp.java    From FxDock with Apache License 2.0 5 votes vote down vote up
public void addOutline(Node ref, double x, double y, double w, double h)
{
	BoundingBox screenr = new BoundingBox(x, y, w, h);
	Bounds b = ref.localToScreen(screenr);
	b = target.screenToLocal(b);
	
	Region r = new Region();
	r.relocate(b.getMinX(), b.getMinY());
	r.resize(b.getWidth(), b.getHeight());
	r.setBackground(FX.background(Color.color(0, 0, 0, 0.1)));
	
	add(r);
}
 
Example #29
Source File: DropOp.java    From FxDock with Apache License 2.0 5 votes vote down vote up
public void addRect(Node ref, double x, double y, double w, double h)
{
	BoundingBox screenr = new BoundingBox(x, y, w, h);
	Bounds b = ref.localToScreen(screenr);
	b = target.screenToLocal(b);
	
	Region r = new Region();
	r.relocate(b.getMinX(), b.getMinY());
	r.resize(b.getWidth(), b.getHeight());
	r.setBackground(FX.background(Color.color(0, 0, 0, 0.3)));
	
	add(r);
}
 
Example #30
Source File: ResizeTransformSelectedOnHandleDragHandler.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private Bounds getBounds(Rectangle sel,
		IContentPart<? extends Node> targetPart) {
	double x1 = sel.getX() + sel.getWidth() * relX1.get(targetPart);
	double x2 = sel.getX() + sel.getWidth() * relX2.get(targetPart);
	double y1 = sel.getY() + sel.getHeight() * relY1.get(targetPart);
	double y2 = sel.getY() + sel.getHeight() * relY2.get(targetPart);
	return new BoundingBox(x1, y1, x2 - x1, y2 - y1);
}