-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example that demonstrates how to listen to spot property changes.
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/test/java/org/mastodon/mamut/model/ModelPropertyListenerExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |