MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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 //------------------------------------------------------
55 //------------------------------------------------------
57 inline MemoryImage()
58 : _subImg()
59 , _isValid(false)
60 , _userControlled(false)
61 , _calculationPending(false)
62 , _calculationPendingProcessingScope(-1)
63 , _currentlyUsedMemoryTracker(nullptr)
64 {}
65
69
70
71 //------------------------------------------------------
74 //------------------------------------------------------
77 {
78 return _subImg;
79 }
80
82 inline const SubImage& getImage() const
83 {
84 return _subImg;
85 }
86
88 inline void setValid(bool valid)
89 {
90 Lock lock(_mutex);
91 _isValid = valid;
92 }
93
95 inline bool isValid() const
96 {
97 Lock lock(_mutex);
98 return _isValid;
99 }
100
103 inline MLint getSizeInBytes() const
104 {
105 return _subImg.getSizeInBytes();
106 }
107
121 {
122 _userControlled = userControlled;
123 }
124
127 inline bool isUserControlled() const
128 {
129 return _userControlled;
130 }
131
136 inline void setCalculationPending(bool flag, int processingScope = -1)
137 {
138 Lock lock(_mutex);
139 _calculationPending = flag;
140 _calculationPendingProcessingScope = processingScope;
141 }
142
145 inline bool isCalculationPending(int processingScope) const
146 {
147 Lock lock(_mutex);
148 return _calculationPending && (_calculationPendingProcessingScope == processingScope);
149 }
150
152 MLEXPORT std::string getAsString() const;
153
158
159 //-----------------------------------------------------------------------------
168 //-----------------------------------------------------------------------------
169 [[nodiscard]]
172 void* progressCallbackUserData = nullptr);
173
174 //-----------------------------------------------------------------------------
180 //-----------------------------------------------------------------------------
182
185
186private:
187 void updateProfilingData();
188
190 mutable Mutex _mutex;
191
193 SubImage _subImg;
194
196 bool _isValid;
197
199 bool _userControlled;
200
202 bool _calculationPending;
203
205 int _calculationPendingProcessingScope;
206
208 MemoryImageCurrentlyUsedMemoryTracker* _currentlyUsedMemoryTracker;
209
211 mutable MLMetaProfilePtr _metaProfilePtr;
212
213 friend class MemoryImageCurrentlyUsedMemoryTracker;
214};
215
216
218
219
220//-----------------------------------------------------------------------------------
221// Stream output for std::ostream
222//-----------------------------------------------------------------------------------
223namespace std
224{
225
227 inline ostream& operator<<(ostream& s, const ML_NAMESPACE::MemoryImage& mi)
228 {
229 return s << mi.getAsString().c_str();
230 }
231
232} // namespace std
233
234
235#endif
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:592
MLint32 MLErrorCode
Type of an ML Error code.
Definition mlTypeDefs.h:772
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:489
std::ostream & operator<<(std::ostream &out, const ml::Variant &variant)
Definition mlVariant.h:231
boost::mutex::scoped_lock Lock
Defines a lock for locking a non-recursive mutex.
Definition mlMutex.h:41
STL namespace.