Re: Synchronize windows at different z levels?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: Synchronize windows at different z levels?

Brian Sloan
FWIW, here is my own solution. The Sync windows plugin was much more sophisticated than I needed, so it was easier to write a new plugin from scratch. Borrowing heavily from the great documentation (thanks!!) it was fairly trivial to write - I have done it in Python. This plugin simply adds a key listener to all open canvases and then waits for page up/page down (or Num Pad 4,6) to step through all open image stacks. This has the advantage that individual images can still be scrolled with the mouse wheel to fine-tune registration. The scrolling stops as soon as at least one image has reached the top or bottom of its stack.

Of course you can have the same image open in several windows, but with (say) different filters  or LUTs applied, which is also useful

If a new window is opened after the plugin has run, it will also be controlled by page up/down, but will not have a listener attached to it (ie will not drive synchronised scrolling if the new window has focus). This behaviour suits me fine, but you could easily check that all open windows had the keyboard listener active after each step up or down.

Regards
Brian


from java.awt.event import KeyEvent, KeyAdapter
 
def scrollAllWindows(imp, keyEvent):
        #Check if numberpad 4 or page up keys pressed
        if (keyEvent.getKeyCode() == 100 or keyEvent.getKeyCode() == 33):
                #check if any of the open image stacks are at their maximum slice
                limit = 0
                for imp2 in map(WindowManager.getImage, WindowManager.getIDList()):
                        if (imp2.getSlice() == imp2.stackSize ):
                                limit+=1
                #only scroll down if no image stacks at their highest slice already
                if (limit == 0):
                        for imp2 in map(WindowManager.getImage, WindowManager.getIDList()):
                                imp2.setSlice(imp2.getSlice()+1)
        #Check if numberpad 6 or page down keys pressed
        elif (keyEvent.getKeyCode() == 102 or keyEvent.getKeyCode() == 34):
                #check if any of the open image stacks are at their minimum slice
                limit = 0
                for imp2 in map(WindowManager.getImage, WindowManager.getIDList()):
                        if (imp2.getSlice() == 1 ):
                                limit+=1
                #only scroll down if no image stacks at their lowest slice already
                if (limit == 0):
                        for imp2 in map(WindowManager.getImage, WindowManager.getIDList()):
                                imp2.setSlice(imp2.getSlice()-1)
        # Prevent further propagation of the key event:
        keyEvent.consume()
 
class ListenToKey(KeyAdapter):
        def keyPressed(this, event):
                imp = event.getSource().getImage()
                scrollAllWindows(imp, event)
 
listener = ListenToKey()
 
for imp in map(WindowManager.getImage, WindowManager.getIDList()):
        win = imp.getWindow()
        if win is None:
                continue
        canvas = win.getCanvas()
        # Remove existing key listeners
        kls = canvas.getKeyListeners()
        map(canvas.removeKeyListener, kls)
        # Add our key listener
        canvas.addKeyListener(listener)
        # Optionally re-add existing key listeners
        map(canvas.addKeyListener, kls)

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html