MeVisLab Toolbox Reference
mlClassicHost.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_CLASSIC_HOST_H
14#define ML_CLASSIC_HOST_H
15
19
20//ML-includes
21#include "mlInitSystemML.h"
22#include "mlPagedImage.h"
23#include "mlWaitCondition.h"
24#include <mlThread.h>
25
27
29
31class Module;
32class ThreadDataClass;
33class ProcessAllPagesHandler;
34class Host;
36
39{
40
41public:
44
45 //------------------------------------------------------
48 //------------------------------------------------------
49
62 [[nodiscard]]
64 SubImageBox location,
65 MLDataType dataType,
66 void** data,
68
70
71 // ------------------------------------------------------------------------------
73 // ------------------------------------------------------------------------------
74 [[nodiscard]]
79 );
80
81 //----------------------------------------------------------------------------------------
83 //----------------------------------------------------------------------------------------
85
87 void enableTimeLineProfiling(bool flag) { _useTimeLineProfiling = flag; }
88
91
92protected:
93
94 // ------------------------------------------------------------------------------
109 // ------------------------------------------------------------------------------
110 [[nodiscard]]
112 const SubImageBox &location,
113 MLDataType dataType,
114 void *data,
117
119
120
123 [[nodiscard]]
125 SubImageBox location,
126 MLDataType dataType,
127 void *data,
129
130 //------------------------------------------------------
133 //------------------------------------------------------
134
137
157 const std::vector <MLint> pageIDs,
160
161 //----------------------------------------------------------------------------------------
166 //----------------------------------------------------------------------------------------
168
169 //----------------------------------------------------------------------------------------
173 //----------------------------------------------------------------------------------------
175
177 friend struct CalcPagesWorkerThreadFunction;
178
179 //----------------------------------------------------------------------------------------
181 //----------------------------------------------------------------------------------------
183
184 //----------------------------------------------------------------------------------------
186 //----------------------------------------------------------------------------------------
188
189 //------------------------------------------------------
192 //------------------------------------------------------
193
196
199
202
204 std::vector<Thread*> _workerThreads;
205
207 std::vector<ThreadDataClass**> _workerThreadClassData;
208
211
215
218
221
224
227
230
233
234 std::vector<ProcessingTimeLine::TimeLine*> _workerThreadTimeLines;
236
238
239};
240
242
243#endif
244
245
246
The strong handle of a MLMemoryBlock.
Classic ML host used internally to calculate getTile and processAllPages requests.
WaitCondition _workAvailable
A wait condition to signal waiting worker threads that there is more work to be done.
WaitCondition _workDone
A wait condition that signals that all threads have done their work.
MLErrorCode _processPagesHelper(PagedImage &outputImage, const SubImageBox &location, MLDataType dataType, void *data, const ScaleShiftData &scaleShiftData, bool calledByProcessAllPages)
Helper function doing the real page processing work for processAllPages or getTile methods.
std::vector< ThreadDataClass ** > _workerThreadClassData
The offset into the current ThreadDataClass array, sorted by worker threads.
ClassicHost(Host *host)
static void _calcPagesMT(ThreadDataClass **threadDataContainers, ProcessingTimeLine::TimeLine *timeLine)
Calculates a sequence of output pages where each one has a set of input pages.
bool _shutdownWorkerThreadsFlag
Flag that signals that the worker threads should shutdown.
size_t _maxNumPagesToCalculateInSingleWorkerThread
The maximum number of pages that a single worker thread will calculate.
MLErrorCode getTile(PagedImage &outputImage, SubImageBox location, MLDataType dataType, void **data, const ScaleShiftData &scaleShiftData=ScaleShiftData())
Requests the image region location from the image outputImage.
ProcessingTimeLine & getProcessingTimeLine()
Get access to the processing time line.
void shutdownWorkerThreads()
Shuts down and frees all worker threads (all threads are joined when this method returns).
std::vector< Thread * > _workerThreads
The worker threads that are currently started.
MLint32 _errorCounter
Counter for errors detected in calcPagesMT, usually in different threads. Only valid during thread ca...
std::vector< ProcessingTimeLine::TimeLine * > _workerThreadTimeLines
Mutex _workAvailableMutex
Mutex that protects the work assignment to the worker threads.
MLErrorCode processAllPages(Module &module, MLint outputIndex, SubImageBox region, ProcessAllPagesHandler *handler)
Internal implementation of processAllPages functionality.
void _initializePageData(ThreadDataClass &tData, bool permitInCaching)
Initializes the buffer tData with all settings which is needed to compute one output page.
void _calcPages(PagedImage &outputImage, const std::vector< MLint > pageIDs, MLMemoryBlockHandle *memoryBlockHandles)
For the output image outputImage, all invalid pages with numbers given by pageIDs are calculated.
void enableTimeLineProfiling(bool flag)
Enable time line profiling.
Host * _host
The core host.
MLint32 _numLaunchedThreads
Counter for the number of really launched threads. Only valid during thread calculations.
ThreadDataClass ** _getWorkForWorkerThread(size_t workIndex)
Returns the work for worker thread with workIndex.
MLint32 _numFinishedThreads
Counter for the number of already finished threads. Only valid during thread calculations.
ProcessingTimeLine _profile
ProcessingTimeLine::TimeLine * _guiTimeLine
void _increaseErrorCounter()
Increases the error counter (threadsafe).
MLErrorCode _getTileCore(PagedImage &outputImage, SubImageBox location, MLDataType dataType, void *data, const ScaleShiftData &scaleShiftData)
Core of the getTile method: It fills a chunk of memory assuming that it has the correct size.
Mutex _countSyncMutex
A mutex used at many position for safe manipulations of members in the host instance by threads.
The Host is the central image processing class in the ML.
Definition mlHost.h:115
Base class for an image processing module of the ML.
Definition mlModule.h:151
Class which represents an image, which manages properties of an image and image data which is located...
Base class for handlers that are used for the Module::processAllPages facility.
Timeline for a single thread.
Stores a processing time line for multiple threads.
WaitCondition implements a wait condition for thread synchronization.
#define ML_DISALLOW_COPY_AND_ASSIGN(className)
Defines basic macros.
Definition mlMacros.h:23
MLint32 MLDataType
MLDataType.
Definition mlTypeDefs.h:596
MLint32 MLErrorCode
Type of an ML Error code.
Definition mlTypeDefs.h:716
boost::mutex Mutex
Defines a non-recursive mutex.
Definition mlMutex.h:39
#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.
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition mlTypeDefs.h:490
signed int MLint32
Definition mlTypeDefs.h:161