25 : accessor_( accessor )
27 , params_( std::move( parameters ) )
28 , layers_( params_.preloadedLayerCount )
29 , firstLayerVoxelId_( params_.preloadedLayerCount )
32 for (
auto & l : layers_ )
33 l.resize( indexer_.sizeXY() );
45 assert( 0 <= z && z < indexer_.
dims().z );
47 for (
auto layerIndex = 0; layerIndex < layers_.size(); ++layerIndex )
49 if ( indexer_.
dims().z <= z_ + layerIndex )
51 preloadLayer_( layerIndex );
59 for (
auto i = 0; i + 1 < layers_.size(); ++i )
61 std::swap( layers_[i], layers_[i + 1] );
62 firstLayerVoxelId_[i] = firstLayerVoxelId_[i + 1];
71 const auto layerIndex = loc.
pos.z - z_;
72 assert( 0 <= layerIndex && layerIndex < layers_.size() );
73 assert( loc.
id >= firstLayerVoxelId_[layerIndex] );
74 assert( loc.
id < firstLayerVoxelId_[layerIndex] + indexer_.
sizeXY() );
75 return layers_[layerIndex][loc.
id - firstLayerVoxelId_[layerIndex]];
79 [[nodiscard]]
size_t toLayerIndex(
const Vector3i& pos )
const
81 return indexer_.
toVoxelId( { pos.x, pos.y, 0 } );
84 void preloadLayer_(
size_t layerIndex )
87 assert( layerIndex < layers_.size() );
88 auto& layer = layers_[layerIndex];
89 const auto z = z_ + (int)layerIndex;
90 const auto& dims = indexer_.
dims();
91 assert( 0 <= z && z < dims.z );
92 auto loc = indexer_.
toLoc( Vector3i{ 0, 0, z } );
93 firstLayerVoxelId_[layerIndex] = loc.id;
95 for ( loc.pos.y = 0; loc.pos.y < dims.y; ++loc.pos.y )
96 for ( loc.pos.x = 0; loc.pos.x < dims.x; ++loc.pos.x, ++loc.id, ++n )
97 layer[n] = accessor_.get( loc );
101 const VoxelsVolumeAccessor<V>& accessor_;
102 VolumeIndexer indexer_;
106 std::vector<std::vector<ValueType>> layers_;
107 std::vector<VoxelId> firstLayerVoxelId_;
#define MR_TIMER
Definition MRTimer.h:53
Definition MRVolumeIndexer.h:65
helper class for generalized voxel volume data access
Definition MRVoxelsVolumeAccess.h:14
Definition MRVoxelsVolumeCachingAccessor.h:13
V VolumeType
Definition MRVoxelsVolumeCachingAccessor.h:15
typename V::ValueType ValueType
Definition MRVoxelsVolumeCachingAccessor.h:16
ValueType get(const VoxelLocation &loc) const
get voxel volume data
Definition MRVoxelsVolumeCachingAccessor.h:69
int currentLayer() const
get current layer
Definition MRVoxelsVolumeCachingAccessor.h:37
void preloadNextLayer()
preload the next layer
Definition MRVoxelsVolumeCachingAccessor.h:56
VoxelsVolumeCachingAccessor(const VoxelsVolumeAccessor< V > &accessor, const VolumeIndexer &indexer, Parameters parameters={})
Definition MRVoxelsVolumeCachingAccessor.h:24
void preloadLayer(int z)
preload layers, starting from z
Definition MRVoxelsVolumeCachingAccessor.h:43
VoxelId toVoxelId(const Vector3i &pos) const
Definition MRVolumeIndexer.h:141
const Vector3i & dims() const
Definition MRVolumeIndexer.h:69
VoxelLocation toLoc(VoxelId id) const
Definition MRVolumeIndexer.h:83
VoxelId id
Definition MRVolumeIndexer.h:57
Vector3i pos
Definition MRVolumeIndexer.h:58
size_t sizeXY() const
Definition MRVolumeIndexer.h:77
Definition MRCameraOrientationPlugin.h:8
contains both linear Id and 3D coordinates of the same voxel
Definition MRVolumeIndexer.h:56
Definition MRVoxelsVolumeCachingAccessor.h:19
size_t preloadedLayerCount
amount of layers to be preloaded
Definition MRVoxelsVolumeCachingAccessor.h:21