1 package org.simantics.opencascade.vtk;
\r
3 import java.util.HashSet;
\r
4 import java.util.List;
\r
5 import java.util.Set;
\r
7 import javax.vecmath.Point3d;
\r
8 import javax.vecmath.Vector3d;
\r
10 import org.simantics.utils.datastructures.MapList;
\r
13 import vtk.vtkIdList;
\r
15 import vtk.vtkPoints;
\r
16 import vtk.vtkPolyData;
\r
17 import vtk.vtkProgrammableFilter;
\r
18 import vtk.vtkVertex;
\r
20 public class EdgePointsFilter extends vtkProgrammableFilter {
\r
21 vtkPoints outputPoints;
\r
24 public EdgePointsFilter() {
\r
25 SetExecuteMethod(this, "compute");
\r
28 public void compute() {
\r
29 vtkPolyData polyDataInput = GetPolyDataInput();
\r
30 vtkPolyData polyDataOutput = GetPolyDataOutput();
\r
31 vtkPoints inputPoints = polyDataInput.GetPoints();
\r
33 outputPoints = new vtkPoints();
\r
35 MapList<Integer, Integer> edgeIndices = new MapList<Integer, Integer>();
\r
36 for (int i = 0; i <polyDataInput.GetNumberOfCells(); i++) {
\r
37 vtkCell cell= polyDataInput.GetCell(i);
\r
38 if (cell.IsA("vtkLine") > 0) {
\r
39 vtkLine line = (vtkLine)cell;
\r
40 int i1 = line.GetPointId(0);
\r
41 int i2 = line.GetPointId(1);
\r
42 if (!edgeIndices.contains(i1, i2)) {
\r
43 edgeIndices.add(i1, i2);
\r
44 edgeIndices.add(i2, i1);
\r
50 Set<Integer> vertices = new HashSet<Integer>();
\r
51 for (Integer i : edgeIndices.getKeys()) {
\r
52 List<Integer> edges = edgeIndices.getValues(i);
\r
53 if (edges.size() != 2)
\r
56 double tp[] = inputPoints.GetPoint(i);
\r
57 double ep1[] = inputPoints.GetPoint(edges.get(0));
\r
58 double ep2[] = inputPoints.GetPoint(edges.get(1));
\r
59 Point3d t = new Point3d(tp);
\r
60 Vector3d v1 = new Vector3d(ep1);
\r
61 Vector3d v2 = new Vector3d(ep2);
\r
64 double angle = Math.PI - v1.angle(v2);
\r
65 if (angle > Math.PI/6)
\r
69 for (int i : vertices) {
\r
70 outputPoints.InsertNextPoint(inputPoints.GetPoint(i));
\r
72 polyDataOutput.Allocate(vertices.size(), vertices.size());
\r
74 vtkVertex vertex = new vtkVertex();
\r
75 vtkIdList list = vertex.GetPointIds();
\r
76 for (int i = 0; i < vertices.size(); i++) {
\r
78 polyDataOutput.InsertNextCell(vertex.GetCellType(), list);
\r
81 polyDataOutput.SetPoints(outputPoints);
\r
87 polyDataOutput.Delete();
\r
88 polyDataInput.Delete();
\r
93 public void Delete() {
\r
94 outputPoints.Delete();
\r