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;
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
79 getDeviceGrid(uint32_t n = 0)
const;
82 static T* no_const(
const T* ptr) {
return const_cast<T*
>(ptr); }
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); }
172template<
typename BufferT>
173template<
typename ValueT>
174inline const NanoGrid<ValueT>* GridHandle<BufferT>::getGrid(uint32_t index)
const
176 using GridT =
const NanoGrid<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;
189template<
typename BufferT>
190template<
typename ValueT,
typename U>
191inline typename std::enable_if<BufferTraits<U>::hasDeviceDual,
const NanoGrid<ValueT>*>::type
192GridHandle<BufferT>::getDeviceGrid(uint32_t index)
const
194 using GridT =
const NanoGrid<ValueT>;
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;
HostBuffer - a buffer that contains a shared or private bump pool to either externally or internally ...
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:102
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 & operator=(const GridHandle &)=delete
Disallow copy assignment operation.
GridHandle(BufferT &&buffer)
Move constructor from a buffer.
Definition: GridHandle.h:86
NanoGrid< ValueT > * grid(uint32_t n=0)
Returns a pointer to the n'th NanoVDB grid encoded in this GridHandle.
Definition: GridHandle.h:137
BufferT & buffer()
Return a reference to the buffer.
Definition: GridHandle.h:107
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
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
GridHandle(const GridHandle &)=delete
Disallow copy-construction.
GridHandle & operator=(GridHandle &&other) noexcept
Move copy assignment operation.
Definition: GridHandle.h:94
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
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
uint8_t * data() override
Returns a non-const pointer to the data.
Definition: GridHandle.h:115
const BufferT & buffer() const
Return a const reference to the buffer.
Definition: GridHandle.h:110
GridHandle(GridHandle &&other) noexcept
Move copy-constructor.
Definition: GridHandle.h:100
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:145
const uint8_t * data() const override
Returns a const pointer to the data.
Definition: GridHandle.h:120
void reset()
clear the buffer
Definition: GridHandle.h:104
GridHandle()=default
Empty ctor.
Highest level of the data structure. Contains a tree and a world->index transform (that currently onl...
Definition: NanoVDB.h:2308
GridType
List of types that are currently supported by NanoVDB.
Definition: NanoVDB.h:216