ML Reference
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
22ML_START_NAMESPACE
23
24class TileRequest;
25class PageRequestQueueInterface;
26
27//-------------------------------------------------------------------------------------------
30//-------------------------------------------------------------------------------------------
31class PageRequest
32{
33public:
35 static PageRequest* allocate();
36
38 static void deallocate(PageRequest* request);
39
41 static void clearFreeList();
42
43private:
44 PageRequest();
45
47 void cleanup();
48
50 PageRequest* _freeListNext;
51
53 static PageRequest* _freeListHead;
55 static Mutex _freeListMutex;
56
57public:
58
60 void init(PagedImage* outputImage, MLint pageId, int processingScope);
61
62 //------------------------------------------------------
65 //------------------------------------------------------
66
71
76 void addNeededBy(TileRequest* request) {
77 _neededByTiles.push_back(request);
78 }
79
82
84 inline bool isNeededByTiles() { return _neededByTiles.size()!=0; }
85
87
88 //------------------------------------------------------
91 //------------------------------------------------------
92
96
100
104
107
109 MLint getPageId() { return _pageId; }
110
112 int getProcessingScope() const { return _processingScope; }
113
115
116 //------------------------------------------------------
119 //------------------------------------------------------
120
124
129
131 void collectPageRequestsWithErrors(std::set<PageRequest*>& result);
132
134 bool hasError() const { return _error!=ML_RESULT_OK; }
135
137 void setError(MLErrorCode error) { _error = error; }
138
141
143
144protected:
147
149 friend class PageRequestCursor;
150
152 std::vector <TileRequest*> _inputTiles;
155
156 // TODO: replace with atomic counter of _inputTilesNeeded
158
161
166
173
176
179
181 std::vector <TileRequest*> _neededByTiles;
182
185};
186
187
188ML_END_NAMESPACE
189
190#endif //of __mlPageRequest_H
191
Virtual interface for queuing PageRequests that are ready for processing.
MLErrorCode runCalculateOutputSubImage(UserThreadData *userThreadData)
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)
int getProcessingScope() const
Returns the assigned processing scope.
bool propagateCancellationDownIfRequestNotNeededAnymore()
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.
friend class PageRequestCursor
PageRequestCursor is a friend, since it directly accesses the traversal state.
std::vector< TileRequest * > _neededByTiles
A list of links to the dependent TileRequests that need this PageRequest to complete.
void copyPageToTileRequests(PageRequestQueueInterface &queue)
Mutex _inputTilesNeededMutex
void createInputTileRequests()
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)
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()
Base class for thread local data that is passed to CalculateOutputImageHandler::calculateOutputSubIma...
MLint32 MLErrorCode
Type of an ML Error code.
Definition mlTypeDefs.h:715
#define ML_RESULT_OK
No error. Everything seems to be okay.
Definition mlTypeDefs.h:723
boost::mutex Mutex
Definition mlMutex.h:39
MLint64 MLint
Definition mlTypeDefs.h:489