| /******************************************************************************* |
| * 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, |
| <<<<<<< HEAD |
| * Sebastien Gemme |
| * |
| ======= |
| * Sebastien Gemme - initial API and implementation |
| * |
| >>>>>>> refs/heads/eclipse_pa |
| * SPDX-License-Identifier: EPL-1.0 |
| * |
| *******************************************************************************/ |
| package org.eclipse.apogy.common.geometry.data3d.las.ui; |
| |
| import java.io.IOException; |
| import java.util.ArrayList; |
| import java.util.List; |
| |
| import org.eclipse.apogy.common.geometry.data3d.ApogyCommonGeometryData3DFacade; |
| import org.eclipse.apogy.common.geometry.data3d.ApogyCommonGeometryData3DFactory; |
| import org.eclipse.apogy.common.geometry.data3d.CartesianCoordinatesSet; |
| import org.eclipse.apogy.common.geometry.data3d.CartesianPositionCoordinates; |
| import org.eclipse.apogy.common.geometry.data3d.las.ApogyCommonGeometryData3DLASFactory; |
| import org.eclipse.apogy.common.geometry.data3d.las.LASHeader; |
| import org.eclipse.apogy.common.geometry.data3d.las.LASPoint; |
| import org.eclipse.apogy.common.geometry.data3d.las.LASReader; |
| import org.eclipse.apogy.common.topology.ApogyCommonTopologyFactory; |
| import org.eclipse.apogy.common.topology.ContentNode; |
| import org.eclipse.apogy.common.topology.GroupNode; |
| import org.eclipse.apogy.common.topology.ui.ApogyCommonTopologyUIFactory; |
| import org.eclipse.apogy.common.topology.ui.GraphicsContext; |
| import org.eclipse.apogy.common.topology.ui.GraphicsContextAdapter; |
| import org.eclipse.core.resources.IFile; |
| import org.eclipse.core.runtime.IProgressMonitor; |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| public class GraphicsContextLasAdapter implements GraphicsContextAdapter { |
| |
| private static final Logger Logger = LoggerFactory.getLogger(GraphicsContextLasAdapter.class); |
| |
| public static final String SUPPORTED_EXTENSION = "las"; |
| |
| public GraphicsContextLasAdapter() { |
| } |
| |
| @Override |
| public boolean isAdapterFor(Object obj) { |
| |
| boolean ok = false; |
| |
| // We respond to IFile selection ending with SUPPORTED_EXTENSION |
| if (obj instanceof IFile) { |
| IFile file = (IFile) obj; |
| |
| ok = file.getName().endsWith("." + SUPPORTED_EXTENSION); |
| } |
| |
| return ok; |
| } |
| |
| @Override |
| public GraphicsContext getAdapter(Object obj, Object context) { |
| |
| System.out.println("GraphicsContextLasAdapter.getAdapter()"); |
| |
| GraphicsContext grContext = null; |
| |
| if (isAdapterFor(obj)) { |
| IFile file = (IFile) obj; |
| |
| // We import the file |
| try { |
| LASReader reader = ApogyCommonGeometryData3DLASFactory.eINSTANCE.createLASReader(); |
| reader.setFile(file.getLocation().toOSString()); |
| |
| if (context instanceof IProgressMonitor) { |
| System.out.println("GraphicsContextLasAdapter.getAdapter() setting progress monitor"); |
| reader.setProgressMonitor((IProgressMonitor) context); |
| } |
| |
| System.out.println("GraphicsContextLasAdapter.getAdapter() reading file " + reader.getFile()); |
| reader.read(); |
| |
| List<LASPoint> points = reader.getPoints(); |
| |
| LASHeader header = reader.getHeader(); |
| |
| double xOffset = header.getXOffset(); |
| double xScale = header.getXScaleFactor(); |
| |
| double yOffset = header.getYOffset(); |
| double yScale = header.getYScaleFactor(); |
| |
| double zOffset = header.getZOffset(); |
| double zScale = header.getZScaleFactor(); |
| |
| // We convert the points into a cartesian coordinates set |
| CartesianCoordinatesSet pts = ApogyCommonGeometryData3DFactory.eINSTANCE |
| .createCartesianCoordinatesSet(); |
| |
| List<CartesianPositionCoordinates> pointList = new ArrayList<CartesianPositionCoordinates>( |
| points.size()); |
| |
| for (LASPoint p : points) { |
| |
| double x = (p.getX() * xScale) + xOffset; |
| double y = (p.getY() * yScale) + yOffset; |
| double z = (p.getZ() * zScale) + zOffset; |
| |
| CartesianPositionCoordinates point = ApogyCommonGeometryData3DFacade.INSTANCE |
| .createCartesianPositionCoordinates(x, y, z); |
| pointList.add(point); |
| } |
| |
| pts.getPoints().addAll(pointList); |
| |
| // We create a topology |
| GroupNode root = ApogyCommonTopologyFactory.eINSTANCE.createAggregateGroupNode(); |
| |
| ContentNode<CartesianCoordinatesSet> pointNode = org.eclipse.apogy.common.topology.ApogyCommonTopologyFacade.INSTANCE |
| .createContentNode(pts); |
| |
| root.getChildren().add(pointNode); |
| |
| // We create a graphics context |
| grContext = ApogyCommonTopologyUIFactory.eINSTANCE.createGraphicsContext(); |
| grContext.setTopology(root); |
| |
| } catch (IOException e) { |
| Logger.error(e.getMessage(), e); |
| } |
| } |
| return grContext; |
| } |
| |
| @Override |
| public Class<?> getAdaptedClass() { |
| return IFile.class; |
| } |
| |
| } |