Dear All,
I am sending a procedure that causes ArrayIndexOutOfBoundsException in the getNextNumber() method. I wander what is the reason. According to me, there should not be such behavior. Or is it a bug in ImageJ? Any suggestions? best regards Dimiter private boolean showDialog() { if (imp==null) return true; int width = imp.getWidth(); int height = imp.getHeight(); Calibration cal = imp.getCalibration(); int places; if (cal.scaled()) { pixelWidth = cal.pixelWidth; pixelHeight = cal.pixelHeight; units = cal.getUnits(); places = 2; } else { pixelWidth = 1.0; pixelHeight = 1.0; units = "pixels"; places = 0; } if (areaPerPoint==0.0) areaPerPoint = (width*cal.pixelWidth*height*cal.pixelHeight)/81.0; // default to 9x9 grid lineWidth = Line.getWidth(); /* ImageWindow win = imp.getWindow(); double mag = win!=null?win.getCanvas().getMagnification():1.0; int scale = (int)(1.0/mag); if (lineWidth<scale) lineWidth = scale;*/ try { GenericDialog gd = new GenericDialog("Grid..."); gd.setAlwaysOnTop(false); gd.addChoice("Grid Type:", types, type); gd.showDialog(); if (gd.wasCanceled()) return false; option=gd.getNextChoiceIndex(); type=types[option]; IJ.log(" "+ type); //type = gd.getNextChoice(); gd.setVisible(false); //gd=null; gd.dispose(); GenericDialog gd2 = new GenericDialog("Grid continued ..."); gd2.addNumericField("Area per Point:", areaPerPoint, places, 6, units+"^2"); gd2.addNumericField("Line width:", lineWidth, 0, 6, "pixels"); gd2.addCheckbox("Random Offset", randomOffset); // gd.addNumericField("ratio:", ratio, 0); if (type=="Boxes") { gd2.addNumericField("ratio:", ratio, 0); } gd2.showDialog(); if (gd2.wasCanceled()) return false; areaPerPoint = gd2.getNextNumber(); IJ.log("APP: "+ areaPerPoint); Line.setWidth((int)gd2.getNextNumber()); lineWidth = Line.getWidth(); IJ.log("line width "+ lineWidth); randomOffset = gd2.getNextBoolean(); IJ.log("random "+ randomOffset); ratio=(int)gd2.getNextNumber(); IJ.log("ratio "+ ratio); } catch (ArrayIndexOutOfBoundsException aiobe) { IJ.log("ArrayIndexOutOfBoundsException"); } double tileSize = Math.sqrt(areaPerPoint); tileWidth = tileSize/pixelWidth; tileHeight = tileSize/pixelHeight; if (randomOffset) { xstart = (int)(random.nextDouble()*tileWidth); ystart = (int)(random.nextDouble()*tileHeight); } else { xstart = (int)(tileWidth/2.0+0.5); ystart = (int)(tileHeight/2.0+0.5); } linesV = (int)((width-xstart)/tileWidth)+1; linesH = (int)((height-ystart)/tileHeight)+1; return true; } _______________________________________________________________________ Dr Dimiter Prodanov, MD, Ph.D. Neural Engineering Rehabilitation Laboratory (Laboratoire de Génie de la Réhabilitation Neurale) Département de Physiologie et Pharmacologie Université catholique de Louvain Avenue Hippocrate, 54 POBox UCL-5446 / B-1200 Bruxelles -Belgique- Phone: 00-322-764 5596 Fax: 00-322-764 9422 http://www.md.ucl.ac.be/gren |
Hi
sounds you have a mismatch of addNumericField and getNextNumber!? In you code, what if types != "Boxes" ? Then you have only 2 addNumericFields but still try to read 3 NextNumbers? Joachim |---------+---------------------------------> | | Dimiter Prodanov | | | <dimiter.prodanov@GREN| | | .UCL.AC.BE> | | | Gesendet von: ImageJ | | | Interest Group | | | <[hidden email]> | | | | | | | | | 19.06.2006 16:43 | | | Bitte antworten an | | | ImageJ Interest Group | |---------+---------------------------------> >-------------------------------------------------------------------------------------------------------------------------------| | | | An: [hidden email] | | Kopie: | | Thema: GenericDialog issue | >-------------------------------------------------------------------------------------------------------------------------------| Dear All, I am sending a procedure that causes ArrayIndexOutOfBoundsException in the getNextNumber() method. I wander what is the reason. According to me, there should not be such behavior. Or is it a bug in ImageJ? Any suggestions? best regards Dimiter private boolean showDialog() { if (imp==null) return true; int width = imp.getWidth(); int height = imp.getHeight(); Calibration cal = imp.getCalibration(); int places; if (cal.scaled()) { pixelWidth = cal.pixelWidth; pixelHeight = cal.pixelHeight; units = cal.getUnits(); places = 2; } else { pixelWidth = 1.0; pixelHeight = 1.0; units = "pixels"; places = 0; } if (areaPerPoint==0.0) areaPerPoint = (width*cal.pixelWidth*height*cal.pixelHeight)/81.0; // default to 9x9 grid lineWidth = Line.getWidth(); /* ImageWindow win = imp.getWindow(); double mag = win!=null?win.getCanvas().getMagnification():1.0; int scale = (int)(1.0/mag); if (lineWidth<scale) lineWidth = scale;*/ try { GenericDialog gd = new GenericDialog("Grid..."); gd.setAlwaysOnTop(false); gd.addChoice("Grid Type:", types, type); gd.showDialog(); if (gd.wasCanceled()) return false; option=gd.getNextChoiceIndex(); type=types[option]; IJ.log(" "+ type); //type = gd.getNextChoice(); gd.setVisible(false); //gd=null; gd.dispose(); GenericDialog gd2 = new GenericDialog("Grid continued ..."); gd2.addNumericField("Area per Point:", areaPerPoint, places, 6, units+"^2"); gd2.addNumericField("Line width:", lineWidth, 0, 6, "pixels"); gd2.addCheckbox("Random Offset", randomOffset); // gd.addNumericField("ratio:", ratio, 0); if (type=="Boxes") { gd2.addNumericField("ratio:", ratio, 0); } gd2.showDialog(); if (gd2.wasCanceled()) return false; areaPerPoint = gd2.getNextNumber(); IJ.log("APP: "+ areaPerPoint); Line.setWidth((int)gd2.getNextNumber()); lineWidth = Line.getWidth(); IJ.log("line width "+ lineWidth); randomOffset = gd2.getNextBoolean(); IJ.log("random "+ randomOffset); ratio=(int)gd2.getNextNumber(); IJ.log("ratio "+ ratio); } catch (ArrayIndexOutOfBoundsException aiobe) { IJ.log("ArrayIndexOutOfBoundsException"); } double tileSize = Math.sqrt(areaPerPoint); tileWidth = tileSize/pixelWidth; tileHeight = tileSize/pixelHeight; if (randomOffset) { xstart = (int)(random.nextDouble()*tileWidth); ystart = (int)(random.nextDouble()*tileHeight); } else { xstart = (int)(tileWidth/2.0+0.5); ystart = (int)(tileHeight/2.0+0.5); } linesV = (int)((width-xstart)/tileWidth)+1; linesH = (int)((height-ystart)/tileHeight)+1; return true; } _______________________________________________________________________ Dr Dimiter Prodanov, MD, Ph.D. Neural Engineering Rehabilitation Laboratory (Laboratoire de Génie de la Réhabilitation Neurale) Département de Physiologie et Pharmacologie Université catholique de Louvain Avenue Hippocrate, 54 POBox UCL-5446 / B-1200 Bruxelles -Belgique- Phone: 00-322-764 5596 Fax: 00-322-764 9422 http://www.md.ucl.ac.be/gren ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ |
Free forum by Nabble | Edit this page |