Login  Register

Re: eval("script", "roi.contains(x, y);");

Posted by jmutterer on Apr 05, 2010; 9:28pm
URL: http://imagej.273.s1.nabble.com/eval-script-roi-contains-x-y-tp3688675p3688676.html

On Mon, Apr 5, 2010 at 8:36 PM, Benn, Douglas K.
<[hidden email]>wrote:

>   roi_flag     =eval("script", "roi.contains(x, y);");
>

Benn, there are several problems in your code.
First, you can not mix macro variables and javascript. Instead, you should
feed the variable's value in the js code:
eval("script", "roi.contains("+x+","+y+");");
Regarding the error you're getting, if you write roi.contains(..), roi is
supposed to be defined first from the active ROI in the active image.
roi = IJ.getImage().getRoi();
Finally, the eval('script',script) macro function does not return anything,
just executes the script, so you can not get the roi.contains() value back
in your macro.

In addition to what Gabriel already suggested to check if a point at (x,y)
is in a given ROI, you could maybe use one of the following approach:
interactively : the getCursorLoc(x,y,z,flags); macro function. In the
returned flags variable, a bit is set if the mouse was clicked inside a ROI.
see http://rsb.info.nih.gov/ij/macros//GetCursorLocDemo.txt
Non intervactively, get the active roi's mask using run("Create Mask") , and
check the mask value at position (x,y) using getPixel(x,y).

Jerome




  if (roi_flag==true) print("roi flag=Inside\n");

>   else print("roi flag=Outside\n");
>
> I get this output in my Log.
>
> ReferenceError: "roi" is not defined. (<Unknown source>#1) in <Unknown
> source> at line number 1
>
> Although it references line number 1 it is not line number 1 of my
> program.What am I doing wrong?
>
> Thanks.
>
> Douglas
> Dr Douglas K Benn, BDS, M.Phil., Ph.D., Dipl. Dental Radiology (Royal
> College of Radiologists, England).
> Professor
> Dept of General Dentistry
> Creighton University Dental School
> 2500 California Plaza
> Omaha
> Nebraska 68178
>
> Tel: (402)280 5025
> Fax: (402)280 5094
>