return values to a plugin called from within another plugin

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

return values to a plugin called from within another plugin

Susanna Trollvad
I have written a plugin(1) which can load a bunch of pictures the call
another plugin/macro(2) which one by one does the same operation on the
pictures and gets a bunch of values from them. I want a way to send the
values obtained (2) to (1) and but all the values in one or more arrays.

Can I write the plugin so that the run method returns the values or will
that make ImageJ go crazy? What other ways is there to do it?

And also in the end I want to use the collected values in (1) to display a
table were each row represents the values for one picture and each column
one of the parameters measured by (2). Any ideas how I best do this?

//Susanna
Reply | Threaded
Open this post in threaded view
|

Re: return values to a plugin called from within another plugin

dscho
Hi Susanna,

On Wed, 18 May 2011, Susanna Trollvad wrote:

> I have written a plugin(1) which can load a bunch of pictures the call
> another plugin/macro(2) which one by one does the same operation on the
> pictures and gets a bunch of values from them. I want a way to send the
> values obtained (2) to (1) and but all the values in one or more arrays.
>
> Can I write the plugin so that the run method returns the values or will
> that make ImageJ go crazy? What other ways is there to do it?

In general, this is not possible, because the run() method is defined not
to return anything.

Having said that, if you can change the code of both (2) and (1), you can
always work around the missing return value(s) by e.g. setting a property
of the current image (if both are plugins) or by communicating via the
call() method to execute static methods that then change a global variable
or some such.

> And also in the end I want to use the collected values in (1) to display
> a table were each row represents the values for one picture and each
> column one of the parameters measured by (2). Any ideas how I best do
> this?

I wrote some tips for ImageJ developers that you might find helpful:

http://pacific.mpi-cbg.de/wiki/index.php/Tips_for_developers#Show_a_results_table

Ciao,
Johannes
Reply | Threaded
Open this post in threaded view
|

Re: return values to a plugin called from within another plugin

Michael Schmid
In reply to this post by Susanna Trollvad
Hi Susanna,

you could have a static Hashtable in plugin 2, and a public method to  
access that Hashtable.

You can populate the Hashtable with e.g. ImagePlus, ImageProcessor or  
Integer(ImageID) as a key and an object containing the array to pass  
as value. Plugin 1 can then access the Hashtable and draw its  
conclusions from the values obtained.

Alternatively, plugin 2 could also call to a static method of plugin  
1 to tell it about the image and the values, and plugin 1 could then  
store the values in a static Hashtable for later use.

Remember that the objects cannot be garbage collected as long as they  
are in the Hashtable. So, remove an entry from there when you don't  
need it any more, otherwise it will remain in memory.

Michael
________________________________________________________________

On 18 May 2011, at 12:28, Susanna Trollvad wrote:

> I have written a plugin(1) which can load a bunch of pictures the call
> another plugin/macro(2) which one by one does the same operation on  
> the
> pictures and gets a bunch of values from them. I want a way to send  
> the
> values obtained (2) to (1) and but all the values in one or more  
> arrays.
>
> Can I write the plugin so that the run method returns the values or  
> will
> that make ImageJ go crazy? What other ways is there to do it?
>
> And also in the end I want to use the collected values in (1) to  
> display a
> table were each row represents the values for one picture and each  
> column
> one of the parameters measured by (2). Any ideas how I best do this?
>
> //Susanna