HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nanovdb::io Namespace Reference

Namespaces

 Internal
 Internal functions for compressed read/write of a NanoVDB GridHandle into a stream.
 

Classes

struct  FileHeader
 Data encoded at the head of each segment of a file or stream. More...
 
struct  FileMetaData
 
struct  FileGridMetaData
 This class defines the meta data stored for each grid in a segment. More...
 
struct  Segment
 This class defines all the data stored in segment of a file. More...
 

Typedefs

using fileSize_t = uint64_t
 

Enumerations

enum  Codec : uint16_t { Codec::NONE = 0, Codec::ZIP = 1, Codec::BLOSC = 2, Codec::END = 3 }
 Define compression codecs. More...
 

Functions

const char * toStr (Codec codec)
 
template<typename StreamT >
void writeUncompressedGrid (StreamT &os, const GridData *gridData, bool raw=false)
 This is a standalone alternative to io::writeGrid(...,Codec::NONE) defined in util/IO.h Unlike the latter this function has no dependencies at all, not even NanoVDB.h, so it also works if client code only includes PNanoVDB.h! More...
 
template<typename GridHandleT , template< typename...> class VecT>
void writeUncompressedGrids (const char *fileName, const VecT< GridHandleT > &handles, bool raw=false)
 write multiple NanoVDB grids to a single file, without compression. More...
 
template<typename GridHandleT , typename StreamT , template< typename...> class VecT>
VecT< GridHandleT > readUncompressedGrids (StreamT &is, const typename GridHandleT::BufferType &pool=typename GridHandleT::BufferType())
 read all uncompressed grids from a stream and return their handles. More...
 
template<typename GridHandleT , template< typename...> class VecT>
VecT< GridHandleT > readUncompressedGrids (const char *fileName, const typename GridHandleT::BufferType &buffer=typename GridHandleT::BufferType())
 Read a multiple un-compressed NanoVDB grids from a file and return them as a vector. More...
 
template<typename BufferT >
void writeGrid (const std::string &fileName, const GridHandle< BufferT > &handle, io::Codec codec=io::Codec::NONE, int verbose=0)
 Write a single grid to file (over-writing existing content of the file) More...
 
template<typename BufferT = HostBuffer, template< typename...> class VecT = std::vector>
void writeGrids (const std::string &fileName, const VecT< GridHandle< BufferT >> &handles, Codec codec=Codec::NONE, int verbose=0)
 Write multiple grids to file (over-writing existing content of the file) More...
 
template<typename BufferT = HostBuffer>
GridHandle< BufferT > readGrid (const std::string &fileName, int n=0, int verbose=0, const BufferT &buffer=BufferT())
 Read and return one or all grids from a file into a single GridHandle. More...
 
template<typename BufferT = HostBuffer>
GridHandle< BufferT > readGrid (const std::string &fileName, const std::string &gridName, int verbose=0, const BufferT &buffer=BufferT())
 Read and return the first grid with a specific name from a file. More...
 
template<typename BufferT = HostBuffer, template< typename...> class VecT = std::vector>
VecT< GridHandle< BufferT > > readGrids (const std::string &fileName, int verbose=0, const BufferT &buffer=BufferT())
 Read all the grids in the file and return them as a vector of multiple GridHandles, each containing all grids encoded in the same segment of the file (i.e. they where written together) More...
 
uint64_t stringHash (const char *cstr)
 Standard hash function to use on strings; std::hash may vary by platform/implementation and is know to produce frequent collisions. More...
 
uint64_t stringHash (const std::string &str)
 Return a uint64_t hash key of a std::string. More...
 
uint64_t reverseEndianness (uint64_t val)
 Return a uint64_t with its bytes reversed so we can check for endianness. More...
 
bool hasGrid (const std::string &fileName, const std::string &gridName)
 Return true if the file contains a grid with the specified name. More...
 
bool hasGrid (std::istream &is, const std::string &gridName)
 Return true if the stream contains a grid with the specified name. More...
 
std::vector< FileGridMetaDatareadGridMetaData (const std::string &fileName)
 Reads and returns a vector of meta data for all the grids found in the specified file. More...
 
std::vector< FileGridMetaDatareadGridMetaData (std::istream &is)
 Reads and returns a vector of meta data for all the grids found in the specified stream. More...
 
 Version ()}
 
 gridName (grid.gridName())
 
template<typename BufferT >
void writeGrid (std::ostream &os, const GridHandle< BufferT > &handle, Codec codec)
 
template<typename BufferT = HostBuffer, template< typename...> class VecT = std::vector>
void writeGrids (std::ostream &os, const VecT< GridHandle< BufferT >> &handles, Codec codec=Codec::NONE)
 
template<typename BufferT >
GridHandle< BufferT > readGrid (std::istream &is, int n, const BufferT &pool)
 
template<typename BufferT >
GridHandle< BufferT > readGrid (std::istream &is, const std::string &gridName, const BufferT &pool)
 Read a specific grid from an input stream given the name of the grid. More...
 
template<typename BufferT = HostBuffer, template< typename...> class VecT = std::vector>
VecT< GridHandle< BufferT > > readGrids (std::istream &is, const BufferT &pool=BufferT())
 

Variables

 c
 

Typedef Documentation

using nanovdb::io::fileSize_t = typedef uint64_t

We fix a specific size for counting bytes in files so that they are saved the same regardless of machine precision. (Note there are still little/bigendian issues, however)

Definition at line 111 of file IO.h.

Enumeration Type Documentation

enum nanovdb::io::Codec : uint16_t
strong

Define compression codecs.

Note
NONE is the default, ZIP is slow but compact and BLOSC offers a great balance.
Exceptions
NanoVDBoptionally supports ZIP and BLOSC compression and will throw an exception if its support is required but missing.
Enumerator
NONE 
ZIP 
BLOSC 
END 

Definition at line 7826 of file NanoVDB.h.

Function Documentation

nanovdb::io::gridName ( grid.  gridName())

Definition at line 332 of file IO.h.

bool nanovdb::io::hasGrid ( const std::string fileName,
const std::string gridName 
)
inline

Return true if the file contains a grid with the specified name.

Definition at line 715 of file IO.h.

bool nanovdb::io::hasGrid ( std::istream &  is,
const std::string gridName 
)
inline

Return true if the stream contains a grid with the specified name.

Definition at line 722 of file IO.h.

template<typename BufferT = HostBuffer>
GridHandle< BufferT > nanovdb::io::readGrid ( const std::string fileName,
int  n = 0,
int  verbose = 0,
const BufferT &  buffer = BufferT() 
)

Read and return one or all grids from a file into a single GridHandle.

Read the n'th grid.

Template Parameters
BufferTType of buffer used memory allocation
Parameters
fileNamestring name of file to be read from
nzero-based signed index of the grid to be read. The default value of 0 means read only first grid. A negative value of n means read all grids in the file.
verbosespecify verbosity level. Default value of zero means quiet.
bufferoptional buffer used for memory allocation
Returns
return a single GridHandle with one or all grids found in the file
Exceptions
willthrow a std::runtime_error if the file does not contain a grid with index n

Definition at line 580 of file IO.h.

template<typename BufferT = HostBuffer>
GridHandle< BufferT > nanovdb::io::readGrid ( const std::string fileName,
const std::string gridName,
int  verbose = 0,
const BufferT &  buffer = BufferT() 
)

Read and return the first grid with a specific name from a file.

Read the first grid with a specific name.

Template Parameters
BufferTType of buffer used memory allocation
Parameters
fileNamestring name of file to be read from
gridNamestring name of the grid to be read
verbosespecify verbosity level. Default value of zero means quiet.
bufferoptional buffer used for memory allocation
Returns
return a single GridHandle containing the grid with the specific name
Exceptions
willthrow a std::runtime_error if the file does not contain a grid with the specific name

Definition at line 633 of file IO.h.

template<typename BufferT >
GridHandle<BufferT> nanovdb::io::readGrid ( std::istream &  is,
int  n,
const BufferT &  pool 
)

Definition at line 519 of file IO.h.

template<typename BufferT >
GridHandle<BufferT> nanovdb::io::readGrid ( std::istream &  is,
const std::string gridName,
const BufferT &  pool 
)

Read a specific grid from an input stream given the name of the grid.

Template Parameters
BufferTBuffer type used for allocation
Parameters
isinput stream from which to read the grid
gridNamestring name of the (first) grid to be returned
pooloptional memory pool from which to allocate the grid buffer
Returns
Return the first grid in the input stream with a specific name
Exceptions
std::runtime_errorwith no grid exists with the specified name

Definition at line 603 of file IO.h.

std::vector< FileGridMetaData > nanovdb::io::readGridMetaData ( const std::string fileName)
inline

Reads and returns a vector of meta data for all the grids found in the specified file.

Definition at line 684 of file IO.h.

std::vector< FileGridMetaData > nanovdb::io::readGridMetaData ( std::istream &  is)
inline

Reads and returns a vector of meta data for all the grids found in the specified stream.

Definition at line 691 of file IO.h.

template<typename BufferT = HostBuffer, template< typename...> class VecT = std::vector>
VecT< GridHandle< BufferT > > nanovdb::io::readGrids ( const std::string fileName,
int  verbose = 0,
const BufferT &  buffer = BufferT() 
)

Read all the grids in the file and return them as a vector of multiple GridHandles, each containing all grids encoded in the same segment of the file (i.e. they where written together)

Read all the grids.

Template Parameters
BufferTType of buffer used memory allocation
Parameters
fileNamestring name of file to be read from
verbosespecify verbosity level. Default value of zero means quiet.
bufferoptional buffer used for memory allocation
Returns
Return a vector of GridHandles each containing all grids encoded in the same segment of the file (i.e. they where written together).

Definition at line 673 of file IO.h.

template<typename BufferT = HostBuffer, template< typename...> class VecT = std::vector>
VecT<GridHandle<BufferT> > nanovdb::io::readGrids ( std::istream &  is,
const BufferT &  pool = BufferT() 
)

Definition at line 651 of file IO.h.

template<typename GridHandleT , typename StreamT , template< typename...> class VecT>
VecT<GridHandleT> nanovdb::io::readUncompressedGrids ( StreamT &  is,
const typename GridHandleT::BufferType &  pool = typename GridHandleT::BufferType() 
)

read all uncompressed grids from a stream and return their handles.

Exceptions
std::invalid_argumentif stream does not contain a single uncompressed valid NanoVDB grid

StreamT class must support: "bool read(char*, size_t)" and "void skip(uint32_t)"

Definition at line 7966 of file NanoVDB.h.

template<typename GridHandleT , template< typename...> class VecT>
VecT<GridHandleT> nanovdb::io::readUncompressedGrids ( const char *  fileName,
const typename GridHandleT::BufferType &  buffer = typename GridHandleT::BufferType() 
)

Read a multiple un-compressed NanoVDB grids from a file and return them as a vector.

Definition at line 8011 of file NanoVDB.h.

uint64_t nanovdb::io::reverseEndianness ( uint64_t  val)
inline

Return a uint64_t with its bytes reversed so we can check for endianness.

Definition at line 136 of file IO.h.

uint64_t nanovdb::io::stringHash ( const char *  cstr)
inline

Standard hash function to use on strings; std::hash may vary by platform/implementation and is know to produce frequent collisions.

Definition at line 739 of file IO.h.

uint64_t nanovdb::io::stringHash ( const std::string str)
inline

Return a uint64_t hash key of a std::string.

Definition at line 133 of file IO.h.

const char* nanovdb::io::toStr ( Codec  codec)
inline

Definition at line 7879 of file NanoVDB.h.

nanovdb::io::Version ( )
template<typename BufferT >
void nanovdb::io::writeGrid ( const std::string fileName,
const GridHandle< BufferT > &  handle,
io::Codec  codec = io::Codec::NONE,
int  verbose = 0 
)

Write a single grid to file (over-writing existing content of the file)

Definition at line 487 of file IO.h.

template<typename BufferT >
void nanovdb::io::writeGrid ( std::ostream &  os,
const GridHandle< BufferT > &  handle,
Codec  codec 
)

Definition at line 472 of file IO.h.

template<typename BufferT = HostBuffer, template< typename...> class VecT = std::vector>
void nanovdb::io::writeGrids ( const std::string fileName,
const VecT< GridHandle< BufferT >> &  handles,
Codec  codec = Codec::NONE,
int  verbose = 0 
)

Write multiple grids to file (over-writing existing content of the file)

Definition at line 508 of file IO.h.

template<typename BufferT = HostBuffer, template< typename...> class VecT = std::vector>
void nanovdb::io::writeGrids ( std::ostream &  os,
const VecT< GridHandle< BufferT >> &  handles,
Codec  codec = Codec::NONE 
)

Definition at line 502 of file IO.h.

template<typename StreamT >
void nanovdb::io::writeUncompressedGrid ( StreamT &  os,
const GridData *  gridData,
bool  raw = false 
)

This is a standalone alternative to io::writeGrid(...,Codec::NONE) defined in util/IO.h Unlike the latter this function has no dependencies at all, not even NanoVDB.h, so it also works if client code only includes PNanoVDB.h!

Writes a raw NanoVDB buffer, possibly with multiple grids, to a stream WITHOUT compression. It follows all the conventions in util/IO.h so the stream can be read by all existing client code of NanoVDB.

Note
This method will always write uncompressed grids to the stream, i.e. Blosc or ZIP compression is never applied! This is a fundamental limitation and feature of this standalone function.
Exceptions
std::invalid_argumentif buffer does not point to a valid NanoVDB grid.
Warning
This is pretty ugly code that involves lots of pointer and bit manipulations - not for the faint of heart :)

Definition at line 7908 of file NanoVDB.h.

template<typename GridHandleT , template< typename...> class VecT>
void nanovdb::io::writeUncompressedGrids ( const char *  fileName,
const VecT< GridHandleT > &  handles,
bool  raw = false 
)

write multiple NanoVDB grids to a single file, without compression.

Note
To write all grids in a single GridHandle simply use handle.write("fieNane")

Definition at line 7938 of file NanoVDB.h.

Variable Documentation