OpenVDB  11.0.0
Public Types | Public Member Functions | List of all members
GridHandle< BufferT > Class Template Reference

This class serves to manage a buffer containing one or more NanoVDB Grids. More...

#include <nanovdb/util/GridHandle.h>

Public Types

using BufferType = BufferT
 

Public Member Functions

template<typename T = BufferT, typename enable_if< BufferTraits< T >::hasDeviceDual, int >::type = 0>
 GridHandle (T &&buffer)
 Move constructor from a host buffer. More...
 
template<typename T = BufferT, typename disable_if< BufferTraits< T >::hasDeviceDual, int >::type = 0>
 GridHandle (T &&buffer)
 Move constructor from a dual host-device buffer. More...
 
 GridHandle ()=default
 Constructs an empty GridHandle. More...
 
 GridHandle (const GridHandle &)=delete
 Disallow copy-construction. More...
 
 GridHandle (GridHandle &&other) noexcept
 Move copy-constructor. More...
 
void reset ()
 clear this GridHandle to an empty handle More...
 
GridHandleoperator= (const GridHandle &)=delete
 Disallow copy assignment operation. More...
 
GridHandleoperator= (GridHandle &&other) noexcept
 Move copy assignment operation. More...
 
template<typename OtherBufferT = HostBuffer>
GridHandle< OtherBufferT > copy (const OtherBufferT &buffer=OtherBufferT()) const
 Performs a deep copy of the GridHandle, possibly templated on a different buffer type. More...
 
BufferT & buffer ()
 Return a reference to the buffer. More...
 
const BufferT & buffer () const
 Return a const reference to the buffer. More...
 
uint8_t * data ()
 Returns a non-const pointer to the data. More...
 
const uint8_t * data () const
 Returns a const pointer to the data. More...
 
template<typename U = BufferT>
enable_if< BufferTraits< U >::hasDeviceDual, const uint8_t * >::type deviceData () const
 
template<typename U = BufferT>
enable_if< BufferTraits< U >::hasDeviceDual, uint8_t * >::type deviceData ()
 
uint64_t size () const
 Returns the size in bytes of the raw memory buffer managed by this GridHandle. More...
 
 operator bool () const
 Return true if this handle contains any grids. More...
 
template<typename ValueT >
const NanoGrid< ValueT > * grid (uint32_t n=0) const
 Returns a const host pointer to the n'th NanoVDB grid encoded in this GridHandle. More...
 
template<typename ValueT >
NanoGrid< ValueT > * grid (uint32_t n=0)
 Returns a host pointer to the n'th NanoVDB grid encoded in this GridHandle. More...
 
template<typename ValueT , typename U = BufferT>
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.g. GPU. More...
 
template<typename ValueT , typename U = BufferT>
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.g. GPU. More...
 
template<typename U = BufferT>
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. More...
 
template<typename U = BufferT>
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. More...
 
bool isPadded () const
 Check if the buffer is this handle has any padding, i.e. if the buffer is larger than the combined size of all its grids. More...
 
uint32_t gridCount () const
 Return the total number of grids contained in this buffer. More...
 
uint64_t gridSize (uint32_t n=0) const
 Return the grid size of the n'th grid in this GridHandle. More...
 
GridType gridType (uint32_t n=0) const
 Return the GridType of the n'th grid in this GridHandle. More...
 
const GridDatagridData (uint32_t n=0) const
 Access to the GridData of the n'th grid in the current handle. More...
 
const GridMetaDatagridMetaData (uint32_t n=0) const
 Returns a const point to the n'th grid meta data. More...
 
void write (std::ostream &os, uint32_t n) const
 Write a specific grid in this buffer to an output stream. More...
 
void write (std::ostream &os) const
 Write the entire grid buffer to an output stream. More...
 
void write (const std::string &fileName) const
 Write this entire grid buffer to a file. More...
 
void write (const std::string &fileName, uint32_t n) const
 Write a specific grid to file. More...
 
void read (std::istream &is, const BufferT &pool=BufferT())
 Read an entire raw grid buffer from an input stream. More...
 
void read (std::istream &is, uint32_t n, const BufferT &pool=BufferT())
 Read a specific grid from an input stream containing a raw grid buffer. More...
 
void read (std::istream &is, const std::string &gridName, const BufferT &pool=BufferT())
 Read a specific grid from an input stream containing a raw grid buffer. More...
 
void read (const std::string &fileName, const BufferT &pool=BufferT())
 Read a raw grid buffer from a file. More...
 
void read (const std::string &fileName, uint32_t n, const BufferT &pool=BufferT())
 Read a specific grid from a file containing a raw grid buffer. More...
 
void read (const std::string &fileName, const std::string &gridName, const BufferT &pool=BufferT())
 Read a specific grid from a file containing a raw grid buffer. More...
 
bool empty () const
 Return true if this handle is empty, i.e. has no allocated memory. More...
 
bool isEmpty () const
 Return true if this handle is empty, i.e. has no allocated memory. More...
 

Detailed Description

template<typename BufferT = HostBuffer>
class nanovdb::GridHandle< BufferT >

This class serves to manage a buffer containing one or more NanoVDB Grids.

Note
It is important to note that this class does NOT depend on OpenVDB.

Member Typedef Documentation

using BufferType = BufferT

Constructor & Destructor Documentation

GridHandle ( T &&  buffer)

Move constructor from a host buffer.

Parameters
bufferbuffer containing one or more NanoGrids that will be moved into this GridHandle
Exceptions
Willthrow and error with the buffer does not contain a valid NanoGrid!
GridHandle ( T &&  buffer)

Move constructor from a dual host-device buffer.

Parameters
bufferbuffer containing one or more NanoGrids that will be moved into this GridHandle
Exceptions
Willthrow and error with the buffer does not contain a valid NanoGrid!
GridHandle ( )
default

Constructs an empty GridHandle.

GridHandle ( const GridHandle< BufferT > &  )
delete

Disallow copy-construction.

GridHandle ( GridHandle< BufferT > &&  other)
inlinenoexcept

Move copy-constructor.

Member Function Documentation

BufferT& buffer ( )
inline

Return a reference to the buffer.

const BufferT& buffer ( ) const
inline

Return a const reference to the buffer.

GridHandle< OtherBufferT > copy ( const OtherBufferT &  buffer = OtherBufferT()) const
inline

Performs a deep copy of the GridHandle, possibly templated on a different buffer type.

Template Parameters
OtherBufferTBuffer type of the deep copy
Parameters
bufferoptional buffer used for allocation
Returns
A new handle of the specified buffer type that contains a deep copy of the current handle
uint8_t* data ( )
inline

Returns a non-const pointer to the data.

Warning
Note that the return pointer can be NULL if the GridHandle was not initialized
const uint8_t* data ( ) const
inline

Returns a const pointer to the data.

Warning
Note that the return pointer can be NULL if the GridHandle was not initialized
enable_if<BufferTraits<U>::hasDeviceDual, const uint8_t*>::type deviceData ( ) const
inline
enable_if<BufferTraits<U>::hasDeviceDual, uint8_t*>::type deviceData ( )
inline
enable_if<BufferTraits<U>::hasDeviceDual, void>::type deviceDownload ( void *  stream = nullptr,
bool  sync = true 
)
inline

Download the grid to from the device, e.g. from GPU to CPU.

Note
This method is only available if the buffer supports devices
enable_if< BufferTraits< U >::hasDeviceDual, const NanoGrid< ValueT > * >::type deviceGrid ( uint32_t  n = 0) const
inline

Return a const pointer to the n'th grid encoded in this GridHandle on the device, e.g. GPU.

Template Parameters
ValueTValue type of the grid point to be returned
Parameters
nIndex of the (device) grid pointer to be returned
Warning
Note that the return pointer can be NULL if the GridHandle has no device grid, n is invalid, or if the template parameter does not match the specified grid.
enable_if<BufferTraits<U>::hasDeviceDual, NanoGrid<ValueT>*>::type deviceGrid ( uint32_t  n = 0)
inline

Return a const pointer to the n'th grid encoded in this GridHandle on the device, e.g. GPU.

Template Parameters
ValueTValue type of the grid point to be returned
Parameters
nIndex if of the grid pointer to be returned
verboseif non-zero error messages will be printed in case something failed
Warning
Note that the return pointer can be NULL if the GridHandle was not initialized, n is invalid, or if the template parameter does not match the specified grid.
enable_if<BufferTraits<U>::hasDeviceDual, void>::type deviceUpload ( void *  stream = nullptr,
bool  sync = true 
)
inline

Upload the grid to the device, e.g. from CPU to GPU.

Note
This method is only available if the buffer supports devices
bool empty ( ) const
inline

Return true if this handle is empty, i.e. has no allocated memory.

const NanoGrid< ValueT > * grid ( uint32_t  n = 0) const
inline

Returns a const host pointer to the n'th NanoVDB grid encoded in this GridHandle.

Template Parameters
ValueTValue type of the grid point to be returned
Parameters
nIndex of the (host) grid pointer to be returned
Warning
Note that the return pointer can be NULL if the GridHandle no host grid, n is invalid or if the template parameter does not match the specified grid!
NanoGrid<ValueT>* grid ( uint32_t  n = 0)
inline

Returns a host pointer to the n'th NanoVDB grid encoded in this GridHandle.

Template Parameters
ValueTValue type of the grid point to be returned
Parameters
nIndex of the (host) grid pointer to be returned
Warning
Note that the return pointer can be NULL if the GridHandle no host grid, n is invalid or if the template parameter does not match the specified grid!
uint32_t gridCount ( ) const
inline

Return the total number of grids contained in this buffer.

const GridData * gridData ( uint32_t  n = 0) const
inline

Access to the GridData of the n'th grid in the current handle.

Parameters
nzero-based ID of the grid
Returns
Const pointer to the n'th GridData in the current handle
const GridMetaData * gridMetaData ( uint32_t  n = 0) const
inline

Returns a const point to the n'th grid meta data.

Parameters
nzero-based ID of the grid
Warning
Note that the return pointer can be NULL if the GridHandle was not initialized
uint64_t gridSize ( uint32_t  n = 0) const
inline

Return the grid size of the n'th grid in this GridHandle.

Parameters
nindex of the grid (assumed to be less than gridCount())
Returns
Return the byte size of the specified grid
GridType gridType ( uint32_t  n = 0) const
inline

Return the GridType of the n'th grid in this GridHandle.

Parameters
nindex of the grid (assumed to be less than gridCount())
Returns
Return the GridType of the specified grid
bool isEmpty ( ) const
inline

Return true if this handle is empty, i.e. has no allocated memory.

bool isPadded ( ) const
inline

Check if the buffer is this handle has any padding, i.e. if the buffer is larger than the combined size of all its grids.

Returns
true is the combined size of all grid is smaller than the buffer size
operator bool ( ) const
inline

Return true if this handle contains any grids.

GridHandle& operator= ( const GridHandle< BufferT > &  )
delete

Disallow copy assignment operation.

GridHandle& operator= ( GridHandle< BufferT > &&  other)
inlinenoexcept

Move copy assignment operation.

void read ( std::istream &  is,
const BufferT &  pool = BufferT() 
)

Read an entire raw grid buffer from an input stream.

Parameters
isinput stream containing a raw grid buffer
pooloptional pool from which to allocate the new grid buffer
Exceptions
Willthrow a std::logic_error if the stream does not contain a valid raw grid
void read ( std::istream &  is,
uint32_t  n,
const BufferT &  pool = BufferT() 
)

Read a specific grid from an input stream containing a raw grid buffer.

Parameters
isinput stream containing a raw grid buffer
nzero-based index of the grid to be read
pooloptional pool from which to allocate the new grid buffer
Exceptions
Willthrow a std::logic_error if the stream does not contain a valid raw grid
void read ( std::istream &  is,
const std::string &  gridName,
const BufferT &  pool = BufferT() 
)

Read a specific grid from an input stream containing a raw grid buffer.

Parameters
isinput stream containing a raw grid buffer
gridNamestring name of the grid to be read
pooloptional pool from which to allocate the new grid buffer
Exceptions
Willthrow a std::logic_error if the stream does not contain a valid raw grid with the speficied name
void read ( const std::string &  fileName,
const BufferT &  pool = BufferT() 
)
inline

Read a raw grid buffer from a file.

Parameters
filenamestring name of the input file containing a raw grid buffer
pooloptional pool from which to allocate the new grid buffe
void read ( const std::string &  fileName,
uint32_t  n,
const BufferT &  pool = BufferT() 
)
inline

Read a specific grid from a file containing a raw grid buffer.

Parameters
filenamestring name of the input file containing a raw grid buffer
nzero-based index of the grid to be read
pooloptional pool from which to allocate the new grid buffer
Exceptions
Willthrow a std::ios_base::failure if the file does not exist and a std::logic_error if the files does not contain a valid raw grid
void read ( const std::string &  fileName,
const std::string &  gridName,
const BufferT &  pool = BufferT() 
)
inline

Read a specific grid from a file containing a raw grid buffer.

Parameters
filenamestring name of the input file containing a raw grid buffer
gridNamestring name of the grid to be read
pooloptional pool from which to allocate the new grid buffer
Exceptions
Willthrow a std::ios_base::failure if the file does not exist and a std::logic_error if the files does not contain a valid raw grid withe the specified name
void reset ( )
inline

clear this GridHandle to an empty handle

uint64_t size ( ) const
inline

Returns the size in bytes of the raw memory buffer managed by this GridHandle.

void write ( std::ostream &  os,
uint32_t  n 
) const
inline

Write a specific grid in this buffer to an output stream.

Parameters
osoutput stream that the buffer will be written to
nzero-based index of the grid to be written to stream
void write ( std::ostream &  os) const
inline

Write the entire grid buffer to an output stream.

Parameters
osoutput stream that the buffer will be written to
void write ( const std::string &  fileName) const
inline

Write this entire grid buffer to a file.

Parameters
fileNamestring name of the output file
void write ( const std::string &  fileName,
uint32_t  n 
) const
inline

Write a specific grid to file.

Parameters
fileNamestring name of the output file
nzero-based index of the grid to be written to file