| /******************************************************************************* |
| * 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 |
| * |
| *******************************************************************************/ |
| package org.eclipse.apogy.addons.geometry.paths.impl; |
| |
| import org.eclipse.apogy.addons.geometry.paths.ApogyAddonsGeometryPathsFactory; |
| import org.eclipse.apogy.addons.geometry.paths.WayPointPath; |
| import org.eclipse.apogy.common.geometry.data3d.ApogyCommonGeometryData3DFacade; |
| import org.eclipse.apogy.common.geometry.data3d.CartesianPositionCoordinates; |
| import org.eclipse.apogy.common.geometry.data3d.Geometry3DUtilities; |
| |
| public class MinimumDistanceFilterCustomImpl extends MinimumDistanceFilterImpl { |
| |
| @Override |
| public WayPointPath process(WayPointPath input) throws Exception { |
| |
| if (input == null) { |
| throw (new IllegalArgumentException("Cannot pass null WayPointPath as input.")); |
| } |
| |
| // If there are enough points to allow for filtering. |
| if (input.getPoints().size() > 2) { |
| WayPointPath filtered = ApogyAddonsGeometryPathsFactory.eINSTANCE.createWayPointPath(); |
| |
| if (getProgressMonitor() != null) |
| getProgressMonitor().beginTask("Filtering WayPointPath.", input.getPoints().size()); |
| |
| // The first way point is always kept. |
| filtered.getPoints().add(ApogyCommonGeometryData3DFacade.INSTANCE |
| .createCartesianPositionCoordinates(input.getPoints().get(0))); |
| if (getProgressMonitor() != null) |
| getProgressMonitor().worked(1); |
| |
| // Goes through the list of points and adds to the filtered list |
| // only those that are further apart then the specified minimum |
| // distance. |
| CartesianPositionCoordinates previousPoint = input.getPoints().get(0); |
| for (int i = 1; i < input.getPoints().size(); i++) { |
| CartesianPositionCoordinates nextPoint = input.getPoints().get(i); |
| double distance = Geometry3DUtilities.getDistance(previousPoint, nextPoint); |
| |
| if (distance > getMinimumDistance()) { |
| filtered.getPoints().add( |
| ApogyCommonGeometryData3DFacade.INSTANCE.createCartesianPositionCoordinates(nextPoint)); |
| previousPoint = nextPoint; |
| } |
| |
| if (getProgressMonitor() != null) |
| getProgressMonitor().worked(1); |
| } |
| |
| // Adds the last point from the original list if required. |
| if (!input.getEndPoint().equals(filtered.getEndPoint())) { |
| filtered.getPoints().add(input.getEndPoint()); |
| } |
| if (getProgressMonitor() != null) |
| getProgressMonitor().worked(1); |
| |
| // Done. |
| if (getProgressMonitor() != null) |
| getProgressMonitor().done(); |
| return filtered; |
| } else { |
| if (getProgressMonitor() != null) |
| getProgressMonitor().done(); |
| return input; |
| } |
| } |
| } // MinimumDistanceFilterImpl |