26 : accessor_( accessor )
28 , params_( std::move( parameters ) )
29 , layers_( params_.preloadedLayerCount )
30 , firstLayerVoxelId_( params_.preloadedLayerCount )
33 for (
auto & l : layers_ )
34 l.resize( indexer_.sizeXY() );
47 assert( 0 <= z && z < indexer_.
dims().z );
49 for (
size_t layerIndex = 0; layerIndex < layers_.size(); ++layerIndex )
51 if ( indexer_.
dims().z <= z_ + layerIndex )
53 if ( !preloadLayer_( layerIndex,
subprogress( cb, layerIndex, layers_.size() ) ) )
64 for (
auto i = 0; i + 1 < layers_.size(); ++i )
66 std::swap( layers_[i], layers_[i + 1] );
67 firstLayerVoxelId_[i] = firstLayerVoxelId_[i + 1];
77 const auto layerIndex = loc.
pos.z - z_;
78 assert( 0 <= layerIndex && layerIndex < layers_.size() );
79 assert( loc.
id >= firstLayerVoxelId_[layerIndex] );
80 assert( loc.
id < firstLayerVoxelId_[layerIndex] + indexer_.
sizeXY() );
81 return layers_[layerIndex][loc.
id - firstLayerVoxelId_[layerIndex]];
85 [[nodiscard]]
size_t toLayerIndex(
const Vector3i& pos )
const
87 return indexer_.
toVoxelId( { pos.x, pos.y, 0 } );
93 assert( layerIndex < layers_.size() );
94 auto& layer = layers_[layerIndex];
95 const auto z = z_ + (int)layerIndex;
96 const auto& dims = indexer_.
dims();
97 assert( 0 <= z && z < dims.z );
98 firstLayerVoxelId_[layerIndex] = indexer_.
toVoxelId( Vector3i{ 0, 0, z } );
101 auto accessor = accessor_;
102 auto loc = indexer_.toLoc( Vector3i{ 0, y, z } );
103 size_t n = size_t( y ) * dims.x;
104 for ( loc.pos.x = 0; loc.pos.x < dims.x; ++loc.pos.x, ++loc.id, ++n )
105 layer[n] = accessor.get( loc );
110 const VoxelsVolumeAccessor<V>& accessor_;
111 VolumeIndexer indexer_;
115 std::vector<std::vector<ValueType>> layers_;
116 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:14
V VolumeType
Definition MRVoxelsVolumeCachingAccessor.h:16
typename V::ValueType ValueType
Definition MRVoxelsVolumeCachingAccessor.h:17
ValueType get(const VoxelLocation &loc) const
get voxel volume data
Definition MRVoxelsVolumeCachingAccessor.h:75
int currentLayer() const
get current layer
Definition MRVoxelsVolumeCachingAccessor.h:38
bool preloadLayer(int z, const ProgressCallback &cb={})
Definition MRVoxelsVolumeCachingAccessor.h:45
bool preloadNextLayer(const ProgressCallback &cb={})
Definition MRVoxelsVolumeCachingAccessor.h:61
VoxelsVolumeCachingAccessor(const VoxelsVolumeAccessor< V > &accessor, const VolumeIndexer &indexer, Parameters parameters={})
Definition MRVoxelsVolumeCachingAccessor.h:25
auto ParallelFor(I begin, I end, F &&... f)
Definition MRParallelFor.h:95
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:641
VoxelId toVoxelId(const Vector3i &pos) const
Definition MRVolumeIndexer.h:141
const Vector3i & dims() const
Definition MRVolumeIndexer.h:69
VoxelId id
Definition MRVolumeIndexer.h:57
Vector3i pos
Definition MRVolumeIndexer.h:58
size_t sizeXY() const
Definition MRVolumeIndexer.h:77
ProgressCallback subprogress(ProgressCallback cb, float from, float to)
returns a callback that maps [0,1] linearly into [from,to] in the call to
Definition MRProgressCallback.h:49
contains both linear Id and 3D coordinates of the same voxel
Definition MRVolumeIndexer.h:56
Definition MRVoxelsVolumeCachingAccessor.h:20
size_t preloadedLayerCount
amount of layers to be preloaded
Definition MRVoxelsVolumeCachingAccessor.h:22