Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve min radius when editing spot. #163

Merged
merged 1 commit into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions src/main/java/org/mastodon/mamut/MamutViewBdv.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@

import bdv.BigDataViewerActions;
import bdv.tools.InitializeViewerState;
import bdv.util.Affine3DHelpers;
import bdv.viewer.NavigationActions;
import bdv.viewer.Source;
import bdv.viewer.SourceAndConverter;
import bdv.viewer.ViewerPanel;
import net.imglib2.realtransform.AffineTransform3D;

Expand Down Expand Up @@ -290,7 +293,7 @@ else if ( null != featureColorModeName )
final AutoNavigateFocusModel< OverlayVertexWrapper< Spot, Link >, OverlayEdgeWrapper< Spot, Link > > navigateFocusModel = new AutoNavigateFocusModel<>( focusModel, navigationHandler );

BdvSelectionBehaviours.install( viewBehaviours, viewGraph, tracksOverlay, selectionModel, focusModel, navigationHandler );
EditBehaviours.install( viewBehaviours, viewGraph, tracksOverlay, selectionModel, focusModel, model );
EditBehaviours.install( viewBehaviours, viewGraph, tracksOverlay, selectionModel, focusModel, model, getMinRadius( sharedBdvData ) );
EditSpecialBehaviours.install( viewBehaviours, frame.getViewerPanel(), viewGraph, tracksOverlay, selectionModel, focusModel, model );
HighlightBehaviours.install( viewBehaviours, viewGraph, viewGraph.getLock(), viewGraph, highlightModel, model );
FocusActions.install( viewActions, viewGraph, viewGraph.getLock(), navigateFocusModel, selectionModel );
Expand Down Expand Up @@ -338,8 +341,8 @@ else if ( null != featureColorModeName )
// if ( !bdv.tryLoadSettings( bdvFile ) ) // TODO
// InitializeViewerState.initBrightness( 0.001, 0.999, bdv.getViewer(), bdv.getSetupAssignments() );
}
protected OverlayGraphRenderer< OverlayVertexWrapper< Spot, Link >, OverlayEdgeWrapper< Spot, Link > > createRenderer(

protected OverlayGraphRenderer< OverlayVertexWrapper< Spot, Link >, OverlayEdgeWrapper< Spot, Link > > createRenderer(
final OverlayGraphWrapper< Spot, Link > viewGraph,
final HighlightModel< OverlayVertexWrapper< Spot, Link >, OverlayEdgeWrapper< Spot, Link > > highlightModel,
final FocusModel< OverlayVertexWrapper< Spot, Link >, OverlayEdgeWrapper< Spot, Link > > focusModel,
Expand Down Expand Up @@ -373,4 +376,35 @@ public ColoringModel getColoringModel()
{
return coloringModel;
}

/**
* Determine min radius to pass to the edit actions, so that we cannot
* create spots that have a radius smaller than 0.5 pixels in the worst
* case.
*/
private static final double getMinRadius( final SharedBigDataViewerData sharedBdvData )
{
double minRadius = 0.5;
final int level = 0;
for ( final SourceAndConverter< ? > sac : sharedBdvData.getSources() )
{
for ( int t = 0; t < sharedBdvData.getNumTimepoints(); t++ )
{
final Source< ? > source = sac.getSpimSource();
if ( source.isPresent( t ) )
{
final AffineTransform3D transform = new AffineTransform3D();
source.getSourceTransform( t, level, transform );
for ( int d = 0; d < 3; d++ )
{
final double l = Affine3DHelpers.extractScale( transform, d ) / 2.;
if ( l < minRadius )
minRadius = l;
}
break;
}
}
}
return minRadius;
}
}
37 changes: 21 additions & 16 deletions src/main/java/org/mastodon/views/bdv/overlay/EditBehaviours.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ public void getCommandDescriptions( final CommandDescriptions descriptions )

public static final double POINT_SELECT_DISTANCE_TOLERANCE = 5.0;

/** Minimal radius below which changes in vertex size are rejected. */
private static final double MIN_RADIUS = 1.0;

/**
* Ratio by which we change the radius upon change radius action.
*/
Expand Down Expand Up @@ -141,17 +138,18 @@ public void getCommandDescriptions( final CommandDescriptions descriptions )

private final ResizeSpotBehaviour decreaseSpotRadiusBehaviourABit;

private double lastRadius = 10;
private double lastRadius = 5.;

public static < V extends OverlayVertex< V, E >, E extends OverlayEdge< E, V > > void install(
final Behaviours behaviours,
final OverlayGraph< V, E > overlayGraph,
final OverlayGraphRenderer< V, E > renderer,
final SelectionModel< V, E > selection,
final FocusModel< V, E > focus,
final UndoPointMarker undo )
final UndoPointMarker undo,
final double minRadius )
{
final EditBehaviours< V, E > eb = new EditBehaviours<>( overlayGraph, renderer, selection, focus, undo, NORMAL_RADIUS_CHANGE, ABIT_RADIUS_CHANGE, ALOT_RADIUS_CHANGE );
final EditBehaviours< V, E > eb = new EditBehaviours<>( overlayGraph, renderer, selection, focus, undo, NORMAL_RADIUS_CHANGE, ABIT_RADIUS_CHANGE, ALOT_RADIUS_CHANGE, minRadius );

behaviours.namedBehaviour( eb.moveSpotBehaviour, MOVE_SPOT_KEYS );
behaviours.namedBehaviour( eb.addSpotBehaviour, ADD_SPOT_KEYS );
Expand Down Expand Up @@ -183,7 +181,8 @@ private EditBehaviours(
final UndoPointMarker undo,
final double normalRadiusChange,
final double aBitRadiusChange,
final double aLotRadiusChange )
final double aLotRadiusChange,
final double minRadius )
{
this.overlayGraph = overlayGraph;
this.lock = overlayGraph.getLock();
Expand All @@ -194,12 +193,12 @@ private EditBehaviours(

moveSpotBehaviour = new MoveSpotBehaviour( MOVE_SPOT );
addSpotBehaviour = new AddSpotBehaviour( ADD_SPOT );
increaseSpotRadiusBehaviour = new ResizeSpotBehaviour( INCREASE_SPOT_RADIUS, normalRadiusChange );
increaseSpotRadiusBehaviourALot = new ResizeSpotBehaviour( INCREASE_SPOT_RADIUS_ALOT, aLotRadiusChange );
increaseSpotRadiusBehaviourABit = new ResizeSpotBehaviour( INCREASE_SPOT_RADIUS_ABIT, aBitRadiusChange );
decreaseSpotRadiusBehaviour = new ResizeSpotBehaviour( DECREASE_SPOT_RADIUS, -normalRadiusChange / ( 1 + normalRadiusChange ) );
decreaseSpotRadiusBehaviourALot = new ResizeSpotBehaviour( DECREASE_SPOT_RADIUS_ALOT, -aLotRadiusChange / ( 1 + aLotRadiusChange ) );
decreaseSpotRadiusBehaviourABit = new ResizeSpotBehaviour( DECREASE_SPOT_RADIUS_ABIT, -aBitRadiusChange / ( 1 + aBitRadiusChange ) );
increaseSpotRadiusBehaviour = new ResizeSpotBehaviour( INCREASE_SPOT_RADIUS, normalRadiusChange, minRadius );
increaseSpotRadiusBehaviourALot = new ResizeSpotBehaviour( INCREASE_SPOT_RADIUS_ALOT, aLotRadiusChange, minRadius );
increaseSpotRadiusBehaviourABit = new ResizeSpotBehaviour( INCREASE_SPOT_RADIUS_ABIT, aBitRadiusChange, minRadius );
decreaseSpotRadiusBehaviour = new ResizeSpotBehaviour( DECREASE_SPOT_RADIUS, -normalRadiusChange / ( 1 + normalRadiusChange ), minRadius );
decreaseSpotRadiusBehaviourALot = new ResizeSpotBehaviour( DECREASE_SPOT_RADIUS_ALOT, -aLotRadiusChange / ( 1 + aLotRadiusChange ), minRadius );
decreaseSpotRadiusBehaviourABit = new ResizeSpotBehaviour( DECREASE_SPOT_RADIUS_ABIT, -aBitRadiusChange / ( 1 + aBitRadiusChange ), minRadius );
}

private class AddSpotBehaviour extends AbstractNamedBehaviour implements ClickBehaviour
Expand Down Expand Up @@ -339,10 +338,13 @@ private class ResizeSpotBehaviour extends AbstractNamedBehaviour implements Clic

private final JamaEigenvalueDecomposition eig;

public ResizeSpotBehaviour( final String name, final double factor )
private final double minRadius;

public ResizeSpotBehaviour( final String name, final double factor, final double minRadius )
{
super( name );
this.factor = factor;
this.minRadius = minRadius;
mat = new double[ 3 ][ 3 ];
eig = new JamaEigenvalueDecomposition( 3 );
}
Expand All @@ -365,11 +367,14 @@ public void click( final int x, final int y )
eig.decomposeSymmetric( mat );
final double[] eigVals = eig.getRealEigenvalues();
for ( final double eigVal : eigVals )
if ( eigVal < MIN_RADIUS )
{
final double r = Math.sqrt( eigVal );
if ( r < minRadius )
return;
}

vertex.setCovariance( mat );
lastRadius = Math.max( MIN_RADIUS, Math.sqrt( vertex.getBoundingSphereRadiusSquared() ) );
lastRadius = Math.max( minRadius, Math.sqrt( vertex.getBoundingSphereRadiusSquared() ) );
overlayGraph.notifyGraphChanged();
undo.setUndoPoint();

Expand Down