MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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#include <mlModule.h>
35
37
39class Module;
40class ThreadDataClass;
41class ProcessAllPagesHandler;
42class ClassicHost;
43class PageRequestProcessorBase;
44class PageRequestProcessor;
45class ProcessingTimeLine;
46class GetTileJobBase;
48
50#define ML_HOST_UPDATE_PROGRESS_INTERVAL 0.3
51
52//-------------------------------------------------------------------------
114//-------------------------------------------------------------------------
116{
117
118public:
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
203 {
204 return _restrictMaxNumThreads;
205 }
206
209
210protected:
214
219
220public:
221 //------------------------------------------------------
224 //------------------------------------------------------
225
249 [[nodiscard]]
253
281 [[nodiscard]]
285
289 void freeTile(void* data);
291
292 //---------------------------------------------------------------------------
295 //---------------------------------------------------------------------------
298 //---------------------------------------------------------------------------
299 [[nodiscard]]
302 void* progressCallbackUserData = nullptr);
303
304 //------------------------------------------------------------------------------
308 //------------------------------------------------------------------------------
309 [[nodiscard]]
312 void* progressCallbackUserData = nullptr);
313
314 //------------------------------------------------------------------------------
317 //------------------------------------------------------------------------------
318 [[nodiscard]]
321 void* progressCallbackUserData = nullptr);
322
323
324 //-------------------------------------------------------------------------------------------------
331 [[nodiscard]]
333 const SubImageBox& region = SubImageBox(),
335 void* progressCallbackUserData = nullptr);
336
337 //-------------------------------------------------------------------------------------------------
344 [[nodiscard]]
348 void* progressCallbackUserData = nullptr);
349
351
352 //------------------------------------------------------
355 //------------------------------------------------------
356
365 [[deprecated("Use updateImageProperties() with PagedImage instead.")]]
367 {
368 if ((outputIndex < 0) || (outputIndex >= module.getNumOutputImages())) {
370 }
371 else {
372 return updateImageProperties(module.getOutputImage(outputIndex));
373 }
374 }
375
377
384 [[nodiscard]]
387
389 static inline unsigned int getMemoryManagerId()
390 {
391 return _memoryManagerId;
392 }
393
397 int outputIndex);
398
401 {
402 return _classicHost;
403 }
404
407
409 bool getUseClassicHost() const
410 {
411 return _useClassicMLHost;
412 }
413
416
419
422
423private:
425
426 // ------------------------------------------------------------------------------
428 // ------------------------------------------------------------------------------
429 [[nodiscard]]
430 MLErrorCode _processAllPages(Module& module, MLint outputIndex, SubImageBox region, ProcessAllPagesHandler* handler,
431 bool clearPages = true, MLRequestProgressCB* progressCallback = nullptr,
432 void* progressCallbackUserData = nullptr);
433
437 MLErrorCode _requiredTypesRegisteredAndSupported(PagedImage* outputImage);
438
442 [[nodiscard]]
443 MLErrorCode _updateImageProperties(PagedImage* outputImage);
444
450 bool tryDirectCacheAccess(PagedImage& inImage, const SubImageBox& box, MLDataType dataType,
452
453 //------------------------------------------------------
456 //------------------------------------------------------
458 void* _userData;
459
461 MLHostProgressCB* _progressCB;
462
464 bool _insideUpdateProgress;
465
467 GetTileJobBase* _currentTopLevelRequest;
468
470 void* _breakCheckUserData;
471
473 MLHostBreakCheckCB* _breakCheckCB;
474
476 MLint32 _maxNumThreads;
477
479 MLint32 _restrictMaxNumThreads;
480
482 MLuint32 _isProcessingActive;
483
486 static unsigned int _memoryManagerId;
487
489 static Host* _instance;
490
492 ClassicHost* _classicHost;
493
495 PageRequestProcessorBase* _processor;
496
497 bool _useClassicMLHost;
498
500
501}; // End of class Host
502
504
505//-----------------------------------------------------------------------------------
506// Stream output for std::ostream
507//-----------------------------------------------------------------------------------
508namespace std
509{
510
512 MLEXPORT ostream& operator<<(ostream& s, const ML_NAMESPACE::Host& host);
513
514} // namespace std
515
516#endif // of __mlHost_H
Classic ML host used internally to calculate getTile and processAllPages requests.
Base class for all fields used in the ML.
Definition mlField.h:73
Base class for TileRequest based jobs.
The Host is the central image processing class in the ML.
Definition mlHost.h:116
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.
ProcessingTimeLine & getProcessingTimeLine()
Returns access to the processing timeline.
static void registerWithMemoryManager()
Registers the Host as library using the memory manager and initializes the memory manager ID.
Host()
Constructor.
Field * getPressedNotifyField()
Checks whether a notify button was pressed (outside of normal notification).
bool shouldTerminate() const
Checks whether the 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.
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:409
MLHostProgressCB * getProgressCB() const
Returns current callback for progress/busy cursor updates.
MLHostBreakCheckCB * getBreakCheckCB() const
Returns the 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)
Enables/disables timeline profiling.
void freeTile(void *data)
Frees (image) memory that 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...
Definition mlHost.h:366
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:389
MLErrorCode processMissingPages(Module &module, MLint outputIndex, SubImageBox region=SubImageBox(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
See Module::processMissingPages() for details on this method.
ClassicHost * getClassicHostDebug()
Returns access to the classic ML host (for debugging purposes only!).
Definition mlHost.h:400
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.
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.
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)
Requests the image region location from the image outputImage.
MLErrorCode updateImageProperties(PagedImage *outputImage)
virtual ~Host()
Destructor.
void setRestrictMaxNumThreads(MLint32 numThreads)
Restricts the maximum number of permitted worker threads to be less or equal to 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)
Updates the module graph under outputImage->getModule() and including outputImage.
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:150
PagedImage * getOutputImage(MLint outputIndex=0) const
Returns the output image outputIndex. The index needs to be in the range [0, getNumOutputImages()-1].
MLint getNumOutputImages() const
Returns the number of output images of this module.
A multithreaded processor that takes one or even multiple tile requests and can process them iterativ...
Base class for single and multithreaded processor.
Abstract base class for page request processors.
The class PagedImage, representing a fragmented image that manages properties and data of an image lo...
Base class for handlers that are used for the Module::processAllPages facility.
Stores a processing timeline 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 that is organized linearly in memory.
Definition mlSubImage.h:75
#define ML_DISALLOW_COPY_AND_ASSIGN(className)
Defines basic macros.
Definition mlMacros.h:21
MLint32 MLDataType
MLDataType.
Definition mlTypeDefs.h:592
MLint32 MLErrorCode
Type of an ML Error code.
Definition mlTypeDefs.h:772
#define ML_BAD_OPERATOR_OUTPUT_INDEX
A bad output number of a module/operator has been specified.
Definition mlTypeDefs.h:804
#define MLEXPORT
To export symbols from a DLL/shared object, we need to mark them with the MLEXPORT symbol.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
MLint32 MLHostBreakCheckCB(void *usrData, void **hitField)
unsigned int MLuint32
Definition mlTypeDefs.h:185
void MLRequestProgressCB(void *usrData, double progress)
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition mlTypeDefs.h:489
signed int MLint32
Definition mlTypeDefs.h:161
void MLHostProgressCB(void *usrData, const char *info1, const char *info2)
STL namespace.
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator '<<' for stream output of Field objects.