Login  Register

Re: Create pre-defined ROI on mouse click and add to ROI manager

Posted by Olivier Burri on Jun 19, 2014; 9:05am
URL: http://imagej.273.s1.nabble.com/Create-pre-defined-ROI-on-mouse-click-and-add-to-ROI-manager-tp5008292p5008310.html

Hi all,

Like Voklo I had used this approach before, but like he mentions, this can still lead to problems.

I'm using this strategy now:
When you press the left button. Register that the button has been pressed but draw the ROI only when it is released.

Here is the new code. I also added the option "DisablePopupMenu" so that right clicking while in your macro does not cause the contextual menu to popup.

Best

Oli

macro CircleOn_MouseClick{
        setOption("DisablePopupMenu", true);
        getPixelSize(unit, pixelWidth, pixelHeight);
        setTool("rectangle");
        leftButton=16;
        rightButton=4;
        radius = 100;
        Dialog.create("Settings");
        Dialog.addNumber("Set radius of circle", radius);
        Dialog.show();
        radius = Dialog.getNumber();
        height = 2*pixelHeight*radius;
        width = 2*pixelWidth*radius;
        x2=-1; y2=-1; z2=-1; flags2=-1;
        getCursorLoc(x, y, z, flags);
        wasLeftPressed = false;
        while (flags&rightButton==0){
                getCursorLoc(x, y, z, flags);
               
                if (flags&leftButton!=0) {
                // Wait for it to be released
                wasLeftPressed = true;
                } else if (wasLeftPressed) {
                wasLeftPressed = false;
                if (x!=x2 || y!=y2 || z!=z2 || flags!=flags2) {
                                x = x - width/2;
                                y = y - height/2;
                                makeOval(x, y, width, height);
                                roiManager("Add");
                                 
                        }
                }
      }
      setOption("DisablePopupMenu", false);
}

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