23#ifndef NANOVDB_TOOLS_GRIDCHECKSUM_H_HAS_BEEN_INCLUDED
24#define NANOVDB_TOOLS_GRIDCHECKSUM_H_HAS_BEEN_INCLUDED
41#define NANOVDB_CRC32_LOG2_BLOCK_SIZE 12
94 uint32_t &cs = lut[n];
95 for (
int i = 0; i < 8; ++i) cs = (cs >> 1) ^ ((cs & 1) ? 0xEDB88320 : 0);
106 std::unique_ptr<uint32_t[]> lut(
new uint32_t[256]);
120 for (
auto *p = (
const uint8_t*)data, *q = p + size; p != q; ++p) {
122 for (
int j = 0; j < 8; ++j) crc = (crc >> 1) ^ (0xEDB88320 & (-(crc & 1)));
136 return crc32(begin, (
const char*)end - (
const char*)begin, crc);
145inline __hostdev__ uint32_t
crc32(
const void *data,
size_t size,
const uint32_t lut[256], uint32_t crc = 0)
149 for (
auto *p = (
const uint8_t*)data, *q = p + size; p != q; ++p) crc = lut[(crc ^ *p) & 0xFF] ^ (crc >> 8);
159inline __hostdev__ uint32_t
crc32(
const void *begin,
const void *end,
const uint32_t lut[256], uint32_t crc = 0)
163 return crc32(begin, (
const char*)end - (
const char*)begin, lut, crc);
171inline uint32_t
blockedCrc32(
const void *data,
size_t size,
const uint32_t *lut)
173 if (size == 0 )
return ~uint32_t(0);
175 std::unique_ptr<uint32_t[]> checksums(
new uint32_t[blockCount]);
178 for (
auto i = r.begin(); i != r.end(); ++i) {
183 return crc32(checksums.get(),
sizeof(uint32_t)*blockCount, lut);
191inline uint32_t
blockedCrc32(
const void *begin,
const void *end,
const uint32_t *lut)
216 const uint8_t *begin = (
const uint8_t*)(gridData), *mid = begin +
sizeof(
GridData) +
sizeof(
TreeData);
217 if (gridData->
mVersion <=
Version(32,6,0)) mid = (
const uint8_t*)(gridData->template nodePtr<2>());
227 const uint8_t *begin = (
const uint8_t*)(gridData), *mid = begin +
sizeof(
GridData) +
sizeof(
TreeData);
228 if (gridData->
mVersion <=
Version(32,6,0)) mid = (
const uint8_t*)(gridData->template nodePtr<2>());
235template <
typename ValueT>
239 const auto &tree = grid->
tree();
241 auto *nodeMgr = nodeMgrHandle.template mgr<ValueT>();
243 const auto nodeCount = tree.nodeCount(0) + tree.nodeCount(1) + tree.nodeCount(2);
244 std::vector<uint32_t> checksums(nodeCount, 0);
246 uint32_t *p = checksums.data() + r.begin();
247 for (auto i = r.begin(); i != r.end(); ++i) {
248 const auto &node = nodeMgr->upper(static_cast<uint32_t>(i));
249 *p++ = util::crc32(&node, node.memUsage(), lut);
253 uint32_t *p = checksums.data() + r.begin() + tree.nodeCount(2);
254 for (auto i = r.begin(); i != r.end(); ++i) {
255 const auto &node = nodeMgr->lower(static_cast<uint32_t>(i));
256 *p++ = util::crc32(&node, node.memUsage(), lut);
260 uint32_t *p = checksums.data() + r.begin() + tree.nodeCount(1) + tree.nodeCount(2);
261 for (auto i = r.begin(); i != r.end(); ++i) {
262 const auto &leaf = nodeMgr->leaf(static_cast<uint32_t>(i));
263 *p++ = util::crc32(&leaf, leaf.memUsage(), lut);
266 return util::crc32(checksums.data(),
sizeof(uint32_t)*checksums.size(), lut);
270 template <
typename BuildT>
277 throw std::runtime_error(
"Cannot call Crc32TailOld with grid of unknown type");
286 const uint8_t *begin = (
const uint8_t*)(gridData);
293template <
typename ValueT>
298 const uint8_t *begin = (
const uint8_t*)(grid);
312template <
typename ValueT>
325template <
typename ValueT>
326[[deprecated(
"Use evalChecksum(const NanoGrid<ValueT> *grid, CheckMode mode) instead")]]
341[[deprecated(
"Use evalChecksum(const NanoGrid*, CheckMode) instead")]]
344template <
typename ValueT>
345[[deprecated(
"Use checksum(const NanoGrid*, CheckMode) instead")]]
355template <
typename ValueT>
380template <
typename ValueT>
381[[deprecated(
"Use validateChecksum(const NanoGrid*, CheckMode) instead")]]
390template <
typename ValueT>
393template <
typename ValueT>
397template <
typename ValueT>
398[[deprecated(
"Use updateChecksum(const NanoGrid*, CheckMode) instead")]]
A unified wrapper for tbb::parallel_for and a naive std::thread fallback.
Implements a light-weight self-contained VDB data-structure in a single file! In other words,...
Class that encapsulates two CRC32 checksums, one for the Grid, Tree and Root node meta data and one f...
Definition NanoVDB.h:1873
uint32_t tail() const
Definition NanoVDB.h:1913
bool isHalf() const
Definition NanoVDB.h:1919
CheckMode mode() const
return the mode of the 64 bit checksum
Definition NanoVDB.h:1930
bool isEmpty() const
return true if the 64 bit checksum is disables (unset)
Definition NanoVDB.h:1925
uint32_t head() const
Definition NanoVDB.h:1911
DataType * data()
Definition NanoVDB.h:2205
const TreeT & tree() const
Return a const reference to the tree.
Definition NanoVDB.h:2236
Bit-compacted representation of all three version numbers.
Definition NanoVDB.h:730
#define __hostdev__
Definition SampleFromVoxels.h:29
Definition GridChecksum.h:86
uint32_t blockedCrc32(const void *data, size_t size, const uint32_t *lut)
Definition GridChecksum.h:171
__hostdev__ uint32_t crc32(const void *data, size_t size, uint32_t crc=0)
Compute crc32 checksum of data of size bytes (without a lookup table))
Definition GridChecksum.h:116
static int64_t PtrDiff(const void *p, const void *q)
Compute the distance, in bytes, between two pointers, dist = p - q.
Definition Util.h:510
__hostdev__ void initCrc32Lut(uint32_t lut[256], uint32_t n)
Initiate single entry in look-up-table for CRC32 computations.
Definition GridChecksum.h:91
std::unique_ptr< uint32_t[]> createCrc32Lut()
Create and initiate entire look-up-table for CRC32 computations.
Definition GridChecksum.h:104
void forEach(RangeT range, const FuncT &func)
simple wrapper for tbb::parallel_for with a naive std fallback
Definition ForEach.h:42
Range< 1, size_t > Range1D
Definition Range.h:33
Defines a simple memory pool used to call cub functions that use dynamic temporary storage.
Definition GridHandle.h:31
auto callNanoGrid(GridDataT *gridData, ArgsT &&... args)
Below is an example of the struct used for generic programming with callNanoGrid.
Definition NanoVDB.h:4846
Grid< NanoTree< BuildT > > NanoGrid
Definition NanoVDB.h:4742
CheckMode
List of different modes for computing for a checksum.
Definition NanoVDB.h:1846
@ Default
Definition NanoVDB.h:1850
@ Full
Definition NanoVDB.h:1851
@ Disable
Definition NanoVDB.h:1846
@ Half
Definition NanoVDB.h:1848
@ Empty
Definition NanoVDB.h:1847
static bool isAligned(const void *p)
return true if the specified pointer is 32 byte aligned
Definition NanoVDB.h:600
NodeManagerHandle< BufferT > createNodeManager(const NanoGrid< BuildT > &grid, const BufferT &buffer=BufferT())
brief Construct a NodeManager and return its handle
Definition NodeManager.h:307
This class allows for sequential access to nodes in a NanoVDB tree on both the host and device.
#define NANOVDB_ASSERT(x)
Definition Util.h:53
Struct with all the member data of the Grid (useful during serialization of an openvdb grid)
Definition NanoVDB.h:1977
Version mVersion
Definition NanoVDB.h:1981
uint64_t mGridSize
Definition NanoVDB.h:1985
Checksum mChecksum
Definition NanoVDB.h:1980
uint32_t mGridCount
Definition NanoVDB.h:1984
uint32_t mGridIndex
Definition NanoVDB.h:1983
Definition NanoVDB.h:2426