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 
25 ML_START_NAMESPACE
26 
27 //-----------------------------------------------------------------------
28 
31 
33 {
35 
36 public:
37 
38  ImagingBackgroundTask(void* owner);
40 
44  UseMemoryManager = TileRequest::UseMemoryManager, //<! This will allocate the memory using the MemoryManager.
45  UseMLAlloc = TileRequest::UseMLAlloc, //<! This will allocate the memory using MLAlloc.
46  NoAllocation = TileRequest::NoAllocation, //<! This can be used if no data should be allocated at all (e.g., for 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 = 16, //<! Request the data of the AsyncTileRequest as read-only page data, this requires that the given box
51  //<! matches a page's box and data type, and that scale/shift has the default value. This overrides the
52  //<! allocation policy above.
53  ReceiveProgressMessages = 32 //<! Receive progress messages for the AsyncTileRequest.
54  };
55 
58  public:
59  AsyncTileRequest ():_tileId(0),_task(nullptr) {};
61  : _tileId(tileId), _task(task)
62  {}
63 
67  bool found;
68  return _task->getFinishedRequest(_tileId, found);
69  };
70 
71  private:
72  BackgroundRequestId _tileId;
73  ImagingBackgroundTask* _task;
74  };
75 
76 
79  public:
80  ProcessAllPagesRequest():_id(0),_task(nullptr) {};
82  : _id(tileId), _task(task)
83  {}
84 
90  return _task->waitForProcessAllPages(_id);
91  }
92 
93  private:
95  ImagingBackgroundTask* _task;
96  };
97 
98 protected:
101  return _nextTileRequestId++;
102  }
103 
104 private:
107  friend class AsyncTileRequest ;
109 
111  struct RequestResult
112  {
113  RequestResult(BackgroundRequestId idArg, ProcessAllPagesHandler* handlerArg) {
114  this->id = idArg;
115  this->handler = handlerArg;
116  this->image = nullptr;
117  }
118 
119  RequestResult(BackgroundRequestId idArg, ManagedSubImage* imageArg) {
120  this->id = idArg;
121  this->image = imageArg;
122  this->handler = nullptr;
123  }
124 
125  void free() {
126  delete image;
127  image = nullptr;
128  delete handler;
129  handler = nullptr;
130  }
131 
132  // Public access to variables
134  ProcessAllPagesHandler* handler;
135  ManagedSubImage* image;
136  };
137 
141  ManagedSubImage* takeRequestIfAvailable(BackgroundRequestId tileId, bool& found);
142 
144  ManagedSubImage* getFinishedRequest(BackgroundRequestId tileId, bool& found);
145 
147  bool waitForProcessAllPages(BackgroundRequestId id);
148 
152  void addFinishedRequest(BackgroundRequestId tileId, ManagedSubImage* image);
153 
157  void addFinishedRequest(BackgroundRequestId tileId, ProcessAllPagesHandler* handler);
158 
160  std::deque<RequestResult> _availableTiles;
162  BackgroundRequestId _nextTileRequestId;
163 
164 };
165 
166 
167 ML_END_NAMESPACE
168 
169 #endif
170 
171 
#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:23
unsigned int MLuint32
Definition: mlTypeDefs.h:185
MLuint32 BackgroundRequestId
The ID of a tile request.