16template <
typename Accessor>
26 : volume_( volume ), accessor_( accessor )
28 if constexpr ( std::is_same_v<VolumeType, VdbVolume> )
30 openvdb::Coord coord = volume.data->evalActiveVoxelBoundingBox().min();
31 minCoord_ = { coord.x(), coord.y(), coord.z() };
39 : volume_(
other.volume_ ), accessor_( accessor ), minCoord_(
other.minCoord_ )
45 IndexAndPos index = getIndexAndPos(pos);
47 float cx[2] = { 1.0f - index.pos.x, index.pos.x };
48 float cy[2] = { 1.0f - index.pos.y, index.pos.y };
49 float cz[2] = { 1.0f - index.pos.z, index.pos.z };
50 for (
int i = 0; i < 8; i++ )
52 Vector3i d{ i & 1, ( i >> 1 ) & 1, i >> 2 };
53 const auto voxPos = index.index + d;
54 if ( voxPos.x >= 0 && voxPos.x < volume_.dims.x &&
55 voxPos.y >= 0 && voxPos.y < volume_.dims.y &&
56 voxPos.z >= 0 && voxPos.z < volume_.dims.z )
58 value += accessor_.get( voxPos ) * ( cx[d.x] * cy[d.y] * cz[d.z] );
66 const Accessor& accessor_;
75 IndexAndPos getIndexAndPos( Vector3f pos )
const
78 res.pos.x = pos.x / volume_.voxelSize.x;
79 res.pos.y = pos.y / volume_.voxelSize.y;
80 res.pos.z = pos.z / volume_.voxelSize.z;
81 pos.x =
floor( res.pos.x );
82 pos.y =
floor( res.pos.y );
83 pos.z =
floor( res.pos.z );
84 res.index.x = int( pos.x );
85 res.index.y = int( pos.y );
86 res.index.z = int( pos.z );
90 if constexpr ( std::is_same_v<VolumeType, VdbVolume> )
91 res.index -= minCoord_;
97template <
typename Accessor>
99 const typename Accessor::VolumeType &volume,
100 const Accessor &accessor,
101 const Vector3f &newVoxelSize )
103 SimpleVolumeMinMax res{
104 { .voxelSize{ newVoxelSize } },
105 { volume.min, volume.max }
107 res.dims.x = int( volume.dims.x * volume.voxelSize.x / res.voxelSize.x );
108 res.dims.y = int( volume.dims.y * volume.voxelSize.y / res.voxelSize.y );
109 res.dims.z = int( volume.dims.z * volume.voxelSize.z / res.voxelSize.z );
110 res.data.resize(
size_t( res.dims.x ) * res.dims.y * res.dims.z );
114 for (
int k = 0; k < res.dims.z; k++ )
115 for (
int j = 0; j < res.dims.y; j++ )
116 for (
int i = 0; i < res.dims.x; i++ )
117 res.data[indexer.
toVoxelId( { i, j, k } )] = interpolator.
get(
118 { i * res.voxelSize.x, j * res.voxelSize.y, k * res.voxelSize.z } );
Definition MRVolumeIndexer.h:65
Definition MRVolumeInterpolation.h:18
VoxelsVolumeInterpolatedAccessor(const VoxelsVolumeInterpolatedAccessor &)=delete
delete copying constructor to avoid accidentally creating non-thread-safe accessors
ValueType get(const Vector3f &pos) const
get value at specified coordinates
Definition MRVolumeInterpolation.h:43
VoxelsVolumeInterpolatedAccessor(const VolumeType &volume, const Accessor &accessor)
Definition MRVolumeInterpolation.h:25
typename Accessor::VolumeType VolumeType
Definition MRVolumeInterpolation.h:20
typename Accessor::ValueType ValueType
Definition MRVolumeInterpolation.h:21
VoxelsVolumeInterpolatedAccessor(const VoxelsVolumeInterpolatedAccessor &other, const Accessor &accessor)
a copying-like constructor with explicitly provided accessor
Definition MRVolumeInterpolation.h:38
VoxelId toVoxelId(const Vector3i &pos) const
Definition MRVolumeIndexer.h:141
constexpr A floor(A a)
Definition MRImGuiVectorOperators.h:126
Definition MRCameraOrientationPlugin.h:8
SimpleVolumeMinMax resampleVolumeByInterpolation(const typename Accessor::VolumeType &volume, const Accessor &accessor, const Vector3f &newVoxelSize)
sample function that resamples the voxel volume using interpolating accessor
Definition MRVolumeInterpolation.h:98