Re: Possible bugs within RoiListener and Roi

Posted by CARL Philippe (LBP) on
URL: http://imagej.273.s1.nabble.com/Possible-bugs-within-RoiListener-and-Roi-tp5022556p5022565.html

Hi Michael,
How are you doing?
I thank you very much for your very detailled explanations.
Actually with the roiListenner method I'm using is the following method:
public void roiModified(ImagePlus imp, int id)
which already gives me a handle to the given ImagePlus.
But I completely missed the fact that the Roi.addRoiListenner was a static method and thus I wrongly thought that I needed to activate it for each ImagePlus I want to listen.
Thus for each detected Roi event I got 2 outputs within the method which is obvious now that I got your explanations.
The answer of Wayne already linked me to my mistake but your answer gave me even further explanations on this.
Very obviously my knowledge of the listenner classes is still perfectible!!!
Also, if you don't mind I would have another listenner issue where you could help me.
I added a MouseListener to a picture canvas and look what is hapenning within the following method:
public void mouseClicked(MouseEvent evt)
But I would like to push things even further, i.e. know whether a given detected click has been done inside a ROI of a given picture in which case I do something and if not I just do nothing.
Thus, how can I get a handle to know whether this click has been detected within a given picture (and then use a getRoi() method) and if this is the case which picture?
I thank you very much in advance for your lighting on this.
Kindest 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

----- Mail original -----
De: "Michael Schmid" <[hidden email]>
À: "imagej" <[hidden email]>
Envoyé: Mardi 22 Octobre 2019 11:02:00
Objet: Re: Possible bugs within RoiListener and Roi

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

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