Created
January 15, 2016 15:56
-
-
Save tpietzsch/a2066fb2ee7b868b98a5 to your computer and use it in GitHub Desktop.
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
package bdv.examples.boundingbox; | |
import java.awt.BorderLayout; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.WindowEvent; | |
import javax.swing.AbstractAction; | |
import javax.swing.ActionMap; | |
import javax.swing.InputMap; | |
import javax.swing.JButton; | |
import javax.swing.SwingUtilities; | |
import mpicbg.spim.data.SpimDataException; | |
import net.imglib2.Interval; | |
import net.imglib2.util.Intervals; | |
import bdv.BigDataViewer; | |
import bdv.tools.ToggleDialogAction; | |
import bdv.tools.boundingbox.BoundingBoxDialog; | |
import bdv.tools.brightness.SetupAssignments; | |
import bdv.util.AbstractNamedAction.NamedActionAdder; | |
import bdv.util.KeyProperties; | |
import bdv.util.KeyProperties.KeyStrokeAdder; | |
import bdv.viewer.DisplayMode; | |
import bdv.viewer.NavigationActions; | |
import bdv.viewer.ViewerFrame; | |
import bdv.viewer.ViewerPanel; | |
public class BdvBoundingBoxExample | |
{ | |
protected BdvBoundingBoxExample( final String xmlFilename ) throws SpimDataException | |
{ | |
final BigDataViewer bdv = new BigDataViewer( xmlFilename, "box", null ); | |
final ViewerFrame viewerFrame = bdv.getViewerFrame(); | |
final ViewerPanel viewer = bdv.getViewer(); | |
final SetupAssignments setupAssignments = bdv.getSetupAssignments(); | |
// =============== the bounding box dialog ================== | |
final int boxSetupId = 9999; // some non-existing setup id | |
final Interval initialInterval = Intervals.createMinMax( 500, 100, -100, 1500, 800, 300 ); // the initially selected bounding box | |
final Interval rangeInterval = Intervals.createMinMax( -500, -500, -500, 3000, 3000, 1000 ); // the range (bounding box of possible bounding boxes) | |
final BoundingBoxDialog boundingBoxDialog = new BoundingBoxDialog( viewerFrame, "bounding box", viewer, setupAssignments, boxSetupId, initialInterval, rangeInterval ) | |
{ | |
@Override | |
public void createContent() | |
{ | |
// button prints the bounding box interval | |
final JButton button = new JButton( "ok" ); | |
button.addActionListener( new AbstractAction() | |
{ | |
private static final long serialVersionUID = 1L; | |
@Override | |
public void actionPerformed( final ActionEvent e ) | |
{ | |
System.out.println( "bounding box:" + net.imglib2.util.Util.printInterval( boxRealRandomAccessible.getInterval() ) ); | |
} | |
} ); | |
getContentPane().add( boxSelectionPanel, BorderLayout.NORTH ); | |
getContentPane().add( button, BorderLayout.SOUTH ); | |
pack(); | |
} | |
private static final long serialVersionUID = 1L; | |
}; | |
// =============== install shortcut B for boundingbox dialogs ================== | |
final KeyProperties keyProperties = KeyProperties.readPropertyFile(); | |
NavigationActions.installActionBindings( viewerFrame.getKeybindings(), viewer, keyProperties ); | |
final String BOUNDING_BOX_DIALOG = "bounding box"; | |
final ActionMap actionMap = new ActionMap(); | |
final NamedActionAdder amap = new NamedActionAdder( actionMap ); | |
amap.put( new ToggleDialogAction( BOUNDING_BOX_DIALOG, boundingBoxDialog ) ); | |
final InputMap inputMap = new InputMap(); | |
final KeyStrokeAdder imap = new KeyProperties( null ).adder( inputMap ); | |
imap.put( BOUNDING_BOX_DIALOG, "B" ); | |
viewerFrame.getKeybindings().addActionMap( "bdvbox", actionMap ); | |
viewerFrame.getKeybindings().addInputMap( "bdvbox", inputMap ); | |
// =============== go to fused mode (overlay all sources) such that bounding box will be visible ================== | |
viewer.setDisplayMode( DisplayMode.FUSED ); | |
} | |
public static void disposeViewerWindow( final BigDataViewer bdv ) | |
{ | |
try | |
{ | |
SwingUtilities.invokeAndWait( new Runnable() | |
{ | |
@Override | |
public void run() | |
{ | |
final ViewerFrame frame = bdv.getViewerFrame(); | |
final WindowEvent windowClosing = new WindowEvent( frame, WindowEvent.WINDOW_CLOSING ); | |
frame.dispatchEvent( windowClosing ); | |
} | |
} ); | |
} | |
catch ( final Exception e ) | |
{} | |
} | |
public static void main( final String[] args ) | |
{ | |
final String fn = "/Users/Pietzsch/Desktop/bdv example/drosophila 2.xml"; | |
try | |
{ | |
System.setProperty("apple.laf.useScreenMenuBar", "true"); | |
new BdvBoundingBoxExample( fn ); | |
} | |
catch ( final Exception e ) | |
{ | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment