| /******************************************************************************* |
| * 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.common.geometry.data3d.impl; |
| |
| import java.util.ArrayList; |
| import java.util.List; |
| |
| import javax.vecmath.Point3d; |
| import javax.vecmath.Vector3d; |
| |
| import org.eclipse.apogy.common.geometry.data3d.ApogyCommonGeometryData3DFactory; |
| import org.eclipse.apogy.common.geometry.data3d.CartesianPositionCoordinates; |
| import org.eclipse.apogy.common.geometry.data3d.CartesianTriangularMesh; |
| import org.eclipse.apogy.common.geometry.data3d.NormalPointCloud; |
| import org.eclipse.apogy.common.geometry.data3d.TriangularMeshNormalsCalculator; |
| |
| public class TriangularMeshToNormalPointCloudCustomImpl extends TriangularMeshToNormalPointCloudImpl { |
| @Override |
| public NormalPointCloud process(CartesianTriangularMesh input) throws Exception { |
| |
| NormalPointCloud output = ApogyCommonGeometryData3DFactory.eINSTANCE.createNormalPointCloud(); |
| |
| List<Vector3d> normals = null; |
| |
| // We extract the points from input. |
| List<Point3d> points = new ArrayList<Point3d>(input.getPoints().size()); |
| |
| for (CartesianPositionCoordinates point : input.getPoints()) { |
| points.add(point.asPoint3d()); |
| } |
| |
| // If the normals are not present, we compute the normals. |
| if (input.getNormals() == null || input.getNormals().size() != input.getPoints().size()) { |
| // We compute the normals. |
| TriangularMeshNormalsCalculator normalsCalculator = ApogyCommonGeometryData3DFactory.eINSTANCE |
| .createTriangularMeshNormalsCalculator(); |
| input = normalsCalculator.process(input); |
| } |
| |
| // We process the normals. |
| if (input.getNormals() != null && input.getNormals().size() > 0) { |
| normals = new ArrayList<Vector3d>(input.getNormals().size()); |
| |
| for (Vector3d normal : input.getNormals()) { |
| normals.add(new Vector3d(normal)); |
| } |
| } |
| |
| output.setPoints(points); |
| output.setNormals(normals); |
| |
| return output; |
| } |
| |
| } // TriangularMeshToNormalPointCloudImpl |