Skip to content

Commit

Permalink
Add methods getMaxTimepoint() and getMinTimepoint() to TreeUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhahmann authored and tinevez committed Jan 15, 2024
1 parent a8654a3 commit dc0a103
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/main/java/org/mastodon/util/TreeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
import org.mastodon.graph.Edge;
import org.mastodon.graph.Graph;
import org.mastodon.graph.Vertex;
import org.mastodon.mamut.model.Model;
import org.mastodon.mamut.model.Spot;
import org.mastodon.pool.PoolCollectionWrapper;

public class TreeUtils
{
Expand Down Expand Up @@ -227,4 +230,30 @@ private static < V extends Vertex<E>, E extends Edge< V > > RefSet< V > filterRo
roots.add( node );
return roots;
}

/**
* Gets the minimum timepoint in the given {@link Model} at which at least one {@link Spot} exists in the Model.
* @param model the {@link Model}
* @return the timepoint
*/
public static int getMinTimepoint( final Model model )
{
int minTimepoint = Integer.MAX_VALUE;
for ( Spot spot : model.getGraph().vertices() )
minTimepoint = Math.min( minTimepoint, spot.getTimepoint() );
return minTimepoint;
}

/**
* Gets the maximum timepoint in the given {@link Model} at which at least one {@link Spot} exists in the Model.
* @param model the {@link Model}
* @return the timepoint
*/
public static int getMaxTimepoint( final Model model )
{
int max = 0;
for ( Spot spot : model.getGraph().vertices() )
max = Math.max( max, spot.getTimepoint() );
return max;
}
}
16 changes: 16 additions & 0 deletions src/test/java/org/mastodon/util/TreeUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.mastodon.collection.RefCollections;
import org.mastodon.collection.RefList;
import org.mastodon.collection.RefSet;
import org.mastodon.mamut.feature.branch.exampleGraph.ExampleGraph1;
import org.mastodon.mamut.feature.branch.exampleGraph.ExampleGraph2;
import org.mastodon.mamut.model.ModelGraph;
import org.mastodon.mamut.model.Spot;
Expand Down Expand Up @@ -175,4 +176,19 @@ private static < T > Set< T > createSet( final T... elements )
{
return new HashSet<>( Arrays.asList( elements ) );
}

@Test
public void testGetMinTimepoint()
{
assertEquals( 0, TreeUtils.getMinTimepoint( new ExampleGraph1().getModel() ) );
assertEquals( 0, TreeUtils.getMinTimepoint( new ExampleGraph2().getModel() ) );

}

@Test
public void testGetMaxTimepoint()
{
assertEquals( 3, TreeUtils.getMaxTimepoint( new ExampleGraph1().getModel() ) );
assertEquals( 7, TreeUtils.getMaxTimepoint( new ExampleGraph2().getModel() ) );
}
}

0 comments on commit dc0a103

Please sign in to comment.