Skip to content

Commit

Permalink
perf: improve MaskedSourceEditorMouseListener behavior
Browse files Browse the repository at this point in the history
* can edit center of rotation for imported transform
* some cleanup
* oops, missing imports in BigWarpInitDialog
  • Loading branch information
bogovicj committed Nov 15, 2024
1 parent 7d1d832 commit 51de248
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 45 deletions.
3 changes: 2 additions & 1 deletion src/main/java/bdv/gui/BigWarpInitDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public class BigWarpInitDialog extends JFrame
private BigWarpSourceTableModel sourceTableModel;
private JComboBox<String> imagePlusDropdown;
private JButton addImageButton, addPathButton, addTransformButton;
private DatasetSelectorDialog selectionDialog, transformSelectionDialog;
private DatasetSelectorDialog selectionDialog;
private TransformSelectorDialog transformSelectionDialog;

private String lastOpenedContainer = "";
private String lastBrowsePath = null;
Expand Down
106 changes: 80 additions & 26 deletions src/main/java/bdv/gui/MaskedSourceEditorMouseListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
import bigwarp.BigWarp;
import bigwarp.source.PlateauSphericalMaskRealRandomAccessible;
import bigwarp.transforms.AbstractTransformSolver;
import bigwarp.transforms.BigWarpTransform;
import bigwarp.transforms.MaskedSimRotTransformSolver;
import net.imglib2.RealPoint;
import net.imglib2.realtransform.AffineTransform3D;

public class MaskedSourceEditorMouseListener implements MouseListener, MouseMotionListener, MouseWheelListener
{
private static final String MASK_NONE_MSG = "No mask to edit.";

protected PlateauSphericalMaskRealRandomAccessible mask;
protected BigWarpViewerPanel viewer;
protected List<BigWarpMaskSphereOverlay> overlays;
Expand All @@ -33,6 +36,8 @@ public class MaskedSourceEditorMouseListener implements MouseListener, MouseMoti

private BigWarp<?> bw;

private MaskedSimRotTransformSolver<?> solver;

private static final double fastSpeed = 10.0;
private static final double slowSpeed = 0.1;

Expand All @@ -57,15 +62,34 @@ public MaskedSourceEditorMouseListener( int nd, BigWarp<?> bw, BigWarpViewerPane

public void setActive( boolean active )
{

final String maskInterpType = bw.getBwTransform().getMaskInterpolationType();
if( active && maskInterpType.equals( BigWarpTransform.NO_MASK_INTERP))
{
bw.getViewerFrameP().getViewerPanel().showMessage( MASK_NONE_MSG );
bw.getViewerFrameQ().getViewerPanel().showMessage( MASK_NONE_MSG );
mask = null;
return;
}

this.active = active;
updateMask();
bw.getViewerFrameP().setTransformEnabled( !active );
bw.getViewerFrameQ().setTransformEnabled( !active );

updateSolver();

final String msg = active ? "Mask Edit On" : "Mask Edit Off";
bw.getViewerFrameP().getViewerPanel().showMessage( msg );
bw.getViewerFrameQ().getViewerPanel().showMessage( msg );
}

private void updateMask() {

setMask(bw.getTransformPlateauMaskSource().getRandomAccessible());
}


public void toggleActive( )
{
setActive( !active );
Expand Down Expand Up @@ -111,8 +135,10 @@ public void mouseDragged( MouseEvent e )
// store starting center at start of drag
if( !dragged )
{
// c.setPosition( mask.getCenter() );
mask.getCenter().localize( c );
if( mask != null ) {
storeMaskCenter();
}

viewer.getGlobalMouseCoordinates( pressPt );
dragged = true;
}
Expand All @@ -122,20 +148,18 @@ public void mouseDragged( MouseEvent e )

if( e.isControlDown() )
{
mask.getCenter().localize( c );
final double d = PlateauSphericalMaskRealRandomAccessible.squaredDistance( p, c );
synchronized ( mask )
{
mask.setSquaredRadius( d );
if( mask != null ) {
storeMaskCenter();
final double r2 = PlateauSphericalMaskRealRandomAccessible.squaredDistance( p, c );
updateMaskSquaredRadius(r2);
}
}
else if( e.isShiftDown() )
{
mask.getCenter().localize( c );
final double d = Math.sqrt( PlateauSphericalMaskRealRandomAccessible.squaredDistance( p, c ));
synchronized ( mask )
{
mask.setSigma( d - Math.sqrt( mask.getSquaredRadius()) );
if( mask != null ) {
storeMaskCenter();
final double d = Math.sqrt( PlateauSphericalMaskRealRandomAccessible.squaredDistance( p, c ));
updateMaskSigma(d);
}
}
else
Expand All @@ -146,16 +170,8 @@ else if( e.isShiftDown() )
for( int i = 0; i < p.numDimensions(); i++ )
p.setPosition( c.getDoublePosition(i) + p.getDoublePosition(i) - pressPt.getDoublePosition(i), i);

synchronized ( mask )
{
mask.setCenter(p);
}

AbstractTransformSolver< ? > solver = bw.getBwTransform().getSolver();
if( solver instanceof MaskedSimRotTransformSolver )
{
((MaskedSimRotTransformSolver)solver).setCenter( p );
}
updateMaskCenter(p);
updateSolverCenter(p);
}

bw.getViewerFrameP().getViewerPanel().requestRepaint();
Expand All @@ -174,14 +190,14 @@ public void mouseReleased( MouseEvent e ) {
if( !dragged )
{
viewer.getGlobalMouseCoordinates( pressPt );
synchronized ( mask )
{
mask.setCenter( pressPt );
}

updateMaskCenter(pressPt);

bw.setAutoEstimateMask( false );
bw.getViewerFrameP().getViewerPanel().requestRepaint();
bw.getViewerFrameQ().getViewerPanel().requestRepaint();

updateSolverCenter(pressPt);
}
else
dragged = false;
Expand Down Expand Up @@ -209,5 +225,43 @@ else if ( e.isControlDown() )
bw.getViewerFrameQ().getViewerPanel().requestRepaint();
}

private void updateSolver() {

final AbstractTransformSolver<?> solver = bw.getBwTransform().getSolver();
if (solver instanceof MaskedSimRotTransformSolver)
this.solver = (MaskedSimRotTransformSolver<?>)solver;
}

private void updateSolverCenter(final RealPoint p) {

if (solver != null)
solver.setCenter(p);
}

private void storeMaskCenter() {

mask.getCenter().localize(c);
}

private void updateMaskCenter(final RealPoint p) {

synchronized (mask) {
mask.setCenter(p);
}
}

private void updateMaskSigma(final double d) {

synchronized (mask) {
mask.setSigma(d - Math.sqrt(mask.getSquaredRadius()));
}
}

private void updateMaskSquaredRadius(final double r2) {

synchronized (mask) {
mask.setSquaredRadius(r2);
}
}

}
4 changes: 2 additions & 2 deletions src/main/java/bdv/viewer/BigWarpLandmarkFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class BigWarpLandmarkFrame extends JFrame {

private static final long serialVersionUID = -5160678226566479257L;

private final BigWarp bw;
private final BigWarp<?> bw;

private BigWarpLandmarkPanel lmPanel;

Expand All @@ -51,7 +51,7 @@ public class BigWarpLandmarkFrame extends JFrame {

private final TriggerBehaviourBindings triggerbindings;

public BigWarpLandmarkFrame( String name, BigWarpLandmarkPanel panel, BigWarp< ? > bw, KeymapManager keymapManager )
public BigWarpLandmarkFrame( String name, BigWarpLandmarkPanel panel, BigWarp<?> bw, KeymapManager keymapManager )
{
super( name, AWTUtils.getSuitableGraphicsConfiguration( AWTUtils.RGB_COLOR_MODEL ) );
this.bw = bw;
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/bigwarp/BigWarp.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,6 @@ public class BigWarp< T >

protected MouseLandmarkTableListener landmarkTableListener;

protected MaskedSourceEditorMouseListener maskSourceMouseListenerP;

protected MaskedSourceEditorMouseListener maskSourceMouseListenerQ;

protected BigWarpMessageAnimator message;
Expand Down Expand Up @@ -2305,7 +2303,6 @@ public void setGridType( final GridSource.GRID_TYPE method )
*/
public void transformationsFromCoordinateSystem() {

System.out.println( "transformationsFromCoordinateSystem" );
final TransformGraph graph = warpVisDialog.transformGraphPanel.getGraph();
if( graph == null )
return;
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/bigwarp/landmarks/LandmarkTableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1482,11 +1482,12 @@ public void copyLandmarks( int tableIndex, double[][] movingLandmarks, double[][

public void copyLandmarks( double[][] movingLandmarks, double[][] targetLandmarks )
{
logger.trace(
String.format("copyLandmarks. nActive=%d. sizes = %d x %d ; %d x %d ", numActive,
movingLandmarks.length, movingLandmarks[0].length,
targetLandmarks.length, targetLandmarks[0].length));

synchronized(this) {
logger.trace(
String.format("copyLandmarks. nActive=%d. sizes = %d x %d ; %d x %d ", numActive,
movingLandmarks.length, movingLandmarks[0].length,
targetLandmarks.length, targetLandmarks[0].length));
int k = 0;
for ( int i = 0; i < this.numRows; i++ )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public void setCenter( RealLocalizable c )
@SuppressWarnings("rawtypes")
public WrappedIterativeInvertibleRealTransform<?> solve( final double[][] mvgPts, final double[][] tgtPts )
{
// WrappedCoordinateTransform simXfm = interpSolver.solve( mvgPts, tgtPts );
final WrappedCoordinateTransform simXfm = interpSolver.solve( tgtPts, mvgPts );

RealTransform msim;
Expand All @@ -121,9 +120,6 @@ public WrappedIterativeInvertibleRealTransform<?> solve( final double[][] mvgPts
msim = new MaskedSimilarityTransform( sim, lambda, center, interp );
}

// final double[][] xfmMvg = transformPoints( msim, mvgPts );
// final InvertibleRealTransform baseTransform = baseSolver.solve( xfmMvg, tgtPts );

final double[][] xfmTgt = transformPoints( msim, tgtPts );
final InvertibleRealTransform baseTransform = baseSolver.solve( mvgPts, xfmTgt );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public SimilarityTransformInterpolator2D( final AffineTransform2D transform, fin

double[] params = GeomUtils.scalesAngle( transformEnd );
thtDiff = params[ 2 ];
// double s = ( params[ 0 ] + params[ 1 ] ) / 2.0 ;
// sDiff = s - 1.0;

sDiff = ( params[ 0 ] + params[ 1 ] ) / 2.0 - 1.0;

// translation needed to from reconstructed to target transformation
Expand Down Expand Up @@ -95,8 +92,6 @@ public static void main( String[] args )


final SimilarityTransformInterpolator2D interp = new SimilarityTransformInterpolator2D( t, c );
//// System.out.println( interp );
// System.out.println( interp.get( 0 ) );

System.out.println( t );
System.out.println( interp.get( 1 ) );
Expand Down

0 comments on commit 51de248

Please sign in to comment.