From 61bd94810ba92a5892c5064b077f5672cd6fe8c8 Mon Sep 17 00:00:00 2001 From: Christian Tischer Date: Tue, 31 Oct 2023 18:47:17 +0100 Subject: [PATCH] Add method to ManualTransformationEditor to transform a custom set of sources --- .../ManualTransformationEditor.java | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/src/main/java/bdv/tools/transformation/ManualTransformationEditor.java b/src/main/java/bdv/tools/transformation/ManualTransformationEditor.java index 97480cc9..7b0aa1ce 100644 --- a/src/main/java/bdv/tools/transformation/ManualTransformationEditor.java +++ b/src/main/java/bdv/tools/transformation/ManualTransformationEditor.java @@ -30,6 +30,7 @@ import java.awt.event.KeyEvent; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.function.Consumer; @@ -76,6 +77,8 @@ public class ManualTransformationEditor implements TransformListener< AffineTran private final Consumer< String > viewerMessageDisplay; + private Collection< SourceAndConverter< ? > > customSources; + public ManualTransformationEditor( final AbstractViewerPanel viewer, final InputActionBindings inputActionBindings ) { this( viewer.transformListeners(), viewer.state(), viewer::showMessage, inputActionBindings ); @@ -154,6 +157,12 @@ public synchronized void reset() } } + public synchronized void transform( Collection< SourceAndConverter< ? > > customSources ) + { + this.customSources = customSources; + setActive( true ); + } + public synchronized void setActive( final boolean a ) { if ( this.active == a ) @@ -163,18 +172,25 @@ public synchronized void setActive( final boolean a ) { // Enter manual edit mode final ViewerState state = this.viewerState.snapshot(); - final List< SourceAndConverter< ? > > currentSources = new ArrayList<>(); - switch ( state.getDisplayMode() ) + final List< SourceAndConverter< ? > > transformableSources = new ArrayList<>(); + if ( customSources != null ) { - case FUSED: - currentSources.add( state.getCurrentSource() ); - break; - case FUSEDGROUP: - currentSources.addAll( state.getSourcesInGroup( state.getCurrentGroup() ) ); - break; - default: - viewerMessageDisplay.accept( "Can only do manual transformation when in FUSED mode." ); - return; + transformableSources.addAll( customSources ); + } + else + { + switch ( state.getDisplayMode() ) + { + case FUSED: + transformableSources.add( state.getCurrentSource() ); + break; + case FUSEDGROUP: + transformableSources.addAll( state.getSourcesInGroup( state.getCurrentGroup() ) ); + break; + default: + viewerMessageDisplay.accept( "Can only do manual transformation when in FUSED mode." ); + return; + } } state.getViewerTransform( frozenTransform ); sourcesToModify.clear(); @@ -183,7 +199,7 @@ public synchronized void setActive( final boolean a ) { if ( source.getSpimSource() instanceof TransformedSource ) { - if ( currentSources.contains( source ) ) + if ( transformableSources.contains( source ) ) sourcesToModify.add( ( TransformedSource< ? > ) source.getSpimSource() ); else sourcesToFix.add( ( TransformedSource< ? > ) source.getSpimSource() ); @@ -198,6 +214,7 @@ public synchronized void setActive( final boolean a ) { // Exit manual edit mode. active = false; + customSources = null; viewerTransformListeners.remove( this ); bindings.removeInputMap( "manual transform" ); final AffineTransform3D tmp = new AffineTransform3D();