Skip to content

Commit 081e3be

Browse files
maarztStefan Hahmann
authored andcommitted
GraphUtils: fix getRootsAfterTimepoint method
1 parent a9f6bb9 commit 081e3be

2 files changed

Lines changed: 31 additions & 12 deletions

File tree

src/main/java/org/mastodon/mamut/tomancak/lineage_registration/GraphUtils.java

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,43 @@ public class GraphUtils
1313
/**
1414
* @return the set of root nodes of the given graph.
1515
*/
16-
public static < V extends Vertex< E >, E extends Edge< V > > RefSet< V > getRoots( ReadOnlyGraph< V, E > graph )
16+
public static < V extends Vertex< ? > > RefSet< V > getRoots( ReadOnlyGraph< V, ? > graph )
1717
{
1818
Predicate< V > isRoot = spot -> spot.incomingEdges().isEmpty();
1919
return RefCollectionUtils.filterSet( graph.vertices(), isRoot );
2020
}
2121

22-
public static < V extends Vertex< E > & HasTimepoint, E extends Edge< V > > RefSet< V > getRoots( ReadOnlyGraph< V, E > graph, int timepoint )
23-
{
24-
Predicate< V > isRoot = spot -> spot.getTimepoint() == timepoint || ( spot.incomingEdges().isEmpty() && spot.getTimepoint() > timepoint );
25-
return RefCollectionUtils.filterSet( graph.vertices(), isRoot );
26-
}
27-
2822
/**
29-
* @return true if the given spot is part of a branch that divides.
23+
* Returns the vertices of the graph that would be roots if all vertices with
24+
* {@code vertex.getTimepoint() < timepoint} would be discarded.
3025
*/
31-
public static boolean doesBranchDivide( final Spot spot, final Spot ref )
26+
public static < V extends Vertex< E > & HasTimepoint, E extends Edge< V > > RefSet< V > getRootsAfterTimepoint( ReadOnlyGraph< V, E > graph, int timepoint )
3227
{
33-
Spot branchEnd = BranchGraphUtils.getBranchEnd( spot, ref );
34-
return branchEnd.outgoingEdges().size() > 1;
28+
V ref = graph.vertexRef();
29+
try
30+
{
31+
Predicate< V > isRoot = spot -> {
32+
33+
if ( spot.getTimepoint() < timepoint )
34+
return false;
35+
36+
if ( spot.incomingEdges().isEmpty() )
37+
return true;
38+
39+
for ( E edge : spot.incomingEdges() )
40+
{
41+
V source = edge.getSource( ref );
42+
if ( source.getTimepoint() >= timepoint )
43+
return false;
44+
}
45+
46+
return true;
47+
};
48+
return RefCollectionUtils.filterSet( graph.vertices(), isRoot );
49+
}
50+
finally
51+
{
52+
graph.releaseRef( ref );
53+
}
3554
}
3655
}

src/main/java/org/mastodon/mamut/tomancak/trackmatching/RootsPairing.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static RefRefMap< Spot, Spot > pairDividingRoots( ModelGraph graphA, int timepoi
7373

7474
private static RefSet< Spot > getRoots( ModelGraph graph, int timepoint )
7575
{
76-
return getBranchStarts( filterDividingSpots( GraphUtils.getRoots( graph, timepoint ) ) );
76+
return getBranchStarts( filterDividingSpots( GraphUtils.getRootsAfterTimepoint( graph, timepoint ) ) );
7777
}
7878

7979
private static RefRefMap< Spot, Spot > pairSpotsBasedOnLabel( RefSet< Spot > spotsA, RefSet< Spot > spotsB )

0 commit comments

Comments
 (0)