Skip to content

Commit 20ecc21

Browse files
committed
GraphUtils: fix getRootsAfterTimepoint method
1 parent 4e57359 commit 20ecc21

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

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

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +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 )
22+
/**
23+
* Returns the vertices of the graph that would be roots if all vertices with
24+
* {@code vertex.getTimepoint() < timepoint} would be discarded.
25+
*/
26+
public static < V extends Vertex< E > & HasTimepoint, E extends Edge< V > > RefSet< V > getRootsAfterTimepoint( ReadOnlyGraph< V, E > graph, int timepoint )
2327
{
24-
Predicate< V > isRoot = spot -> spot.getTimepoint() == timepoint || ( spot.incomingEdges().isEmpty() && spot.getTimepoint() > timepoint );
25-
return RefCollectionUtils.filterSet( graph.vertices(), isRoot );
26-
}
28+
V ref = graph.vertexRef();
29+
try
30+
{
31+
Predicate< V > isRoot = spot -> {
2732

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+
}
54+
}
2855
}

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

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

4545
private static RefSet< Spot > getRoots( ModelGraph graph, int timepoint )
4646
{
47-
return getBranchStarts( filterDividingSpots( GraphUtils.getRoots( graph, timepoint ) ) );
47+
return getBranchStarts( filterDividingSpots( GraphUtils.getRootsAfterTimepoint( graph, timepoint ) ) );
4848
}
4949

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

0 commit comments

Comments
 (0)