MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
mlTileRequest.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_TILE_REQUEST_H
14#define ML_TILE_REQUEST_H
15
17
18// ML-includes
19#include "mlInitSystemML.h"
20
21#include "mlSubImage.h"
22#include "mlPagedImage.h"
23#include "mlPageIDIterator.h"
24
25#include <set>
26
28
29class TileRequest;
30class PageRequest;
31class PageRequestQueueInterface;
32
34typedef void TileRequestFinishedCB(void* data, TileRequest* request);
35
36//-------------------------------------------------------------------------------------------
48//-------------------------------------------------------------------------------------------
50{
51
52public:
55
58
60 static void clearFreeList();
61
62private:
64
66 void cleanup();
67
69 TileRequest* _freeListNext;
70
72 static TileRequest* _freeListHead;
74 static Mutex _freeListMutex;
75
76public:
81 void init(PagedImage* inputImage, const SubImageBox& box, MLDataType dataType, const ScaleShiftData& scaleShift,
82 bool readOnlyInputTile = false, bool tryToBecomeMemoryImage = false);
83
86 UseMemoryManager = 0, //<! This will allocate the memory using the MemoryManager.
87 UseMLAlloc = 1, //<! This will allocate the memory using MLAlloc.
88 NoAllocation = 2, //<! This can be used if no data should be allocated at all (e.g., for processAllPages).
89 ExternalBuffer =
90 3 //<! This can be used to provide the data by the user and to avoid freeing the data if something goes wrong.
91 };
92
93 //------------------------------------------------------
96 //------------------------------------------------------
97
102
105
110 {
111 _neededByPageRequest = request;
112 }
113
117
122
124
125 //------------------------------------------------------
128 //------------------------------------------------------
129
135 {
136 _allocationPolicy = policy;
137 }
138
141 {
142 return _allocationPolicy;
143 }
144
147
150 {
151 _subImage.setData(nullptr);
152 }
153
155 void freeData()
156 {
157 if (_allocationPolicy != ExternalBuffer) {
158 _subImage.free();
159 }
160 }
161
163 const SubImage& getSubImage() const
164 {
165 return _subImage;
166 }
167
170 void setExternalDataBuffer(void* data)
171 {
172 setAllocationPolicy(TileRequest::ExternalBuffer);
173 _subImage.setData(data);
174 }
175
179 {
180 _readOnlyInputTile = flag;
181 }
182
184
185 //------------------------------------------------------
188 //------------------------------------------------------
189
191 bool hasFinished() const;
192
196 void setTileRequestFinishedCB(TileRequestFinishedCB* cb, void* data)
197 {
198 _finishedCB = cb;
199 _finishedCBData = data;
200 }
201
204 void setInternalTileRequestFinishedCB(TileRequestFinishedCB* cb, void* data)
205 {
206 _internalFinishedCB = cb;
207 _internalFinishedCBData = data;
208 }
209
211 double getProgress() const;
212
214
215 //------------------------------------------------------
218 //------------------------------------------------------
219
221 bool hasError() const
222 {
223 return _error != ML_RESULT_OK;
224 }
225
228
231 {
232 return _error;
233 }
234
238
243
245 void collectPageRequestsWithErrors(std::set<PageRequest*>& result);
246
248
249 //------------------------------------------------------
252 //------------------------------------------------------
253
256
259 {
260 return _processingScope;
261 }
262
265 {
266 _processingScope = scope;
267 }
268
270 const SubImageBox& getBox() const
271 {
272 return _subImage.getBox();
273 }
274
277
280
282
283protected:
285 friend class PageRequestCursor;
286
293
297
300
303
306
309
312
317
320
323
326
330
333
336
339
342
347
352
353public:
355 static void enableAllocationFailure(int count = 1);
358 {
359 _forceAllocationFailure = false;
360 }
361
362private:
363 static bool _forceAllocationFailure;
364 static int _forceAllocationFailureCount;
365 static int _forceAllocationFailureModulo;
366};
367
369
370#endif // of __mlTileRequest_H
A class that allows to incrementally iterate over all IDs of pages have an intersection with a given ...
A cursor to create page and tile requests iteratively, allowing breaks and resumption at any time,...
Virtual interface for queuing PageRequests that are ready for processing.
A PageRequest represents the request for the calculation of a single page of a PagedImage.
The class PagedImage, representing a fragmented image that manages properties and data of an image lo...
This class manages/represents a rectangular 6D image region that is organized linearly in memory.
Definition mlSubImage.h:75
A TileRequest either represents the input subimage that is needed by a PageRequest or if it is a root...
void createInputPageIds()
Creates the page IDs for all required input pages.
int getProcessingScope() const
Returns the assigned processing scope.
bool isBlockedByMemoryImage()
Checks whether the tile request is blocked by a pending memory image being calculated by another Tile...
void setProcessingScope(int scope)
Returns the assigned processing scope.
static void enableAllocationFailure(int count=1)
Enables failing on every count allocation.
void freeData()
Frees the allocated data using SubImage::free(), except if the AllocationPolicy is UserAllocation.
bool propagateCancellationDownIfRequestNotNeededAnymore()
Recursively walks up to all tree roots and checks whether they are canceled.
void forgetData()
Tells the tile to forget its data so that it is not freed in freeData().
int _processingScope
The processing scope.
void allocateData()
Allocates the data using the internal AllocationPolicy.
static TileRequest * allocate()
Tile requests are allocated via the allocate method, they can not be created with new.
double getProgress() const
Returns the progress of this tile (TODO: not very detailed yet, only the ratio of copied/total pages)...
TileRequestFinishedCB * _internalFinishedCB
Callback to signal that the TileRequest has finished.
bool _readOnlyInputTile
Flag that the TileRequest should try to not copy data, since it will not be written to.
PageIDIterator _inputPageIds
Since a tile can have many page requests, we use a PageIdIterator to generate the IDs on the fly.
bool copyDataFromSubImg(SubImage &pageImage)
Copies the data from the given image.
void sendTileRequestFinished(PageRequestQueueInterface &queue)
Tells the dependend page requests that the tile request has finished.
void setUseTileReadOnly(bool flag)
This allows to make read-only use of input pages or memory image if box/data type match and shift/sca...
MLint _inputPagesNeeded
Overall number of pages needed. This is getNumPages() of _inputPageIds at the beginning and will decr...
bool hasFinished() const
Returns whether the request has finished. If an error happened, this returns true as well.
bool _tileWillBecomeMemoryImage
Flag that the TileRequest should become the MemoryImage when it has finished.
PagedImage * _image
The image from which the data should be requested.
void setInternalTileRequestFinishedCB(TileRequestFinishedCB *cb, void *data)
Sets the internal tile request finished callback.
void emitFinishedCallback()
Calls the finished callbacks.
void propagateErrorUpwards(MLErrorCode error)
Propagates an error upwards through the PageRequest it depends on.
MLint _traversalCursorPosition
Current _inputPageIds position to indicate the next page request to create.
const SubImageBox & getBox() const
Returns the box that this tile request covers.
void setError(MLErrorCode error)
Sets the error that happened.
static void disableAllocationFailure()
Disables allocation failure (default!).
Mutex _inputPagesNeededMutex
TODO: replace above with atomic counter and remove the mutex.
PageRequest * createPageRequest(MLint pageId, PageRequestQueueInterface &queue)
Creates a new page request and queues it if it has no dependencies.
AllocationPolicy getAllocationPolicy() const
Returns the allocation policy.
bool hasError() const
Returns whether the request has an error (and the data is thus unusable/invalid).
MLErrorCode _error
The current error state.
void updateSourceImageExtent()
Updates the source image extent according to the image.
void setTileRequestFinishedCB(TileRequestFinishedCB *cb, void *data)
Sets the tile request finished callback.
static void deallocate(TileRequest *request)
Tile requests are deallocated with the deallocate method, they can not be deleted directly.
const SubImage & getSubImage() const
Returns the stored subimage including the data pointer.
void collectPageRequestsWithErrors(std::set< PageRequest * > &result)
Collects all page requests that have error()!=ML_RESULT_OK up to the roots of the tree.
bool prepareForCursorVisit()
This is called before a cursor steps down into the TileRequest and may return false,...
void setAllocationPolicy(AllocationPolicy policy)
Sets which allocation policy should be used.
void setNeededBy(PageRequest *request)
Stores the PageRequest that needs this TileRequest.
AllocationPolicy
Defines how the TileRequest will allocate its memory.
MLErrorCode getError() const
Returns the error that happened (or ML_RESULT_OK).
bool intersectsPagedImage() const
Returns whether the request has an intersection with the paged image.
PageRequest * _neededByPageRequest
The PageRequest that depends on this TileRequest (or NULL if it is a root TileRequest).
SubImage _subImage
The subimage that represents the TileRequest's box, data type, and data.
MLErrorCode updateImageProperties()
Updates the image properties of the complete graph starting at this tile request via the host.
void init(PagedImage *inputImage, const SubImageBox &box, MLDataType dataType, const ScaleShiftData &scaleShift, bool readOnlyInputTile=false, bool tryToBecomeMemoryImage=false)
Creates a TileRequest for inputImage with given box, dataType, and scaleShift.
TileRequestFinishedCB * _finishedCB
Callback to signal that the TileRequest has finished.
AllocationPolicy _allocationPolicy
Defines which allocation method to use.
void * _internalFinishedCBData
Callback data to signal that the TileRequest has finished.
ScaleShiftData _scaleShiftData
The additional scale/shift information.
void setExternalDataBuffer(void *data)
This allows to set the data buffer from an external buffer.
void pageRequestFinished(SubImage &pageImage, PageRequestQueueInterface &queue)
Called by all finished PageRequests that may be copied to output buffer.
void * _finishedCBData
Callback data to signal that the TileRequest has finished.
static void clearFreeList()
Clears the internal free list of deallocated TileRequests.
MLint32 MLDataType
MLDataType.
Definition mlTypeDefs.h:592
MLint32 MLErrorCode
Type of an ML Error code.
Definition mlTypeDefs.h:772
#define ML_RESULT_OK
No error. Everything seems to be okay.
Definition mlTypeDefs.h:780
boost::mutex Mutex
Defines a non-recursive mutex.
Definition mlMutex.h:39
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition mlTypeDefs.h:489
void TileRequestFinishedCB(void *data, TileRequest *request)
Callback for a finished TileRequest.