Skip to content

Commit

Permalink
fix: warp vis menu options
Browse files Browse the repository at this point in the history
  • Loading branch information
bogovicj committed Oct 30, 2023
1 parent 797c515 commit e0716b3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 68 deletions.
76 changes: 39 additions & 37 deletions src/main/java/bigwarp/BigWarp.java
Original file line number Diff line number Diff line change
Expand Up @@ -2409,8 +2409,9 @@ private static < T > WarpMagnitudeSource addWarpMagnitudeSource( final BigWarpDa
return magSource;
}

private static < T > GridSource addGridSource( final int ndims, final BigWarpData< T > data, final String name )
private static < T > GridSource addGridSource( final int ndims, final BigWarpData< T > data, final String name, boolean isTransformed )
{
// this does not set the transformation
// TODO think about whether its worth it to pass a type parameter.
final GridSource gridSource = new GridSource<>( name, data, new FloatType(), null );
gridSource.setMethod( GridSource.GRID_TYPE.LINE );
Expand All @@ -2420,6 +2421,10 @@ private static < T > GridSource addGridSource( final int ndims, final BigWarpDat
BigWarpInit.add( data, infos );
wrapMovingSources( ndims, data, GRID_SOURCE_ID );

// the source is transformed
final SourceAndConverter<?> sourceAndConverter = data.sourceInfos.get(GRID_SOURCE_ID).getSourceAndConverter();
( ( WarpedSource< ? > ) sourceAndConverter.getSpimSource() ).setIsTransformed( isTransformed );

return gridSource;
}

Expand Down Expand Up @@ -2772,29 +2777,20 @@ public enum WarpVisType
NONE, WARPMAG, JACDET, GRID
}

@Deprecated
public void setWarpVisMode( final WarpVisType type, BigWarpViewerFrame viewerFrame, final boolean both )
{
if ( viewerFrame == null )
{
if ( viewerFrameP.isActive() )
{
viewerFrame = viewerFrameP;
}
else if ( viewerFrameQ.isActive() )
{
viewerFrame = viewerFrameQ;
}
else if ( both )
{
setWarpVisMode( type, viewerFrameP, false );
setWarpVisMode( type, viewerFrameQ, false );
return;
}
else
{
return;
}
}
setWarpVisMode( type );
}

protected void setWarpVisMode( final WarpVisType type )
{
// TODO replace the above with this method
BigWarpViewerFrame viewerFrame ;
if ( viewerFrameP.isActive() )
viewerFrame = viewerFrameP;
else
viewerFrame = viewerFrameQ;

if ( currentTransform == null )
{
Expand Down Expand Up @@ -2845,7 +2841,8 @@ else if ( both )
// turn grid vis on
if ( gridSource == null )
{
gridSource = addGridSource( ndims, data, "Transform grid" );
gridSource = addGridSource( ndims, data, "Transform grid", isMovingDisplayTransformed() );
setTransform( data.sourceInfos.get(GRID_SOURCE_ID), currentTransform );
synchronizeSources();
data.getConverterSetup( GRID_SOURCE_ID ).setDisplayRange( 0, 512 );
}
Expand Down Expand Up @@ -2972,22 +2969,27 @@ private void setTransformationMovingSourceOnly( final InvertibleRealTransform tr
{
this.currentTransform = transform;
data.sourceInfos.values().forEach( sourceInfo -> {
if ( sourceInfo.isMoving() )
{
// the xfm must always be 3d for bdv to be happy.
// when bigwarp has 2d images though, the z- component will be left unchanged
// InverseRealTransform xfm = new InverseRealTransform( new TpsTransformWrapper( 3, transform ));

// the updateTransform method creates a copy of the transform
final SourceAndConverter< ? > sac = sourceInfo.getSourceAndConverter();
final WarpedSource< ? > wsrc = ( WarpedSource< ? > ) sac.getSpimSource();
wsrc.updateTransform( transform );
if ( sac.asVolatile() != null )
( ( WarpedSource< ? > ) sourceInfo.getSourceAndConverter().asVolatile().getSpimSource() ).updateTransform( transform );
}
setTransform( sourceInfo, transform );
} );
}

private void setTransform( final SourceInfo sourceInfo, final InvertibleRealTransform transform )
{
if ( sourceInfo.isMoving() )
{
// the xfm must always be 3d for bdv to be happy.
// when bigwarp has 2d images though, the z- component will be left unchanged
// InverseRealTransform xfm = new InverseRealTransform( new TpsTransformWrapper( 3, transform ));

// the updateTransform method creates a copy of the transform
final SourceAndConverter< ? > sac = sourceInfo.getSourceAndConverter();
final WarpedSource< ? > wsrc = ( WarpedSource< ? > ) sac.getSpimSource();
wsrc.updateTransform( transform );
if ( sac.asVolatile() != null )
( ( WarpedSource< ? > ) sourceInfo.getSourceAndConverter().asVolatile().getSpimSource() ).updateTransform( transform );
}
}

public void updateSourceBoundingBoxEstimators()
{
data.sourceInfos.values().forEach( sourceInfo -> {
Expand Down Expand Up @@ -4251,7 +4253,7 @@ private void addInternalSource(int id) {
switch ( id )
{
case GRID_SOURCE_ID:
gridSource = addGridSource( ndims, data, "GridSource" );
gridSource = addGridSource( ndims, data, "GridSource", isMovingDisplayTransformed());
setGridType( GridSource.GRID_TYPE.LINE );
break;
case WARPMAG_SOURCE_ID:
Expand Down
43 changes: 22 additions & 21 deletions src/main/java/bigwarp/BigWarpActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ public static void installViewerActions(
actions.namedAction( new ToggleDialogAction( SHOW_WARPTYPE_DIALOG, bw.warpVisDialog ), SHOW_WARPTYPE_DIALOG_KEYS );
actions.namedAction( new ToggleDialogAction( PREFERENCES_DIALOG, bw.preferencesDialog ), PREFERENCES_DIALOG_KEYS );

// warp vis options
for( final BigWarp.WarpVisType t: BigWarp.WarpVisType.values())
actions.namedAction( new SetWarpVisTypeAction( t, bw ), NOT_MAPPED );

// landmarks unbound
actions.runnableAction( () -> { bw.getLandmarkPanel().getJTable().selectAll(); }, LANDMARK_SELECT_ALL, NOT_MAPPED );
actions.runnableAction( () -> { bw.getLandmarkPanel().getJTable().clearSelection(); }, LANDMARK_DESELECT_ALL, NOT_MAPPED );
Expand Down Expand Up @@ -559,6 +563,10 @@ public static void installTableActions(
actions.namedAction( new ToggleDialogAction( SHOW_WARPTYPE_DIALOG, bw.warpVisDialog ), SHOW_WARPTYPE_DIALOG_KEYS );
actions.namedAction( new ToggleDialogAction( PREFERENCES_DIALOG, bw.preferencesDialog ), PREFERENCES_DIALOG_KEYS );

// warp vis options
for( final BigWarp.WarpVisType t: BigWarp.WarpVisType.values())
actions.namedAction( new SetWarpVisTypeAction( t, bw ), NOT_MAPPED );

// landmarks
actions.runnableAction( () -> { bw.getLandmarkPanel().getJTable().selectAll(); }, LANDMARK_SELECT_ALL, LANDMARK_SELECT_ALL_KEYS );
actions.runnableAction( () -> { bw.getLandmarkPanel().getJTable().clearSelection(); }, LANDMARK_DESELECT_ALL, LANDMARK_DESELECT_ALL_KEYS );
Expand Down Expand Up @@ -653,12 +661,10 @@ public static InputMap createInputMapViewer( final KeyStrokeAdder.Factory keyPro
map.put( JUMP_TO_PREV_POINT, "ctrl shift D" );
map.put( JUMP_TO_NEAREST_POINT, "E" );

map.put( EXPORT_IMAGE, "ctrl E" );
map.put( EXPORT_WARP, "ctrl W" );
map.put( EXPORT_AFFINE, "ctrl A" );

map.put( EXPORT_IMAGE, "F6" );


map.put( GO_TO_BOOKMARK, "B" );
map.put( GO_TO_BOOKMARK_ROTATION, "O" );
map.put( SET_BOOKMARK, "shift B" );
Expand All @@ -677,8 +683,6 @@ public static ActionMap createActionMapViewer( final BigWarp< ? > bw )
for( final BigWarp.WarpVisType t: BigWarp.WarpVisType.values())
{
new SetWarpVisTypeAction( t, bw ).put( actionMap );
new SetWarpVisTypeAction( t, bw, bw.getViewerFrameP() ).put( actionMap );
new SetWarpVisTypeAction( t, bw, bw.getViewerFrameQ() ).put( actionMap );
}

new ResetActiveViewerAction( bw ).put( actionMap );
Expand Down Expand Up @@ -1238,39 +1242,36 @@ public static class SetWarpVisTypeAction extends AbstractNamedAction
private static final long serialVersionUID = 7370813069619338918L;

private BigWarp< ? > bw;
private BigWarpViewerFrame p;
private BigWarp.WarpVisType type;

public SetWarpVisTypeAction( final BigWarp.WarpVisType type, final BigWarp< ? > bw )
{
this( type, bw, null );
super( getName( type ));
this.bw = bw;
this.type = type;
}

@Deprecated
public SetWarpVisTypeAction( final BigWarp.WarpVisType type, final BigWarp< ? > bw, BigWarpViewerFrame p )
{
super( getName( type, p ));
this.bw = bw;
this.p = p;
this.type = type;
this( type, bw );
}

@Override
public void actionPerformed( ActionEvent e )
{
if( p == null )
bw.setWarpVisMode( type, p, true );
else
bw.setWarpVisMode( type, p, false );
bw.setWarpVisMode( type );
}

@Deprecated
public static String getName( final BigWarp.WarpVisType type, BigWarpViewerFrame p )
{
if( p == null )
return String.format( SET_WARPTYPE_VIS, type.name() );
else if( p.isMoving() )
return String.format( SET_WARPTYPE_VIS_P, type.name() );
else
return String.format( SET_WARPTYPE_VIS_Q, type.name() );
return getName( type );
}

protected static String getName( final BigWarp.WarpVisType type )
{
return String.format( SET_WARPTYPE_VIS, type.name() );
}
}

Expand Down
26 changes: 16 additions & 10 deletions src/main/java/bigwarp/WarpVisFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ public void stateChanged( ChangeEvent e )
public void setActions()
{
final ActionMap actionMap = bw.getViewerFrameP().getKeybindings().getConcatenatedActionMap();

landmarkColorButton.addActionListener( new ActionListener()
{
@Override
Expand Down Expand Up @@ -478,18 +477,25 @@ public void stateChanged( ChangeEvent e )
warpMagSimilarityButton.setText("Similarity");
warpMagRigidButton.setText("Rigid");

warpGridLineButton.setAction(
actionMap.get( String.format( BigWarpActions.WARPVISGRID, GridSource.GRID_TYPE.LINE )));
warpGridModButton.setAction(
actionMap.get( String.format( BigWarpActions.WARPVISGRID, GridSource.GRID_TYPE.MOD )));
warpGridLineButton.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if( warpGridLineButton.isSelected() )
WarpVisFrame.this.bw.setWarpVisGridType( GridSource.GRID_TYPE.LINE );
}
});

warpGridModButton.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if( warpGridModButton.isSelected() )
WarpVisFrame.this.bw.setWarpVisGridType( GridSource.GRID_TYPE.MOD );
}

});

warpGridLineButton.setText( "Line" );
warpGridModButton.setText( "Modulo" );

// turn on the default values
// setWarpVisOffButton.doClick();
// warpMagAffineButton.doClick();
// warpGridLineButton.doClick();
}

public void addListeners()
Expand Down

0 comments on commit e0716b3

Please sign in to comment.