Skip to content

Commit

Permalink
Add new method getFirstSpot to TreeUtils
Browse files Browse the repository at this point in the history
* Convenience method to retrieve the first spot of a branch spot
  • Loading branch information
stefanhahmann committed Apr 10, 2024
1 parent 9921855 commit e75aafb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/org/mastodon/util/TreeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}
}
10 changes: 10 additions & 0 deletions src/test/java/org/mastodon/util/TreeUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}
}

0 comments on commit e75aafb

Please sign in to comment.