MeVisLab Toolbox Reference
mlHost.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2007, 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_HOST_H
14 #define ML_HOST_H
15 
26 
27 //ML-includes
28 #include "mlInitSystemML.h"
29 #include "mlPagedImage.h"
30 #include "mlSubImage.h"
31 #include "mlFields.h"
32 #include "mlWaitCondition.h"
33 #include "mlThread.h"
34 
35 ML_START_NAMESPACE
36 
38 class Module;
39 class ThreadDataClass;
40 class ProcessAllPagesHandler;
41 class ClassicHost;
42 class PageRequestProcessorBase;
43 class PageRequestProcessor;
44 class ProcessingTimeLine;
45 class GetTileJobBase;
47 
49 #define ML_HOST_UPDATE_PROGRESS_INTERVAL 0.3
50 
51 //-------------------------------------------------------------------------
113 //-------------------------------------------------------------------------
115 {
116 
117 public:
118 
119  friend class PageRequestProcessor;
122  friend class ClassicHost;
123 
124  //------------------------------------------------------
127  //------------------------------------------------------
131 
135  Host();
136 
138  virtual ~Host();
140 
141  //--- Progress Callback
143  void setProgressCB(void *userData, MLHostProgressCB *callback);
144 
147 
149  void *getProgressCBUserData() const;
150 
157  void updateProgress(const char* info1, const char* info2);
158 
159  //--- Break check callback
161  void setBreakCheckCB(void *userData, MLHostBreakCheckCB *callback);
162 
165 
167  void *getBreakCheckCBUserData() const;
168 
169 
172  bool shouldTerminate() const;
173 
179 
181  static Host &getDefaultHost();
182 
184  static void destroyDefaultHost();
185 
190  void setMaxNumThreads(MLint32 numThreads);
191 
194 
200 
202  MLint32 getRestrictMaxNumThreads() const { return _restrictMaxNumThreads; }
203 
206 
207 protected:
211 
216 
217 public:
218  //------------------------------------------------------
221  //------------------------------------------------------
222 
246  [[nodiscard]]
248  SubImageBox location,
249  MLDataType dataType,
250  void** data,
251  const ScaleShiftData& scaleShiftData = ScaleShiftData(),
252  MLRequestProgressCB* progressCallback = nullptr,
253  void* progressCallbackUserData = nullptr);
254 
282  [[nodiscard]]
284  SubImage& subImage,
285  const ScaleShiftData& scaleShiftData = ScaleShiftData(),
286  MLRequestProgressCB* progressCallback = nullptr,
287  void* progressCallbackUserData = nullptr);
288 
292  void freeTile(void* data);
294 
295  //---------------------------------------------------------------------------
298  //---------------------------------------------------------------------------
301  //---------------------------------------------------------------------------
302  [[nodiscard]]
304  MLint outputIndex,
305  SubImageBox region = SubImageBox(),
306  MLRequestProgressCB* progressCallback = nullptr,
307  void* progressCallbackUserData = nullptr);
308 
309  //------------------------------------------------------------------------------
313  //------------------------------------------------------------------------------
314  [[nodiscard]]
316  ProcessAllPagesHandler& handler,
317  SubImageBox region=SubImageBox(),
318  MLRequestProgressCB* progressCallback = nullptr,
319  void* progressCallbackUserData = nullptr);
320 
321  //------------------------------------------------------------------------------
324  //------------------------------------------------------------------------------
325  [[nodiscard]]
327  MLRequestProgressCB* progressCallback = nullptr,
328  void* progressCallbackUserData = nullptr);
329 
330 
331  //-------------------------------------------------------------------------------------------------
338  [[nodiscard]]
340  MLRequestProgressCB* progressCallback = nullptr,
341  void* progressCallbackUserData = nullptr);
342 
343  //-------------------------------------------------------------------------------------------------
350  [[nodiscard]]
351  MLErrorCode processAllPagesWithInputImages(const std::vector<PagedImage*>& inputImages, ProcessAllPagesHandler& handler, const SubImageBox& region= SubImageBox(),
352  MLRequestProgressCB* progressCallback = nullptr,
353  void* progressCallbackUserData = nullptr);
354 
356 
357  //------------------------------------------------------
360  //------------------------------------------------------
361 
370  [[nodiscard]]
372 
379  [[nodiscard]]
382 
384  static inline unsigned int getMemoryManagerId() { return _memoryManagerId; }
385 
388  static SubImageBox calculateInputSubImageBoxDebug(Module& module, int inIndex, const SubImageBox& outputSubImageBox, int outputIndex);
389 
391  ClassicHost* getClassicHostDebug() { return _classicHost; }
392 
394  void setUseClassicHost(bool flag);
395 
397  bool getUseClassicHost() const { return _useClassicMLHost; }
398 
401 
404 
406  void enableTimeLineProfiling(bool flag);
407 
408 #if ML_DEPRECATED_SINCE(3,5,0)
409 
412 
413 public:
414 
417  [[nodiscard]]
418  ML_DEPRECATED MLErrorCode getTile(Module &op,
419  MLint outIndex,
420  SubImageBox loc,
421  MLDataType dataType,
422  void **data,
423  const ScaleShiftData &scaleShiftData=ScaleShiftData());
426  [[nodiscard]]
427  ML_DEPRECATED MLErrorCode getTile(Module &op,
428  MLint outIndex,
429  SubImage &subImg,
430  const ScaleShiftData &scaleShiftData=ScaleShiftData());
433  [[nodiscard]]
434  inline ML_DEPRECATED MLErrorCode updateImageProps(Module &op, MLint outIndex) { return updateImageProperties(op, outIndex); }
435 
438  inline static ML_DEPRECATED SubImageBox calcInSubImageBoxDebug(Module& module,
439  int inIndex,
440  const SubImageBox& outSubImgBox,
441  int outIndex)
442  {
443  return calculateInputSubImageBoxDebug(module, inIndex, outSubImgBox, outIndex);
444  }
445 
446 #endif
447 
448 
449 private:
451 
452  // ------------------------------------------------------------------------------
454  // ------------------------------------------------------------------------------
455  [[nodiscard]]
456  MLErrorCode _processAllPages(Module& module,
457  MLint outputIndex,
458  SubImageBox region,
459  ProcessAllPagesHandler* handler,
460  bool clearPages = true,
461  MLRequestProgressCB* progressCallback = nullptr,
462  void* progressCallbackUserData = nullptr);
463 
467  MLErrorCode _requiredTypesRegisteredAndSupported(PagedImage* outputImage);
468 
472  [[nodiscard]]
473  MLErrorCode _updateImageProperties(PagedImage* outputImage);
474 
480  bool tryDirectCacheAccess(PagedImage& inImage, const SubImageBox& box, MLDataType dataType, const ScaleShiftData& scaleShiftData, void** data, MLErrorCode& resultCode);
481 
482  //------------------------------------------------------
485  //------------------------------------------------------
487  void* _userData;
488 
490  MLHostProgressCB* _progressCB;
491 
493  bool _insideUpdateProgress;
494 
496  GetTileJobBase* _currentTopLevelRequest;
497 
499  void* _breakCheckUserData;
500 
502  MLHostBreakCheckCB* _breakCheckCB;
503 
505  MLint32 _maxNumThreads;
506 
508  MLint32 _restrictMaxNumThreads;
509 
511  MLuint32 _isProcessingActive;
512 
515  static unsigned int _memoryManagerId;
516 
518  static Host* _instance;
519 
521  ClassicHost* _classicHost;
522 
524  PageRequestProcessorBase* _processor;
525 
526  bool _useClassicMLHost;
527 
528 #ifdef MACOS
529  // Actual type is: os_log_t
530  void* _splog;
531 #endif
532 
534 
535 }; //End of class Host
536 
537 ML_END_NAMESPACE
538 
539 //-----------------------------------------------------------------------------------
540 // Stream output for std::ostream
541 //-----------------------------------------------------------------------------------
542 namespace std {
543 
545  MLEXPORT ostream& operator<<(ostream& s, const ML_NAMESPACE::Host &host);
546 
547 }
548 
549 #endif //of __mlHost_H
#define ML_DEPRECATED
Definition: CSOGroup.h:371
Classic ML host used internally to calculate getTile and processAllPages requests.
Definition: mlClassicHost.h:39
Base class for all fields used in the ML.
Definition: mlField.h:73
The Host is the central image processing class in the ML.
Definition: mlHost.h:115
MLErrorCode processAllPages(Module &module, ProcessAllPagesHandler &handler, SubImageBox region=SubImageBox(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
Processes input images with a ProcessAllPagesHandler on a temporary output image (which allocates no ...
void setMaxNumThreads(MLint32 numThreads)
Sets maximum number of permitted worker threads to numThreads.
MLErrorCode getTile(PagedImage &outputImage, SubImage &subImage, const ScaleShiftData &scaleShiftData=ScaleShiftData(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
Requests the image region subImage.getBox() from output image outputImage.
static void registerWithMemoryManager()
Registers the Host as library using the memory manager and initializes the memory manager id.
Host()
Constructor.
bool shouldTerminate() const
Checks if current calculation should be terminated.
MLErrorCode processAllPagesWithInputImage(PagedImage &inputImage, ProcessAllPagesHandler &handler, const SubImageBox &region=SubImageBox(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
Processes all pages as specified by the handler using inputImage as single input.
MLint32 getMaxNumThreads() const
Returns maximum number of permitted worker threads.
bool getUseClassicHost() const
Returns if classic ML host is used.
Definition: mlHost.h:397
MLHostProgressCB * getProgressCB() const
Returns current callback for progress/busy cursor updates.
void * getBreakCheckCBUserData() const
Returns user data of current callback for break checking.
void _unsetProcessingActive()
Disables the flag that indicates active image processing.
void _setProcessingActive()
Enables the flag that indicates active image processing.
void enableTimeLineProfiling(bool flag)
Enable/disable time line profiling.
ClassicHost * getClassicHostDebug()
Get access to classic ML host (for debugging purposes only!)
Definition: mlHost.h:391
void freeTile(void *data)
Frees (image) memory which has been allocated with any getTile() function of the Host class.
MLErrorCode updateImageProperties(Module &module, MLint outputIndex)
/deprecated Updates the module graph under module and including the output image at outputIndex of mo...
void setUseClassicHost(bool flag)
Enable/disable usage of classic ML host.
static unsigned int getMemoryManagerId()
Returns the memory manager id that is used for allocation of memory by the ML.
Definition: mlHost.h:384
MLErrorCode processMissingPages(Module &module, MLint outputIndex, SubImageBox region=SubImageBox(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
See Module::processMissingPages() for details on this method.
PageRequestProcessor * getPageRequestProcessor()
Get the currently responsible page request processor.
void updateProgress(const char *info1, const char *info2)
Calls the busy cursor/progress callback if it is set.
static SubImageBox calculateInputSubImageBoxDebug(Module &module, int inIndex, const SubImageBox &outputSubImageBox, int outputIndex)
This is a method that allows access to the (otherwise protected) calculateInputSubImageBox of a modul...
MLErrorCode processAllPagesWithInputImages(const std::vector< PagedImage * > &inputImages, ProcessAllPagesHandler &handler, const SubImageBox &region=SubImageBox(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
Processes all pages as specified by the handler using inputImages as inputs.
void setBreakCheckCB(void *userData, MLHostBreakCheckCB *callback)
Sets callback for break checking.
void * getProgressCBUserData() const
Returns user data of current callback for progress/busy cursor updates.
ProcessingTimeLine & getProcessingTimeLine()
Get access to the processing time line.
void setProgressCB(void *userData, MLHostProgressCB *callback)
Sets callback for progress/busy cursor updates.
Field * getPressedNotifyField()
Checks if a notify button was pressed (outside of normal notification) It returns the notify field or...
static void destroyDefaultHost()
Destroys and cleans up allocated memory of default Host.
static Host & getDefaultHost()
Return a reference to the Host singleton.
MLErrorCode getTile(PagedImage &outputImage, SubImageBox location, MLDataType dataType, void **data, const ScaleShiftData &scaleShiftData=ScaleShiftData(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
Requests the image region location from the image outputImage.
virtual ~Host()
Destructor.
void setRestrictMaxNumThreads(MLint32 numThreads)
Restricts the maximum number of permitted worker threads to be lower or equal to numThreads.
MLint32 getRestrictMaxNumThreads() const
Get the restriction for setMaxNumThreads().
Definition: mlHost.h:202
MLuint32 isProcessingActive() const
Non-zero return values mean that (image) processing is currently active.
MLErrorCode updateImageProperties(PagedImage &outputImage)
Updates the module graph under outputImage->getModule() and including outputImage.
MLHostBreakCheckCB * getBreakCheckCB() const
Returns current callback for break checking.
MLErrorCode processAllPages(Module &module, MLint outputIndex, SubImageBox region=SubImageBox(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
See Module::processAllPages() for details on this method.
Base class for an image processing module of the ML.
Definition: mlModule.h:156
A multi-threaded processor that takes one or even multiple tile requests and can process them iterati...
Abstract base class for page request processors.
Class which represents an image, which manages properties of an image and image data which is located...
Definition: mlPagedImage.h:70
Base class for handlers that are used for the Module::processAllPages facility.
Stores a processing time line for multiple threads.
A single-threaded processor that takes one or even multiple tile requests and can process them iterat...
This class manages/represents a rectangular 6d image region which is organized linearly in memory.
Definition: mlSubImage.h:75
#define ML_DISALLOW_COPY_AND_ASSIGN(className)
Defines basic macros.
Definition: mlMacros.h:23
MLint32 MLDataType
MLDataType.
Definition: mlTypeDefs.h:684
MLint32 MLErrorCode
Type of an ML Error code.
Definition: mlTypeDefs.h:818
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator "<<" for stream output of Field objects.
#define MLEXPORT
To export symbols from a dll/shared object, we need to mark them with the MLEXPORT symbol.
MLint32 MLHostBreakCheckCB(void *usrData, void **hitField)
Definition: mlTypeDefs.h:1317
unsigned int MLuint32
Definition: mlTypeDefs.h:191
void MLRequestProgressCB(void *usrData, double progress)
Definition: mlTypeDefs.h:1318
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
signed int MLint32
Definition: mlTypeDefs.h:167
void MLHostProgressCB(void *usrData, const char *info1, const char *info2)
Definition: mlTypeDefs.h:1316
TScaleShiftData< MLdouble > ScaleShiftData
Double version of TScaleShiftData for maximum reasonable precision.
TSubImageBox< MLint > SubImageBox
Define the standard SubImageBox type used in the ML. Its size varies with the size of the MLint type.