MeVisLabToolboxReference
mlVirtualVolume.h
Go to the documentation of this file.
1 // **InsertLicense** code
2 //----------------------------------------------------------------------------------
5 
24 //----------------------------------------------------------------------------------
25 #ifndef __mlVirtualVolume_H
26 #define __mlVirtualVolume_H
27 
28 // Include dll-specific settings.
29 #include "MLToolsSystem.h"
30 
31 // Include most ml specific things.
32 #include "mlModuleIncludes.h"
33 
34 #include <mlMemoryManager.h>
35 
36 class MLMemoryProfile;
37 
38 ML_START_NAMESPACE
39 
42  class VirtualVolume;
43  class BitImage;
44  struct PageBuffer;
45  template<class DATATYPE> class TVirtualVolume;
46 
47  class VirtualVolumeMemoryTracker;
48 
49  //--------------------------------------------------------------------------------
65  //--------------------------------------------------------------------------------
67 
68  public:
69 
70  // ---- Public member functions:
71 
75  MLDataType dType,
76  MLint maxNumKB = -1,
77  bool areExceptionsOnFlag = false);
78 
87  VirtualVolume(const ImageVector &ext = ImageVector(0),
88  MLdouble fillVal = 0,
89  MLDataType dType = MLuint8Type,
90  MLint maxNumKB = -1,
91  bool areExceptionsOnFlag = false);
92 
94  virtual ~VirtualVolume() { _reset(); }
95 
97  inline MLint getDim() const { return _dim; }
98 
100  inline const SubImageBox &getBox() const { return _pagedImgBox; }
101 
103  inline ImageVector getExtent() const { return _pagedImgBox.getExtent(); }
104 
106  inline MLDataType getDataType() const { return _dataType; }
107 
110  inline Module *getModule() const { return _module; }
111 
114  inline PagedImage *getInputImage() const { return _pagedImg; }
115 
117  inline MLint getInputIndex() const { return _module ? _outIdx : -1; }
118 
120  inline bool isValid() const { return _valid; }
121 
123  inline void invalidate() { _valid = false; _cleanUpMemory(); }
124 
126  inline MLuint getNumMappedPages() const { return _numMappedPages; }
127 
129  inline MLuint getNumWrittenPages() { _updateWrittenPages(); return _numWrittenPages;}
130 
132  inline MLuint getNumPages() { return _numMappedPages+getNumWrittenPages(); }
133 
135  inline MLuint getNumBytes() { return getNumPages()*_numPageBytes; }
136 
138  inline bool areExceptionsOn() const { return _areExceptionsOn; }
139 
141  inline const ImageVector &getPageExtent() const { return _pageExt; }
142 
144  inline const ImageVector &getPageArrayExtent() const { return _pageArrayExt; }
145 
148  inline const SubImageBox &getWrittenPageBox(MLuint32 wp);
149 
156  void *getWrittenPageData(MLuint32 wp);
157 
162  void unMapAndClearWrittenPages();
163 
166  enum PageMapped { IsMapped, IsUnMapped };
167 
173  typedef void (*PageFunc) (VirtualVolume *obj, PageBuffer *page, PageMapped mapped, void *userData);
174 
179  void registerPageFunction(PageFunc pFunc, void *userData);
180 
195  void resize(const ImageVector &newExt);
196 
207  void copyTileFromInputImage(const SubImageBox &box,
208  PagedImage &image,
209  const ImageVector &shift,
210  const ScaleShiftData &scaleShift=ScaleShiftData());
211 
212 
219  void copyToSubImage(SubImage &outSubImg);
220 
221 #if 0
222  // Copy area from inImg into virtual volume. This non-template version is still
223  // not implemented but desirable. Only valid areas are copied; regions outside
224  // input or virtual volume areas are not handled.
225  // Errors are reported by thrown exceptions if exception handling is enabled;
226  // otherwise they lead to ML_PRINT_ERROR or ML_PRINT_FATAL_ERROR messages.
227  // Only valid regions of the virtual volume are written; box is clipped against
228  // the virtual volume extents before writing the data region.
229  void copyFromSubImg(const SubImage &inImg,
230  const SubImageBox &box,
231  const ImageVector &pos);
232 #endif
233 
241  BitImage *getUsedPagesMask(bool enableMappedPages=true,
242  bool enableWrittenPages=true) const;
243 
246  void *createTypedVirtualVolume();
247 
250  static void destroyTypedVirtualVolume(void *tVV, MLDataType dt);
251 
252 #ifdef ML_DEPRECATED
253 
255 
256 
257 #ifdef WIN32
258 #pragma warning(push)
259 #pragma warning(disable : 4996 )
260 #endif
261 
262 public:
265  inline ML_DEPRECATED ImageVector getExt() const { return getExtent(); }
266 
269  ML_DEPRECATED BaseOp* getBaseOp() const;
270 
273  inline ML_DEPRECATED PagedImage* getInImg() const { return _pagedImg; }
274 
277  inline ML_DEPRECATED MLint getInIdx() const { return _module ? _outIdx : -1; }
278 
281  inline ML_DEPRECATED const ImageVector& getPageExt() const { return _pageExt; }
282 
285  inline ML_DEPRECATED const ImageVector& getPageArrayExt() const { return _pageArrayExt; }
286 
290  PagedImage &image,
291  const ImageVector &shift,
292  const ScaleShiftData &scaleShift=ScaleShiftData()) { copyTileFromInputImage(box, image, shift, scaleShift); }
293 
296  inline ML_DEPRECATED void copyToSubImg(SubImage &outSubImg) { copyToSubImage(outSubImg); }
297 
301  MLint connIdx,
302  MLDataType dType,
303  MLint maxNumKB = -1,
304  bool areExceptionsOnFlag = false,
305  bool useOutConnectors = false);
306 
309  ML_DEPRECATED void copyTileFromInImg(const SubImageBox &box,
310  Module &op,
311  MLint outIdx,
312  const ImageVector &shift,
313  const ScaleShiftData &scaleShift=ScaleShiftData());
314 
315 #ifdef WIN32
316 #pragma warning(pop)
317 #endif
318 
319 #endif // ML_DEPRECATED
320 
321  protected:
322 
343  void _init(PagedImage *img,
344  const ImageVector &ext,
345  MLdouble fillVal,
346  MLDataType dType,
347  MLint maxNumKB = -1,
348  bool areExceptionsOnFlag = false);
349 
351  void _reset();
352 
354  void _cleanUpMemory();
355 
356 
357 
358  // ---- Protected member functions:
359 
361  template<typename> friend class TVirtualVolume;
362 
364  void _default();
365 
367  inline static void* _getPageCB(PageBuffer *pageBuffer);
368 
374  static void* _loadPageCB(PageBuffer *pageBuffer);
375 
379  void* _loadPage(PageBuffer *pageBuffer);
380 
383  void _updateWrittenPages();
384 
387  PageBuffer *_getPageBuffer6D(const ImageVector &pos);
388 
389  private:
390 
398  MLuint _makePowerOfTwo(MLint &num) const;
399 
402  long _getPowerOfTwo(MLuint num) const;
403 
406  MLMemoryProfile* _getMemoryProfile();
407 
408 
409  // ---- Members:
410 
411 
413 
414 
417  bool _valid;
418 
420  Module *_module;
421 
423  MLint32 _outIdx;
424 
426  PagedImage *_pagedImg;
427 
429  SubImageBox _pagedImgBox;
430 
432  ImageVector _origVolumeExt;
433 
435  ImageVector _pageExt;
436 
438  long _maxNumKB;
439 
441  MLDataType _dataType;
442 
444  MLdouble _fillValue;
445 
448  bool _areExceptionsOn;
449 
452  PageFunc _pageFunc;
453 
456  void *_pageFuncData;
458 
459 
461  MLuint _numPageBytes;
462 
464  ImageVector _volumeExt;
465 
467  MLint _dim;
468 
470  ImageVector _pageArrayExt;
471 
473  MLuint _numPageArrayEntries;
474 
476  MLuint _maxMappedPages;
477 
478 
480  ImageVector _strides;
481 
483  ImageVector _pStrides;
484 
487  ImageVector _rShift;
488 
490  ImageVector _idxMask;
491 
492 
494  PageBuffer *_pageArray;
495 
497  PageBuffer **_mappedPages;
498 
500  MLuint _numMappedPages;
501 
503  PageBuffer **_writtenPages;
504 
506  MLuint _numWrittenPages;
507 
509  MLuint _nextThrowPage;
510 
512  VirtualVolumeMemoryTracker* _currentlyUsedMemoryTracker;
513 
516 
517  friend class VirtualVolumeMemoryTracker;
518  };
519 
520  //--------------------------------------------------------------------------------
531  //--------------------------------------------------------------------------------
533 
535  typedef void *(*ReturnPageFunc)(PageBuffer *toMePtr);
536 
538  inline PageBuffer(): _virtVol(NULL), _page(NULL), _locked(false), _getPageFkt(NULL) { }
539 
542 
545 
548 
552  void *_page;
553 
555  bool _locked;
556 
558  ReturnPageFunc _getPageFkt;
559  };
560 
563  inline void* VirtualVolume::_getPageCB(PageBuffer *pageBuffer) { return pageBuffer->_page; }
564 
565 ML_END_NAMESPACE
566 
567 // For compatibilities we include the TVirtualVolume here.
568 #include "mlTVirtualVolume.h"
569 
570 #endif // __mlVirtualVolume_H
VirtualVolume * _virtVol
Pointer to the virtual volume object.
SubImageBox _box
Box of original image mapped in this page.
void invalidate()
Invalidates state of virtual volume, e.g. after an error.
MLint32 MLDataType
MLDataType.
Definition: mlTypeDefs.h:692
void copyToSubImg(SubImage &outSubImg)
signed int MLint32
Definition: mlTypeDefs.h:189
#define MLTOOLS_EXPORT
Definition: MLToolsSystem.h:20
Defines and implements management and access classes for random access to a paged image or a pure vir...
MLint getInputIndex() const
Returns the output index of the input baseOp or -1 if there is no input baseOp.
bool isValid() const
Returns true if instance is valid, otherwise false.
MLDataType getDataType() const
Return data type enum.
const ImageVector & getPageExt() const
ImageVector getExtent() const
Get extents of input volume.
MLuint64 MLuint
An unsigned ML integer type with at least 64 bits used for index calculations on very large images ev...
Definition: mlTypeDefs.h:592
TScaleShiftData< MLdouble > ScaleShiftData
Double version of TScaleShiftData for maximum reasonable precision.
#define ML_DEPRECATED
Definition: mlMacros.h:40
ImageVector getExt() const
ReturnPageFunc _getPageFkt
Pointer to function to return the page managed by the PageBuffer.
PageMapped
Enum which describes whether a page is mapped into the currently used page list or unmapped from used...
MLint getDim() const
Return dimension of specified volume.
MLuint getNumBytes()
Returns number of bytes currently allocated as pages in the virtual volume.
MLuint getNumWrittenPages()
Returns number of written (and therefore locked) pages.
Class which represents an image, which manages properties of an image and image data which is located...
Definition: mlPagedImage.h:66
The TVirtualVolume class implements random access to a paged input image or a pure virtual image with...
MLMemoryBlockHandle _memoryBlockHandle
The memory block handle for holding the page data locked.
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition: mlTypeDefs.h:576
This class manages a virtual volume organizing efficient voxel access to the output image of an input...
MLuint getNumPages()
Returns number of all (mapped and written) pages.
const ImageVector & getPageExtent() const
Returns the extent of any written/read page used by the virtual volume.
ML_LINEAR_ALGEBRA_EXPORT typedef TImageVector< MLint > ImageVector
Defines the standard ImageVector type which is used by the ML for indexing and coordinates.
The strong handle of a MLMemoryBlock.
const ImageVector & getPageArrayExtent() const
Returns the extent of the array of page buffers.
Class to manage a binary image.
Definition: mlBitImage.h:60
bool areExceptionsOn() const
Returns true if exception handling is enabled otherwise false.
MLint getInIdx() const
Module * getModule() const
Returns the pointer to the module which contains the paged image the virtual volume is associated wit...
Overview documentation of the MLMemoryManager.
PageBuffer is a helper structure to manage one page of input data of the VirtualVolume class and it a...
PagedImage * getInputImage() const
Returns the pointer to the paged image the virtual volume is associated with.
#define ML_DEPRECATED_CONSTRUCTOR
Definition: mlMacros.h:39
const ImageVector & getPageArrayExt() const
void * _page
Pointer to the page data reduced by the offset to the page origin.
virtual ~VirtualVolume()
Destructor.
Enumerator for the unsigned 8 bit ML integer type.
Definition: mlTypeDefs.h:731
#define ML_CLASS_HEADER(className)
Same like ML_CLASS_HEADER_EXPORTED with a non existing export symbol.
Resolves system dependencies for this project.
unsigned int MLuint32
Definition: mlTypeDefs.h:213
This file includes most files needed to implement new ML modules.
Base class for an image processing module of the ML.
Definition: mlModule.h:152
PageBuffer()
Initialize the structure.
bool _locked
If true this page contains written data and must not be removed.
void copyTileFromInImg(const SubImageBox &box, PagedImage &image, const ImageVector &shift, const ScaleShiftData &scaleShift=ScaleShiftData())
PagedImage * getInImg() const
const SubImageBox & getBox() const
Get box extents of input volume.
MLuint getNumMappedPages() const
Returns number of currently mapped (volatile) pages. Written pages are counted only temporarily here...
This class manages/represents a rectangular 6d image region which is organized linearly in memory...
Definition: mlSubImage.h:68
double MLdouble
Definition: mlTypeDefs.h:245