Re: Possible bugs within RoiListener and Roi

Posted by Michael Schmid on
URL: http://imagej.273.s1.nabble.com/Possible-bugs-within-RoiListener-and-Roi-tp5022556p5022562.html

Hi Philippe,

both the ImagePlus.addImageListener as well as the Roi.addRoiListener
methods are static, which means that they are not related to a specific
image or ROI, but you will get the events for *all* images (and *all* rois).

If you call one of these add... methods multiple times, you will also
get the events multiple times.

I did not try, but I guess that if a ROI gets deleted, you should get a
roiModified call with id=DELETED and a non-null ROI (the one that got
deleted).
In any case, I think that the easiest way of writing a roiModified
method would be to retrieve the corresponding ImagePlus with
roi.getImage() and then, if that image is relevant for the current code,
use imp.getRoi() to retrieve the current Roi of that image.
Beware that the return value of roi.getImage() may be null.

Michael
________________________________________________________________
On 21.10.19 16:39, CARL Philippe (LBP) wrote:

> Dear all,
>
> I have a plugin where I want to associate a RoiListener to two given ImagePlus within a plugin (having at least 4 ImagePlus).
> In the case I write .addRoiListener(this); to the 2 ImagePlus I want to listen, I get then always 2 "detections" within the public void roiModified method.
> As if I associate the .addRoiListener(this); to only one picture, I get then 1 "detection" within the public void roiModified method and this on both pictures (i.e. even the one on which I didn't add a RoiListener).
> So is this behavior expected and thus am I doing something wrong or is it a bug?
>
> Besides this let's say a user defines a rectangular ROI within one of these 2 ImagePlus and then clicks next to the already created ROI which then deletes the previously defined Roi.
> I would then expect that if you use the method .getRoi() on this ImagePlus, the result will be null, but in fact the method returns a Roi which (when using the method .getBounds()) has the same origin than the previous one but a width and height equal to 0.
> Is this as well expected or a bug?
>
> I thank you very much for your lighting on this.
>
> My best regards,
>
> Philippe
>
>
>
> Philippe CARL
> Laboratoire de Bioimagerie et Pathologies
> UMR 7021 CNRS - Université de Strasbourg
> Faculté de Pharmacie
> 74 route du Rhin
> 67401 ILLKIRCH
> Tel : +33(0)3 68 85 41 84
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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