ML 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
35ML_START_NAMESPACE
36
38class Module;
39class ThreadDataClass;
40class ProcessAllPagesHandler;
41class ClassicHost;
42class PageRequestProcessorBase;
43class PageRequestProcessor;
44class ProcessingTimeLine;
45class GetTileJobBase;
47
49#define ML_HOST_UPDATE_PROGRESS_INTERVAL 0.3
50
51//-------------------------------------------------------------------------
113//-------------------------------------------------------------------------
115{
116
117public:
118
122 friend class ClassicHost;
123
124 //------------------------------------------------------
127 //------------------------------------------------------
131
136
138 virtual ~Host();
140
141 //--- Progress Callback
143 void setProgressCB(void *userData, MLHostProgressCB *callback);
144
147
150
157 void updateProgress(const char* info1, const char* info2);
158
159 //--- Break check callback
161 void setBreakCheckCB(void *userData, MLHostBreakCheckCB *callback);
162
165
168
169
172 bool shouldTerminate() const;
173
179
182
184 static void destroyDefaultHost();
185
190 void setMaxNumThreads(MLint32 numThreads);
191
194
200
202 MLint32 getRestrictMaxNumThreads() const { return _restrictMaxNumThreads; }
203
206
207protected:
211
216
217public:
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
408private:
410
411 // ------------------------------------------------------------------------------
413 // ------------------------------------------------------------------------------
414 [[nodiscard]]
415 MLErrorCode _processAllPages(Module& module,
416 MLint outputIndex,
417 SubImageBox region,
418 ProcessAllPagesHandler* handler,
419 bool clearPages = true,
420 MLRequestProgressCB* progressCallback = nullptr,
421 void* progressCallbackUserData = nullptr);
422
426 MLErrorCode _requiredTypesRegisteredAndSupported(PagedImage* outputImage);
427
431 [[nodiscard]]
432 MLErrorCode _updateImageProperties(PagedImage* outputImage);
433
439 bool tryDirectCacheAccess(PagedImage& inImage, const SubImageBox& box, MLDataType dataType, const ScaleShiftData& scaleShiftData, void** data, MLErrorCode& resultCode);
440
441 //------------------------------------------------------
444 //------------------------------------------------------
446 void* _userData;
447
449 MLHostProgressCB* _progressCB;
450
452 bool _insideUpdateProgress;
453
455 GetTileJobBase* _currentTopLevelRequest;
456
458 void* _breakCheckUserData;
459
461 MLHostBreakCheckCB* _breakCheckCB;
462
464 MLint32 _maxNumThreads;
465
467 MLint32 _restrictMaxNumThreads;
468
470 MLuint32 _isProcessingActive;
471
474 static unsigned int _memoryManagerId;
475
477 static Host* _instance;
478
480 ClassicHost* _classicHost;
481
483 PageRequestProcessorBase* _processor;
484
485 bool _useClassicMLHost;
486
488
489}; //End of class Host
490
491ML_END_NAMESPACE
492
493//-----------------------------------------------------------------------------------
494// Stream output for std::ostream
495//-----------------------------------------------------------------------------------
496namespace std {
497
499 MLEXPORT ostream& operator<<(ostream& s, const ML_NAMESPACE::Host &host);
500
501}
502
503#endif //of __mlHost_H
Base class for TileRequest based jobs.
MLErrorCode processAllPages(Module &module, ProcessAllPagesHandler &handler, SubImageBox region=SubImageBox(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
void setMaxNumThreads(MLint32 numThreads)
MLErrorCode getTile(PagedImage &outputImage, SubImage &subImage, const ScaleShiftData &scaleShiftData=ScaleShiftData(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
friend class PageRequestProcessor
Definition mlHost.h:119
ProcessingTimeLine & getProcessingTimeLine()
Returns access to the processing timeline.
static void registerWithMemoryManager()
Field * getPressedNotifyField()
bool shouldTerminate() const
MLErrorCode processAllPagesWithInputImage(PagedImage &inputImage, ProcessAllPagesHandler &handler, const SubImageBox &region=SubImageBox(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
void * getProgressCBUserData() const
Returns user data of current callback for progress/busy cursor updates.
MLint32 getMaxNumThreads() const
Returns the maximum number of permitted worker threads.
void * getBreakCheckCBUserData() const
Returns user data of the current callback for break checking.
bool getUseClassicHost() const
Returns whether the classic ML host is used.
Definition mlHost.h:397
MLHostProgressCB * getProgressCB() const
Returns current callback for progress/busy cursor updates.
MLHostBreakCheckCB * getBreakCheckCB() const
Returns the current callback for break checking.
void _unsetProcessingActive()
void _setProcessingActive()
void enableTimeLineProfiling(bool flag)
Enables/disables timeline profiling.
void freeTile(void *data)
MLErrorCode updateImageProperties(Module &module, MLint outputIndex)
void setUseClassicHost(bool flag)
Enables/disables usage of the 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
friend class ClassicHost
Definition mlHost.h:122
MLErrorCode processMissingPages(Module &module, MLint outputIndex, SubImageBox region=SubImageBox(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
ClassicHost * getClassicHostDebug()
Returns access to the classic ML host (for debugging purposes only!).
Definition mlHost.h:391
void updateProgress(const char *info1, const char *info2)
static SubImageBox calculateInputSubImageBoxDebug(Module &module, int inIndex, const SubImageBox &outputSubImageBox, int outputIndex)
MLErrorCode processAllPagesWithInputImages(const std::vector< PagedImage * > &inputImages, ProcessAllPagesHandler &handler, const SubImageBox &region=SubImageBox(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
void setBreakCheckCB(void *userData, MLHostBreakCheckCB *callback)
Sets callback for break checking.
PageRequestProcessor * getPageRequestProcessor()
Returns the currently responsible page request processor.
static Host & getDefaultHost()
Returns a reference to the Host singleton.
void setProgressCB(void *userData, MLHostProgressCB *callback)
Sets callback for progress/busy cursor updates.
friend class MultiThreadedPageRequestProcessor
Definition mlHost.h:121
static void destroyDefaultHost()
Destroys and cleans up allocated memory of default Host.
MLErrorCode getTile(PagedImage &outputImage, SubImageBox location, MLDataType dataType, void **data, const ScaleShiftData &scaleShiftData=ScaleShiftData(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
friend class SingleThreadedPageRequestProcessor
Definition mlHost.h:120
virtual ~Host()
Destructor.
void setRestrictMaxNumThreads(MLint32 numThreads)
MLint32 getRestrictMaxNumThreads() const
Returns 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)
MLErrorCode processAllPages(Module &module, MLint outputIndex, SubImageBox region=SubImageBox(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
Base class for single and multithreaded processor.
Stores a processing timeline for multiple threads.
#define ML_DISALLOW_COPY_AND_ASSIGN(className)
Defines basic macros.
Definition mlMacros.h:21
MLint32 MLDataType
Definition mlTypeDefs.h:595
MLint32 MLErrorCode
Type of an ML Error code.
Definition mlTypeDefs.h:715
#define MLEXPORT
Code it as import symbol if compiled elsewhere.
MLint32 MLHostBreakCheckCB(void *usrData, void **hitField)
unsigned int MLuint32
Definition mlTypeDefs.h:184
void MLRequestProgressCB(void *usrData, double progress)
MLint64 MLint
Definition mlTypeDefs.h:489
signed int MLint32
Definition mlTypeDefs.h:160
void MLHostProgressCB(void *usrData, const char *info1, const char *info2)
TScaleShiftData< MLdouble > ScaleShiftData
Double version of TScaleShiftData for maximum reasonable precision.
TSubImageBox< MLint > SubImageBox
Defines the standard SubImageBox type used in the ML. Its size varies with the size of the MLint type...
STL namespace.
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator '<<' for stream output of Field objects.