17#ifndef NANOVDB_GRID_HANDLE_H_HAS_BEEN_INCLUDED
18#define NANOVDB_GRID_HANDLE_H_HAS_BEEN_INCLUDED
20#include "../NanoVDB.h"
60 return ptr ? ptr->gridCount() : 0;
69template<
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
82 static T* no_const(
const T* ptr) {
return const_cast<T*
>(ptr); }
98 mBuffer = std::move(
other.mBuffer);
112 const BufferT&
buffer()
const {
return mBuffer; }
131 template<
typename ValueT>
138 template<
typename ValueT>
145 template<
typename ValueT,
typename U = BufferT>
146 typename std::enable_if<BufferTraits<U>::hasDeviceDual,
const NanoGrid<ValueT>*>::type
153 template<
typename ValueT,
typename U = BufferT>
154 typename std::enable_if<BufferTraits<U>::hasDeviceDual,
NanoGrid<ValueT>*>::type
160 template<
typename U = BufferT>
161 typename std::enable_if<BufferTraits<U>::hasDeviceDual,
void>::type
167 template<
typename U = BufferT>
168 typename std::enable_if<BufferTraits<U>::hasDeviceDual,
void>::type
174template<
typename BufferT>
175template<
typename ValueT>
176inline const NanoGrid<ValueT>* GridHandle<BufferT>::getGrid(uint32_t index)
const
179 auto *
data = mBuffer.data();
180 GridT *
grid =
reinterpret_cast<GridT*
>(
data);
181 if (
grid ==
nullptr || index >=
grid->gridCount()) {
184 while(index !=
grid->gridIndex()) {
186 grid =
reinterpret_cast<GridT*
>(
data);
191template<
typename BufferT>
192template<
typename ValueT,
typename U>
193inline typename std::enable_if<BufferTraits<U>::hasDeviceDual,
const NanoGrid<ValueT>*>::type
194GridHandle<BufferT>::getDeviceGrid(uint32_t index)
const
197 auto *
data = mBuffer.data();
198 GridT *
grid =
reinterpret_cast<GridT*
>(
data);
199 if (
grid ==
nullptr || index >=
grid->gridCount()) {
202 auto*
dev = mBuffer.deviceData();
203 while(index !=
grid->gridIndex()) {
206 grid =
reinterpret_cast<GridT*
>(
data);
HostBuffer - a buffer that contains a shared or private bump pool to either externally or internally ...
Definition DenseGrid.h:402
DenseGridHandle()=default
uint64_t size() const
Returns the size in bytes of the raw memory buffer managed by this DenseGridHandle's allocator.
Definition DenseGrid.h:440
uint8_t * data()
Returns a non-const pointer to the data.
Definition DenseGrid.h:432
const DenseGrid< ValueT > * grid() const
Returns a const pointer to the NanoVDB grid encoded in the DenseGridHandle.
Definition DenseGrid.h:447
Definition GridHandle.h:28
bool empty() const
Return true if this handle is empty, i.e. has no allocated memory.
Definition GridHandle.h:39
GridType gridType() const
Returns the GridType handled by this instance, and GridType::End if empty.
Definition GridHandle.h:50
virtual uint8_t * data()=0
const GridMetaData * gridMetaData() const
Returns a const point to the grid meta data (see definition above).
Definition GridHandle.h:47
virtual ~GridHandleBase()
Definition GridHandle.h:30
uint32_t gridCount() const
Return the number of grids contained in this buffer.
Definition GridHandle.h:57
virtual uint64_t size() const =0
Returns the size in bytes of the raw memory buffer managed by this GridHandle's allocator.
virtual const uint8_t * data() const =0
This class serves to manage a raw memory buffer of a NanoVDB Grid.
Definition GridHandle.h:71
~GridHandle() override
Default destructor.
Definition GridHandle.h:104
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:162
GridHandle & operator=(const GridHandle &)=delete
Disallow copy assignment operation.
GridHandle(BufferT &&buffer)
Move constructor from a buffer.
Definition GridHandle.h:88
NanoGrid< ValueT > * grid(uint32_t n=0)
Returns a pointer to the n'th NanoVDB grid encoded in this GridHandle.
Definition GridHandle.h:139
BufferT & buffer()
Return a reference to the buffer.
Definition GridHandle.h:109
uint64_t size() const override
Returns the size in bytes of the raw memory buffer managed by this GridHandle's allocator.
Definition GridHandle.h:125
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:169
GridHandle(const GridHandle &)=delete
Disallow copy-construction.
GridHandle & operator=(GridHandle &&other) noexcept
Move copy assignment operation.
Definition GridHandle.h:96
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:132
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:155
uint8_t * data() override
Returns a non-const pointer to the data.
Definition GridHandle.h:117
const BufferT & buffer() const
Return a const reference to the buffer.
Definition GridHandle.h:112
GridHandle(GridHandle &&other) noexcept
Move copy-constructor.
Definition GridHandle.h:102
std::enable_if< BufferTraits< U >::hasDeviceDual, constNanoGrid< 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:147
const uint8_t * data() const override
Returns a const pointer to the data.
Definition GridHandle.h:122
BufferT BufferType
Definition GridHandle.h:85
void reset()
clear the buffer
Definition GridHandle.h:106
GridHandle()=default
Empty ctor.
GridType
List of types that are currently supported by NanoVDB.
Definition NanoVDB.h:243