Posted by
CARL Philippe (LBP) on
Aug 29, 2020; 5:41pm
URL: http://imagej.273.s1.nabble.com/Issue-with-the-RoiManager-getSelectedIndexes-method-tp5023885p5023887.html
Dear Wayne,
I fully validate your findings in the case I try to use your proposed javascript code.
Nevertheless, I'm still able to reproduce my described issue in the case I generate a "more tricky version of it".
And in order to do this, I first launch the following code:
img = IJ.createImage("Untitled", "8-bit black", 400, 400, 1);
img.show();
rm = RoiManager.getRoiManager();
for (i = 0; i < 5; i++)
{
roi = OvalRoi.create(i * 70, i * 70, 70, 70);
rm.addRoi(roi);
}
rm.runCommand (img, "Show All with labels");
IJ.run (img, "Select None", "");
var indexesOfSelectedRoisAsArray = new Array();
for (i = 0; i < rm.getCount(); i++)
indexesOfSelectedRoisAsArray[i] = i;
rm.setSelectedIndexes(indexesOfSelectedRoisAsArray);
Then when I manually select even only one (gives the same by selecting 2, 3,...) ROI(s) within the RoiManager and launch the following (second) code:
rm = RoiManager.getRoiManager();
indexes = rm.getSelectedIndexes();
for (i = 0; i < indexes.length; i++)
print(i + " " + indexes[i]);
The data of all the ROIs within the RoiManager will be printed out.
Even pushing the "Deselect" button before launching the second code won't make the deal, but deactivating the "Labels" option will make it.
At last, this issue only happens in the case you manually select the ROIs, i.e. by using your proposed "rm.setSelectedIndexes([2,4])" the code will be working as well as it should.
I guess this may probably be a quite tricky bug, thus I thank you very much in advance for looking into it and wish you good luck!
Have a nice evening and take care,
Philippe
----- Le 29 Aoû 20, à 4:14, Wayne Rasband
[hidden email] a écrit :
> On Aug 28, 2020, at 6:56 PM, CARL Philippe (LBP) <
[hidden email]> wrote:
>
> Dear all (probably Wayne),
> In the case the Labels option is activated within the RoiManager, the Java method getSelectedIndexes() of the RoiManager class will then be returning the indexes of all the ROIs within the RoiManager and this independently whether they had been selected or not.
> And when the Labels option is desactivated, the getSelectedIndexes() method is then working as expected.
I am unable to reproduce this problem using the following JavaScript code:
img = IJ.createImage("Untitled", "8-bit black", 400, 400, 1);
img.show();
rm = RoiManager.getRoiManager();
rm.reset();
for (i=0; i<5; i++) {
roi = OvalRoi.create(i*70, i*70, 70, 70);
rm.addRoi(roi);
}
rm.setSelectedIndexes([2,4]);
rm.runCommand(img,"Show All with labels");
indexes = rm.getSelectedIndexes();
for (i=0; i<indexes.length; i++)
print(i+" "+indexes[i]);
This is the output:
0 2
1 4
-wayne
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html