MeshLib Documentation
Loading...
Searching...
No Matches
MRVoxelsVolumeAccess.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRVoxelsFwd.h"
4#include "MRVoxelsVolume.h"
5#include "MRVDBFloatGrid.h"
7#include "MRMesh/MRIsNaN.h"
8
9namespace MR
10{
11
13template <typename Volume>
15
17template <>
18class VoxelsVolumeAccessor<VdbVolume>
19{
20public:
21 using VolumeType = VdbVolume;
22 using ValueType = typename VolumeType::ValueType;
23 static constexpr bool cacheEffective = true;
24
25 explicit VoxelsVolumeAccessor( const VolumeType& volume )
26 : accessor_( volume.data->getConstAccessor() )
27 , minCoord_( fromVdb( volume.data->evalActiveVoxelBoundingBox().min() ) )
28 {}
29
30 ValueType get( const Vector3i& pos ) const
31 {
32 ValueType res;
33 if ( !accessor_.probeValue( toVdb( pos + minCoord_ ), res ) )
34 return cQuietNan;
35 return res;
36 }
37
38 ValueType get( const VoxelLocation & loc ) const
39 {
40 return get( loc.pos );
41 }
42
43 const Vector3i& minCoord() const { return minCoord_; }
44
46 Vector3f shift() const { return Vector3f( minCoord_ ); }
47
48private:
49 openvdb::FloatGrid::ConstAccessor accessor_;
50 Vector3i minCoord_;
51};
52
54template <typename T>
55class VoxelsVolumeAccessor<VoxelsVolume<std::vector<T>>>
56{
57public:
58 using VolumeType = VoxelsVolume<std::vector<T>>;
59 using ValueType = typename VolumeType::ValueType;
60 static constexpr bool cacheEffective = false;
61
62 explicit VoxelsVolumeAccessor( const VolumeType& volume )
63 : data_( volume.data )
64 , indexer_( volume.dims )
65 {}
66
67 ValueType get( const Vector3i& pos ) const
68 {
69 return data_[indexer_.toVoxelId( pos )];
70 }
71
72 ValueType get( const VoxelLocation & loc ) const
73 {
74 return data_[loc.id];
75 }
76
78 Vector3f shift() const { return Vector3f::diagonal( 0.5f ); }
79
80private:
81 const std::vector<T>& data_;
82 VolumeIndexer indexer_;
83};
84
86template <typename T>
87class VoxelsVolumeAccessor<VoxelsVolumeMinMax<std::vector<T>>> : public VoxelsVolumeAccessor<VoxelsVolume<std::vector<T>>>
88{
89 using Base = VoxelsVolumeAccessor<VoxelsVolume<std::vector<T>>>;
90public:
91 using VolumeType = VoxelsVolumeMinMax<std::vector<T>>;
92 using ValueType = typename VolumeType::ValueType;
93 using Base::cacheEffective;
94 using Base::Base;
95};
96
98template <typename T>
99class VoxelsVolumeAccessor<VoxelsVolume<VoxelValueGetter<T>>>
100{
101public:
104 static constexpr bool cacheEffective = true;
105
106 explicit VoxelsVolumeAccessor( const VolumeType& volume )
107 : data_( volume.data )
108 {}
109
110 ValueType get( const Vector3i& pos ) const
111 {
112 return data_( pos );
113 }
114
115 ValueType get( const VoxelLocation & loc ) const
116 {
117 return get( loc.pos );
118 }
119
121 Vector3f shift() const { return Vector3f::diagonal( 0.5f ); }
122
123private:
124 const VoxelValueGetter<T>& data_;
125};
126
127} // namespace MR
ValueType get(const VoxelLocation &loc) const
Definition MRVoxelsVolumeAccess.h:38
const Vector3i & minCoord() const
Definition MRVoxelsVolumeAccess.h:43
VdbVolume VolumeType
Definition MRVoxelsVolumeAccess.h:21
Vector3f shift() const
this additional shift shall be added to integer voxel coordinates during transformation in 3D space
Definition MRVoxelsVolumeAccess.h:46
typename VolumeType::ValueType ValueType
Definition MRVoxelsVolumeAccess.h:22
ValueType get(const Vector3i &pos) const
Definition MRVoxelsVolumeAccess.h:30
VoxelsVolumeAccessor(const VolumeType &volume)
Definition MRVoxelsVolumeAccess.h:25
VoxelsVolumeAccessor(const VolumeType &volume)
Definition MRVoxelsVolumeAccess.h:106
ValueType get(const Vector3i &pos) const
Definition MRVoxelsVolumeAccess.h:110
ValueType get(const VoxelLocation &loc) const
Definition MRVoxelsVolumeAccess.h:115
Vector3f shift() const
this additional shift shall be added to integer voxel coordinates during transformation in 3D space
Definition MRVoxelsVolumeAccess.h:121
typename VolumeType::ValueType ValueType
Definition MRVoxelsVolumeAccess.h:103
helper class for generalized voxel volume data access
Definition MRVoxelsVolumeAccess.h:14
MR_BIND_IGNORE Vector3i fromVdb(const openvdb::Coord &v)
Definition MRVDBFloatGrid.h:37
MR_BIND_IGNORE openvdb::Coord toVdb(const Vector3i &v)
Definition MRVDBFloatGrid.h:42
constexpr const V & get(const Box< V > &box) noexcept
get<0> returns min, get<1> returns max
Definition MRMesh/MRBox.h:268
Vector3i pos
Definition MRVolumeIndexer.h:58
Definition MRCameraOrientationPlugin.h:8
constexpr float cQuietNan
Definition MRIsNaN.h:13
contains both linear Id and 3D coordinates of the same voxel
Definition MRVolumeIndexer.h:56
represents a box in 3D space subdivided on voxels stored in T
Definition MRVoxelsVolume.h:39
typename VoxelTraits< T >::ValueType ValueType
Definition MRVoxelsVolume.h:40