13#ifndef ML_TILE_REQUEST_H
14#define ML_TILE_REQUEST_H
31class PageRequestQueueInterface;
74 static Mutex _freeListMutex;
110 _neededByPageRequest =
request;
144 void freeData() {
if (_allocationPolicy!=ExternalBuffer) { _subImage.free(); } }
152 setAllocationPolicy(TileRequest::ExternalBuffer);
153 _subImage.setData(data);
172 _finishedCBData = data;
177 _internalFinishedCB = cb;
178 _internalFinishedCBData = data;
317 static bool _forceAllocationFailure;
318 static int _forceAllocationFailureCount;
319 static int _forceAllocationFailureModulo;
A class that allows to incrementally iterate over all ids of pages have an intersection with a given ...
Class which represents an image, which manages properties of an image and image data which is located...
This class manages/represents a rectangular 6d image region which is organized linearly in memory.
A TileRequest either represents the input sub image that is needed by a PageRequest or if it is a roo...
void createInputPageIds()
Creates the pageids for all required input pages.
int getProcessingScope() const
Get 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)
Get 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 wether they are cancelled.
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 a lot of page requests, we use a PageIdIterator to generate the ids on the fly.
bool copyDataFromSubImg(SubImage &pageImage)
Copies the data from the given image (if in read-only mode, the data might as well be stored instead ...
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/datatype match and shift/scal...
MLint _inputPagesNeeded
Overall number of pages needed (which is getNumPages() of _inputPageIds at the beginning and will dec...
bool hasFinished() const
Returns if 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 cb (NOTE: this should only be used by the request processor)
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
Get 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 (if necessary, otherwise returns NULL) and queue it if it has not dependen...
AllocationPolicy getAllocationPolicy() const
Returns the allocation policy.
bool hasError() const
Returns if the request has an error (and the data is thus unusable/invalid).
MLErrorCode _error
The current error state.
void updateSourceImageExtent()
Update the source image extent according to the image.
void setTileRequestFinishedCB(TileRequestFinishedCB *cb, void *data)
Sets the tile request finished cb (NOTE: in the current implementation, the TileRequest may NOT be de...
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 sub image (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 which 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 if 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 sub image that represents the TileRequest's box,datatype and data.
MLErrorCode updateImageProperties()
Updates the image properties of the complete graph stating 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, which may be copied to output buffer.
void * _finishedCBData
Callback data to signal that the TileRequest has finished.
static void clearFreeList()
Clear the internal free list of deallocated TileRequests.
MLint32 MLDataType
MLDataType.
MLint32 MLErrorCode
Type of an ML Error code.
#define ML_RESULT_OK
No error. Everything seems to be okay.
boost::mutex Mutex
Defines a non-recursive mutex.
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 ...
void TileRequestFinishedCB(void *data, TileRequest *request)
Callback for a finished TileRequest.