20#ifndef NANOVDB_TOOLS_GRID_VALIDATOR_H_HAS_BEEN_INCLUDED
21#define NANOVDB_TOOLS_GRID_VALIDATOR_H_HAS_BEEN_INCLUDED
39template <
typename ValueT>
45template<
typename ValueT>
52 if (grid ==
nullptr) {
53 return util::sprint(error,
"Invalid pointer: Grid is NULL");
55 return util::sprint(error,
"Invalid pointer: Grid is misaligned");
75 auto &tree = grid->
tree();
76 if (
auto *p = tree.getRoot()) {
79 return util::strcpy(error,
"Invalid pointer: Root is NULL");
83 auto &root = tree.root();
84 auto *rootData = root.data();
85 if (rootData ==
nullptr) {
86 return util::strcpy(error,
"Invalid pointer: Root is NULL");
87 }
else if (!
isAligned((
const void*)rootData)) {
88 return util::strcpy(error,
"Invalid pointer: Root is misaligned");
89 }
else if ( (
const uint8_t*)(rootData) < (
const uint8_t*)(&tree+1)) {
90 return util::strcpy(error,
"Invalid root pointer (should be located after the Grid and Tree)");
91 }
else if ( (
const void*)(rootData) >
util::PtrAdd(rootData, root.memUsage())) {
92 return util::strcpy(error,
"Invalid root pointer (appears to be located after the end of the buffer)");
94 const void *bounds[2] = {rootData + 1,
util::PtrAdd(rootData, root.memUsage())};
95 for (uint32_t i = 0; i<rootData->mTableSize; ++i) {
96 const void *tile = rootData->tile(i);
97 if ( tile < bounds[0] ) {
98 return util::strcpy(error,
"Invalid root tile pointer (below lower bound");
99 }
else if (tile >= bounds[1]) {
100 return util::strcpy(error,
"Invalid root tile pointer (above higher bound");
108 auto *n0 = tree.template getFirstNode<0>();
109 auto *n1 = tree.template getFirstNode<1>();
110 auto *n2 = tree.template getFirstNode<2>();
113 auto check = [&](
const void *ptr,
int level) ->
bool {
115 util::strcpy(error,
"Invalid node pointer: node is NULL");
117 util::strcpy(error,
"Invalid node pointer: node is misaligned");
118 }
else if (test && level == 0 && (
const void*)(n0++) != ptr) {
119 util::strcpy(error,
"Leaf node is not stored breadth-first");
120 }
else if (test && level == 1 && (
const void*)(n1++) != ptr) {
121 util::strcpy(error,
"Lower node is not stored breadth-first");
122 }
else if (test && level == 2 && (
const void*)(n2++) != ptr) {
123 util::strcpy(error,
"Upper node is not stored breadth-first");
124 }
else if ( ptr < bounds[level][0] ) {
125 util::strcpy(error,
"Invalid node pointer: below lower bound");
126 }
else if ( ptr >= bounds[level][1] ) {
127 util::strcpy(error,
"Invalid node pointer: above higher bound");
132 for (
auto it2 = root.cbeginChild(); it2; ++it2) {
133 if (check(&*it2, 2))
return error;
134 for (
auto it1 = it2->cbeginChild(); it1; ++it1) {
135 if (check(&*it1, 1))
return error;
136 for (
auto it0 = it1->cbeginChild(); it0; ++it0)
if (check(&*it0, 0))
return error;
145template <
typename ValueT>
148 std::unique_ptr<char[]> strUP(
new char[100]);
149 char *str = strUP.get();
154 if (verbose && !
util::empty(str)) std::cerr <<
"Validation failed: " << str << std::endl;
162 template <
typename BuildT>
171 std::cerr <<
"Unsupported GridType: \"" <<
toStr(str, gridData->
mGridType) <<
"\"\n" << std::endl;
184template <
typename Gr
idHandleT>
189 }
else if (gridID >= handle.gridCount()) {
190 if (verbose) std::cerr <<
"grid index " << gridID <<
" exceeds available grid count " << handle.gridCount() << std::endl;
204template <
typename Gr
idHandleT>
208 for (uint32_t gridID=0; gridID<handle.gridCount(); ++gridID) {
209 if (!
validateGrid(handle, gridID, mode, verbose))
return false;
Computes a pair of uint32_t checksums, of a Grid, by means of 32 bit Cyclic Redundancy Check (CRC32)
Implements a light-weight self-contained VDB data-structure in a single file! In other words,...
#define NANOVDB_MAGIC_GRID
Definition NanoVDB.h:140
#define NANOVDB_MAGIC_NUMB
Definition NanoVDB.h:139
#define __hostdev__
Definition SampleFromVoxels.h:29
bool isBreadthFirst() const
Definition NanoVDB.h:2301
uint64_t gridSize() const
Return memory usage in bytes for this class only.
Definition NanoVDB.h:2188
const TreeT & tree() const
Return a const reference to the tree.
Definition NanoVDB.h:2211
bool isCompatible() const
Definition NanoVDB.h:757
static DstT * PtrAdd(void *p, int64_t offset)
Adds a byte offset to a non-const pointer to produce another non-const pointer.
Definition Util.h:555
char * strcpy(char *dst, const char *src)
Copy characters from src to dst.
Definition Util.h:209
bool empty(const char *str)
tests if a c-string str is empty, that is its first value is '\0'
Definition Util.h:187
char * sprint(char *dst, T var1, Types... var2)
prints a variable number of string and/or numbers to a destination string
Definition Util.h:329
Defines a simple memory pool used to call cub functions that use dynamic temporary storage.
Definition GridHandle.h:34
auto callNanoGrid(GridDataT *gridData, ArgsT &&... args)
Below is an example of the struct used for generic programming with callNanoGrid.
Definition NanoVDB.h:4805
GridType toGridType()
Maps from a templated build type to a GridType enum.
Definition NanoVDB.h:848
Grid< NanoTree< BuildT > > NanoGrid
Definition NanoVDB.h:4699
@ End
Definition NanoVDB.h:303
@ End
Definition NanoVDB.h:250
CheckMode
List of different modes for computing for a checksum.
Definition NanoVDB.h:1831
@ Full
Definition NanoVDB.h:1836
@ Disable
Definition NanoVDB.h:1831
@ Half
Definition NanoVDB.h:1833
MagicType toMagic(uint64_t magic)
maps 64 bits of magic number to enum
Definition NanoVDB.h:370
char * toStr(char *dst, GridType gridType)
Maps a GridType to a c-string.
Definition NanoVDB.h:257
static bool isAligned(const void *p)
return true if the specified pointer is 32 byte aligned
Definition NanoVDB.h:597
Struct with all the member data of the Grid (useful during serialization of an openvdb grid)
Definition NanoVDB.h:1952
Version mVersion
Definition NanoVDB.h:1956
GridType mGridType
Definition NanoVDB.h:1966
uint64_t mMagic
Definition NanoVDB.h:1954
GridClass mGridClass
Definition NanoVDB.h:1965
uint32_t mGridCount
Definition NanoVDB.h:1959
uint32_t mGridIndex
Definition NanoVDB.h:1958