| /******************************************************************************* |
| <<<<<<< 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 javax.measure.unit.Unit; |
| |
| import org.eclipse.apogy.addons.sensors.imaging.AbstractCamera; |
| import org.eclipse.apogy.addons.sensors.imaging.camera.OverlayAlignment; |
| import org.eclipse.apogy.common.emf.AbstractFeatureListNode; |
| import org.eclipse.apogy.common.emf.AbstractFeatureSpecifier; |
| import org.eclipse.apogy.common.emf.ApogyCommonEMFFacade; |
| import org.eclipse.apogy.common.images.AbstractEImage; |
| import org.eclipse.apogy.core.invocator.ApogyCoreInvocatorFacade; |
| import org.eclipse.apogy.core.invocator.VariableFeatureReference; |
| import org.eclipse.emf.ecore.ETypedElement; |
| |
| public class EMFFeatureAzimuthElevationFOVOverlayCustomImpl extends EMFFeatureAzimuthElevationFOVOverlayImpl { |
| |
| private final Unit<?> degreeUnits = Unit.valueOf("°"); |
| |
| @Override |
| public AbstractEImage applyOverlay(AbstractCamera camera, AbstractEImage cameraImage, |
| OverlayAlignment overlayAlignment, int overlayWidth, int overlayHeight) { |
| try { |
| // Updates the azimuth and elevation from the refered features. |
| changeAzimuth(getAzimuth()); |
| changeElevation(getElevation()); |
| |
| // Gets the overlay. |
| return super.applyOverlay(camera, cameraImage, overlayAlignment, overlayWidth, overlayHeight); |
| } catch (Throwable t) { |
| return cameraImage; |
| } |
| } |
| |
| protected double getAzimuth() { |
| return getValue(getAzimuthFeatureReference()); |
| } |
| |
| protected double getElevation() { |
| return getValue(getElevationFeatureReference()); |
| } |
| |
| protected double getValue(VariableFeatureReference variableFeatureReference) { |
| Number featureValue = (Number) ApogyCoreInvocatorFacade.INSTANCE.getEMFFeatureValue(variableFeatureReference); |
| |
| // Gets the feature associated with the azimuth. |
| AbstractFeatureListNode abstractFeatureListNode = ApogyCommonEMFFacade.INSTANCE |
| .getLeaf(variableFeatureReference.getFeatureRoot()); |
| AbstractFeatureSpecifier abstractFeatureSpecifier = (AbstractFeatureSpecifier) abstractFeatureListNode; |
| ETypedElement eTypedElement = abstractFeatureSpecifier.getStructuralFeature(); |
| |
| // Gets the units associated with the feature |
| Unit<?> units = ApogyCommonEMFFacade.INSTANCE.getEngineeringUnits(eTypedElement); |
| |
| double value = featureValue.doubleValue(); |
| if (units != null) { |
| // Converts to degrees through units. |
| value = units.getConverterTo(getDegreesUnits()).convert(value); |
| } |
| |
| return value; |
| } |
| |
| protected Unit<?> getDegreesUnits() { |
| return this.degreeUnits; |
| } |
| } // EMFFeatureAzimuthElevationFOVOverlayImpl |