OpenVDB 13.1.0
Loading...
Searching...
No Matches
IO.h File Reference

Implements I/O for NanoVDB grids. Features optional BLOSC and ZIP file compression, support for multiple grids per file as well as multiple grid types. More...

#include <nanovdb/NanoVDB.h>
#include <nanovdb/GridHandle.h>
#include <nanovdb/tools/GridChecksum.h>
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <cstring>
#include <memory>
#include <vector>

Go to the source code of this file.

Classes

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

Namespaces

namespace  nanovdb
 Defines a simple memory pool used to call cub functions that use dynamic temporary storage.
namespace  nanovdb::io

Typedefs

using fileSize_t = uint64_t

Functions

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)
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>
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.
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.
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). This method also works if the file contains a raw grid buffer in which case a single GridHandle is returned.
uint64_t stringHash (const char *cstr)
 Internal functions for compressed read/write of a NanoVDB GridHandle into a stream.
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.
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< FileGridMetaDatareadGridMetaData (const std::string &fileName)
 Reads and returns a vector of meta data for all the grids found in the specified file.
std::vector< FileGridMetaDatareadGridMetaData (std::istream &is)
 Reads and returns a vector of meta data for all the grids found in the specified stream.
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.
template<typename BufferT = HostBuffer, template< typename... > class VecT = std::vector>
VecT< GridHandle< BufferT > > readGrids (std::istream &is, const BufferT &pool=BufferT())
template<typename T>
std::ostream & operator<< (std::ostream &os, const nanovdb::math::BBox< nanovdb::math::Vec3< T > > &b)
std::ostream & operator<< (std::ostream &os, const nanovdb::CoordBBox &b)
std::ostream & operator<< (std::ostream &os, const nanovdb::Coord &ijk)
template<typename T>
std::ostream & operator<< (std::ostream &os, const nanovdb::math::Vec3< T > &v)
template<typename T>
std::ostream & operator<< (std::ostream &os, const nanovdb::math::Vec4< T > &v)

Detailed Description

Implements I/O for NanoVDB grids. Features optional BLOSC and ZIP file compression, support for multiple grids per file as well as multiple grid types.

Author
Ken Museth
Date
May 1, 2020
Note
This file does NOT depend on OpenVDB, but optionally on ZIP and BLOSC

NanoVDB files take on one of the two following formats: 1) multiple segments each with multiple grids (segments have easy to access metadata about its grids) 2) starting with verion 32.6.0 nanovdb files also support a raw buffer with one or more grids (just a dump of a raw grid buffer, so no new metadata in headers as when using segments mentioned above).

Example of case 1: | <---------------------------------— segment 1 with N grids --------------------------------------> | <— segment 2 ... FileHeader, FileMetaData0, gridName0...FileMetaDataN, gridNameN, compressed Grid0, ... compressed GridN FileHeader ... Example of case 2: | <– grid buffer ---> | Grid0, Grid1, ... GridN

Note that FileHeader and FileMetaData (both defined in NanoVDB.h) have fixed sizes of respectively 16B and 176B. However, GridNameX and GridX have variable sizes!

Function Documentation

◆ operator<<() [1/5]

std::ostream & operator<< ( std::ostream & os,
const nanovdb::Coord & ijk )
inline

◆ operator<<() [2/5]

std::ostream & operator<< ( std::ostream & os,
const nanovdb::CoordBBox & b )
inline

◆ operator<<() [3/5]

template<typename T>
std::ostream & operator<< ( std::ostream & os,
const nanovdb::math::BBox< nanovdb::math::Vec3< T > > & b )
inline

◆ operator<<() [4/5]

template<typename T>
std::ostream & operator<< ( std::ostream & os,
const nanovdb::math::Vec3< T > & v )
inline

◆ operator<<() [5/5]

template<typename T>
std::ostream & operator<< ( std::ostream & os,
const nanovdb::math::Vec4< T > & v )
inline