Commit 24c1644f authored by rhaase's avatar rhaase
Browse files

bugfix: must delete edges in right order to keep the rest consistent

parent 665a0995
......@@ -41,6 +41,19 @@ public class SkeletonAnalyser {
init(sr.getGraph());
}
/**
* Copy constructor
* @param skeletonAnalyser Object to copy
*/
public SkeletonAnalyser(SkeletonAnalyser skeletonAnalyser)
{
this.allEdges = new ArrayList<Edge>();
this.allEdges.addAll(skeletonAnalyser.allEdges);
this.allVertices = new ArrayList<Vertex>();
this.allVertices.addAll(skeletonAnalyser.allVertices);
}
/**
* Internal initializer
* @param graphs
......@@ -524,6 +537,10 @@ public class SkeletonAnalyser {
{
throw new Exception("Edges have no common junction");
}
System.out.println("edges at vertex to remove: " + getEdgesStartingAtJunction(vertexToRemove).size());
ArrayList<Point> slabs = getPointsAlongPath(path);
slabs.remove(0);
slabs.remove(slabs.size() - 1);
......@@ -538,16 +555,32 @@ public class SkeletonAnalyser {
newEdge.setType(edge1.getType());
allEdges.add(newEdge);
// remove former edges
allEdges.remove(index1);
allEdges.remove(index2);
Point a = getCenterOfJunction(newEdge.getV1());
Point b = getCenterOfJunction(newEdge.getV2());
System.out.println("New Edge from " + a + " to " + b );
System.out.println("remove an edge1 " + index1);
System.out.println("remove an egde2 " + index2);
// remove former edges
if (index1 > index2) {
allEdges.remove(index1);
allEdges.remove(index2);
}
else
{
allEdges.remove(index2);
allEdges.remove(index1);
}
// remove vertices if no other edge contains them
ArrayList<Edge> edgesStillAtJunction = getEdgesStartingAtJunction(vertexToRemove);
System.out.println("edges still at vertex to remove: " + edgesStillAtJunction.size());
if (edgesStillAtJunction.size() == 0) {
for (Vertex vertex : allVertices) {
if (junctionsEqual(vertex, vertexToRemove)) {
System.out.println("remove a vertex " + getCenterOfJunction(vertex));
allVertices.remove(vertex);
}
}
......@@ -559,25 +592,58 @@ public class SkeletonAnalyser {
*/
public void removeUnneededJunctions()
{
Vertex soma = getLargestJunction();
boolean deletedSome = true;
while (deletedSome) {
deletedSome = false;
System.out.println("Restart search for unneeded edges " + allVertices.size() + " " + allEdges.size());
for (Vertex vertex : allVertices) {
ArrayList<Edge> edges = getEdgesStartingAtJunction(vertex);
if (edges.size() == 2)
{
try {
joinEdges(edges.get(0), edges.get(1));
deletedSome = true;
break;
}
catch (Exception e)
{
System.out.println(e.toString());
// special handling: exclude soma
if (vertex != soma) {
ArrayList<Edge> edges = getEdgesStartingAtJunction(vertex);
if (edges.size() == 2) {
Point v = getCenterOfJunction(vertex);
System.out.println("Vertex at " + v + " has only two edges... ");
try {deletedSome = true;
joinEdges(edges.get(0), edges.get(1));
System.out.println("Deleted some - break");
} catch (Exception e) {
System.out.println("its here");
System.out.println(e.toString());
}
if (deletedSome)
{
break;
}
}
}
System.out.println("continue loop");
}
System.out.println("leave loop");
}
}
public void removeLeaf(Vertex leaf) throws Exception {
ArrayList<Edge> edges = getEdgesStartingAtJunction(leaf);
if (edges.size() > 1)
{
throw new Exception("Cannot remove leaf because it is no leaf, it has several connected edges");
}
if (edges.size() == 1)
{
int index = findEdge(edges.get(0));
allEdges.remove(index);
}
allVertices.remove(leaf);
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment