MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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:
39
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
46 // processAllPages).
47 ExternalBuffer = TileRequest::ExternalBuffer, //<! This can be used to provide the data by the user.
48 AllocationPolicyMask = 0xf, //<! Mask to get a AsyncTileRequest ::AllocationPolicy enum from the flags value.
49
50 RequestReadOnlyPage =
51 16, //<! Request the data of the AsyncTileRequest as read-only page data, this requires that the given box
52 //<! matches a page's box and data type, and that scale/shift has the default value. This overrides the
53 //<! allocation policy above.
54 ReceiveProgressMessages = 32 //<! Receive progress messages for the AsyncTileRequest.
55 };
56
59 {
60 public:
62 : _tileId(0)
63 , _task(nullptr) {};
68
72 {
73 bool found;
74 return _task->getFinishedRequest(_tileId, found);
75 };
76
77 private:
78 BackgroundRequestId _tileId;
80 };
81
82
85 {
86 public:
88 : _id(0)
89 , _task(nullptr) {};
94
100 {
101 return _task->waitForProcessAllPages(_id);
102 }
103
104 private:
107 };
108
109protected:
112 {
113 return _nextTileRequestId++;
114 }
115
116private:
119 friend class AsyncTileRequest;
121
123 struct RequestResult
124 {
126 {
127 this->id = idArg;
128 this->handler = handlerArg;
129 this->image = nullptr;
130 }
131
133 {
134 this->id = idArg;
135 this->image = imageArg;
136 this->handler = nullptr;
137 }
138
139 void free()
140 {
141 delete image;
142 image = nullptr;
143 delete handler;
144 handler = nullptr;
145 }
146
147 // Public access to variables
149 ProcessAllPagesHandler* handler;
150 ManagedSubImage* image;
151 };
152
156 ManagedSubImage* takeRequestIfAvailable(BackgroundRequestId tileId, bool& found);
157
159 ManagedSubImage* getFinishedRequest(BackgroundRequestId tileId, bool& found);
160
162 bool waitForProcessAllPages(BackgroundRequestId id);
163
167 void addFinishedRequest(BackgroundRequestId tileId, ManagedSubImage* image);
168
172 void addFinishedRequest(BackgroundRequestId tileId, ProcessAllPagesHandler* handler);
173
175 std::deque<RequestResult> _availableTiles;
177 BackgroundRequestId _nextTileRequestId;
178};
179
180
182
183#endif
#define MLBACKGROUNDTASKS_EXPORT
An asynchronous tile request. This is copyable!
ManagedSubImage * getTile()
Returns the requested tile.
AsyncTileRequest(BackgroundRequestId tileId, ImagingBackgroundTask *task)
An asynchronous process all pages request. This is copyable!
bool waitUntilFinished()
Waits until the process all pages request has finished, and returns false if the request failed.
ProcessAllPagesRequest(BackgroundRequestId tileId, ImagingBackgroundTask *task)
TileRequestFlags
Defines flags that can be passed with requestTile().
ImagingBackgroundTask(void *owner)
BackgroundRequestId generateBackgroundRequestId()
Generates 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:21
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.