MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
mlPageRequest.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_PAGE_REQUEST_H
14#define ML_PAGE_REQUEST_H
15
17
18#include "mlPagedImage.h"
19
20#include <set>
21
23
24class TileRequest;
25class PageRequestQueueInterface;
26
27//-------------------------------------------------------------------------------------------
30//-------------------------------------------------------------------------------------------
32{
33public:
36
39
41 static void clearFreeList();
42
43private:
45
47 void cleanup();
48
50 PageRequest* _freeListNext;
51
53 static PageRequest* _freeListHead;
55 static Mutex _freeListMutex;
56
57public:
59 void init(PagedImage* outputImage, MLint pageId, int processingScope);
60
61 //------------------------------------------------------
64 //------------------------------------------------------
65
70
76 {
77 _neededByTiles.push_back(request);
78 }
79
82
84 inline bool isNeededByTiles()
85 {
86 return _neededByTiles.size() != 0;
87 }
88
90
91 //------------------------------------------------------
94 //------------------------------------------------------
95
99
103
107
110 {
111 return _image;
112 }
113
116 {
117 return _pageId;
118 }
119
122 {
123 return _processingScope;
124 }
125
127
128 //------------------------------------------------------
131 //------------------------------------------------------
132
136
141
143 void collectPageRequestsWithErrors(std::set<PageRequest*>& result);
144
146 bool hasError() const
147 {
148 return _error != ML_RESULT_OK;
149 }
150
153 {
154 _error = error;
155 }
156
159 {
160 return _error;
161 }
162
164
165protected:
168
170 friend class PageRequestCursor;
171
173 std::vector<TileRequest*> _inputTiles;
176
177 // TODO: replace with atomic counter of _inputTilesNeeded
179
182
187
194
197
200
202 std::vector<TileRequest*> _neededByTiles;
203
206};
207
208
210
211#endif // of __mlPageRequest_H
The strong handle of a MLMemoryBlock.
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.
MLErrorCode runCalculateOutputSubImage(UserThreadData *userThreadData)
Allocates the page and calls Module::calculateOutputSubImage with the given output page and input til...
bool tileRequestFinished()
Called when one of the tile requests has finished, and returns true if all input tiles are finished.
bool _needsToBeRemovedFromPagedImage
Flag whether we need to be removed from the paged image.
void setError(MLErrorCode error)
Sets the error that happened (on this single request, not on the tree).
int _traversalCreatedTiles
The number of tiles that have already been created.
bool hasError() const
Returns whether the request has an error (making the data unusable or invalid).
static void clearFreeList()
Clears the internal free list of deallocated PageRequests.
int _traversalCursorPosition
Offset into _inputTiles to indicate the next tile request to fill with pages.
MLErrorCode _error
The error that happened.
void freeInputTiles()
Frees the input tiles and their data.
bool isNeededByTiles()
Returns whether this PageRequest is needed by any tiles (if not, it should not be deleted).
int _totalInputTilesNeeded
The total number of input tiles (without empty tiles)
void propagateErrorUpwards(MLErrorCode error)
Propagates an error upwards through the request tree, sets the error on all dependend TileRequest and...
int getProcessingScope() const
Returns the assigned processing scope.
bool propagateCancellationDownIfRequestNotNeededAnymore()
Recursively walks up to all tree roots and checks whether they are canceled.
MLErrorCode getError()
Returns the error that happened.
PagedImage * _image
The image from which the page should be requested.
static void deallocate(PageRequest *request)
Page requests are deallocated with the deallocate method; they can not be deleted directly.
std::vector< TileRequest * > _neededByTiles
A list of links to the dependent TileRequests that need this PageRequest to complete.
void copyPageToTileRequests(PageRequestQueueInterface &queue)
Copies data to dependent tile requests (may only be called after a successful runCalculateOutputSubIm...
Mutex _inputTilesNeededMutex
void createInputTileRequests()
Creates the TileRequests that are needed for this PageRequest.
int _inputTilesNeeded
The number of still needed input tiles (excluding empty tiles), decremented whenever a tile is finish...
MLint _pageId
The pageid that should be requested.
MLint getPageId()
Returns the page ID.
PagedImage * getPagedImage()
Returns access to the associated paged image (never NULL!).
void init(PagedImage *outputImage, MLint pageId, int processingScope)
Initializes a PageRequests for the given pageId on the given outputImage.
MLMemoryBlockHandle _page
The page data, which locks the data in the cache since it uses an MLMemoryBlockHandle.
void addNeededBy(TileRequest *request)
Adds that the given TileRequest request depends on this page.
static PageRequest * allocate()
Page requests are allocated via the allocate method; they can not be created with new.
void collectPageRequestsWithErrors(std::set< PageRequest * > &result)
Collects all page requests that have error()!=ML_RESULT_OK up to the roots of the tree.
std::vector< TileRequest * > _inputTiles
Array of input tiles; it may contain NULL for empty boxes (array is empty on data sources).
int _processingScope
The processing scope.
bool isReadyForProcessing()
Returns whether the request is ready for the page calculation and can be placed in the work queue.
The class PagedImage, representing a fragmented image that manages properties and data of an image lo...
A TileRequest either represents the input subimage that is needed by a PageRequest or if it is a root...
Base class for thread local data that is passed to CalculateOutputImageHandler::calculateOutputSubIma...
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