diff --git a/src/main/java/org/mastodon/util/TreeUtils.java b/src/main/java/org/mastodon/util/TreeUtils.java index 0a8734354..c7b7a511f 100644 --- a/src/main/java/org/mastodon/util/TreeUtils.java +++ b/src/main/java/org/mastodon/util/TreeUtils.java @@ -39,6 +39,7 @@ import org.mastodon.graph.Vertex; import org.mastodon.mamut.model.Model; import org.mastodon.mamut.model.Spot; +import org.mastodon.mamut.model.branch.BranchSpot; public class TreeUtils { @@ -255,4 +256,18 @@ public static int getMaxTimepoint( final Model model ) max = Math.max( max, spot.getTimepoint() ); return max; } + + /** + * Gets the first {@link Spot} within the given {@link BranchSpot}. + * @param model the {@link Model} to which the {@link BranchSpot} belongs + * @param branchSpot the {@link BranchSpot} to query + * @return the first {@link Spot} + */ + public static Spot getFirstSpot( final Model model, final BranchSpot branchSpot ) + { + Spot ref = model.getGraph().vertexRef(); + Spot first = model.getBranchGraph().getFirstLinkedVertex( branchSpot, ref ); + model.getGraph().releaseRef( ref ); + return first; + } } diff --git a/src/test/java/org/mastodon/util/TreeUtilsTest.java b/src/test/java/org/mastodon/util/TreeUtilsTest.java index 803f991f7..b6407bbe4 100644 --- a/src/test/java/org/mastodon/util/TreeUtilsTest.java +++ b/src/test/java/org/mastodon/util/TreeUtilsTest.java @@ -191,4 +191,14 @@ public void testGetMaxTimepoint() assertEquals( 3, TreeUtils.getMaxTimepoint( new ExampleGraph1().getModel() ) ); assertEquals( 7, TreeUtils.getMaxTimepoint( new ExampleGraph2().getModel() ) ); } + + @Test + public void testGetFirstSpot() + { + ExampleGraph1 exampleGraph1 = new ExampleGraph1(); + assertEquals( exampleGraph1.spot0, TreeUtils.getFirstSpot( exampleGraph1.getModel(), exampleGraph1.branchSpotA ) ); + + ExampleGraph2 exampleGraph2 = new ExampleGraph2(); + assertEquals( exampleGraph2.spot5, TreeUtils.getFirstSpot( exampleGraph2.getModel(), exampleGraph2.branchSpotD ) ); + } }