MeVisLab Toolbox Reference
mlVirtualVolume.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_VIRTUAL_VOLUME_H
14#define ML_VIRTUAL_VOLUME_H
15
16
19
35
36// Include dll-specific settings.
37#include "MLToolsSystem.h"
38
39// Include most ml specific things.
40#include "mlModuleIncludes.h"
41
42#include <mlMemoryManager.h>
43
44class MLMemoryProfile;
45
46ML_START_NAMESPACE
47
50 class VirtualVolume;
51 class BitImage;
52 struct PageBuffer;
53 template<class DATATYPE> class TVirtualVolume;
54
55 class VirtualVolumeMemoryTracker;
56
57 //--------------------------------------------------------------------------------
73 //--------------------------------------------------------------------------------
75
76 public:
77
78 // ---- Public member functions:
79
83 MLDataType dType,
84 MLint maxNumKB = -1,
85 bool areExceptionsOnFlag = false);
86
96 MLdouble fillVal = 0,
97 MLDataType dType = MLuint8Type,
98 MLint maxNumKB = -1,
99 bool areExceptionsOnFlag = false);
100
102 VirtualVolume(const ImageVector &extent, const ImageVector& pageExtent,
103 MLdouble fillVal = 0,
104 MLDataType dType = MLuint8Type,
105 MLint maxNumKB = -1,
106 bool areExceptionsOnFlag = false);
107
109 virtual ~VirtualVolume() { _reset(); }
110
112 inline MLint getDim() const { return _dim; }
113
115 inline const SubImageBox &getBox() const { return _pagedImgBox; }
116
118 inline ImageVector getExtent() const { return _pagedImgBox.getExtent(); }
119
121 inline MLDataType getDataType() const { return _dataType; }
122
125 inline Module *getModule() const { return _module; }
126
129 inline PagedImage *getInputImage() const { return _pagedImg; }
130
132 inline MLint getInputIndex() const { return _module ? _outIdx : -1; }
133
135 inline bool isValid() const { return _valid; }
136
138 inline void invalidate() { _valid = false; _cleanUpMemory(); }
139
141 inline MLuint getNumMappedPages() const { return _numMappedPages; }
142
144 inline MLuint getNumWrittenPages() { _updateWrittenPages(); return _numWrittenPages;}
145
147 inline MLuint getNumPages() { return _numMappedPages+getNumWrittenPages(); }
148
150 inline MLuint getNumBytes() { return getNumPages()*_numPageBytes; }
151
153 inline bool areExceptionsOn() const { return _areExceptionsOn; }
154
156 inline const ImageVector &getPageExtent() const { return _pageExt; }
157
159 inline const ImageVector &getPageArrayExtent() const { return _pageArrayExt; }
160
164
172
178
182
188 typedef void (*PageFunc) (VirtualVolume *obj, PageBuffer *page, PageMapped mapped, void *userData);
189
194 void registerPageFunction(PageFunc pFunc, void *userData);
195
210 void resize(const ImageVector &newExt);
211
223 PagedImage &image,
224 const ImageVector &shift,
225 const ScaleShiftData &scaleShift=ScaleShiftData());
226
227
234 void copyToSubImage(SubImage &outSubImg);
235
243 BitImage *getUsedPagesMask(bool enableMappedPages=true,
244 bool enableWrittenPages=true) const;
245
249
252 static void destroyTypedVirtualVolume(void *tVV, MLDataType dt);
253
254 protected:
255
276 void _init(PagedImage *img,
277 const ImageVector &ext,
278 const ImageVector &pageExtent,
279 MLdouble fillVal,
280 MLDataType dType,
281 MLint maxNumKB = -1,
282 bool areExceptionsOnFlag = false);
283
285 void _reset();
286
289
290
291
292 // ---- Protected member functions:
293
295 template<typename> friend class TVirtualVolume;
296
298 void _default();
299
301 inline static void* _getPageCB(PageBuffer *pageBuffer);
302
308 static void* _loadPageCB(PageBuffer *pageBuffer);
309
313 void* _loadPage(PageBuffer *pageBuffer);
314
318
322
323 private:
324
332 MLuint _makePowerOfTwo(MLint &num) const;
333
336 MLint _getPowerOfTwo(MLuint num) const;
337
340 MLMemoryProfile* _getMemoryProfile();
341
342
343 // ---- Members:
344
345
348
351 bool _valid;
352
354 Module *_module;
355
357 MLint32 _outIdx;
358
360 PagedImage *_pagedImg;
361
363 SubImageBox _pagedImgBox;
364
366 ImageVector _origVolumeExt;
367
369 ImageVector _pageExt;
370
372 MLint _maxNumKB;
373
375 MLDataType _dataType;
376
378 MLdouble _fillValue;
379
382 bool _areExceptionsOn;
383
386 PageFunc _pageFunc;
387
390 void *_pageFuncData;
392
393
395 MLuint _numPageBytes;
396
398 ImageVector _volumeExt;
399
401 MLint _dim;
402
404 ImageVector _pageArrayExt;
405
407 MLuint _numPageArrayEntries;
408
410 MLuint _maxMappedPages;
411
412
414 ImageVector _strides;
415
417 ImageVector _pStrides;
418
421 ImageVector _rShift;
422
424 ImageVector _idxMask;
425
426
428 PageBuffer *_pageArray;
429
431 PageBuffer **_mappedPages;
432
434 MLuint _numMappedPages;
435
437 PageBuffer **_writtenPages;
438
440 MLuint _numWrittenPages;
441
443 MLuint _nextThrowPage;
444
446 VirtualVolumeMemoryTracker* _currentlyUsedMemoryTracker;
447
449 };
450
451 //--------------------------------------------------------------------------------
462 //--------------------------------------------------------------------------------
464
466 typedef void *(*ReturnPageFunc)(PageBuffer *toMePtr);
467
469 inline PageBuffer(): _virtVol(nullptr), _page(nullptr), _locked(false), _getPageFkt(nullptr) { }
470
473
476
479
483 void *_page;
484
487
490 };
491
494 inline void* VirtualVolume::_getPageCB(PageBuffer *pageBuffer) { return pageBuffer->_page; }
495
496ML_END_NAMESPACE
497
498// For compatibilities we include the TVirtualVolume here.
499#include "mlTVirtualVolume.h"
500
501#endif // __mlVirtualVolume_H
#define MLTOOLS_EXPORT
Class to manage a binary image.
Definition mlBitImage.h:67
const ImageVector & getPageExtent() const
Returns the extent of any written/read page used by the virtual volume.
void(* PageFunc)(VirtualVolume *obj, PageBuffer *page, PageMapped mapped, void *userData)
void * _loadPage(PageBuffer *pageBuffer)
MLuint getNumWrittenPages()
Returns number of written (and therefore locked) pages.
void _cleanUpMemory()
Cleans up all allocated memory areas.
VirtualVolume(PagedImage *image, MLDataType dType, MLint maxNumKB=-1, bool areExceptionsOnFlag=false)
MLint getDim() const
Return dimension of specified volume.
PageBuffer * _getPageBuffer6D(const ImageVector &pos)
void copyTileFromInputImage(const SubImageBox &box, PagedImage &image, const ImageVector &shift, const ScaleShiftData &scaleShift=ScaleShiftData())
void resize(const ImageVector &newExt)
MLuint getNumBytes()
Returns number of bytes currently allocated as pages in the virtual volume.
void * getWrittenPageData(MLuint32 wp)
MLDataType getDataType() const
Return data type enum.
void _init(PagedImage *img, const ImageVector &ext, const ImageVector &pageExtent, MLdouble fillVal, MLDataType dType, MLint maxNumKB=-1, bool areExceptionsOnFlag=false)
VirtualVolume(const ImageVector &ext=ImageVector(0), MLdouble fillVal=0, MLDataType dType=MLuint8Type, MLint maxNumKB=-1, bool areExceptionsOnFlag=false)
bool isValid() const
Returns true if instance is valid; otherwise, it returns false.
MLuint getNumMappedPages() const
Returns number of currently mapped (volatile) pages. Written pages are counted only temporarily here.
const SubImageBox & getBox() const
Get box extents of input volume.
friend class TVirtualVolume
For performance reasons permit direct member access of TVirtualVolume to this class.
Module * getModule() const
BitImage * getUsedPagesMask(bool enableMappedPages=true, bool enableWrittenPages=true) const
void _reset()
Cleans up all allocated memory and resets instance to state after _default().
MLint getInputIndex() const
Returns the output index of the input baseOp or -1 if there is no input baseOp.
const SubImageBox & getWrittenPageBox(MLuint32 wp)
MLuint getNumPages()
Returns number of all (mapped and written) pages.
void _default()
Set all members to default values without freeing anything.
void unMapAndClearWrittenPages()
void copyToSubImage(SubImage &outSubImg)
VirtualVolume(const ImageVector &extent, const ImageVector &pageExtent, MLdouble fillVal=0, MLDataType dType=MLuint8Type, MLint maxNumKB=-1, bool areExceptionsOnFlag=false)
Constructor that allows to pass the pageExtent.
friend class VirtualVolumeMemoryTracker
void * createTypedVirtualVolume()
static void destroyTypedVirtualVolume(void *tVV, MLDataType dt)
const ImageVector & getPageArrayExtent() const
Returns the extent of the array of page buffers.
void registerPageFunction(PageFunc pFunc, void *userData)
static void * _loadPageCB(PageBuffer *pageBuffer)
PagedImage * getInputImage() const
virtual ~VirtualVolume()
Destructor.
ImageVector getExtent() const
Get extents of input volume.
static void * _getPageCB(PageBuffer *pageBuffer)
Simply return the data of the page. This is the normal access function to page data.
void _updateWrittenPages()
bool areExceptionsOn() const
Returns true if exception handling is enabled otherwise false.
void invalidate()
Invalidates state of virtual volume, e.g. after an error.
MLint32 MLDataType
Definition mlTypeDefs.h:595
@ MLuint8Type
Enumerator for the unsigned 8-bit ML integer type.
Definition mlTypeDefs.h:620
unsigned int MLuint32
Definition mlTypeDefs.h:184
MLuint64 MLuint
Definition mlTypeDefs.h:505
double MLdouble
Definition mlTypeDefs.h:216
MLint64 MLint
Definition mlTypeDefs.h:489
signed int MLint32
Definition mlTypeDefs.h:160
TScaleShiftData< MLdouble > ScaleShiftData
Double version of TScaleShiftData for maximum reasonable precision.
TSubImageBox< MLint > SubImageBox
Defines the standard SubImageBox type used in the ML. Its size varies with the size of the MLint type...
TImageVector< MLint > ImageVector
Defines the standard ImageVector type that is used by the ML for indexing and coordinates.
SubImageBox _box
Box of original image mapped in this page.
VirtualVolume * _virtVol
Pointer to the virtual volume object.
ReturnPageFunc _getPageFkt
Pointer to function to return the page managed by the PageBuffer.
MLMemoryBlockHandle _memoryBlockHandle
The memory block handle for holding the page data locked.
bool _locked
If true this page contains written data and must not be removed.
PageBuffer()
Initialize the structure.
void *(* ReturnPageFunc)(PageBuffer *toMePtr)
Function to return the data page of the PageBuffer.