14#ifndef NANOVDB_GRIDVALIDATOR_H_HAS_BEEN_INCLUDED
15#define NANOVDB_GRIDVALIDATOR_H_HAS_BEEN_INCLUDED
17#include "../NanoVDB.h"
27template <
typename ValueT>
28bool isValid(
const NanoGrid<ValueT> &grid,
bool detailed =
true,
bool verbose =
false);
31template <
typename ValueT>
35 inline static void checkTree(
const GridT&, std::string&,
bool);
36 inline static void checkRoot(
const GridT&, std::string&,
bool);
37 inline static void checkNodes(
const GridT&, std::string&);
52template <
typename ValueT>
61 errorStr.assign(
"Grid is not 32B aligned");
66 errorStr.assign(
"Mis-matching checksum");
70 }
else if (
data->mVersion <
Version(29,0,0) &&
data->mVersion.id() != 28u) {
71 ss <<
"Invalid old major version number: Expected 28 or newer, but read " <<
data->mVersion.id();
74 errorStr.assign(
"Invalid GridClass");
78 errorStr.assign(
"Invalid combination of ValueType and GridType");
80 errorStr.assign(
"Invalid combination of GridType and GridClass");
82 errorStr.assign(
"Invalid Tree pointer");
91template<
typename ValueT>
95 errorStr.assign(
"Tree is not 32B aligned");
97 errorStr.assign(
"Invalid root pointer (should be located after the Grid and Tree)");
99 errorStr.assign(
"Invalid root pointer (appears to be located after the end of the buffer)");
107template<
typename ValueT>
108void GridValidator<ValueT>::checkRoot(
const GridT &grid, std::string &errorStr,
bool detailed)
110 auto &root =
grid.tree().root();
113 errorStr.assign(
"Root is not 32B aligned");
118 const auto *tile =
data->tile(i);
120 errorStr.assign(
"Invalid root tile pointer (below lower bound");
121 }
else if ( (
const uint8_t *) tile >
maxPtr -
sizeof(*tile) ) {
122 errorStr.assign(
"Invalid root tile pointer (above higher bound");
131template<
typename ValueT>
132void GridValidator<ValueT>::checkNodes(
const GridT &grid, std::string &errorStr)
134 auto &root =
grid.tree().root();
138 auto check = [&](
const void * ptr,
size_t ptrSize) ->
bool {
140 errorStr.assign(
"Invalid node pointer: not 32B aligned");
142 errorStr.assign(
"Invalid node pointer: below lower bound");
144 errorStr.assign(
"Invalid node pointer: above higher bound");
149 for (
auto it2 =
grid.tree().root().beginChild();
it2; ++
it2) {
167template <
typename ValueT>
171 if (
verbose && !str.empty()) std::cerr <<
"Validation failed: " << str << std::endl;
Computes a pair of 32bit checksums, og a Grid, by means of Cyclic Redundancy Check (CRC)
#define NANOVDB_MAJOR_VERSION_NUMBER
Definition NanoVDB.h:123
#define NANOVDB_MAGIC_NUMBER
Definition NanoVDB.h:121
Definition DenseGrid.h:402
DenseGridHandle()=default
uint8_t * data()
Returns a non-const pointer to the data.
Definition DenseGrid.h:432
const DenseGrid< ValueT > * grid() const
Returns a const pointer to the NanoVDB grid encoded in the DenseGridHandle.
Definition DenseGrid.h:447
Allows for the construction of NanoVDB grids without any dependecy.
Definition GridValidator.h:33
static std::string check(const GridT &grid, bool detailed=true)
Returns an error message (an empty string means no error)
Definition GridValidator.h:53
Highest level of the data structure. Contains a tree and a world->index transform (that currently onl...
Definition NanoVDB.h:2556
Bit-compacted representation of all three version numbers.
Definition NanoVDB.h:648
bool validateChecksum(const NanoGrid< ValueT > &grid, ChecksumMode mode=ChecksumMode::Default)
Return true if the checksum of the grid matches the expected value already encoded into the grid's me...
Definition GridChecksum.h:269
static bool isValid(const void *p)
return true if the specified pointer is aligned and not NULL
Definition NanoVDB.h:504
Struct with all the member data of the Grid (useful during serialization of an openvdb grid)
Definition NanoVDB.h:2432