MeVisLab Toolbox Reference
|
ModuleBackgroundTask extends the ImagingBackgroundTask with several useful methods that allow asynchronous access to a Module's images. More...
#include <mlModuleBackgroundTask.h>
Public Member Functions | |
ModuleBackgroundTask (Module *module, FloatField *progressField=nullptr, StringField *statusField=nullptr) | |
~ModuleBackgroundTask () override | |
void | setProgressField (FloatField *field) |
Sets the progress field. More... | |
void | setStatusField (StringField *field) |
Sets the status field. More... | |
bool | hasProgressField () |
Returns whether this task has a progress field. More... | |
bool | hasStatusField () |
Returns whether this task has a status field. More... | |
void | setStatusString (const std::string &status) override |
Updates the status string while processing. More... | |
void | setProgress (float progress) override |
Updates the progress while processing. More... | |
AsyncTileRequest | requestTile (int inputImageIndex, const SubImageBox &box, MLDataType type, const ScaleShiftData &shift=ScaleShiftData(), int getTileFlags=ImagingBackgroundTask::UseMemoryManager) |
Asynchronously request the tile. More... | |
AsyncTileRequest | requestTileWithExternalBuffer (int inputImageIndex, const SubImageBox &box, MLDataType type, const ScaleShiftData &shift, ManagedSubImage *externalBuffer, int getTileFlags=ImagingBackgroundTask::ExternalBuffer) |
Asynchronously request the tile. More... | |
ProcessAllPagesRequest | requestProcessAllPages (ProcessAllPagesHandler *handler, const SubImageBox &box=SubImageBox()) |
Asynchronously request a processing of pages using the given handler. More... | |
ProcessAllPagesRequest | requestProcessAllPages (const SubImageBox &box=SubImageBox()) |
Asynchronously request a processing of pages and running Module::processAllPages(-1). More... | |
virtual bool | shouldCancelOnInputImageChange (int) const |
Returns whether the task should be canceled when the given input image has changed. More... | |
ImageVector | getInputImageExtent (int index=0) const |
Returns the extent of the input image at index . More... | |
ImageVector | getInputImagePageExtent (int index=0) const |
Returns the page extent of the input image at index . More... | |
MLDataType | getInputImageDataType (int index=0) const |
Returns the data type of the input image at index . More... | |
double | getInputImageMinVoxelValue (int index=0) const |
Returns the minimum voxel value of the input image at index . More... | |
double | getInputImageMaxVoxelValue (int index=0) const |
Returns the maximum voxel value of the input image at index . More... | |
const MedicalImageProperties & | getInputImageProperties (int index=0) const |
Returns the image properties of the input image at index . More... | |
bool | hasValidInputImage (int index=0) const |
Returns whether the input image at index is valid and thus its properties can be requested. More... | |
int | getNumInputImages () const |
Returns the number of input images. More... | |
![]() | |
ImagingBackgroundTask (void *owner) | |
~ImagingBackgroundTask () override | |
![]() | |
MessagingBackgroundTask (void *ownerArg) | |
template<typename Object , typename Method > | |
void | callMethodOnGUI (const DistantObject< Object > &target, Method method) |
template<typename Object , typename Method , typename Arg1 > | |
void | callMethodOnGUI (const DistantObject< Object > &target, Method method, const Arg1 &arg1) |
template<typename Object , typename Method , typename Arg1 , typename Arg2 > | |
void | callMethodOnGUI (const DistantObject< Object > &target, Method method, const Arg1 &arg1, const Arg2 &arg2) |
template<typename Object , typename Method , typename Arg1 , typename Arg2 , typename Arg3 > | |
void | callMethodOnGUI (const DistantObject< Object > &target, Method method, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) |
template<typename Object , typename Method , typename Arg1 , typename Arg2 , typename Arg3 , typename Arg4 > | |
void | callMethodOnGUI (const DistantObject< Object > &target, Method method, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) |
template<typename Object , typename Method , typename Arg1 , typename Arg2 , typename Arg3 , typename Arg4 , typename Arg5 > | |
void | callMethodOnGUI (const DistantObject< Object > &target, Method method, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) |
![]() | |
BackgroundTask (void *owner) | |
Creates a new task with given owner . More... | |
virtual | ~BackgroundTask () |
virtual void | run ()=0 |
Method that needs to be reimplemented. This is called from the worker thread. More... | |
bool | isSynchronous () const |
Checks whether the task is synchronous, which means it is not executed in a different thread. More... | |
void | setSynchronous (bool flag) |
Sets whether the task is handled synchronously. Call this only in the setup of the task, not while it is already running. More... | |
void | setSynchronousCancelField (NotifyField *field) |
Sets a cancel field that is used in synchronous mode to check whether cancel was pressed. More... | |
Status | status () const |
Returns the status of the task. More... | |
void | cancel () |
Cancels the task (i.e., it sets status to canceled). More... | |
bool | isCanceled () const |
Checks whether the task was canceled. More... | |
bool | shouldStop () |
Returns whether the task should stop its work because it has been canceled. More... | |
void | resume () |
Resumes the task after it was suspended. More... | |
void | suspend () |
Suspends the task. More... | |
std::string | statusString () const |
Returns current status string. More... | |
float | progress () const |
Returns current progress This is thread-safe. More... | |
void | setOwnerWasDeleted () |
Tells the task that its owner was deleted and cancels the thread. More... | |
bool | hasOwner () const |
Returns whether the owner was deleted. More... | |
void * | owner () const |
Returns the owner of the task Call this from GUI thread only! More... | |
void | waitAndExecuteNextMessage () |
Executes the next message. More... | |
bool | executeNextMessage () |
Executes the next message. More... | |
void | sendMessageToGUI (BackgroundTaskMessage *message) |
Sends the message to the GUI. More... | |
void | logMessage (const std::string &message) |
Logs a message. More... | |
bool | isVerbose () const |
Checks whether task uses verbose logging. More... | |
void | setVerbose (bool flag) |
Sets whether task uses verbose logging. More... | |
double | runningTime () const |
Returns the running time in seconds of the task. More... | |
double | idleTime () const |
Returns the idle time in seconds of the task (e.g., the time it waited for getTile to complete). More... | |
void | getStatusInformation (BackgroundTaskStatusInformation &info) |
Returns the complete status information. More... | |
MLuint32 | taskId () const |
Returns the unique id of this task. The id of a task never changes. More... | |
void | setTaskFinishedCB (BackgroundTaskFinishedCB *callback, void *userdata) |
Set this directly after the initialization of the task from the GUI thread. More... | |
void | addObserver (Observer *observer) |
Adds the given observer. More... | |
void | removeObserver (Observer *observer) |
Removes the given observer. More... | |
Additional Inherited Members | |
![]() | |
enum | TileRequestFlags { UseMemoryManager = TileRequest::UseMemoryManager , UseMLAlloc = TileRequest::UseMLAlloc , NoAllocation = TileRequest::NoAllocation , ExternalBuffer = TileRequest::ExternalBuffer , AllocationPolicyMask = 0xf , RequestReadOnlyPage = 16 , ReceiveProgressMessages = 32 } |
Defines flags that can be passed with requestTile(). More... | |
![]() | |
enum | Status { NotInTaskManager , Queued , Running , Finished , Canceled , Suspended } |
Defines current status of the task. More... | |
![]() | |
BackgroundRequestId | generateBackgroundRequestId () |
Generates next generateBackgroundRequestId(). More... | |
![]() | |
void | sendStatusChangedToObservers () |
Sends the status change to all observers. More... | |
void | sendStatusStringChangedToObservers () |
Sends the status string change to all observers. More... | |
void | sendLogMessageToObservers (const std::string &msg) |
Sends the status string change to all observers. More... | |
void | addIdleTime (double timeInSecs) |
Adds given timeInSecs as spent idle time. More... | |
ModuleBackgroundTask extends the ImagingBackgroundTask with several useful methods that allow asynchronous access to a Module's images.
It allows the passing of a progressField and a statusField so that setStatusString() and setProgress() will update these fields accordingly.
Definition at line 50 of file mlModuleBackgroundTask.h.
ml::ModuleBackgroundTask::ModuleBackgroundTask | ( | Module * | module, |
FloatField * | progressField = nullptr , |
||
StringField * | statusField = nullptr |
||
) |
|
override |
MLDataType ml::ModuleBackgroundTask::getInputImageDataType | ( | int | index = 0 | ) | const |
Returns the data type of the input image at index
.
ImageVector ml::ModuleBackgroundTask::getInputImageExtent | ( | int | index = 0 | ) | const |
Returns the extent of the input image at index
.
double ml::ModuleBackgroundTask::getInputImageMaxVoxelValue | ( | int | index = 0 | ) | const |
Returns the maximum voxel value of the input image at index
.
double ml::ModuleBackgroundTask::getInputImageMinVoxelValue | ( | int | index = 0 | ) | const |
Returns the minimum voxel value of the input image at index
.
ImageVector ml::ModuleBackgroundTask::getInputImagePageExtent | ( | int | index = 0 | ) | const |
Returns the page extent of the input image at index
.
const MedicalImageProperties& ml::ModuleBackgroundTask::getInputImageProperties | ( | int | index = 0 | ) | const |
Returns the image properties of the input image at index
.
Most members are available directly via getInputImage*, but for, e.g., the voxel size or the world matrix, access to the MedicalImageProperties is useful.
|
inline |
Returns the number of input images.
Definition at line 158 of file mlModuleBackgroundTask.h.
|
inline |
Returns whether this task has a progress field.
Call this only from the GUI thread!
Definition at line 67 of file mlModuleBackgroundTask.h.
|
inline |
Returns whether this task has a status field.
Call this only from the GUI thread!
Definition at line 71 of file mlModuleBackgroundTask.h.
bool ml::ModuleBackgroundTask::hasValidInputImage | ( | int | index = 0 | ) | const |
Returns whether the input image at index
is valid and thus its properties can be requested.
ProcessAllPagesRequest ml::ModuleBackgroundTask::requestProcessAllPages | ( | const SubImageBox & | box = SubImageBox() | ) |
Asynchronously request a processing of pages and running Module::processAllPages(-1).
Note: It is preferable to use the version above using a ProcessAllPagesHandler, as this avoids side effects with the Module! We strongly encourage you to use a ProcessAllPagesHandler instead, as it will be much clearer what happens and it will not interfere with a processAllPages(-1) call that the Module might issue while the background task is running.
ProcessAllPagesRequest ml::ModuleBackgroundTask::requestProcessAllPages | ( | ProcessAllPagesHandler * | handler, |
const SubImageBox & | box = SubImageBox() |
||
) |
Asynchronously request a processing of pages using the given handler.
Note: The ownership of the handler is passed to the method. This way, it must not be accessed or deleted until ProcessAllPagesRequest::waitUntilFinished() returns true
.
A common use of this method is the following:
AsyncTileRequest ml::ModuleBackgroundTask::requestTile | ( | int | inputImageIndex, |
const SubImageBox & | box, | ||
MLDataType | type, | ||
const ScaleShiftData & | shift = ScaleShiftData() , |
||
int | getTileFlags = ImagingBackgroundTask::UseMemoryManager |
||
) |
Asynchronously request the tile.
getTileFlags
specifies an "or" combination of the BackgroundTask::TileRequestFlags enum.
AsyncTileRequest ml::ModuleBackgroundTask::requestTileWithExternalBuffer | ( | int | inputImageIndex, |
const SubImageBox & | box, | ||
MLDataType | type, | ||
const ScaleShiftData & | shift, | ||
ManagedSubImage * | externalBuffer, | ||
int | getTileFlags = ImagingBackgroundTask::ExternalBuffer |
||
) |
Asynchronously request the tile.
getTileFlags
specifies an "or" combination of the BackgroundTask::TileRequestFlags enum. Note that the ownership of externalBuffer
is passed to the method. This way, you are not allowed to delete it before you get it back via TileRequest::getTile(). If getTile() returns NULL, the externalBuffer has already been deleted internally. To support own destruction of the memory, you must derive from ManagedSubImage and reimplement the destructor.
|
overridevirtual |
Updates the progress while processing.
Call this only from the run() method.
Reimplemented from ml::BackgroundTask.
|
inline |
Sets the progress field.
Call this only from the GUI thread!
Definition at line 59 of file mlModuleBackgroundTask.h.
|
inline |
Sets the status field.
Call this only from the GUI thread!
Definition at line 63 of file mlModuleBackgroundTask.h.
|
overridevirtual |
Updates the status string while processing.
Call this only from the run() method.
Reimplemented from ml::BackgroundTask.
|
inlinevirtual |
Returns whether the task should be canceled when the given input image has changed.
The default implementation returns true
. This way, any input image change will cancel the task. Note: this flag needs to be used in handleNotification(), and this is typically done in BackgroundTaskBaseModule. If you reimplement this method, make sure that it can safely be called from the GUI thread.
Definition at line 130 of file mlModuleBackgroundTask.h.