MeVisLab Toolbox Reference
mlMemoryImage.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_MEMORY_IMAGE_H
14#define ML_MEMORY_IMAGE_H
15
18
19// ML-includes
20#include "mlInitSystemML.h"
21#include "mlRuntime.h"
22#include "mlRuntimeSubClass.h"
23#include "mlSubImage.h"
24
25#include <mlMetaProfilePtr.h>
26
27
29
31class MemoryImageCurrentlyUsedMemoryTracker;
32class Module;
33class PagedImage;
35
36//-------------------------------------------------------------------------
47//-------------------------------------------------------------------------
49{
50
51public:
52
53 //------------------------------------------------------
56 //------------------------------------------------------
58 inline MemoryImage() :
59 _subImg(),
60 _isValid(false),
61 _userControlled(false),
62 _calculationPending(false),
63 _calculationPendingProcessingScope(-1),
64 _currentlyUsedMemoryTracker(nullptr)
65 {
66 }
67
71
72
73 //------------------------------------------------------
76 //------------------------------------------------------
78 inline SubImage& getImage() { return _subImg; }
79
81 inline const SubImage& getImage() const { return _subImg; }
82
84 inline void setValid(bool valid)
85 {
86 Lock lock(_mutex);
87 _isValid = valid;
88 }
89
91 inline bool isValid() const { Lock lock(_mutex); return _isValid; }
92
95 inline MLint getSizeInBytes() const
96 {
97 return _subImg.getSizeInBytes();
98 }
99
113 {
114 _userControlled = userControlled;
115 }
116
119 inline bool isUserControlled() const
120 {
121 return _userControlled;
122 }
123
128 inline void setCalculationPending(bool flag, int processingScope = -1)
129 {
130 Lock lock(_mutex);
131 _calculationPending = flag;
132 _calculationPendingProcessingScope = processingScope;
133 }
134
137 inline bool isCalculationPending(int processingScope) const
138 {
139 Lock lock(_mutex);
140 return _calculationPending && (_calculationPendingProcessingScope == processingScope);
141 }
142
144 MLEXPORT std::string getAsString() const;
145
150
151 //-----------------------------------------------------------------------------
160 //-----------------------------------------------------------------------------
161 [[nodiscard]]
164 void* progressCallbackUserData = nullptr);
165
166 //-----------------------------------------------------------------------------
172 //-----------------------------------------------------------------------------
174
177
178private:
179 void updateProfilingData();
180
182 mutable Mutex _mutex;
183
185 SubImage _subImg;
186
188 bool _isValid;
189
191 bool _userControlled;
192
194 bool _calculationPending;
195
197 int _calculationPendingProcessingScope;
198
200 MemoryImageCurrentlyUsedMemoryTracker* _currentlyUsedMemoryTracker;
201
203 mutable MLMetaProfilePtr _metaProfilePtr;
204
205 friend class MemoryImageCurrentlyUsedMemoryTracker;
206};
207
208
210
211
212
213//-----------------------------------------------------------------------------------
214// Stream output for std::ostream
215//-----------------------------------------------------------------------------------
216namespace std {
217
219 inline ostream& operator<<(ostream& s, const ML_NAMESPACE::MemoryImage &mi)
220 {
221 return s << mi.getAsString().c_str();
222 }
223
224}
225
226
227#endif
228
229
230
The pointer is automatically reset when the metaprofile is destroyed.
A memory cache for the complete output image of an output connector.
void setUserControlled(bool userControlled)
Sets the control modes for the memory image to userControlled.
void setCalculationPending(bool flag, int processingScope=-1)
Sets a flag that the memory image is being calculated and that is is best to wait until the calculati...
MLEXPORT void updateWithSubImage(const SubImage &image)
Sets the memory image to the given image and clears the previous data.
MLEXPORT std::string getAsString() const
Returns an information string about memory image.
MLint getSizeInBytes() const
Returns the currently used size of memory image in bytes.
MemoryImage()
Defines a memory image that is always a member of a paged image with empty content.
MLEXPORT void clear()
Clears the memory image if it is handled by the ML.
virtual MLEXPORT ~MemoryImage()
Destructor. Cleans up allocated memory.
MLEXPORT MLErrorCode update(PagedImage *image, const SubImageBox &roi, MLDataType newDataType, MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
Updates the given image.
const SubImage & getImage() const
Returns a constant subimage representing the data.
MLEXPORT MLMetaProfilePtr & getMetaProfile() const
Returns the profiling metaprofile pointer.
bool isValid() const
Returns true if image contents is valid. Otherwise, false is returned.
SubImage & getImage()
Returns a subimage representing the data.
void setValid(bool valid)
If set to true, the image data is valid; otherwise, it is not valid.
bool isCalculationPending(int processingScope) const
Returns whether a calculation is pending on the given processingScope.
bool isUserControlled() const
Returns who controls the memory image.
The class PagedImage, representing a fragmented image that manages properties and data of an image lo...
This class manages/represents a rectangular 6D image region that is organized linearly in memory.
Definition mlSubImage.h:75
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.
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:490
std::ostream & operator<<(std::ostream &out, const ml::Variant &variant)
Definition mlVariant.h:210
boost::mutex::scoped_lock Lock
Defines a lock for locking a non-recursive mutex.
Definition mlMutex.h:41
STL namespace.