1 /*******************************************************************************
\r
2 * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.opencascade.vtk;
\r
14 import java.util.HashSet;
\r
15 import java.util.List;
\r
16 import java.util.Set;
\r
18 import javax.vecmath.Point3d;
\r
19 import javax.vecmath.Vector3d;
\r
21 import org.simantics.utils.datastructures.MapList;
\r
24 import vtk.vtkIdList;
\r
26 import vtk.vtkPoints;
\r
27 import vtk.vtkPolyData;
\r
28 import vtk.vtkProgrammableFilter;
\r
29 import vtk.vtkVertex;
\r
31 public class EdgePointsFilter extends vtkProgrammableFilter {
\r
32 vtkPoints outputPoints;
\r
35 public EdgePointsFilter() {
\r
36 SetExecuteMethod(this, "compute");
\r
39 public void compute() {
\r
40 vtkPolyData polyDataInput = GetPolyDataInput();
\r
41 vtkPolyData polyDataOutput = GetPolyDataOutput();
\r
42 vtkPoints inputPoints = polyDataInput.GetPoints();
\r
44 outputPoints = new vtkPoints();
\r
46 MapList<Integer, Integer> edgeIndices = new MapList<Integer, Integer>();
\r
47 for (int i = 0; i <polyDataInput.GetNumberOfCells(); i++) {
\r
48 vtkCell cell= polyDataInput.GetCell(i);
\r
49 if (cell.IsA("vtkLine") > 0) {
\r
50 vtkLine line = (vtkLine)cell;
\r
51 int i1 = line.GetPointId(0);
\r
52 int i2 = line.GetPointId(1);
\r
53 if (!edgeIndices.contains(i1, i2)) {
\r
54 edgeIndices.add(i1, i2);
\r
55 edgeIndices.add(i2, i1);
\r
61 Set<Integer> vertices = new HashSet<Integer>();
\r
62 for (Integer i : edgeIndices.getKeys()) {
\r
63 List<Integer> edges = edgeIndices.getValues(i);
\r
64 if (edges.size() != 2)
\r
67 double tp[] = inputPoints.GetPoint(i);
\r
68 double ep1[] = inputPoints.GetPoint(edges.get(0));
\r
69 double ep2[] = inputPoints.GetPoint(edges.get(1));
\r
70 Point3d t = new Point3d(tp);
\r
71 Vector3d v1 = new Vector3d(ep1);
\r
72 Vector3d v2 = new Vector3d(ep2);
\r
75 double angle = Math.PI - v1.angle(v2);
\r
76 if (angle > Math.PI/6)
\r
80 for (int i : vertices) {
\r
81 outputPoints.InsertNextPoint(inputPoints.GetPoint(i));
\r
83 polyDataOutput.Allocate(vertices.size(), vertices.size());
\r
85 vtkVertex vertex = new vtkVertex();
\r
86 vtkIdList list = vertex.GetPointIds();
\r
87 for (int i = 0; i < vertices.size(); i++) {
\r
89 polyDataOutput.InsertNextCell(vertex.GetCellType(), list);
\r
92 polyDataOutput.SetPoints(outputPoints);
\r
98 polyDataOutput.Delete();
\r
99 polyDataInput.Delete();
\r
104 public void Delete() {
\r
105 outputPoints.Delete();
\r