Skip to content

Commit

Permalink
Example that demonstrates how to listen to spot property changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tinevez committed Jul 17, 2024
1 parent 8dfaecd commit 6b91b6e
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.mastodon.mamut.model;

import org.mastodon.properties.PropertyChangeListener;

/**
* Example that demonstrates how to listen to spot property changes.
*/
public class ModelPropertyListenerExample
{

public static void main( final String[] args )
{
final Model model = new Model();
final ModelGraph graph = model.getGraph();

final double radius = 3.;
final Spot spot = graph.addVertex().init( 0, new double[] { 0., 0., 0. }, radius );

final PropertyChangeListener< Spot > listener = s -> System.out.println( "The covariance of " + s + " changed!" );
graph.getVertexPool().covariance.propertyChangeListeners().add( listener );

final double[][] cov = new double[ 3 ][ 3 ];
final double newRadius = 10. * 10.;
covarianceFromRadiusSquared( newRadius, cov );
spot.setCovariance( cov );
}

private static void covarianceFromRadiusSquared( final double rsqu, final double[][] cov )
{
for ( int row = 0; row < 3; ++row )
for ( int col = 0; col < 3; ++col )
cov[ row ][ col ] = ( row == col ) ? rsqu : 0;
}
}

0 comments on commit 6b91b6e

Please sign in to comment.