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 
28 ML_START_NAMESPACE
29 
31 class MemoryImageCurrentlyUsedMemoryTracker;
32 class Module;
33 class PagedImage;
35 
36 //-------------------------------------------------------------------------
47 //-------------------------------------------------------------------------
48 class ML_UNIX_ONLY_EXPORT(MLEXPORT) MemoryImage
49 {
50 
51 public:
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 
112  inline void setUserControlled(bool userControlled)
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 
148  MLEXPORT void clear();
150 
151  //-----------------------------------------------------------------------------
160  //-----------------------------------------------------------------------------
161  [[nodiscard]]
162  MLEXPORT MLErrorCode update(PagedImage* image, const SubImageBox& roi, MLDataType newDataType,
163  MLRequestProgressCB* progressCallback = nullptr,
164  void* progressCallbackUserData = nullptr);
165 
166  //-----------------------------------------------------------------------------
172  //-----------------------------------------------------------------------------
174 
177 
178 private:
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 #if ML_DEPRECATED_SINCE(3,5,0)
208 
211 
212 public:
213 
216  MLEXPORT ML_DEPRECATED MLErrorCode update(Module *op, MLint outIndex, const SubImageBox &roi, MLDataType newDT);
219  inline ML_DEPRECATED SubImage& getImg() { return getImage(); }
222  inline ML_DEPRECATED const SubImage& getConstImg() const { return getImage(); }
225  inline ML_DEPRECATED MLint getMemoryImgSize() const { return getSizeInBytes(); }
228  inline MLEXPORT ML_DEPRECATED void clearMemoryImg() { clear(); }
231  inline MLEXPORT ML_DEPRECATED void updateWithSubImg(const SubImage& image) { updateWithSubImage(image); }
234  inline ML_DEPRECATED void setManualControl(bool flag) { return setUserControlled(flag); }
237  inline ML_DEPRECATED bool getManualControl() const { return isUserControlled(); }
238 
240 
241 #endif
242 
243 };
244 
245 
246 #if ML_DEPRECATED_SINCE(3,5,0)
251 ML_DEPRECATED typedef MemoryImage MemoryImg;
253 #endif
254 
255 
256 ML_END_NAMESPACE
257 
258 
259 
260 //-----------------------------------------------------------------------------------
261 // Stream output for std::ostream
262 //-----------------------------------------------------------------------------------
263 namespace std {
264 
266  inline ostream& operator<<(ostream& s, const ML_NAMESPACE::MemoryImage &mi)
267  {
268  return s << mi.getAsString().c_str();
269  }
270 
271 }
272 
273 
274 #endif
275 
276 
277 
#define ML_DEPRECATED
Definition: CSOGroup.h:371
The pointer is automatically reset when the meta profile is destroyed.
A memory cache for the complete output image of an output connector.
Definition: mlMemoryImage.h:49
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 by somebody and that is is best to wait until t...
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 info string about memory image.
MLEXPORT MLMetaProfilePtr & getMetaProfile() const
Returns the profiling meta profile pointer.
MLint getSizeInBytes() const
Returns the currently used size of memory image in bytes.
Definition: mlMemoryImage.h:95
MemoryImage()
Defines a memory image always as member of a paged image with empty content.
Definition: mlMemoryImage.h:58
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.
SubImage & getImage()
Returns a subimage representing the data.
Definition: mlMemoryImage.h:78
bool isValid() const
Returns true if image contents is valid. Otherwise false is returned.
Definition: mlMemoryImage.h:91
void setValid(bool valid)
If set to true, the image data is valid, otherwise not.
Definition: mlMemoryImage.h:84
bool isCalculationPending(int processingScope) const
Returns if a calculation is pending on the given processingScope.
bool isUserControlled() const
Returns who controls the memory image.
const SubImage & getImage() const
Returns a constant subimage representing the data.
Definition: mlMemoryImage.h:81
Base class for an image processing module of the ML.
Definition: mlModule.h:156
Class which represents an image, which manages properties of an image and image data which is located...
Definition: mlPagedImage.h:70
This class manages/represents a rectangular 6d image region which is organized linearly in memory.
Definition: mlSubImage.h:75
MLint32 MLDataType
MLDataType.
Definition: mlTypeDefs.h:684
MLint32 MLErrorCode
Type of an ML Error code.
Definition: mlTypeDefs.h:818
boost::mutex Mutex
Defines a non-recursive mutex.
Definition: mlMutex.h:39
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator "<<" for stream output of Field objects.
#define MLEXPORT
To export symbols from a dll/shared object, we need to mark them with the MLEXPORT symbol.
void MLRequestProgressCB(void *usrData, double progress)
Definition: mlTypeDefs.h:1318
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition: mlTypeDefs.h:578
boost::mutex::scoped_lock Lock
Defines a lock for locking a non-recursive mutex.
Definition: mlMutex.h:41