Edge edgeB = this.edges.get(this.segments.get(sB));
Edge edgeC = this.edges.get(this.segments.get(sC));
if (edgeA == null || edgeB == null || edgeC == null)
continue;
Triangle triangle = new Triangle(i, qet.isBorder()?true:false);
triangle.addEdge(edgeA);
triangle.addEdge(edgeB);
triangle.addEdge(edgeC);
edgeA.addTriangle(triangle);
edgeB.addTriangle(triangle);
edgeC.addTriangle(triangle);
this.triangles.put(i, triangle);
i++;
}
// add triangle neighbourood
for (Edge edge : this.edges.values()) {
if (edge.getTriangles().size() > 1) {
Triangle tA = edge.getTriangles().get(0);
Triangle tB = edge.getTriangles().get(1);
tA.addNeighbour(tB);
tB.addNeighbour(tA);
}
}
// concave hull algorithm
int index = 0;
while (index != -1) {
index = -1;
Edge e = null;
// find the max length (smallest id so first entry)
int si = this.lengths.size();
if (si != 0) {
Entry<Integer, Edge> entry = this.lengths.firstEntry();
int ind = entry.getKey();
if (entry.getValue().getGeometry().getLength() > this.threshold) {
index = ind;
e = entry.getValue();
}
}
if (index != -1) {
Triangle triangle = e.getTriangles().get(0);
List<Triangle> neighbours = triangle.getNeighbours();
// irregular triangle test
if (neighbours.size() == 1) {
this.shortLengths.put(e.getId(), e);
this.lengths.remove(e.getId());
} else {
Edge e0 = triangle.getEdges().get(0);
Edge e1 = triangle.getEdges().get(1);
// test if all the vertices are on the border
if (e0.getOV().isBorder() && e0.getEV().isBorder()
&& e1.getOV().isBorder() && e1.getEV().isBorder()) {
this.shortLengths.put(e.getId(), e);
this.lengths.remove(e.getId());
} else {
// management of triangles
if (neighbours.size() < 1) continue; //not sure this is safe
Triangle tA = neighbours.get(0);
Triangle tB = neighbours.get(1);
tA.setBorder(true); // FIXME not necessarily useful
tB.setBorder(true); // FIXME not necessarily useful
this.triangles.remove(triangle.getId());
tA.removeNeighbour(triangle);
tB.removeNeighbour(triangle);
// new edges
List<Edge> ee = triangle.getEdges();
Edge eA = ee.get(0);
Edge eB = ee.get(1);