/******************************************************************************* * Copyright (c) 2012, 2013 Association for Decentralized Information Management in * Industry THTH ry. * 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: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.opencascade.vtk; import java.util.HashSet; import java.util.List; import java.util.Set; import javax.vecmath.Point3d; import javax.vecmath.Vector3d; import org.simantics.utils.datastructures.MapList; import vtk.vtkCell; import vtk.vtkIdList; import vtk.vtkLine; import vtk.vtkPoints; import vtk.vtkPolyData; import vtk.vtkProgrammableFilter; import vtk.vtkVertex; public class EdgePointsFilter extends vtkProgrammableFilter { vtkPoints outputPoints; public EdgePointsFilter() { SetExecuteMethod(this, "compute"); } public void compute() { vtkPolyData polyDataInput = GetPolyDataInput(); vtkPolyData polyDataOutput = GetPolyDataOutput(); vtkPoints inputPoints = polyDataInput.GetPoints(); outputPoints = new vtkPoints(); MapList edgeIndices = new MapList(); for (int i = 0; i 0) { vtkLine line = (vtkLine)cell; int i1 = line.GetPointId(0); int i2 = line.GetPointId(1); if (!edgeIndices.contains(i1, i2)) { edgeIndices.add(i1, i2); edgeIndices.add(i2, i1); } line.Delete(); } } Set vertices = new HashSet(); for (Integer i : edgeIndices.getKeys()) { List edges = edgeIndices.getValues(i); if (edges.size() != 2) vertices.add(i); else { double tp[] = inputPoints.GetPoint(i); double ep1[] = inputPoints.GetPoint(edges.get(0)); double ep2[] = inputPoints.GetPoint(edges.get(1)); Point3d t = new Point3d(tp); Vector3d v1 = new Vector3d(ep1); Vector3d v2 = new Vector3d(ep2); v1.sub(t); v2.sub(t); double angle = Math.PI - v1.angle(v2); if (angle > Math.PI/6) vertices.add(i); } } for (int i : vertices) { outputPoints.InsertNextPoint(inputPoints.GetPoint(i)); } polyDataOutput.Allocate(vertices.size(), vertices.size()); vtkVertex vertex = new vtkVertex(); vtkIdList list = vertex.GetPointIds(); for (int i = 0; i < vertices.size(); i++) { list.SetId(0, i); polyDataOutput.InsertNextCell(vertex.GetCellType(), list); } polyDataOutput.SetPoints(outputPoints); list.Delete(); vertex.Delete(); polyDataOutput.Delete(); polyDataInput.Delete(); } @Override public void Delete() { outputPoints.Delete(); super.Delete(); } }