Hi all,
I would like to implement a new type of ROI that would behave like any existing ImageJ ROI. Could someone point me to the interface to implement, or what methods are key to have the nice floating drawing we currently have? Cheers jy -- Jean-Yves Tinevez PFID - Imagopole Institut Pasteur 25-28, rue du Docteur Roux 75724 Paris cedex 15 France tel: +33 1 40 61 31 77 |
Hi J-Y,
On Mon, 23 Nov 2009, Jean-Yves Tinevez wrote: > I would like to implement a new type of ROI that would behave like any > existing ImageJ ROI. > > Could someone point me to the interface to implement, or what methods > are key to have the nice floating drawing we currently have? As far as I can tell, there is no easy way to have a floating drawing except using the overlay mechanism: http://pacific.mpi-cbg.de/cgi-bin/gitweb.cgi?p=imagej.git;a=blob;f=ij/ImagePlus.java;h=2757dccd0bd37c2e94ee90d32b91140be10d8c44;hb=1394c52029d82c2a791355d8e533f04c442a5067#l1963 (It might be better to use the next one, where you have to specify a Shape, a Color and a BasicStroke instead of an untyped list.) You'll have to represent your ROI in the form of a Shape (which should be easy, as java.awt.geom.GeneralPath is an implementation of Shape). The trickier part is to interact with the mouse. You have at least two options: - use a macro-based approach, such as was done with the original ROIBrush: http://pacific.mpi-cbg.de/cgi-bin/gitweb.cgi?p=VIB.git;a=blob;f=ROIBrush_.java;h=739c4e989279a32879ae9b812a12e321cf914a44;hb=8abc8d608b729752a84ad633ed53c1e78316a982 - register mouse and mouse motion listeners with the image window (possibly checking that the correct tool is selected in the Toolbar all the time). Here you have to make sure that you register/deregister the listeners appropriately with a WindowListener that you register with the addImageListener() method of the class ij.ImageJ. If you go with the second approach, I would be interested in helping you turn this into an abstract Tool class which can then be reused by other plugins implementing tools. Ciao, Johannes |
In reply to this post by Jean-Yves Tinevez-2
Hi Jean-Yves,
you could try to implement your own subclass of ij.gui.Roi - I have not tried, but I guess that it would work. See e.g. OvalRoi.java and PolygonRoi.java. public void draw(Graphics g) should do the display on the screen. Your roi should have x, y positions and width, height like all other rois. For modifying the roi with the mouse, you have to supersede isHandle, moveHandle(int sx, int sy), mouseDownInHandle(int handle, int sx, int sy), handleMouseUp(int sx, int sy), Your class should also have getMask(), contains(x, y), getLength(), drawPixels(ImageProcessor ip) and (if possible) getPolygon methods. Another problem occurs if you want to create the the roi via a suitable tool. Currently, as far as I know, 'external' tools have to be macros, so you need a macro (in your startup macros) that calls a static method, but this won't interface so easily with the ImageCanvas methods that finally call the moveHandle etc. methods. Michael ________________________________________________________________ On 23 Nov 2009, at 12:59, Jean-Yves Tinevez wrote: > Hi all, > > I would like to implement a new type of ROI that would behave like > any existing ImageJ ROI. > Could someone point me to the interface to implement, or what > methods are key to have the nice floating drawing we currently have? > Cheers > jy > > -- > Jean-Yves Tinevez > PFID - Imagopole > Institut Pasteur > 25-28, rue du Docteur Roux > 75724 Paris cedex 15 > France > tel: +33 1 40 61 31 77 |
Free forum by Nabble | Edit this page |