Hello Wayne,
When doing particle analysis on a stack (~75k particles), I
eventually get an StringIndexOutOfBoundsException (-1) thrown.
(ijI38r on OSX. java 1.5.0_07).
I traced it through a call in ParticleAnalyzer (line 688) to
RoiManager.add and then in RoiManager to getLabel() (line 284). I
wrapped the offending line in a try/catch. The problem seems to be
that when the object count passed in (n) is large, the check on
ys.length causes the digit variable to increase; which is correct for
ys but not for xs: the exception is thrown on the xs.substring
(xs.length()-digits) portion of line 284 since digit is now too large
(by 1 in my case) compared to xs.length.
I hacked around the problem by adding an extra digit variable for the
x's (xdigit) and explicitly using the correct digit in the substring
call. I arbitrarily chose the xdigit for use in the stack slice
prefix calculation (line 286), but I'm not exactly sure that's the
right thing to do there. (My hacked RoiManager.getLabel method below)
Seem like a reasonable fix? or have I misinterpreted the
RoiManager.getLabel() method? Wanted to be sure I had it right since
I note that the label generated here is sometimes parsed and used for
control elsewhere.
Thanks,
-william
------------
William Beaver
[hidden email]
=begin code================
String getLabel(ImagePlus imp, Roi roi, int n) {
Rectangle r = roi.getBounds();
int xc = r.x + r.width/2;
int yc = r.y + r.height/2;
if (n>=0)
{xc = yc; yc=n;}
if (xc<0) xc = 0;
if (yc<0) yc = 0;
int xdigits = 4;
int ydigits = 4;
String xs = "" + xc;
if (xs.length()>xdigits) xdigits = xs.length();
String ys = "" + yc;
if (ys.length()>ydigits) ydigits = ys.length();
xs = "000" + xc;
ys = "000" + yc;
String label=null;
try {
label = ys.substring(ys.length()-ydigits) + "-" + xs.substring
(xs.length()-xdigits);
} catch(StringIndexOutOfBoundsException e){
System.out.print(e.getMessage());
}
if (imp.getStackSize()>1) {
String zs = "000" + imp.getCurrentSlice();
label = zs.substring(zs.length()-xdigits) + "-" + label;
}
return label;
}
=end code==================