17 #ifndef NANOVDB_GRID_HANDLE_H_HAS_BEEN_INCLUDED 18 #define NANOVDB_GRID_HANDLE_H_HAS_BEEN_INCLUDED 20 #include "../NanoVDB.h" 33 virtual uint64_t
size()
const = 0;
35 virtual uint8_t*
data() = 0;
36 virtual const uint8_t*
data()
const = 0;
42 operator bool()
const {
return !this->
empty(); }
60 return ptr ? ptr->gridCount() : 0;
69 template<
typename BufferT = HostBuffer>
74 template<
typename ValueT>
77 template<
typename ValueT,
typename U = BufferT>
78 typename std::enable_if<BufferTraits<U>::hasDeviceDual,
const NanoGrid<ValueT>*>::type
79 getDeviceGrid(uint32_t n = 0)
const;
82 static T* no_const(
const T* ptr) {
return const_cast<T*
>(ptr); }
86 GridHandle(BufferT&& buffer) { mBuffer = std::move(buffer); }
96 mBuffer = std::move(other.mBuffer);
110 const BufferT&
buffer()
const {
return mBuffer; }
115 uint8_t*
data()
override {
return mBuffer.data(); }
120 const uint8_t*
data()
const override {
return mBuffer.data(); }
123 uint64_t
size()
const override {
return mBuffer.size(); }
129 template<
typename ValueT>
136 template<
typename ValueT>
143 template<
typename ValueT,
typename U = BufferT>
144 typename std::enable_if<BufferTraits<U>::hasDeviceDual,
const NanoGrid<ValueT>*>::type
145 deviceGrid(uint32_t n = 0)
const {
return this->
template getDeviceGrid<ValueT>(n); }
151 template<
typename ValueT,
typename U = BufferT>
152 typename std::enable_if<BufferTraits<U>::hasDeviceDual,
NanoGrid<ValueT>*>::type
153 deviceGrid(uint32_t n = 0) {
return no_const(this->
template getDeviceGrid<ValueT>(n)); }
158 template<
typename U = BufferT>
159 typename std::enable_if<BufferTraits<U>::hasDeviceDual,
void>::type
160 deviceUpload(
void* stream =
nullptr,
bool sync =
true) { mBuffer.deviceUpload(stream, sync); }
165 template<
typename U = BufferT>
166 typename std::enable_if<BufferTraits<U>::hasDeviceDual,
void>::type
167 deviceDownload(
void* stream =
nullptr,
bool sync =
true) { mBuffer.deviceDownload(stream, sync); }
172 template<
typename BufferT>
173 template<
typename ValueT>
177 auto *
data = mBuffer.data();
178 GridT *grid =
reinterpret_cast<GridT*
>(
data);
179 if (grid ==
nullptr || index >= grid->gridCount()) {
182 while(index != grid->gridIndex()) {
183 data += grid->gridSize();
184 grid =
reinterpret_cast<GridT*
>(
data);
186 return grid->gridType() == mapToGridType<ValueT>() ? grid :
nullptr;
189 template<
typename BufferT>
190 template<
typename ValueT,
typename U>
191 inline typename std::enable_if<BufferTraits<U>::hasDeviceDual,
const NanoGrid<ValueT>*>::type
195 auto *
data = mBuffer.data();
196 GridT *grid =
reinterpret_cast<GridT*
>(
data);
197 if (grid ==
nullptr || index >= grid->gridCount()) {
200 auto* dev = mBuffer.deviceData();
201 while(index != grid->gridIndex()) {
202 data += grid->gridSize();
203 dev += grid->gridSize();
204 grid =
reinterpret_cast<GridT*
>(
data);
206 return grid->gridType() == mapToGridType<ValueT>() ? reinterpret_cast<GridT*>(dev) :
nullptr;
211 #endif // NANOVDB_GRID_HANDLE_H_HAS_BEEN_INCLUDED GridType gridType() const
Returns the GridType handled by this instance, and GridType::End if empty.
Definition: GridHandle.h:50
Highest level of the data structure. Contains a tree and a world->index transform (that currently onl...
Definition: NanoVDB.h:2307
GridHandle(BufferT &&buffer)
Move constructor from a buffer.
Definition: GridHandle.h:86
std::enable_if< BufferTraits< U >::hasDeviceDual, void >::type deviceUpload(void *stream=nullptr, bool sync=true)
Upload the grid to the device, e.g. from CPU to GPU.
Definition: GridHandle.h:160
~GridHandle() override
Default destructor.
Definition: GridHandle.h:102
HostBuffer - a buffer that contains a shared or private bump pool to either externally or internally ...
uint32_t gridCount() const
Return the number of grids contained in this buffer.
Definition: GridHandle.h:57
NanoGrid< ValueT > * grid(uint32_t n=0)
Returns a pointer to the n'th NanoVDB grid encoded in this GridHandle.
Definition: GridHandle.h:137
std::enable_if< BufferTraits< U >::hasDeviceDual, const NanoGrid< ValueT > * >::type deviceGrid(uint32_t n=0) const
Return a const pointer to the n'th grid encoded in this GridHandle on the device, e...
Definition: GridHandle.h:145
void reset()
clear the buffer
Definition: GridHandle.h:104
This class serves to manage a raw memory buffer of a NanoVDB Grid.
Definition: GridHandle.h:70
BufferT & buffer()
Return a reference to the buffer.
Definition: GridHandle.h:107
const uint8_t * data() const override
Returns a const pointer to the data.
Definition: GridHandle.h:120
Definition: NanoVDB.h:184
Definition: GridHandle.h:27
uint8_t * data() override
Returns a non-const pointer to the data.
Definition: GridHandle.h:115
std::enable_if< BufferTraits< U >::hasDeviceDual, void >::type deviceDownload(void *stream=nullptr, bool sync=true)
Download the grid to from the device, e.g. from GPU to CPU.
Definition: GridHandle.h:167
virtual uint64_t size() const =0
Returns the size in bytes of the raw memory buffer managed by this GridHandle's allocator.
virtual ~GridHandleBase()
Definition: GridHandle.h:30
bool empty() const
Return true if this handle is empty, i.e. has no allocated memory.
Definition: GridHandle.h:39
const BufferT & buffer() const
Return a const reference to the buffer.
Definition: GridHandle.h:110
GridType
List of types that are currently supported by NanoVDB.
Definition: NanoVDB.h:216
virtual uint8_t * data()=0
const NanoGrid< ValueT > * grid(uint32_t n=0) const
Returns a const pointer to the n'th NanoVDB grid encoded in this GridHandle.
Definition: GridHandle.h:130
GridHandle & operator=(GridHandle &&other) noexcept
Move copy assignment operation.
Definition: GridHandle.h:94
const GridMetaData * gridMetaData() const
Returns a const point to the grid meta data (see definition above).
Definition: GridHandle.h:47
uint64_t size() const override
Returns the size in bytes of the raw memory buffer managed by this GridHandle's allocator.
Definition: GridHandle.h:123
GridHandle(GridHandle &&other) noexcept
Move copy-constructor.
Definition: GridHandle.h:100
std::enable_if< BufferTraits< U >::hasDeviceDual, NanoGrid< ValueT > * >::type deviceGrid(uint32_t n=0)
Return a const pointer to the n'th grid encoded in this GridHandle on the device, e...
Definition: GridHandle.h:153