MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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
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
47
50class VirtualVolume;
51class BitImage;
52struct PageBuffer;
53template <class DATATYPE> class TVirtualVolume;
54
55class VirtualVolumeMemoryTracker;
56
57//--------------------------------------------------------------------------------
73//--------------------------------------------------------------------------------
75{
76
77public:
78 // ---- Public member functions:
79
83
93 MLint maxNumKB = -1, bool areExceptionsOnFlag = false);
94
98
101 {
102 _reset();
103 }
104
106 inline MLint getDim() const
107 {
108 return _dim;
109 }
110
112 inline const SubImageBox& getBox() const
113 {
114 return _pagedImgBox;
115 }
116
118 inline ImageVector getExtent() const
119 {
120 return _pagedImgBox.getExtent();
121 }
122
124 inline MLDataType getDataType() const
125 {
126 return _dataType;
127 }
128
131 inline Module* getModule() const
132 {
133 return _module;
134 }
135
138 inline PagedImage* getInputImage() const
139 {
140 return _pagedImg;
141 }
142
144 inline MLint getInputIndex() const
145 {
146 return _module ? _outIdx : -1;
147 }
148
150 inline bool isValid() const
151 {
152 return _valid;
153 }
154
156 inline void invalidate()
157 {
158 _valid = false;
159 _cleanUpMemory();
160 }
161
164 {
165 return _numMappedPages;
166 }
167
170 {
171 _updateWrittenPages();
172 return _numWrittenPages;
173 }
174
177 {
178 return _numMappedPages + getNumWrittenPages();
179 }
180
183 {
184 return getNumPages() * _numPageBytes;
185 }
186
188 inline bool areExceptionsOn() const
189 {
190 return _areExceptionsOn;
191 }
192
194 inline const ImageVector& getPageExtent() const
195 {
196 return _pageExt;
197 }
198
200 inline const ImageVector& getPageArrayExtent() const
201 {
202 return _pageArrayExt;
203 }
204
208
216
222
227 IsUnMapped
228 };
229
235 typedef void (*PageFunc)(VirtualVolume* obj, PageBuffer* page, PageMapped mapped, void* userData);
236
241 void registerPageFunction(PageFunc pFunc, void* userData);
242
258
269 void copyTileFromInputImage(const SubImageBox& box, PagedImage& image, const ImageVector& shift,
270 const ScaleShiftData& scaleShift = ScaleShiftData());
271
272
279 void copyToSubImage(SubImage& outSubImg);
280
289
293
297
298protected:
320 MLint maxNumKB = -1, bool areExceptionsOnFlag = false);
321
323 void _reset();
324
327
328
329 // ---- Protected member functions:
330
332 template <typename> friend class TVirtualVolume;
333
335 void _default();
336
338 inline static void* _getPageCB(PageBuffer* pageBuffer);
339
346
351
355
359
360private:
368 MLuint _makePowerOfTwo(MLint& num) const;
369
372 MLint _getPowerOfTwo(MLuint num) const;
373
376 MLMemoryProfile* _getMemoryProfile();
377
378
379 // ---- Members:
380
381
384
387 bool _valid;
388
390 Module* _module;
391
393 MLint32 _outIdx;
394
396 PagedImage* _pagedImg;
397
399 SubImageBox _pagedImgBox;
400
402 ImageVector _origVolumeExt;
403
405 ImageVector _pageExt;
406
408 MLint _maxNumKB;
409
411 MLDataType _dataType;
412
414 MLdouble _fillValue;
415
418 bool _areExceptionsOn;
419
422 PageFunc _pageFunc;
423
426 void* _pageFuncData;
428
429
431 MLuint _numPageBytes;
432
434 ImageVector _volumeExt;
435
437 MLint _dim;
438
440 ImageVector _pageArrayExt;
441
443 MLuint _numPageArrayEntries;
444
446 MLuint _maxMappedPages;
447
448
450 ImageVector _strides;
451
453 ImageVector _pStrides;
454
457 ImageVector _rShift;
458
460 ImageVector _idxMask;
461
462
464 PageBuffer* _pageArray;
465
467 PageBuffer** _mappedPages;
468
470 MLuint _numMappedPages;
471
473 PageBuffer** _writtenPages;
474
476 MLuint _numWrittenPages;
477
479 MLuint _nextThrowPage;
480
482 VirtualVolumeMemoryTracker* _currentlyUsedMemoryTracker;
483
484 friend class VirtualVolumeMemoryTracker;
485};
486
487//--------------------------------------------------------------------------------
498//--------------------------------------------------------------------------------
500{
501
503 typedef void* (*ReturnPageFunc)(PageBuffer* toMePtr);
504
506 inline PageBuffer()
507 : _virtVol(nullptr)
508 , _page(nullptr)
509 , _locked(false)
510 , _getPageFkt(nullptr)
511 {}
512
515
518
521
525 void* _page;
526
529
531 ReturnPageFunc _getPageFkt;
532};
533
536inline void* VirtualVolume::_getPageCB(PageBuffer* pageBuffer)
537{
538 return pageBuffer->_page;
539}
540
542
543// For compatibilities we include the TVirtualVolume here.
544#include "mlTVirtualVolume.h"
545
546#endif // __mlVirtualVolume_H
#define MLTOOLS_EXPORT
Resolves system dependencies for this project.
The strong handle of a MLMemoryBlock.
Class to manage a binary image.
Definition mlBitImage.h:68
Base class for an image processing module of the ML.
Definition mlModule.h:150
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
The TVirtualVolume class implements random access to a paged input image or a pure virtual image with...
This class manages a virtual volume organizing efficient voxel access to the output image of an input...
const ImageVector & getPageExtent() const
Returns the extent of any written/read page used by the virtual volume.
void * _loadPage(PageBuffer *pageBuffer)
This function really loads the page into the memory and updates the corresponding page buffer so that...
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)
Constructor to map a pagedImg.
MLint getDim() const
Return dimension of specified volume.
PageBuffer * _getPageBuffer6D(const ImageVector &pos)
Returns the pageBuffer containing the voxel passed as position.
void copyTileFromInputImage(const SubImageBox &box, PagedImage &image, const ImageVector &shift, const ScaleShiftData &scaleShift=ScaleShiftData())
Copy an image region box from the image and write to the position resulting from box + shift into the...
void resize(const ImageVector &newExt)
This method resizes the virtual volume to the extents given by ext.
MLuint getNumBytes()
Returns number of bytes currently allocated as pages in the virtual volume.
void * getWrittenPageData(MLuint32 wp)
Returns untyped pointer to data of written page with page id 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)
Constructor-like initialization of the instance.
VirtualVolume(const ImageVector &ext=ImageVector(0), MLdouble fillVal=0, MLDataType dType=MLuint8Type, MLint maxNumKB=-1, bool areExceptionsOnFlag=false)
Constructor to map an image of extents ext (default is 256) filled with fillVal (default is 0).
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.
Module * getModule() const
Returns the pointer to the module which contains the paged image the virtual volume is associated wit...
BitImage * getUsedPagesMask(bool enableMappedPages=true, bool enableWrittenPages=true) const
Returns a pointer BitImage containing a bit for each page of the virtual volume.
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)
Returns box of written page no.
MLuint getNumPages()
Returns number of all (mapped and written) pages.
void _default()
Set all members to default values without freeing anything.
void unMapAndClearWrittenPages()
This function throws away all written pages.
void copyToSubImage(SubImage &outSubImg)
Copy area from virtual volume into 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.
void * createTypedVirtualVolume()
Creates and returns a typed version of this virtual volume as void pointer or NULL on failure.
static void destroyTypedVirtualVolume(void *tVV, MLDataType dt)
Destroys a typed version of a virtual volume given by a void pointer tVV of data type dt.
const ImageVector & getPageArrayExtent() const
Returns the extent of the array of page buffers.
void registerPageFunction(PageFunc pFunc, void *userData)
Register a function to be called when a page is mapped or unmapped.
static void * _loadPageCB(PageBuffer *pageBuffer)
This function calls the page loading method of Virtual volume.
PagedImage * getInputImage() const
Returns the pointer to the paged image the virtual volume is associated with.
virtual ~VirtualVolume()
Destructor.
PageMapped
Enum which describes whether a page is mapped into the currently used page list or unmapped from used...
ImageVector getExtent() const
Get extents of input volume.
void _updateWrittenPages()
This function moves all written pages to _writtenPages to have a valid base to work on all written pa...
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
MLDataType.
Definition mlTypeDefs.h:592
@ MLuint8Type
Enumerator for the unsigned 8-bit ML integer type.
Definition mlTypeDefs.h:617
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
unsigned int MLuint32
Definition mlTypeDefs.h:185
MLuint64 MLuint
An unsigned ML integer type with at least 64 bits used for index calculations on very large images ev...
Definition mlTypeDefs.h:505
double MLdouble
Definition mlTypeDefs.h:217
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
signed int MLint32
Definition mlTypeDefs.h:161
PageBuffer is a helper structure to manage one page of input data of the VirtualVolume class and it a...
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 * _page
Pointer to the page data reduced by the offset to the page origin.