I am trying to determine the correct way to interrupt processing of a segmentation pipeline. This will be from a user request, application shutdown, etc. The segmentation is running in a worker thread and the cancellation controlled from the GUI thread. I have searched the documentation and manuals and have not found anything useful - the documentation in the itk::ProcessObject::AbortGenerateDataOn function for instance is ‘Turn on and off the AbortGenerateData flag.’ which offers little guidance on how to actually perform and handle an abort.
From trial and error and reading examples from others, my (partial) understanding is as follows:
Setting the abort flag can only be done in the thread running the Update(), i.e. via an observer callback. Setting the flag from a separate thread (e.g. the GUI thread) causes issues.
Just the currently running filter should have its abort flag set (I have tried setting the flag on all downstream filters and the final filter, but this either causes problems (hangs caused by filters waiting for their threads to generate data) or nothing happens. As a side note here, the reason I thought that just the final filter needed the abort flag set was because I accidentally had a circular pipeline which caused a stack overflow when setting the abort flag due to the process objects propagating the flag recursively.
Once the abort has completed, the itk::ProcessAborted exception is thrown from the Update() call. This needs to be handled and dealt with.
In order to re-use the pipeline, ResetPipeline() needs to be called. I am unclear whether this should be called on the ProcessObject that was aborted, all process objects, the final ProcessObject or even the final itk::Image (with the assumption that it propagates down the pipeline). I am assuming that the handler for the exception mentioned above is the right place to do this. I seem to have most success from resetting all ProcessObjects, I get hangs otherwise.
Any guidance on how to use this functionality properly would be greatly appreciated as it is not at all clear from the documentation.