MeVisLab Toolbox 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 
22 ML_START_NAMESPACE
23 
24 class TileRequest;
25 class PageRequestQueueInterface;
26 
27 //-------------------------------------------------------------------------------------------
30 //-------------------------------------------------------------------------------------------
32 {
33 public:
35  static PageRequest* allocate();
36 
38  static void deallocate(PageRequest* request);
39 
41  static void clearFreeList();
42 
43 private:
44  PageRequest();
45 
47  void cleanup();
48 
50  PageRequest* _freeListNext;
51 
53  static PageRequest* _freeListHead;
55  static Mutex _freeListMutex;
56 
57 public:
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 
106  PagedImage* getPagedImage() { return _image; }
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 
140  MLErrorCode getError() { return _error; }
141 
143 
144 protected:
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 
188 ML_END_NAMESPACE
189 
190 #endif //of __mlPageRequest_H
191 
The strong handle of a MLMemoryBlock.
A cursor to create page and tile requests in an iterative manner, to allow breaking/resuming at any t...
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.
Definition: mlPageRequest.h:32
MLErrorCode runCalculateOutputSubImage(UserThreadData *userThreadData)
Allocates the page and call Module::calculateOutputSubImage with given output page and input tiles (m...
bool tileRequestFinished()
Called when one of the tile requests has finished, returns true if all input tiles are finished.
bool _needsToBeRemovedFromPagedImage
flag if we need to be removed from the paged image
void setError(MLErrorCode error)
Sets the error that happened (on this single request, not an the tree).
int _traversalCreatedTiles
Number of tiles that has already been created.
bool hasError() const
Returns if the request has an error (and the data is thus unusable/invalid).
static void clearFreeList()
Clear 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 if this PageRequest is needed by any tiles (if not, it should not be deleted).
Definition: mlPageRequest.h:84
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
Get the assigned processing scope.
bool propagateCancellationDownIfRequestNotNeededAnymore()
Recursively walks up to all tree roots and checks whether they are canceled.
PagedImage * getPagedImage()
Get access to the associated paged image (never NULL!)
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 dependend TileRequests which 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 (without empty tiles) (is decremented whenever a tile has fini...
MLint _pageId
The pageid that should be requested.
MLint getPageId()
Get the page id.
void init(PagedImage *outputImage, MLint pageId, int processingScope)
Inits 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 a MLMemoryBlockHandle).
void addNeededBy(TileRequest *request)
Adds that the given TileRequest request depends on this page.
Definition: mlPageRequest.h:76
void collectPageRequestsWithErrors(std::set< PageRequest * > &result)
Collects all page requests that have error()!=ML_RESULT_OK up to the roots of the tree.
static PageRequest * allocate()
Page requests are allocated via the allocate method, they can not be created with new.
std::vector< TileRequest * > _inputTiles
Array of input tiles, may contain NULL for empty boxes (array is empty on data sources).
int _processingScope
the processing scope
bool isReadyForProcessing()
Returns if the request is ready for the page calculation and can be placed in the work queue.
Class which represents an image, which manages properties of an image and image data which is located...
Definition: mlPagedImage.h:70
A TileRequest either represents the input sub image that is needed by a PageRequest or if it is a roo...
Definition: mlTileRequest.h:50
Base class for thread local data that is passed to CalculateOutputImageHandler::calculateOutputSubIma...
MLint32 MLErrorCode
Type of an ML Error code.
Definition: mlTypeDefs.h:818
#define ML_RESULT_OK
No error. Everything seems to be okay.
Definition: mlTypeDefs.h:826
boost::mutex Mutex
Defines a non-recursive mutex.
Definition: mlMutex.h:39
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition: mlTypeDefs.h:578