| /******************************************************************************* |
| <<<<<<< HEAD |
| * Copyright (c) 2018 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| ======= |
| * Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Pierre Allard, |
| * Regent L'Archeveque - initial API and implementation |
| * |
| * SPDX-License-Identifier: EPL-1.0 |
| * |
| >>>>>>> refs/heads/eclipse_pa |
| *******************************************************************************/ |
| package org.eclipse.apogy.addons.sensors.imaging.camera.impl; |
| |
| import java.awt.Color; |
| import java.text.DecimalFormat; |
| |
| import org.eclipse.apogy.addons.sensors.fov.RectangularFrustrumFieldOfView; |
| import org.eclipse.apogy.addons.sensors.imaging.AbstractCamera; |
| import org.eclipse.apogy.addons.sensors.imaging.AzimuthDirection; |
| import org.eclipse.apogy.addons.sensors.imaging.ElevationDirection; |
| import org.eclipse.apogy.addons.sensors.imaging.ImageSnapshot; |
| import org.eclipse.apogy.addons.sensors.imaging.ImagingUtilities; |
| import org.eclipse.apogy.addons.sensors.imaging.camera.OverlayAlignment; |
| import org.eclipse.apogy.common.images.AbstractEImage; |
| import org.eclipse.apogy.common.images.EImagesUtilities; |
| import org.eclipse.swt.graphics.Point; |
| |
| public class FOVOverlayCustomImpl extends FOVOverlayImpl { |
| |
| protected DecimalFormat angleFormat = new DecimalFormat("0.0"); |
| |
| @Override |
| public String getToolTipText(AbstractCamera camera, ImageSnapshot imageSnapshot, int mouseButton, int x, int y) { |
| String text = null; |
| |
| if (imageSnapshot != null) { |
| double hAngle = Math.toDegrees(imageSnapshot.convertToHorizontalAngle(x)); |
| double vAngle = Math.toDegrees(imageSnapshot.convertToVerticalAngle(y)); |
| |
| if (getAzimuthDirection() == AzimuthDirection.POSITIVE_TOWARD_RIGHT) { |
| hAngle = -hAngle; |
| } |
| |
| if (getElevationDirection() == ElevationDirection.POSITIVE_DOWN) { |
| vAngle = -vAngle; |
| } |
| |
| text = this.angleFormat.format(hAngle) + "°, " + this.angleFormat.format(vAngle) + "°"; |
| } |
| |
| return text; |
| } |
| |
| @Override |
| public AbstractEImage applyOverlay(AbstractCamera camera, AbstractEImage cameraImage, |
| OverlayAlignment overlayAlignment, int overlayWidth, int overlayHeight) { |
| RectangularFrustrumFieldOfView fov = camera.getFieldOfView(); |
| double horizontalFOVAngle = Math.toDegrees(fov.getHorizontalFieldOfViewAngle()); |
| double verticalFOVAngle = Math.toDegrees(fov.getVerticalFieldOfViewAngle()); |
| |
| AbstractEImage overlayImage = ImagingUtilities.INSTANCE.getAzimuthElevationOverlay(overlayWidth, overlayHeight, |
| 0.0, 0.0, horizontalFOVAngle, verticalFOVAngle, getAzimuthDirection(), getElevationDirection(), |
| getAngleInterval(), getFontName(), getFontSize(), getColorOfPositive(), getColorOfNegative(), |
| getLineWidth()); |
| |
| AbstractEImage result = EImagesUtilities.INSTANCE.applyOverlay(cameraImage, overlayImage, false); |
| |
| return result; |
| } |
| |
| protected Color getColorOfPositive() { |
| if (getPositiveValuesColor() != null) { |
| return new Color(getPositiveValuesColor().getX(), getPositiveValuesColor().getY(), |
| getPositiveValuesColor().getZ()); |
| } else { |
| return Color.GREEN; |
| } |
| } |
| |
| protected Color getColorOfNegative() { |
| if (getNegativeValueColor() != null) { |
| return new Color(getNegativeValueColor().getX(), getNegativeValueColor().getY(), |
| getNegativeValueColor().getZ()); |
| } else { |
| return Color.GREEN; |
| } |
| } |
| |
| protected Point getImageLocation(AbstractCamera camera, AbstractEImage cameraImage, double hAngle, double vAngle) { |
| RectangularFrustrumFieldOfView fov = camera.getFieldOfView(); |
| |
| int width = cameraImage.getWidth(); |
| int height = cameraImage.getHeight(); |
| |
| int hDistanceToCenter = (int) Math.ceil((hAngle / fov.getHorizontalFieldOfViewAngle()) * width); |
| int vDistanceToCenter = (int) Math.ceil((vAngle / fov.getVerticalFieldOfViewAngle()) * height); |
| |
| int hPosition = 0; |
| if (getAzimuthDirection() == AzimuthDirection.POSITIVE_TOWARD_LEFT) { |
| hPosition = (int) (Math.floor(width * 0.5f) - hDistanceToCenter); |
| } else { |
| hPosition = (int) (Math.floor(width * 0.5f) + hDistanceToCenter); |
| } |
| |
| int vPosition = 0; |
| |
| if (getElevationDirection() == ElevationDirection.POSITIVE_UP) { |
| vPosition = (int) (Math.floor(height * 0.5f) - vDistanceToCenter); |
| } else { |
| vPosition = (int) (Math.floor(height * 0.5f) + vDistanceToCenter); |
| } |
| |
| Point point = new Point(hPosition, vPosition); |
| |
| return point; |
| } |
| |
| } // FOVOverlayImpl |