Hi, I have a question on the details of calling a plugin's method from
another plugin. I've read this post ( https://list.nih.gov/cgi-bin/wa?A2=ind0306&L=IMAGEJ&D=0&I=-3&P=31044 ) dated 27 Jun 2003 in which Adrian explained how to use a plugin from another by means of its public methods (see code below). I tried someting similar with the Object_Counter3D plugin ( http://rsb.info.nih.gov/ij/plugins/track/objects.html ), since it is prepared to be used that way. However, I am forced to place the file MyPlugin.java and Object_Counter3D.java in the same folder. Otherwise, the compiler gives an error ("Class ReUsable not found") Is there a way to put each plugin in a different folder? Is it necessary to import Object_Counter3D in my plugin? Thank you in advance for your answer, Pablo Adrian proposed the following plugin structure: public class ReUsable implements PlugIn { run() { GenericDialog gd = new GenericDialog("..."); ... initThings(); setParams(p1,p2,...); process(); } public initThings() {...} public setParams() {...} public process() {...} } And the code to use it: public class MyPlugin implements PlugIn { ReUsable pi = new ReUsable(); pi.initThings(); pi.setParams(...); pi.process(...); } |
Hi Pablo,
Is there a way to put each plugin in a different folder? Yes Is it necessary to import Object_Counter3D in my plugin? No I created a little test class PlugInFilter to show how to do it, and tested it by calling both an ImageJ PlugInFilter and one of my own PlugInFilter. import ij.IJ; import ij.ImagePlus; import ij.plugin.filter.PlugInFilter; import ij.process.ImageProcessor; /** Shows how how to call one pluginFilter from another. */ public class PlugInFilterCaller_ implements PlugInFilter { String _pluginName; String _arg; int _returnValueForSetup; /** Default is to call dilate from ImageJ Binary. */ public PlugInFilterCaller_() { this("ij.plugin.filter.Binary", "dilate", DOES_8G); } // /** Default is to call ShapeLogic segmenter. */ // public PlugInFilterCaller_() { // this("SBSegment_", "", DOES_8G+DOES_RGB+DOES_STACKS+SUPPORTS_MASKING); // } /** Use this to setup your own plugin runner. */ public PlugInFilterCaller_(String pluginName, String arg, int returnValueForSetup) { _pluginName = pluginName; _arg = arg; _returnValueForSetup = returnValueForSetup; } /** Empty everything is done in setup. */ public void run(ImageProcessor ip) { } public int setup(String arg, ImagePlus imp) { IJ.runPlugIn(_pluginName, _arg); return _returnValueForSetup; } } -Sami Badawi http://www.shapelogic.org On Thu, Apr 10, 2008 at 4:12 PM, Pablo Manuel Jais <[hidden email]> wrote: > Hi, I have a question on the details of calling a plugin's method from > another plugin. I've read this post ( > https://list.nih.gov/cgi-bin/wa?A2=ind0306&L=IMAGEJ&D=0&I=-3&P=31044 ) > dated 27 Jun 2003 in which Adrian explained how to use a plugin from > another by means of its public methods (see code below). > > I tried someting similar with the Object_Counter3D plugin ( > http://rsb.info.nih.gov/ij/plugins/track/objects.html ), since it is > prepared to be used that way. However, I am forced to place the file > MyPlugin.java and Object_Counter3D.java in the same folder. Otherwise, the > compiler gives an error ("Class ReUsable not found") Is there a way to put > each plugin in a different folder? Is it necessary to import > Object_Counter3D in my plugin? > > Thank you in advance for your answer, > Pablo > > > Adrian proposed the following plugin structure: > public class ReUsable implements PlugIn { > run() { > GenericDialog gd = new GenericDialog("..."); > ... > initThings(); > setParams(p1,p2,...); > process(); > } > > public initThings() {...} > public setParams() {...} > public process() {...} > } > > And the code to use it: > public class MyPlugin implements PlugIn { > ReUsable pi = new ReUsable(); > pi.initThings(); > pi.setParams(...); > pi.process(...); > } > |
Sami, thank you very much for your answer. However, the class you propose
works by calling the run method of the plugin. The Binary plugin is prepared to internally execute different methods when an argument is passed in the IJ.runPlugIn(_pluginName, _arg) line. Explicitly, its run method is the following: public void run(ImageProcessor ip) { //Binary plugin ... if (arg.equals("erode")) erode(ip); else if (arg.equals("dilate")) dilate(ip); else if (arg.equals("open")) open(ip); ... } This is not the case of the Object_Counter3D plugin, though. This particular plugin has public methods so I can access them from another plugin directly, whithout a call to IJ.runPlugIn or ObjectCounter3D.run. In fact, calling runPlugin is impossible since the run method is simply: public void run(String arg) { //Object_Counter3D plugin if (! setupGUI(arg)) return; analyze(); } and the setupGUI method is always interactive (and makes no use of the arg string). Of course I could edit Object_Counter3D and change its behaviour, but I don't think one should change every plugin on a whim, but only if its necessary or if it adds functionality. As I stated on my first post, I can already call the analyze method from my plugin, but only if both class files are located in the same folder. Is there a way to place them in different folders? Pablo On Fri, 11 Apr 2008, Sami Badawi wrote: > Hi Pablo, > > Is there a way to put each plugin in a different folder? Yes > Is it necessary to import Object_Counter3D in my plugin? No > > I created a little test class PlugInFilter to show how to do it, and > tested it by calling both an ImageJ PlugInFilter and one of my own > PlugInFilter. > > import ij.IJ; > import ij.ImagePlus; > import ij.plugin.filter.PlugInFilter; > import ij.process.ImageProcessor; > > /** Shows how how to call one pluginFilter from another. */ > public class PlugInFilterCaller_ implements PlugInFilter { > > String _pluginName; > String _arg; > int _returnValueForSetup; > > /** Default is to call dilate from ImageJ Binary. */ > public PlugInFilterCaller_() { > this("ij.plugin.filter.Binary", "dilate", DOES_8G); > } > > // /** Default is to call ShapeLogic segmenter. */ > // public PlugInFilterCaller_() { > // this("SBSegment_", "", DOES_8G+DOES_RGB+DOES_STACKS+SUPPORTS_MASKING); > // } > > /** Use this to setup your own plugin runner. */ > public PlugInFilterCaller_(String pluginName, String arg, int > returnValueForSetup) { > _pluginName = pluginName; > _arg = arg; > _returnValueForSetup = returnValueForSetup; > } > > /** Empty everything is done in setup. */ > public void run(ImageProcessor ip) { > } > > public int setup(String arg, ImagePlus imp) { > IJ.runPlugIn(_pluginName, _arg); > return _returnValueForSetup; > } > } > > -Sami Badawi > http://www.shapelogic.org > > On Thu, Apr 10, 2008 at 4:12 PM, Pablo Manuel Jais <[hidden email]> wrote: > > Hi, I have a question on the details of calling a plugin's method from > > another plugin. I've read this post ( > > https://list.nih.gov/cgi-bin/wa?A2=ind0306&L=IMAGEJ&D=0&I=-3&P=31044 ) > > dated 27 Jun 2003 in which Adrian explained how to use a plugin from > > another by means of its public methods (see code below). > > > > I tried someting similar with the Object_Counter3D plugin ( > > http://rsb.info.nih.gov/ij/plugins/track/objects.html ), since it is > > prepared to be used that way. However, I am forced to place the file > > MyPlugin.java and Object_Counter3D.java in the same folder. Otherwise, the > > compiler gives an error ("Class ReUsable not found") Is there a way to put > > each plugin in a different folder? Is it necessary to import > > Object_Counter3D in my plugin? > > > > Thank you in advance for your answer, > > Pablo > > > > > > Adrian proposed the following plugin structure: > > public class ReUsable implements PlugIn { > > run() { > > GenericDialog gd = new GenericDialog("..."); > > ... > > initThings(); > > setParams(p1,p2,...); > > process(); > > } > > > > public initThings() {...} > > public setParams() {...} > > public process() {...} > > } > > > > And the code to use it: > > public class MyPlugin implements PlugIn { > > ReUsable pi = new ReUsable(); > > pi.initThings(); > > pi.setParams(...); > > pi.process(...); > > } > > > |
Hi Pablo,
I looked at Object_Counter3D. It is a PlugIn, not a PlugInFilter as my example, but that should not be a problem. The class Object_Counter3D does not have a package definition so it should live in the default package. Say that you want to have your PlugIn live in a folder called org.pablo.Pablo_Counter3D This was possible up to Java 1.3, but starting from 1.4 this became illegal. A class in the default package can only be accessed from another class in the default package. Bug report to Sun: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4491314 Sun's answer: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4743555 You could change your JDK to 1.3, or have both files in the same folder. -Sami Badawi http://www.shapelogic.org |
Free forum by Nabble | Edit this page |