MeVisLab Toolbox Reference
ml::ModuleBackgroundTask Class Reference

#include <mlModuleBackgroundTask.h>

Inheritance diagram for ml::ModuleBackgroundTask:
ml::ImagingBackgroundTask ml::MessagingBackgroundTask ml::BackgroundTask ml::ProcessAllPagesBackgroundTask ml::RTObjectSaveBackgroundTask

Public Member Functions

 ModuleBackgroundTask (Module *module, FloatField *progressField=nullptr, StringField *statusField=nullptr)
 ~ModuleBackgroundTask () override
void setProgressField (FloatField *field)
void setStatusField (StringField *field)
bool hasProgressField ()
bool hasStatusField ()
void setStatusString (const std::string &status) override
void setProgress (float progress) override
AsyncTileRequest requestTile (int inputImageIndex, const SubImageBox &box, MLDataType type, const ScaleShiftData &shift=ScaleShiftData(), int getTileFlags=ImagingBackgroundTask::UseMemoryManager)
AsyncTileRequest requestTileWithExternalBuffer (int inputImageIndex, const SubImageBox &box, MLDataType type, const ScaleShiftData &shift, ManagedSubImage *externalBuffer, int getTileFlags=ImagingBackgroundTask::ExternalBuffer)
ProcessAllPagesRequest requestProcessAllPages (ProcessAllPagesHandler *handler, const SubImageBox &box=SubImageBox())
ProcessAllPagesRequest requestProcessAllPages (const SubImageBox &box=SubImageBox())
virtual bool shouldCancelOnInputImageChange (int) const
ImageVector getInputImageExtent (int index=0) const
 Returns the extent of the input image at index.
ImageVector getInputImagePageExtent (int index=0) const
 Returns the page extent of the input image at index.
MLDataType getInputImageDataType (int index=0) const
 Returns the data type of the input image at index.
double getInputImageMinVoxelValue (int index=0) const
 Returns the minimum voxel value of the input image at index.
double getInputImageMaxVoxelValue (int index=0) const
 Returns the maximum voxel value of the input image at index.
const MedicalImagePropertiesgetInputImageProperties (int index=0) const
 Returns the image properties of the input image at index.
bool hasValidInputImage (int index=0) const
 Returns whether the input image at index is valid and thus its properties can be requested.
int getNumInputImages () const
 Returns the number of input images.
Public Member Functions inherited from ml::ImagingBackgroundTask
 ImagingBackgroundTask (void *owner)
 ~ImagingBackgroundTask () override
Public Member Functions inherited from ml::MessagingBackgroundTask
 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)
Public Member Functions inherited from ml::BackgroundTask
 BackgroundTask (void *owner)
virtual ~BackgroundTask ()
virtual void run ()=0
 Method that needs to be reimplemented. This is called from the worker thread.
bool isSynchronous () const
 Checks whether the task is synchronous, which means it is not executed in a different thread.
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.
void setSynchronousCancelField (NotifyField *field)
 Sets a cancel field that is used in synchronous mode to check whether cancel was pressed.
Status status () const
void cancel ()
bool isCanceled () const
bool shouldStop ()
void resume ()
void suspend ()
std::string statusString () const
float progress () const
void setOwnerWasDeleted ()
bool hasOwner () const
void * owner () const
void waitAndExecuteNextMessage ()
bool executeNextMessage ()
void sendMessageToGUI (BackgroundTaskMessage *message)
void logMessage (const std::string &message)
bool isVerbose () const
 Checks whether task uses verbose logging.
void setVerbose (bool flag)
double runningTime () const
double idleTime () const
void getStatusInformation (BackgroundTaskStatusInformation &info)
MLuint32 taskId () const
 Returns the unique id of this task. The id of a task never changes.
void setTaskFinishedCB (BackgroundTaskFinishedCB *callback, void *userdata)
void addObserver (Observer *observer)
void removeObserver (Observer *observer)

Additional Inherited Members

Public Types inherited from ml::ImagingBackgroundTask
enum  TileRequestFlags {
  UseMemoryManager = TileRequest::UseMemoryManager , UseMLAlloc = TileRequest::UseMLAlloc , NoAllocation = TileRequest::NoAllocation , ExternalBuffer = TileRequest::ExternalBuffer ,
  AllocationPolicyMask = 0xf , RequestReadOnlyPage = 16 , ReceiveProgressMessages = 32
}
Public Types inherited from ml::BackgroundTask
enum  Status {
  NotInTaskManager , Queued , Running , Finished ,
  Canceled , Suspended
}
 Defines current status of the task. More...
Protected Member Functions inherited from ml::ImagingBackgroundTask
BackgroundRequestId generateBackgroundRequestId ()
 Generates next generateBackgroundRequestId().
Protected Member Functions inherited from ml::BackgroundTask
void sendStatusChangedToObservers ()
 Sends the status change to all observers.
void sendStatusStringChangedToObservers ()
 Sends the status string change to all observers.
void sendLogMessageToObservers (const std::string &msg)
 Sends the status string change to all observers.
void addIdleTime (double timeInSecs)
 Adds given timeInSecs as spent idle time.

Detailed Description

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.

Constructor & Destructor Documentation

◆ ModuleBackgroundTask()

ml::ModuleBackgroundTask::ModuleBackgroundTask ( Module * module,
FloatField * progressField = nullptr,
StringField * statusField = nullptr )

◆ ~ModuleBackgroundTask()

ml::ModuleBackgroundTask::~ModuleBackgroundTask ( )
override

Member Function Documentation

◆ getInputImageDataType()

MLDataType ml::ModuleBackgroundTask::getInputImageDataType ( int index = 0) const

Returns the data type of the input image at index.

◆ getInputImageExtent()

ImageVector ml::ModuleBackgroundTask::getInputImageExtent ( int index = 0) const

Returns the extent of the input image at index.

◆ getInputImageMaxVoxelValue()

double ml::ModuleBackgroundTask::getInputImageMaxVoxelValue ( int index = 0) const

Returns the maximum voxel value of the input image at index.

◆ getInputImageMinVoxelValue()

double ml::ModuleBackgroundTask::getInputImageMinVoxelValue ( int index = 0) const

Returns the minimum voxel value of the input image at index.

◆ getInputImagePageExtent()

ImageVector ml::ModuleBackgroundTask::getInputImagePageExtent ( int index = 0) const

Returns the page extent of the input image at index.

◆ getInputImageProperties()

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.

◆ getNumInputImages()

int ml::ModuleBackgroundTask::getNumInputImages ( ) const
inline

Returns the number of input images.

Definition at line 158 of file mlModuleBackgroundTask.h.

◆ hasProgressField()

bool ml::ModuleBackgroundTask::hasProgressField ( )
inline

Returns whether this task has a progress field. Call this only from the GUI thread!

Definition at line 67 of file mlModuleBackgroundTask.h.

◆ hasStatusField()

bool ml::ModuleBackgroundTask::hasStatusField ( )
inline

Returns whether this task has a status field. Call this only from the GUI thread!

Definition at line 71 of file mlModuleBackgroundTask.h.

◆ hasValidInputImage()

bool ml::ModuleBackgroundTask::hasValidInputImage ( int index = 0) const

Returns whether the input image at index is valid and thus its properties can be requested.

◆ requestProcessAllPages() [1/2]

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.

◆ requestProcessAllPages() [2/2]

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:

MyProcessAllPagesHandler* handler = new MyProcessAllPagesHandler;
// set up the handler
//handler->setSomeParameters();
bool result = requestProcessAllPages(handler).waitUntilFinished();
if (result) {
// get result values of handler
// handler->getSomeResult();
// only delete handler if we received result==true
delete handler;
}
ProcessAllPagesRequest requestProcessAllPages(ProcessAllPagesHandler *handler, const SubImageBox &box=SubImageBox())

◆ requestTile()

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.

References ml::ImagingBackgroundTask::UseMemoryManager.

◆ requestTileWithExternalBuffer()

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.

References ml::ImagingBackgroundTask::ExternalBuffer.

◆ setProgress()

void ml::ModuleBackgroundTask::setProgress ( float progress)
overridevirtual

Updates the progress while processing. Call this only from the run() method.

Reimplemented from ml::BackgroundTask.

References ml::BackgroundTask::progress().

◆ setProgressField()

void ml::ModuleBackgroundTask::setProgressField ( FloatField * field)
inline

Sets the progress field. Call this only from the GUI thread!

Definition at line 59 of file mlModuleBackgroundTask.h.

◆ setStatusField()

void ml::ModuleBackgroundTask::setStatusField ( StringField * field)
inline

Sets the status field. Call this only from the GUI thread!

Definition at line 63 of file mlModuleBackgroundTask.h.

◆ setStatusString()

void ml::ModuleBackgroundTask::setStatusString ( const std::string & status)
overridevirtual

Updates the status string while processing. Call this only from the run() method.

Reimplemented from ml::BackgroundTask.

References ml::BackgroundTask::status().

◆ shouldCancelOnInputImageChange()

virtual bool ml::ModuleBackgroundTask::shouldCancelOnInputImageChange ( int ) const
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.


The documentation for this class was generated from the following file: