Loading...
Searching...
No Matches
nanovdb::io Namespace Reference

## Namespaces

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

## Classes

struct | Header
| Data encoded at the head of each segment of a file or stream. More...
struct | MetaData
| Data encoded for each of the grids associated with a segment. More...
struct | GridMetaData
struct | Segment

## Typedefs

using | fileSize_t = uint64_t

## Enumerations

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

## Functions

template<typename StreamT>
void | writeUncompressedGrid (StreamT &os, const void *buffer)
| 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!
template<typename GridHandleT, template< typename... > class VecT>
void | writeUncompressedGrids (const char *fileName, const VecT< GridHandleT > &handles)
| write multiple NanoVDB grids to a single file, without compression.
template<typename GridHandleT, typename StreamT, template< typename... > class VecT>
VecT< GridHandleT > | readUncompressedGrids (StreamT &is, const typename GridHandleT::BufferType &buffer=typename GridHandleT::BufferType())
| read all uncompressed grids from a stream and return their handles.
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.
const char * | toStr (Codec codec)
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.
uint64_t | stringHash (const std::string &str)
| Return a uint64_t hash key of a std::string.
uint64_t | reverseEndianness (uint64_t val)
| Return a uint64_t with its bytes reversed so we can check for endianness.
template<typename BufferT>
void | writeGrid (const std::string &fileName, const GridHandle< BufferT > &handle, Codec codec=Codec::NONE, int verbose=0)
| Write a single grid to file (over-writing existing content of the file).
template<typename BufferT>
void | writeGrid (std::ostream &os, const GridHandle< BufferT > &handle, Codec codec=Codec::NONE)
| Write a single grid to stream (starting at the current position).
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).
template<typename BufferT = HostBuffer, template< typename... > class VecT = std::vector>
void | writeGrids (std::ostream &os, const VecT< GridHandle< BufferT > > &handles, Codec codec=Codec::NONE)
| Writes multiple grids to stream (starting at its current position).
template<typename BufferT = HostBuffer>
GridHandle< BufferT > | readGrid (const std::string &fileName, uint64_t n=0, int verbose=0, const BufferT &buffer=BufferT())
| Read the n'th grid from file (defaults to first grid).
template<typename BufferT = HostBuffer>
GridHandle< BufferT > | readGrid (std::istream &is, uint64_t n=0, const BufferT &buffer=BufferT())
| Read the n'th grid from stream (defaults to first grid).
template<typename BufferT = HostBuffer>
GridHandle< BufferT > | readGrid (const std::string &fileName, const std::string &gridName, int verbose=0, const BufferT &buffer=BufferT())
| Read the first grid with a specific name.
template<typename BufferT = HostBuffer>
GridHandle< BufferT > | readGrid (std::istream &is, const std::string &gridName, const BufferT &buffer=BufferT())
| Read the first grid with a specific name.
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.
template<typename BufferT = HostBuffer, template< typename... > class VecT = std::vector>
VecT< GridHandle< BufferT > > | readGrids (std::istream &is, const BufferT &buffer=BufferT())
| Real all grids at the current position of the input stream.
bool | hasGrid (const std::string &fileName, const std::string &gridName)
| Return true if the file contains a grid with the specified name.
bool | hasGrid (std::istream &is, const std::string &gridName)
| Return true if the stream contains a grid with the specified name.
std::vector< GridMetaData > | readGridMetaData (const std::string &fileName)
| Reads and returns a vector of meta data for all the grids found in the specified file.
std::vector< GridMetaData > | readGridMetaData (std::istream &is)
| Reads and returns a vector of meta data for all the grids found in the specified stream.
template<typename ValueT>
void | writeDense (const DenseGrid< ValueT > &grid, const char *fileName)
template<typename BufferT>
void | writeDense (const DenseGridHandle< BufferT > &handle, const char *fileName)
template<typename BufferT = HostBuffer>
DenseGridHandle< BufferT > | readDense (const char *fileName, const BufferT &allocator=BufferT())

## Typedef Documentation

## fileSize_t

using fileSize_t = 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)

## Enumeration Type Documentation

## Codec

enum class Codec : uint16_t

strong

Optional compression codecs.

Note
  NONE is the default, ZIP is slow but compact and BLOSC offers a great balance.

Warning
  NanoVDB optionally supports ZIP and BLOSC compression and will throw an exception if it support is required but missing.

Enumerator
NONE |
ZIP |
BLOSC |
END |

## Function Documentation

## hasGrid() [1/2]

bool hasGrid | ( | const std::string & | fileName,
|  | const std::string & | gridName )

inline

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

## hasGrid() [2/2]

bool hasGrid | ( | std::istream & | is,
|  | const std::string & | gridName )

inline

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

## readDense()

template<typename BufferT = HostBuffer>

DenseGridHandle< BufferT > readDense | ( | const char * | fileName,
|  | const BufferT & | allocator = BufferT() )

## readGrid() [1/4]

template<typename BufferT = HostBuffer>

GridHandle< BufferT > readGrid | ( | const std::string & | fileName,
|  | const std::string & | gridName,
|  | int | verbose = 0,
|  | const BufferT & | buffer = BufferT() )

Read the first grid with a specific name.

Warning
  If not grid exists with the specified name the resulting GridHandle is empty

## readGrid() [2/4]

template<typename BufferT = HostBuffer>

GridHandle< BufferT > readGrid | ( | const std::string & | fileName,
|  | uint64_t | n = 0,
|  | int | verbose = 0,
|  | const BufferT & | buffer = BufferT() )

Read the n'th grid from file (defaults to first grid).

Read the n'th grid.

Exceptions

  If | n exceeds the number of grids in the file

## readGrid() [3/4]

template<typename BufferT = HostBuffer>

GridHandle< BufferT > readGrid | ( | std::istream & | is,
|  | const std::string & | gridName,
|  | const BufferT & | buffer = BufferT() )

Read the first grid with a specific name.

## readGrid() [4/4]

template<typename BufferT = HostBuffer>

GridHandle< BufferT > readGrid | ( | std::istream & | is,
|  | uint64_t | n = 0,
|  | const BufferT & | buffer = BufferT() )

Read the n'th grid from stream (defaults to first grid).

Exceptions

  If | n exceeds the number of grids in the stream

## readGridMetaData() [1/2]

std::vector< GridMetaData > readGridMetaData | ( | const std::string & | fileName | ) |

inline

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

## readGridMetaData() [2/2]

std::vector< GridMetaData > readGridMetaData | ( | std::istream & | is | ) |

inline

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

## readGrids() [1/2]

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.

Read all the grids.

## readGrids() [2/2]

template<typename BufferT = HostBuffer, template< typename... > class VecT = std::vector>

VecT< GridHandle< BufferT > > readGrids | ( | std::istream & | is,
|  | const BufferT & | buffer = BufferT() )

Real all grids at the current position of the input stream.

## readUncompressedGrids() [1/2]

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.

## readUncompressedGrids() [2/2]

template<typename GridHandleT, typename StreamT, template< typename... > class VecT>

VecT< GridHandleT > readUncompressedGrids | ( | StreamT & | is,
|  | const typename GridHandleT::BufferType & | buffer = typename GridHandleT::BufferType() )

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

Exceptions

  std::invalid_argument | if stream does not contain a single uncompressed valid NanoVDB grid

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

## reverseEndianness()

uint64_t reverseEndianness | ( | uint64_t | val | ) |

inline

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

## stringHash() [1/2]

uint64_t 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.

## stringHash() [2/2]

uint64_t stringHash | ( | const std::string & | str | ) |

inline

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

## toStr()

const char * toStr | ( | Codec | codec | ) |

inline

## writeDense() [1/2]

template<typename ValueT>

void writeDense | ( | const DenseGrid< ValueT > & | grid,
|  | const char * | fileName )

## writeDense() [2/2]

template<typename BufferT>

void writeDense | ( | const DenseGridHandle< BufferT > & | handle,
|  | const char * | fileName )

## writeGrid() [1/2]

template<typename BufferT>

void writeGrid | ( | const std::string & | fileName,
|  | const GridHandle< BufferT > & | handle,
|  | Codec | codec = Codec::NONE,
|  | int | verbose = 0 )

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

## writeGrid() [2/2]

template<typename BufferT>

void writeGrid | ( | std::ostream & | os,
|  | const GridHandle< BufferT > & | handle,
|  | Codec | codec = Codec::NONE )

Write a single grid to stream (starting at the current position).

Note
  This method can be used to append grid to an existing stream

## writeGrids() [1/2]

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).

## writeGrids() [2/2]

template<typename BufferT = HostBuffer, template< typename... > class VecT = std::vector>

void writeGrids | ( | std::ostream & | os,
|  | const VecT< GridHandle< BufferT > > & | handles,
|  | Codec | codec = Codec::NONE )

Writes multiple grids to stream (starting at its current position).

Note
  This method can be used to append multiple grids to an existing stream

## writeUncompressedGrid()

template<typename StreamT>

void writeUncompressedGrid | ( | StreamT & | os,
|  | const void * | buffer )

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_argument | if 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 :)

## writeUncompressedGrids()

template<typename GridHandleT, template< typename... > class VecT>

void writeUncompressedGrids | ( | const char * | fileName,
|  | const VecT< GridHandleT > & | handles )

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