ML 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 
28 ML_START_NAMESPACE
29 
31 class Module;
32 class ThreadDataClass;
33 class ProcessAllPagesHandler;
34 class Host;
36 
39 {
40 
41 public:
42  ClassicHost(Host* host);
44 
45  //------------------------------------------------------
48  //------------------------------------------------------
49 
62  [[nodiscard]]
64  SubImageBox location,
65  MLDataType dataType,
66  void** data,
67  const ScaleShiftData& scaleShiftData=ScaleShiftData());
68 
70 
71  // ------------------------------------------------------------------------------
73  // ------------------------------------------------------------------------------
74  [[nodiscard]]
76  MLint outputIndex,
77  SubImageBox region,
78  ProcessAllPagesHandler* handler
79  );
80 
81  //----------------------------------------------------------------------------------------
83  //----------------------------------------------------------------------------------------
85 
87  void enableTimeLineProfiling(bool flag) { _useTimeLineProfiling = flag; }
88 
90  ProcessingTimeLine& getProcessingTimeLine() { return _profile; }
91 
92 protected:
93 
94  // ------------------------------------------------------------------------------
107  // ------------------------------------------------------------------------------
108  [[nodiscard]]
110  const SubImageBox &location,
111  MLDataType dataType,
112  void *data,
113  const ScaleShiftData &scaleShiftData,
114  bool calledByProcessAllPages);
115 
117 
118 
121  [[nodiscard]]
123  SubImageBox location,
124  MLDataType dataType,
125  void *data,
126  const ScaleShiftData &scaleShiftData);
127 
128  //------------------------------------------------------
131  //------------------------------------------------------
132 
135 
154  void _calcPages(PagedImage &outputImage,
155  const std::vector <MLint> pageIDs,
156  MLMemoryBlockHandle* memoryBlockHandles);
158 
159  //----------------------------------------------------------------------------------------
164  //----------------------------------------------------------------------------------------
165  void _initializePageData(ThreadDataClass &tData, bool permitInCaching);
166 
167  //----------------------------------------------------------------------------------------
171  //----------------------------------------------------------------------------------------
172  static void _calcPagesMT(ThreadDataClass** threadDataContainers, ProcessingTimeLine::TimeLine* timeLine);
173 
175  friend struct CalcPagesWorkerThreadFunction;
176 
177  //----------------------------------------------------------------------------------------
179  //----------------------------------------------------------------------------------------
180  ThreadDataClass** _getWorkForWorkerThread(size_t workIndex);
181 
182  //----------------------------------------------------------------------------------------
184  //----------------------------------------------------------------------------------------
186 
187  //------------------------------------------------------
190  //------------------------------------------------------
191 
194 
197 
200 
202  std::vector<Thread*> _workerThreads;
203 
205  std::vector<ThreadDataClass**> _workerThreadClassData;
206 
209 
213 
216 
219 
222 
225 
228 
231 
232  std::vector<ProcessingTimeLine::TimeLine*> _workerThreadTimeLines;
234 
236 
237 };
238 
239 ML_END_NAMESPACE
240 
241 #endif
242 
243 
244 
The strong handle of a MLMemoryBlock.
Classic ML host used internally to calculate getTile and processAllPages requests.
Definition: mlClassicHost.h:39
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 _useTimeLineProfiling
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.
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 that are 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)
Enables timeline profiling.
Definition: mlClassicHost.h:87
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 & getProcessingTimeLine()
Returns access to the processing timeline.
Definition: mlClassicHost.h:90
ProcessingTimeLine _profile
ProcessingTimeLine::TimeLine * _guiTimeLine
void _increaseErrorCounter()
Increases the error counter (thread-safe).
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 a 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
The class PagedImage, representing a fragmented image that manages properties and data of an image lo...
Definition: mlPagedImage.h:66
Base class for handlers that are used for the Module::processAllPages facility.
Timeline for a single thread.
Stores a processing timeline 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.
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
TScaleShiftData< MLdouble > ScaleShiftData
Double version of TScaleShiftData for maximum reasonable precision.