Login  Register

Re: Segmented Line Tool

Posted by Gabriel Landini on Jan 12, 2007; 11:50am
URL: http://imagej.273.s1.nabble.com/Segmented-Line-Tool-tp3700625p3700626.html

On Thursday 11 January 2007 16:25, Christophe Leterrier wrote:
> I'm trying to replicate the Segmented Line Tool with a Macro Tool using
> getcursorLoc().

Not sure if it will help, but here is my routine to handle points in a macro.
I updated to the right click does not bring the popup menu.

Left click, selects
Right click aborts.

Connecting the collected points to create a polyline or polygon should be
easy.

Mind the line breaks introduced by the mailer.
Cheers,

Gabriel

//--------------8<----------------------
//  GetPointsDemo.txt/
//  by G. Landini, derived from GetCursorLocDemo.txt macro
//  12/1/2007
//
//  This macro demonstrates how to use the getCursorLoc() function
//  to get pixel values interactively from inside a macro.
//  Run the macro, move the cursor over the active image, then
//  press left mouse button to get the point values.
//  Press the right mouse button to end the macro.

requires("1.37r");
leftButton=16;
rightButton=4;
run("Select None");
setOption("DisablePopupMenu", true);
// get points
getCursorLoc(x, y, z, flags);

while (flags&rightButton==0)  { //until right pressed
     getCursorLoc(x, y, z, flags);
     if (flags&leftButton!=0 ){ //left pressed
          makeRectangle(x, y, 1, 1);
          p=getPixel(x,y);

          if (bitDepth()==24)
               print("x:" + x +"  y:" + y + "  R:" + p&0xff0000>>16 + "  G:" +
p&0x00ff00>>8 + "  B:" + p&0x0000ff);
          else
               print("x:" + x +"  y:" + y + "  grey:" + p);

          while (flags&leftButton!=0){  //trap until left released
               getCursorLoc(x, y, z, flags);
          }
     }
}
run("Select None");
setOption("DisablePopupMenu", false);
print("Finished");
//--------------8<----------------------