MeVisLab Toolbox Reference
mlImagingBackgroundTask.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2009, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_IMAGING_BACKGROUND_TASK_H
14#define ML_IMAGING_BACKGROUND_TASK_H
15
16// Local includes
18
20#include "mlManagedSubImage.h"
21#include <mlTimeCounter.h>
22#include <host/mlTileRequest.h>
23#include <mlModuleIncludes.h>
24
26
27//-----------------------------------------------------------------------
28
31
33{
35
36public:
37
40
43 UseMemoryManager = TileRequest::UseMemoryManager, //<! This will allocate the memory using the MemoryManager
44 UseMLAlloc = TileRequest::UseMLAlloc, //<! This will allocate the memory using MLAlloc
45 NoAllocation = TileRequest::NoAllocation, //<! This can be used if no data should be allocated at all (e.g. for processAllPages)
46 ExternalBuffer = TileRequest::ExternalBuffer, //<! This can be used to provide the data by the user
47 AllocationPolicyMask = 0xf, //<! Mask to get a AsyncTileRequest ::AllocationPolicy enum from the flags value.
48
49 RequestReadOnlyPage = 16, //<! Request the data of the AsyncTileRequest as read-only page data, this requires that the given box
50 //<! matches a page's box, datatype and that scale/shift has the default value. This override the
51 //<! allocation policy above.
52 ReceiveProgressMessages = 32 //<! Receive progress messages for the AsyncTileRequest .
53 };
54
57 public:
58 AsyncTileRequest ():_tileId(0),_task(nullptr) {};
62
66 bool found;
67 return _task->getFinishedRequest(_tileId, found);
68 };
69
70 private:
71 BackgroundRequestId _tileId;
73 };
74
75
78 public:
79 ProcessAllPagesRequest():_id(0),_task(nullptr) {};
83
89 return _task->waitForProcessAllPages(_id);
90 }
91
92 private:
95 };
96
97protected:
100 return _nextTileRequestId++;
101 }
102
103private:
106 friend class AsyncTileRequest ;
108
110 struct RequestResult
111 {
113 this->id = idArg;
114 this->handler = handlerArg;
115 this->image = nullptr;
116 }
117
119 this->id = idArg;
120 this->image = imageArg;
121 this->handler = nullptr;
122 }
123
124 void free() {
125 delete image;
126 image = nullptr;
127 delete handler;
128 handler = nullptr;
129 }
130
131 // public access to variables
133 ProcessAllPagesHandler* handler;
134 ManagedSubImage* image;
135 };
136
139 ManagedSubImage* takeRequestIfAvailable(BackgroundRequestId tileId, bool& found);
140
142 ManagedSubImage* getFinishedRequest(BackgroundRequestId tileId, bool& found);
143
145 bool waitForProcessAllPages(BackgroundRequestId id);
146
148 void addFinishedRequest(BackgroundRequestId tileId, ManagedSubImage* image);
149
151 void addFinishedRequest(BackgroundRequestId tileId, ProcessAllPagesHandler* handler);
152
154 std::deque<RequestResult> _availableTiles;
156 BackgroundRequestId _nextTileRequestId;
157
158};
159
160
162
163#endif
164
165
#define MLBACKGROUNDTASKS_EXPORT
Project global and OS specific declarations.
an asynchronous tile request (copyable!)
ManagedSubImage * getTile()
get the requested tile (this will block until the tile is received) it returns NULL if the task was c...
AsyncTileRequest(BackgroundRequestId tileId, ImagingBackgroundTask *task)
an asynchronous process all pages request (copyable!)
bool waitUntilFinished()
Wait until the process all pages request has finished, returns false if the request failed.
ProcessAllPagesRequest(BackgroundRequestId tileId, ImagingBackgroundTask *task)
TileRequestFlags
Defines flags that can be passed with requestTile(). NOTE: Only one of the allocation schemes can be ...
ImagingBackgroundTask(void *owner)
BackgroundRequestId generateBackgroundRequestId()
generate next generateBackgroundRequestId()
~ImagingBackgroundTask() override
ManagedSubImage is derived from SubImage and frees its allocated memory automatically when it is dest...
MessagingBackgroundTask extends the BackgroundTask with the functionality to call methods on DistantO...
Base class for handlers that are used for the Module::processAllPages facility.
#define ML_DISALLOW_COPY_AND_ASSIGN(className)
Defines basic macros.
Definition mlMacros.h:23
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
unsigned int MLuint32
Definition mlTypeDefs.h:185
MLuint32 BackgroundRequestId
the id of a tile request