Ext. function clash when using 2 externals plugins

Hi,

Is it possible to run external functions from different plugins simultaneously ?
Let me explain. If I run the following it works fine

run("Confocal Series (2.2MB)");
run("3D Manager");
run("Duplicate...", "duplicate channels=2");
run("3D object counter...", "threshold=67 slice=12 min.=2000 max.=4000000 objects");
Ext.Manager3D_AddImage();

But the following fails (I guess) because Ext.Manager3D_AddImage() is for the 3D manager but CLIJ is run between run("3D Manager") and Ext.Manager3D_AddImage().

run("Confocal Series (2.2MB)");
run("3D Manager");
////////////random stuff
run("CLIJ Macro Extensions", "cl_device=");
Ext.CLIJ_push("confocal-series.tif");		
/////
selectWindow("confocal-series.tif");
run("Duplicate...", "duplicate channels=2");
run("3D object counter...", "threshold=67 slice=12 min.=2000 max.=4000000 objects");
Ext.Manager3D_AddImage();

So my question is, is it possible to run those different plugins without needing to initialize them just before using them ? The reason is that I need to run both CLIJ and 3D roi manager sequentially twice and a few thousand times, so it is quite time consuming to initialise them then closing them twice each per file I need to process.

Also every time I close the 3D roi manager, according to the window menu it is still there…Is it normal ?
image

Thank you very much

1 Like

Hey @LPUoO,

thanks for raising this question. I can answer from CLIJ side: You can call the initialisation to CLIJ as often as you want. Just as an example:

startTime = getTime();
run("CLIJ Macro Extensions", "cl_device=");
IJ.log("CLIJ init took " + (getTime() - startTime) + " msec");

startTime = getTime();
run("CLIJ Macro Extensions", "cl_device=");
IJ.log("CLIJ init took " + (getTime() - startTime) + " msec");

If you run this macro twice, the log window shows this output:

CLIJ init took 917 msec
CLIJ init took 28 msec
CLIJ init took 14 msec
CLIJ init took 14 msec

Thus, CLIJ stays initialized in the background; also between macro runs. You just catch it again. The design pattern is called Singleton.

Regarding the 3D manager, I need to forward the question to @ThomasBoudier : Is it possible to run the 3D manager and its macro extensions twice without opening another manager window? I wrote a minimum code example for reproducing the issue. It happens when switching between two macro extensions. Ideally, it would open a 3D manager and put 10 objects into it.

Furthermore, I would like to ask @Wayne: Is there a way to initialize two macro extensions and keep them both initialized? If not, how high would you estimate the coding effort in order to make this happen?

Thanks everyone!

Cheers,
Robert

Hi @haesleinhuepf,

Looking at the code of macro extensions it seems that when the registry for macros extensions is reinitialised each time new macros extensions are registered so it seems impossible to use two macro extensions together.
About 3DManager I did not use the Singleton scheme as I think sometimes it can be useful to get multiple 3DManager when you have multiple images. If really required I could make this singleton approach as an option for 3DManager.

Best,

Thomas

1 Like

Hi @LPUoO and @haesleinhuepf,

About 3DManager appearing multiple times it should not be like this. I register the 3DManager window to the ImageJ WindowManager and remove it from the WindowManager when closing, so I am not sure where is the problem.

Best,

Thomas

Hey @LPUoO,

I just wrote a mini-plugin which solves your problem. Please download the roimanager3dsingleton.jar and put it in the jars directory of your Fiji installation. The updated version of the above mentioned macro will then work:

Hey @ThomasBoudier,

the source code of the mini-plugin is open source online.

Maybe there is some space for it somewhere in https://github.com/mcib3d/mcib3d-plugins/ ? :wink:

I hope that helps.

Cheers,
Robert

3 Likes

Thank you very much @haesleinhuepf !
This saves me about a ton of time in my macro.

About 3DManager I did not use the Singleton scheme as I think sometimes it can be useful to get multiple 3DManager when you have multiple images. If really required I could make this singleton approach as an option for 3DManager.

@ThomasBoudier, I think that having the singleton approach as an option for 3DManager would be great.

Thanks a lot ot both of you.

1 Like

Hi @LPUoO,

Big thanks to @haesleinhuepf for the test and sample code, the singleton option is available in the updated version of 3D Manager. The singleton scheme is the default scheme, you can select multiple instances if you want multiple instances of 3D Manager.

Best,

Thomas

2 Likes