Llamero / Local_Hough_Circle

An improved implementation
GNU General Public License v3.0
10 stars 1 forks source link

Running in headless mode #5

Open jmmroldan opened 6 years ago

jmmroldan commented 6 years ago

I know Fiji/Image J is meant to be a desktop app, but I was trying to move my macro to a cluster, in part to avoid some of the memory problems I have commented on the out of memory issue. When I try to run my macro I get a HeadlessException:

java.awt.HeadlessException
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204)
        at java.awt.Window.<init>(Window.java:536)
        at java.awt.Frame.<init>(Frame.java:420)
        at java.awt.Frame.<init>(Frame.java:385)
        at javax.swing.JFrame.<init>(JFrame.java:189)
        at Hough_Package.Hough_GUI.<init>(Hough_GUI.java:45)

I don't have a virtual desktop available on the cluster so I cannot go for the Xvfb-like solution. Is there a way I can run the Hough Circle Transform plugin with the --headless parameter?

EDIT: I was having a look at the source code. Maybe the issue could be solved if the constructors of the GUI elements (guiPanel, guiFrame...) are called only if isGUI = True? (instead of when they are declared).

Llamero commented 6 years ago

I think I get the problem. The call to a macro at line 146 ignores all GUI elements, but even initializing them is enough to mess-up headless. If you want to make a quick and dirty headless branch of the plugin, I would assume that removing lines 44-82 (all of the GUI elements), replace everything in the else statement in line 221-630 with a simple error message reporting that the macro is not formatted correctly (if desired), delete the functions in lines 699-826, and finally remove lines 841-844. After all this, the compiler should flag any left-over calls to Swing elements, as they are no longer initialized, and so delete those too. The code should then hand the macro code straight to the event dispatch thread without calling any GUI elements.

The Hough_GUI class also has many calls to IJ.showProgress, IJ.showStatus, and IJ.showMessage, but since these are intrinsic GUI elements to IJ, it sounds like they should be ignored in headless mode, hopefully.