ML Reference
MeVis/Foundation/Sources/ML/include/host/mlTileRequest.h
Go to the documentation of this file.
00001 // **InsertLicense** code
00002 //-------------------------------------------------------------------------
00009 //-------------------------------------------------------------------------
00010 #ifndef __mlTileRequest_H
00011 #define __mlTileRequest_H
00012 
00013 // ML-includes
00014 #ifndef __mlInitSystemML_H
00015 #include "mlInitSystemML.h"
00016 #endif
00017 
00018 #include "mlSubImage.h"
00019 #include "mlPagedImage.h"
00020 #include "mlPageIDIterator.h"
00021 
00022 ML_START_NAMESPACE
00023 
00024 class TileRequest;
00025 class PageRequest;
00026 class PageRequestQueueInterface;
00027 
00029 typedef void TileRequestFinishedCB(void* data, TileRequest* request);
00030 
00031 //-------------------------------------------------------------------------------------------
00043 //-------------------------------------------------------------------------------------------
00044 class ML_UNIX_ONLY_EXPORT(MLEXPORT) TileRequest
00045 {
00046 public:
00051   TileRequest(PagedImage* inputImage, const SubImageBox& box, MLDataType dataType,
00052               const ScaleShiftData& scaleShift, bool readOnlyInputTile = false, bool tryToBecomeMemoryImage = false);
00053 
00055   ~TileRequest();
00056 
00058   enum AllocationPolicy {
00059     UseMemoryManager = 0,  //<! This will allocate the memory using the MemoryManager
00060     UseMLAlloc       = 1,  //<! This will allocate the memory using MLAlloc
00061     NoAllocation     = 2,  //<! This can be used if no data should be allocated at all (e.g., for processAllPages)
00062     ExternalBuffer   = 3   //<! This can be used to provide the data by the user (and to avoid freeing the data when something goes wrong)
00063   };
00064 
00065   //------------------------------------------------------
00067 
00068   //------------------------------------------------------
00069 
00073   bool prepareForCursorVisit();
00074 
00076   void  createInputPageIds();
00077 
00081   void  setNeededBy(PageRequest* request) {
00082     _neededByPageRequest = request;
00083   }
00084 
00087   bool  isBlockedByMemoryImg();
00088 
00092   void pageRequestFinished(SubImage& pageImage, PageRequestQueueInterface& queue);
00093 
00095 
00096   //------------------------------------------------------
00098 
00099   //------------------------------------------------------
00100 
00104   void setAllocationPolicy(AllocationPolicy policy) { _allocationPolicy = policy; }
00105 
00107   AllocationPolicy getAllocationPolicy() const { return _allocationPolicy; }
00108 
00110   MLErrorCode allocateData();
00111 
00113   void  forgetData() { _subImage.setData(NULL); }
00114 
00116   void  freeData() { if (_allocationPolicy!=ExternalBuffer) { _subImage.free(); } }
00117 
00119   const SubImage& getSubImage() const { return _subImage; }
00120 
00123   void setExternalDataBuffer(void* data) {
00124     setAllocationPolicy(TileRequest::ExternalBuffer);
00125     _subImage.setData(data);
00126   }
00127 
00129   void setUseTileReadOnly(bool flag) { _readOnlyInputTile = flag; }
00130 
00132 
00133   //------------------------------------------------------
00135 
00136   //------------------------------------------------------
00137 
00139   bool hasFinished() const;
00140 
00142   void setTileRequestFinishedCB(TileRequestFinishedCB* cb, void* data) {
00143     _finishedCB = cb;
00144     _finishedCBData = data;
00145   }
00146 
00148   double getProgress() const;
00149 
00151 
00152   //------------------------------------------------------
00154 
00155   //------------------------------------------------------
00156 
00158   bool hasError() const { return _error!=ML_RESULT_OK; }
00159 
00161   void setError(MLErrorCode error);
00162 
00164   MLErrorCode getError() const { return _error; }
00165 
00167   void propagateErrorUpwards(MLErrorCode error);
00168 
00172   bool propagateCancellationDownIfRequestNotNeededAnymore();
00173 
00175   void collectPageRequestsWithErrors(std::set<PageRequest*>& result);
00176 
00177 #ifdef ML_TILEREQUEST_DEBUG_PRINTING
00178   // TODO: remove or replace with stream ops
00179   void print(int depth);
00180 
00181   // TODO: remove or replace with stream ops
00182   void printCachedPage(int depth, int pageId);
00183 #endif
00184 
00186 
00187   //------------------------------------------------------
00189 
00190   //------------------------------------------------------
00191 
00193   MLErrorCode updateImageProperties();
00194 
00196 
00197 protected:
00199   friend class PageRequestCursor;
00200 
00206   PageRequest* createPageRequest(MLint pageId, PageRequestQueueInterface& queue);
00207 
00210   void         copyDataFromSubImg(SubImage& pageImage);
00211 
00213   void         sendTileRequestFinished(PageRequestQueueInterface& queue);
00214 
00216   SubImage _subImage;
00217 
00219   AllocationPolicy _allocationPolicy;
00220 
00222   ScaleShiftData _scaleShiftData;
00223 
00225   bool           _readOnlyInputTile;
00227   bool           _tileWillBecomeMemoryImage;
00228 
00230   PagedImage*  _image;
00231 
00233   MLint      _inputPagesNeeded;
00234 
00237   PageIDIterator _inputPageIds;
00238 
00240   MLint          _traversalCursorPosition;
00241 
00243   PageRequest*   _neededByPageRequest;
00244 
00246   MLErrorCode    _error;
00247 
00249   TileRequestFinishedCB* _finishedCB;
00251   void*                  _finishedCBData;
00252 };
00253 
00254 ML_END_NAMESPACE
00255 
00256 #endif //of __mlTileRequest_H
00257