Currently I'm working on v1.37u, to write/modify a plugin.
The idea is after open an image (customer file type, grayscale), need to draw (or just display) some points on it. Additional, after user zoom the image in, the size of those points won't be enlarged, so the user is able to find the precise position of every point. After referred to some plugin's code, and numerous tests, that's what I got so far class CustomerWindow extends ImageWindow{ Vector HDPoints; List pointsList = new ArrayList(); // some other methods void getPoints(){ //read file, get points and put into HDPoints } void drawPoints(){ ImagePlus imp = WindowManager.getCurrentImage(); ImageCanvas ic = imp.getCanvas(); double m = ic.getmagnification(); int w = new double((double)3/m).intValue(); //w changed when zoom value changed, keep it relative the same pointsList.clear(); for(int i=0; i<HDPoints.size(); i++){ Object o = HDPoints.elementAt(i); int x = o.getx(); int y = o.gety(); String color = o.getColor(); OvalRoi oval = new OvalRoi(x-w/2, y-w/2, w, w); oval.setColor(color); pointsList.add(oval); IJ.getImage().setRoi(oval); } for(Iterator it = pointsList.iterator(); it.hasNext();){ ShapeRoi roi = new ShapeRoi((OvalRoi)it.next()); IJ.getImage().setRoi(roi); } } If there is only one point, this works perfectly fine, I get everything I wanted. However, if there are many points, then except that last one, points showed up one by one on image, but disappeared in the end. Please help me, Thank you very much Hao Jiang ************************************************************************* PRIVILEGE AND CONFIDENTIALITY NOTICE: The information in this email is intended for the named recipients only. It may contain privileged and confidential information. If you have received this communication in error, any use, copying or dissemination of its contents is strictly prohibited. Please erase all copies of the message along with any included attachments and notify Intermap Technologies or the sender immediately by telephone at the number indicated on this page. ************************************************************************* |
Hi,
On Tue, 15 Jul 2008, Hao Jiang wrote: > > for(Iterator it = pointsList.iterator(); it.hasNext();){ > ShapeRoi roi = new ShapeRoi((OvalRoi)it.next()); > IJ.getImage().setRoi(roi); This will set a new roi with every iteration. That is the reason why it does not work. You need to use the or() method of ShapeRoi to extend the first, and only in the end, i.e. _after_ the loop, set the ROI. IOW: ShapeRoi roi = null; Iterator it = pointsList.iterator(); while (it.hasNext()) { ShapeRoi oval = new ShapeRoi((OvalRoi)it.next()); roi = roi == null ? oval : roi.or(oval); } IJ.getImage().setRoi(roi); Of course, you can do that already in the first for() loop. But you get the idea. Hth, Dscho |
Thank you for you reply, I tried this, it worked fine with only few
points. However, for one test with 20K points, it took almost forever to finish. I believe it's because of "or" operation. Hao -----Original Message----- From: Johannes Schindelin [mailto:[hidden email]] Sent: Tuesday, July 15, 2008 7:14 PM To: Hao Jiang Cc: [hidden email] Subject: Re: need help, I'm frustrated Hi, On Tue, 15 Jul 2008, Hao Jiang wrote: > > for(Iterator it = pointsList.iterator(); it.hasNext();){ > ShapeRoi roi = new ShapeRoi((OvalRoi)it.next()); > IJ.getImage().setRoi(roi); This will set a new roi with every iteration. That is the reason why it does not work. You need to use the or() method of ShapeRoi to extend the first, and only in the end, i.e. _after_ the loop, set the ROI. IOW: ShapeRoi roi = null; Iterator it = pointsList.iterator(); while (it.hasNext()) { ShapeRoi oval = new ShapeRoi((OvalRoi)it.next()); roi = roi == null ? oval : roi.or(oval); } IJ.getImage().setRoi(roi); Of course, you can do that already in the first for() loop. But you get the idea. Hth, Dscho ************************************************************************* PRIVILEGE AND CONFIDENTIALITY NOTICE: The information in this email is intended for the named recipients only. It may contain privileged and confidential information. If you have received this communication in error, any use, copying or dissemination of its contents is strictly prohibited. Please erase all copies of the message along with any included attachments and notify Intermap Technologies or the sender immediately by telephone at the number indicated on this page. ************************************************************************* |
Hi,
On Thu, 17 Jul 2008, Hao Jiang wrote: > Thank you for you reply, I tried this, it worked fine with only few > points. However, for one test with 20K points, it took almost forever to > finish. I believe it's because of "or" operation. That is no wonder. If you want this to scale to an insane amount of points, you will need to do some optimization, and actually understand what the code of "or()" does. You will need to read up on java.awt.Shape. Hth, Dscho |
> Thank you for you reply, I tried this, it worked fine with only few
> points. However, for one test with 20K points, it took almost > forever to finish. I believe it's because of "or" operation. This macro displays 20,000 points as a point selection in just a few seconds. size = 2000; count = 20000; x = newArray(count); y = newArray(count); for (i=0; i<count; i++) { x[i] = random*size; y[i] = random*size; } newImage("Test", "8-bit Black", size, size, 1); run("Point Tool...", "mark=0 selection=yellow"); makeSelection("point", x, y); -wayne |
Hi Wayne, I've not problem to run your macro, but just can't make it
work in my code. public void drawPoints() { if (HDPoints == null) { return; } imp = WindowManager.getCurrentImage(); ImageCanvas ic = imp.getCanvas(); fi = (IntermapFileInfo)imp.getOriginalFileInfo(); int x, y; Calibration cal = imp.getCalibration(); Rectangle r = imp.getWindow().getCanvas().getSrcRect(); displayList = new Vector(); for (int i = 0; i < HDPoints.size(); i++) { x = (int)(((HeightSamplePoint)HDPoints.elementAt(i)).getX() / (fi.decimation)); y = (int)(((HeightSamplePoint)HDPoints.elementAt(i)).getY() / (fi.decimation)) + (int)(cal.yOrigin / fi.decimation); if (y >= 0 && y <= fi.height && x >= r.getX() && x <= r.getX() + r.getWidth()) { displayList.add(HDPoints.elementAt(i)); } } int size = displayList.size(); int[] xPoints = new int[size]; int[] yPoints = new int[size]; for(int i=0; i<size; i++){ HeightSamplePoint point = (HeightSamplePoint)displayList.elementAt(i); xPoints[i]=(int)point.getX(); yPoints[i]=(int)point.getY(); } Roi roi = new PointRoi(xPoints, yPoints, size); IJ.getImage().setRoi(roi); } I used log to output points in the 2nd for loop, all there, but just can't draw them on image What else I have missed? Thanks Hao -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Wayne Rasband Sent: Thursday, July 17, 2008 12:55 PM To: [hidden email] Subject: Re: need help, I'm frustrated > Thank you for you reply, I tried this, it worked fine with only few > points. However, for one test with 20K points, it took almost > forever to finish. I believe it's because of "or" operation. This macro displays 20,000 points as a point selection in just a few seconds. size = 2000; count = 20000; x = newArray(count); y = newArray(count); for (i=0; i<count; i++) { x[i] = random*size; y[i] = random*size; } newImage("Test", "8-bit Black", size, size, 1); run("Point Tool...", "mark=0 selection=yellow"); makeSelection("point", x, y); -wayne ************************************************************************* PRIVILEGE AND CONFIDENTIALITY NOTICE: The information in this email is intended for the named recipients only. It may contain privileged and confidential information. If you have received this communication in error, any use, copying or dissemination of its contents is strictly prohibited. Please erase all copies of the message along with any included attachments and notify Intermap Technologies or the sender immediately by telephone at the number indicated on this page. ************************************************************************* |
Free forum by Nabble | Edit this page |