OpenVDB  12.0.0
PNanoVDB.h
Go to the documentation of this file.
1 
2 // Copyright Contributors to the OpenVDB Project
3 // SPDX-License-Identifier: Apache-2.0
4 
5 /*!
6  \file nanovdb/PNanoVDB.h
7 
8  \author Andrew Reidmeyer
9 
10  \brief This file is a portable (e.g. pointer-less) C99/GLSL/HLSL port
11  of NanoVDB.h, which is compatible with most graphics APIs.
12 */
13 
14 #ifndef NANOVDB_PNANOVDB_H_HAS_BEEN_INCLUDED
15 #define NANOVDB_PNANOVDB_H_HAS_BEEN_INCLUDED
16 
17 // ------------------------------------------------ Configuration -----------------------------------------------------------
18 
19 // platforms
20 //#define PNANOVDB_C
21 //#define PNANOVDB_HLSL
22 //#define PNANOVDB_GLSL
23 
24 // addressing mode
25 // PNANOVDB_ADDRESS_32
26 // PNANOVDB_ADDRESS_64
27 #if defined(PNANOVDB_C)
28 #ifndef PNANOVDB_ADDRESS_32
29 #define PNANOVDB_ADDRESS_64
30 #endif
31 #elif defined(PNANOVDB_HLSL)
32 #ifndef PNANOVDB_ADDRESS_64
33 #define PNANOVDB_ADDRESS_32
34 #endif
35 #elif defined(PNANOVDB_GLSL)
36 #ifndef PNANOVDB_ADDRESS_64
37 #define PNANOVDB_ADDRESS_32
38 #endif
39 #endif
40 
41 // bounds checking
42 //#define PNANOVDB_BUF_BOUNDS_CHECK
43 
44 // enable HDDA by default on HLSL/GLSL, make explicit on C
45 #if defined(PNANOVDB_C)
46 //#define PNANOVDB_HDDA
47 #ifdef PNANOVDB_HDDA
48 #ifndef PNANOVDB_CMATH
49 #define PNANOVDB_CMATH
50 #endif
51 #endif
52 #elif defined(PNANOVDB_HLSL)
53 #define PNANOVDB_HDDA
54 #elif defined(PNANOVDB_GLSL)
55 #define PNANOVDB_HDDA
56 #endif
57 
58 #ifdef PNANOVDB_CMATH
59 #ifndef __CUDACC_RTC__
60 #include <math.h>
61 #endif
62 #endif
63 
64 // ------------------------------------------------ Buffer -----------------------------------------------------------
65 
66 #if defined(PNANOVDB_BUF_CUSTOM)
67 // NOP
68 #elif defined(PNANOVDB_C)
69 #define PNANOVDB_BUF_C
70 #elif defined(PNANOVDB_HLSL)
71 #define PNANOVDB_BUF_HLSL
72 #elif defined(PNANOVDB_GLSL)
73 #define PNANOVDB_BUF_GLSL
74 #endif
75 
76 #if defined(PNANOVDB_BUF_C)
77 #ifndef __CUDACC_RTC__
78 #include <stdint.h>
79 #endif
80 #if defined(__CUDACC__)
81 #define PNANOVDB_BUF_FORCE_INLINE static __host__ __device__ __forceinline__
82 #elif defined(_WIN32)
83 #define PNANOVDB_BUF_FORCE_INLINE static inline __forceinline
84 #else
85 #define PNANOVDB_BUF_FORCE_INLINE static inline __attribute__((always_inline))
86 #endif
87 typedef struct pnanovdb_buf_t
88 {
89  uint32_t* data;
90 #ifdef PNANOVDB_BUF_BOUNDS_CHECK
91  uint64_t size_in_words;
92 #endif
93 }pnanovdb_buf_t;
94 PNANOVDB_BUF_FORCE_INLINE pnanovdb_buf_t pnanovdb_make_buf(uint32_t* data, uint64_t size_in_words)
95 {
96  pnanovdb_buf_t ret;
97  ret.data = data;
98 #ifdef PNANOVDB_BUF_BOUNDS_CHECK
99  ret.size_in_words = size_in_words;
100 #endif
101  return ret;
102 }
103 #if defined(PNANOVDB_ADDRESS_32)
104 PNANOVDB_BUF_FORCE_INLINE uint32_t pnanovdb_buf_read_uint32(pnanovdb_buf_t buf, uint32_t byte_offset)
105 {
106  uint32_t wordaddress = (byte_offset >> 2u);
107 #ifdef PNANOVDB_BUF_BOUNDS_CHECK
108  return wordaddress < buf.size_in_words ? buf.data[wordaddress] : 0u;
109 #else
110  return buf.data[wordaddress];
111 #endif
112 }
113 PNANOVDB_BUF_FORCE_INLINE uint64_t pnanovdb_buf_read_uint64(pnanovdb_buf_t buf, uint32_t byte_offset)
114 {
115  uint64_t* data64 = (uint64_t*)buf.data;
116  uint32_t wordaddress64 = (byte_offset >> 3u);
117 #ifdef PNANOVDB_BUF_BOUNDS_CHECK
118  uint64_t size_in_words64 = buf.size_in_words >> 1u;
119  return wordaddress64 < size_in_words64 ? data64[wordaddress64] : 0llu;
120 #else
121  return data64[wordaddress64];
122 #endif
123 }
124 PNANOVDB_BUF_FORCE_INLINE void pnanovdb_buf_write_uint32(pnanovdb_buf_t buf, uint32_t byte_offset, uint32_t value)
125 {
126  uint32_t wordaddress = (byte_offset >> 2u);
127 #ifdef PNANOVDB_BUF_BOUNDS_CHECK
128  if (wordaddress < buf.size_in_words)
129  {
130  buf.data[wordaddress] = value;
131 }
132 #else
133  buf.data[wordaddress] = value;
134 #endif
135 }
136 PNANOVDB_BUF_FORCE_INLINE void pnanovdb_buf_write_uint64(pnanovdb_buf_t buf, uint32_t byte_offset, uint64_t value)
137 {
138  uint64_t* data64 = (uint64_t*)buf.data;
139  uint32_t wordaddress64 = (byte_offset >> 3u);
140 #ifdef PNANOVDB_BUF_BOUNDS_CHECK
141  uint64_t size_in_words64 = buf.size_in_words >> 1u;
142  if (wordaddress64 < size_in_words64)
143  {
144  data64[wordaddress64] = value;
145  }
146 #else
147  data64[wordaddress64] = value;
148 #endif
149 }
150 #elif defined(PNANOVDB_ADDRESS_64)
151 PNANOVDB_BUF_FORCE_INLINE uint32_t pnanovdb_buf_read_uint32(pnanovdb_buf_t buf, uint64_t byte_offset)
152 {
153  uint64_t wordaddress = (byte_offset >> 2u);
154 #ifdef PNANOVDB_BUF_BOUNDS_CHECK
155  return wordaddress < buf.size_in_words ? buf.data[wordaddress] : 0u;
156 #else
157  return buf.data[wordaddress];
158 #endif
159 }
160 PNANOVDB_BUF_FORCE_INLINE uint64_t pnanovdb_buf_read_uint64(pnanovdb_buf_t buf, uint64_t byte_offset)
161 {
162  uint64_t* data64 = (uint64_t*)buf.data;
163  uint64_t wordaddress64 = (byte_offset >> 3u);
164 #ifdef PNANOVDB_BUF_BOUNDS_CHECK
165  uint64_t size_in_words64 = buf.size_in_words >> 1u;
166  return wordaddress64 < size_in_words64 ? data64[wordaddress64] : 0llu;
167 #else
168  return data64[wordaddress64];
169 #endif
170 }
171 PNANOVDB_BUF_FORCE_INLINE void pnanovdb_buf_write_uint32(pnanovdb_buf_t buf, uint64_t byte_offset, uint32_t value)
172 {
173  uint64_t wordaddress = (byte_offset >> 2u);
174 #ifdef PNANOVDB_BUF_BOUNDS_CHECK
175  if (wordaddress < buf.size_in_words)
176  {
177  buf.data[wordaddress] = value;
178  }
179 #else
180  buf.data[wordaddress] = value;
181 #endif
182 }
183 PNANOVDB_BUF_FORCE_INLINE void pnanovdb_buf_write_uint64(pnanovdb_buf_t buf, uint64_t byte_offset, uint64_t value)
184 {
185  uint64_t* data64 = (uint64_t*)buf.data;
186  uint64_t wordaddress64 = (byte_offset >> 3u);
187 #ifdef PNANOVDB_BUF_BOUNDS_CHECK
188  uint64_t size_in_words64 = buf.size_in_words >> 1u;
189  if (wordaddress64 < size_in_words64)
190  {
191  data64[wordaddress64] = value;
192  }
193 #else
194  data64[wordaddress64] = value;
195 #endif
196 }
197 #endif
198 typedef uint32_t pnanovdb_grid_type_t;
199 #define PNANOVDB_GRID_TYPE_GET(grid_typeIn, nameIn) pnanovdb_grid_type_constants[grid_typeIn].nameIn
200 #elif defined(PNANOVDB_BUF_HLSL)
201 #if defined(PNANOVDB_ADDRESS_32)
202 #define pnanovdb_buf_t StructuredBuffer<uint>
203 uint pnanovdb_buf_read_uint32(pnanovdb_buf_t buf, uint byte_offset)
204 {
205  return buf[(byte_offset >> 2u)];
206 }
207 uint2 pnanovdb_buf_read_uint64(pnanovdb_buf_t buf, uint byte_offset)
208 {
209  uint2 ret;
210  ret.x = pnanovdb_buf_read_uint32(buf, byte_offset + 0u);
211  ret.y = pnanovdb_buf_read_uint32(buf, byte_offset + 4u);
212  return ret;
213 }
214 void pnanovdb_buf_write_uint32(pnanovdb_buf_t buf, uint byte_offset, uint value)
215 {
216  // NOP, by default no write in HLSL
217 }
218 void pnanovdb_buf_write_uint64(pnanovdb_buf_t buf, uint byte_offset, uint2 value)
219 {
220  // NOP, by default no write in HLSL
221 }
222 #elif defined(PNANOVDB_ADDRESS_64)
223 #define pnanovdb_buf_t StructuredBuffer<uint>
224 uint pnanovdb_buf_read_uint32(pnanovdb_buf_t buf, uint64_t byte_offset)
225 {
226  return buf[uint(byte_offset >> 2u)];
227 }
228 uint64_t pnanovdb_buf_read_uint64(pnanovdb_buf_t buf, uint64_t byte_offset)
229 {
230  uint64_t ret;
231  ret = pnanovdb_buf_read_uint32(buf, byte_offset + 0u);
232  ret = ret + (uint64_t(pnanovdb_buf_read_uint32(buf, byte_offset + 4u)) << 32u);
233  return ret;
234 }
235 void pnanovdb_buf_write_uint32(pnanovdb_buf_t buf, uint64_t byte_offset, uint value)
236 {
237  // NOP, by default no write in HLSL
238 }
239 void pnanovdb_buf_write_uint64(pnanovdb_buf_t buf, uint64_t byte_offset, uint64_t value)
240 {
241  // NOP, by default no write in HLSL
242 }
243 #endif
244 #define pnanovdb_grid_type_t uint
245 #define PNANOVDB_GRID_TYPE_GET(grid_typeIn, nameIn) pnanovdb_grid_type_constants[grid_typeIn].nameIn
246 #elif defined(PNANOVDB_BUF_GLSL)
247 struct pnanovdb_buf_t
248 {
249  uint unused; // to satisfy min struct size?
250 };
251 uint pnanovdb_buf_read_uint32(pnanovdb_buf_t buf, uint byte_offset)
252 {
253  return pnanovdb_buf_data[(byte_offset >> 2u)];
254 }
255 uvec2 pnanovdb_buf_read_uint64(pnanovdb_buf_t buf, uint byte_offset)
256 {
257  uvec2 ret;
258  ret.x = pnanovdb_buf_read_uint32(buf, byte_offset + 0u);
259  ret.y = pnanovdb_buf_read_uint32(buf, byte_offset + 4u);
260  return ret;
261 }
262 void pnanovdb_buf_write_uint32(pnanovdb_buf_t buf, uint byte_offset, uint value)
263 {
264  // NOP, by default no write in HLSL
265 }
266 void pnanovdb_buf_write_uint64(pnanovdb_buf_t buf, uint byte_offset, uvec2 value)
267 {
268  // NOP, by default no write in HLSL
269 }
270 #define pnanovdb_grid_type_t uint
271 #define PNANOVDB_GRID_TYPE_GET(grid_typeIn, nameIn) pnanovdb_grid_type_constants[grid_typeIn].nameIn
272 #endif
273 
274 // ------------------------------------------------ Basic Types -----------------------------------------------------------
275 
276 // force inline
277 #if defined(PNANOVDB_C)
278 #if defined(__CUDACC__)
279 #define PNANOVDB_FORCE_INLINE static __host__ __device__ __forceinline__
280 #elif defined(_WIN32)
281 #define PNANOVDB_FORCE_INLINE static inline __forceinline
282 #else
283 #define PNANOVDB_FORCE_INLINE static inline __attribute__((always_inline))
284 #endif
285 #elif defined(PNANOVDB_HLSL)
286 #define PNANOVDB_FORCE_INLINE
287 #elif defined(PNANOVDB_GLSL)
288 #define PNANOVDB_FORCE_INLINE
289 #endif
290 
291 // struct typedef, static const, inout
292 #if defined(PNANOVDB_C)
293 #define PNANOVDB_STRUCT_TYPEDEF(X) typedef struct X X;
294 #if defined(__CUDA_ARCH__)
295 #define PNANOVDB_STATIC_CONST constexpr __constant__
296 #else
297 #define PNANOVDB_STATIC_CONST static const
298 #endif
299 #define PNANOVDB_INOUT(X) X*
300 #define PNANOVDB_IN(X) const X*
301 #define PNANOVDB_DEREF(X) (*X)
302 #define PNANOVDB_REF(X) &X
303 #elif defined(PNANOVDB_HLSL)
304 #define PNANOVDB_STRUCT_TYPEDEF(X)
305 #define PNANOVDB_STATIC_CONST static const
306 #define PNANOVDB_INOUT(X) inout X
307 #define PNANOVDB_IN(X) X
308 #define PNANOVDB_DEREF(X) X
309 #define PNANOVDB_REF(X) X
310 #elif defined(PNANOVDB_GLSL)
311 #define PNANOVDB_STRUCT_TYPEDEF(X)
312 #define PNANOVDB_STATIC_CONST const
313 #define PNANOVDB_INOUT(X) inout X
314 #define PNANOVDB_IN(X) X
315 #define PNANOVDB_DEREF(X) X
316 #define PNANOVDB_REF(X) X
317 #endif
318 
319 // basic types, type conversion
320 #if defined(PNANOVDB_C)
321 #define PNANOVDB_NATIVE_64
322 #ifndef __CUDACC_RTC__
323 #include <stdint.h>
324 #endif
325 #if !defined(PNANOVDB_MEMCPY_CUSTOM)
326 #ifndef __CUDACC_RTC__
327 #include <string.h>
328 #endif
329 #define pnanovdb_memcpy memcpy
330 #endif
331 typedef uint32_t pnanovdb_uint32_t;
332 typedef int32_t pnanovdb_int32_t;
333 typedef int32_t pnanovdb_bool_t;
334 #define PNANOVDB_FALSE 0
335 #define PNANOVDB_TRUE 1
336 typedef uint64_t pnanovdb_uint64_t;
337 typedef int64_t pnanovdb_int64_t;
338 typedef struct pnanovdb_coord_t
339 {
340  pnanovdb_int32_t x, y, z;
341 }pnanovdb_coord_t;
342 typedef struct pnanovdb_vec3_t
343 {
344  float x, y, z;
345 }pnanovdb_vec3_t;
346 PNANOVDB_FORCE_INLINE pnanovdb_int32_t pnanovdb_uint32_as_int32(pnanovdb_uint32_t v) { return (pnanovdb_int32_t)v; }
347 PNANOVDB_FORCE_INLINE pnanovdb_int64_t pnanovdb_uint64_as_int64(pnanovdb_uint64_t v) { return (pnanovdb_int64_t)v; }
348 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_int64_as_uint64(pnanovdb_int64_t v) { return (pnanovdb_uint64_t)v; }
349 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_int32_as_uint32(pnanovdb_int32_t v) { return (pnanovdb_uint32_t)v; }
350 PNANOVDB_FORCE_INLINE float pnanovdb_uint32_as_float(pnanovdb_uint32_t v) { float vf; pnanovdb_memcpy(&vf, &v, sizeof(vf)); return vf; }
351 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_float_as_uint32(float v) { return *((pnanovdb_uint32_t*)(&v)); }
352 PNANOVDB_FORCE_INLINE double pnanovdb_uint64_as_double(pnanovdb_uint64_t v) { double vf; pnanovdb_memcpy(&vf, &v, sizeof(vf)); return vf; }
353 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_double_as_uint64(double v) { return *((pnanovdb_uint64_t*)(&v)); }
354 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_uint64_low(pnanovdb_uint64_t v) { return (pnanovdb_uint32_t)v; }
355 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_uint64_high(pnanovdb_uint64_t v) { return (pnanovdb_uint32_t)(v >> 32u); }
356 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_uint32_as_uint64(pnanovdb_uint32_t x, pnanovdb_uint32_t y) { return ((pnanovdb_uint64_t)x) | (((pnanovdb_uint64_t)y) << 32u); }
357 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_uint32_as_uint64_low(pnanovdb_uint32_t x) { return ((pnanovdb_uint64_t)x); }
358 PNANOVDB_FORCE_INLINE pnanovdb_int32_t pnanovdb_uint64_is_equal(pnanovdb_uint64_t a, pnanovdb_uint64_t b) { return a == b; }
359 PNANOVDB_FORCE_INLINE pnanovdb_int32_t pnanovdb_int64_is_zero(pnanovdb_int64_t a) { return a == 0; }
360 #ifdef PNANOVDB_CMATH
361 PNANOVDB_FORCE_INLINE float pnanovdb_floor(float v) { return floorf(v); }
362 #endif
363 PNANOVDB_FORCE_INLINE pnanovdb_int32_t pnanovdb_float_to_int32(float v) { return (pnanovdb_int32_t)v; }
364 PNANOVDB_FORCE_INLINE float pnanovdb_int32_to_float(pnanovdb_int32_t v) { return (float)v; }
365 PNANOVDB_FORCE_INLINE float pnanovdb_uint32_to_float(pnanovdb_uint32_t v) { return (float)v; }
366 PNANOVDB_FORCE_INLINE float pnanovdb_min(float a, float b) { return a < b ? a : b; }
367 PNANOVDB_FORCE_INLINE float pnanovdb_max(float a, float b) { return a > b ? a : b; }
368 #elif defined(PNANOVDB_HLSL)
369 typedef uint pnanovdb_uint32_t;
370 typedef int pnanovdb_int32_t;
371 typedef bool pnanovdb_bool_t;
372 #define PNANOVDB_FALSE false
373 #define PNANOVDB_TRUE true
374 typedef int3 pnanovdb_coord_t;
375 typedef float3 pnanovdb_vec3_t;
376 pnanovdb_int32_t pnanovdb_uint32_as_int32(pnanovdb_uint32_t v) { return int(v); }
377 pnanovdb_uint32_t pnanovdb_int32_as_uint32(pnanovdb_int32_t v) { return uint(v); }
378 float pnanovdb_uint32_as_float(pnanovdb_uint32_t v) { return asfloat(v); }
379 pnanovdb_uint32_t pnanovdb_float_as_uint32(float v) { return asuint(v); }
380 float pnanovdb_floor(float v) { return floor(v); }
381 pnanovdb_int32_t pnanovdb_float_to_int32(float v) { return int(v); }
382 float pnanovdb_int32_to_float(pnanovdb_int32_t v) { return float(v); }
383 float pnanovdb_uint32_to_float(pnanovdb_uint32_t v) { return float(v); }
384 float pnanovdb_min(float a, float b) { return min(a, b); }
385 float pnanovdb_max(float a, float b) { return max(a, b); }
386 #if defined(PNANOVDB_ADDRESS_32)
387 typedef uint2 pnanovdb_uint64_t;
388 typedef int2 pnanovdb_int64_t;
389 pnanovdb_int64_t pnanovdb_uint64_as_int64(pnanovdb_uint64_t v) { return int2(v); }
390 pnanovdb_uint64_t pnanovdb_int64_as_uint64(pnanovdb_int64_t v) { return uint2(v); }
391 double pnanovdb_uint64_as_double(pnanovdb_uint64_t v) { return asdouble(v.x, v.y); }
392 pnanovdb_uint64_t pnanovdb_double_as_uint64(double v) { uint2 ret; asuint(v, ret.x, ret.y); return ret; }
393 pnanovdb_uint32_t pnanovdb_uint64_low(pnanovdb_uint64_t v) { return v.x; }
394 pnanovdb_uint32_t pnanovdb_uint64_high(pnanovdb_uint64_t v) { return v.y; }
395 pnanovdb_uint64_t pnanovdb_uint32_as_uint64(pnanovdb_uint32_t x, pnanovdb_uint32_t y) { return uint2(x, y); }
396 pnanovdb_uint64_t pnanovdb_uint32_as_uint64_low(pnanovdb_uint32_t x) { return uint2(x, 0); }
397 bool pnanovdb_uint64_is_equal(pnanovdb_uint64_t a, pnanovdb_uint64_t b) { return (a.x == b.x) && (a.y == b.y); }
398 bool pnanovdb_int64_is_zero(pnanovdb_int64_t a) { return a.x == 0 && a.y == 0; }
399 #else
400 typedef uint64_t pnanovdb_uint64_t;
401 typedef int64_t pnanovdb_int64_t;
402 pnanovdb_int64_t pnanovdb_uint64_as_int64(pnanovdb_uint64_t v) { return int64_t(v); }
403 pnanovdb_uint64_t pnanovdb_int64_as_uint64(pnanovdb_int64_t v) { return uint64_t(v); }
404 double pnanovdb_uint64_as_double(pnanovdb_uint64_t v) { return asdouble(uint(v), uint(v >> 32u)); }
405 pnanovdb_uint64_t pnanovdb_double_as_uint64(double v) { uint2 ret; asuint(v, ret.x, ret.y); return uint64_t(ret.x) + (uint64_t(ret.y) << 32u); }
406 pnanovdb_uint32_t pnanovdb_uint64_low(pnanovdb_uint64_t v) { return uint(v); }
407 pnanovdb_uint32_t pnanovdb_uint64_high(pnanovdb_uint64_t v) { return uint(v >> 32u); }
408 pnanovdb_uint64_t pnanovdb_uint32_as_uint64(pnanovdb_uint32_t x, pnanovdb_uint32_t y) { return uint64_t(x) + (uint64_t(y) << 32u); }
409 pnanovdb_uint64_t pnanovdb_uint32_as_uint64_low(pnanovdb_uint32_t x) { return uint64_t(x); }
410 bool pnanovdb_uint64_is_equal(pnanovdb_uint64_t a, pnanovdb_uint64_t b) { return a == b; }
411 bool pnanovdb_int64_is_zero(pnanovdb_int64_t a) { return a == 0; }
412 #endif
413 #elif defined(PNANOVDB_GLSL)
414 #define pnanovdb_uint32_t uint
415 #define pnanovdb_int32_t int
416 #define pnanovdb_bool_t bool
417 #define PNANOVDB_FALSE false
418 #define PNANOVDB_TRUE true
419 #define pnanovdb_uint64_t uvec2
420 #define pnanovdb_int64_t ivec2
421 #define pnanovdb_coord_t ivec3
422 #define pnanovdb_vec3_t vec3
423 pnanovdb_int32_t pnanovdb_uint32_as_int32(pnanovdb_uint32_t v) { return int(v); }
424 pnanovdb_int64_t pnanovdb_uint64_as_int64(pnanovdb_uint64_t v) { return ivec2(v); }
425 pnanovdb_uint64_t pnanovdb_int64_as_uint64(pnanovdb_int64_t v) { return uvec2(v); }
426 pnanovdb_uint32_t pnanovdb_int32_as_uint32(pnanovdb_int32_t v) { return uint(v); }
427 float pnanovdb_uint32_as_float(pnanovdb_uint32_t v) { return uintBitsToFloat(v); }
428 pnanovdb_uint32_t pnanovdb_float_as_uint32(float v) { return floatBitsToUint(v); }
429 double pnanovdb_uint64_as_double(pnanovdb_uint64_t v) { return packDouble2x32(uvec2(v.x, v.y)); }
430 pnanovdb_uint64_t pnanovdb_double_as_uint64(double v) { return unpackDouble2x32(v); }
431 pnanovdb_uint32_t pnanovdb_uint64_low(pnanovdb_uint64_t v) { return v.x; }
432 pnanovdb_uint32_t pnanovdb_uint64_high(pnanovdb_uint64_t v) { return v.y; }
433 pnanovdb_uint64_t pnanovdb_uint32_as_uint64(pnanovdb_uint32_t x, pnanovdb_uint32_t y) { return uvec2(x, y); }
434 pnanovdb_uint64_t pnanovdb_uint32_as_uint64_low(pnanovdb_uint32_t x) { return uvec2(x, 0); }
435 bool pnanovdb_uint64_is_equal(pnanovdb_uint64_t a, pnanovdb_uint64_t b) { return (a.x == b.x) && (a.y == b.y); }
436 bool pnanovdb_int64_is_zero(pnanovdb_int64_t a) { return a.x == 0 && a.y == 0; }
437 float pnanovdb_floor(float v) { return floor(v); }
438 pnanovdb_int32_t pnanovdb_float_to_int32(float v) { return int(v); }
439 float pnanovdb_int32_to_float(pnanovdb_int32_t v) { return float(v); }
440 float pnanovdb_uint32_to_float(pnanovdb_uint32_t v) { return float(v); }
441 float pnanovdb_min(float a, float b) { return min(a, b); }
442 float pnanovdb_max(float a, float b) { return max(a, b); }
443 #endif
444 
445 // ------------------------------------------------ Coord/Vec3 Utilties -----------------------------------------------------------
446 
447 #if defined(PNANOVDB_C)
448 PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_vec3_uniform(float a)
449 {
450  pnanovdb_vec3_t v;
451  v.x = a;
452  v.y = a;
453  v.z = a;
454  return v;
455 }
456 PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_vec3_add(const pnanovdb_vec3_t a, const pnanovdb_vec3_t b)
457 {
458  pnanovdb_vec3_t v;
459  v.x = a.x + b.x;
460  v.y = a.y + b.y;
461  v.z = a.z + b.z;
462  return v;
463 }
464 PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_vec3_sub(const pnanovdb_vec3_t a, const pnanovdb_vec3_t b)
465 {
466  pnanovdb_vec3_t v;
467  v.x = a.x - b.x;
468  v.y = a.y - b.y;
469  v.z = a.z - b.z;
470  return v;
471 }
472 PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_vec3_mul(const pnanovdb_vec3_t a, const pnanovdb_vec3_t b)
473 {
474  pnanovdb_vec3_t v;
475  v.x = a.x * b.x;
476  v.y = a.y * b.y;
477  v.z = a.z * b.z;
478  return v;
479 }
480 PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_vec3_div(const pnanovdb_vec3_t a, const pnanovdb_vec3_t b)
481 {
482  pnanovdb_vec3_t v;
483  v.x = a.x / b.x;
484  v.y = a.y / b.y;
485  v.z = a.z / b.z;
486  return v;
487 }
488 PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_vec3_min(const pnanovdb_vec3_t a, const pnanovdb_vec3_t b)
489 {
490  pnanovdb_vec3_t v;
491  v.x = a.x < b.x ? a.x : b.x;
492  v.y = a.y < b.y ? a.y : b.y;
493  v.z = a.z < b.z ? a.z : b.z;
494  return v;
495 }
496 PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_vec3_max(const pnanovdb_vec3_t a, const pnanovdb_vec3_t b)
497 {
498  pnanovdb_vec3_t v;
499  v.x = a.x > b.x ? a.x : b.x;
500  v.y = a.y > b.y ? a.y : b.y;
501  v.z = a.z > b.z ? a.z : b.z;
502  return v;
503 }
504 PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_coord_to_vec3(const pnanovdb_coord_t coord)
505 {
506  pnanovdb_vec3_t v;
507  v.x = pnanovdb_int32_to_float(coord.x);
508  v.y = pnanovdb_int32_to_float(coord.y);
509  v.z = pnanovdb_int32_to_float(coord.z);
510  return v;
511 }
512 PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_coord_uniform(const pnanovdb_int32_t a)
513 {
514  pnanovdb_coord_t v;
515  v.x = a;
516  v.y = a;
517  v.z = a;
518  return v;
519 }
520 PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_coord_add(pnanovdb_coord_t a, pnanovdb_coord_t b)
521 {
522  pnanovdb_coord_t v;
523  v.x = a.x + b.x;
524  v.y = a.y + b.y;
525  v.z = a.z + b.z;
526  return v;
527 }
528 #elif defined(PNANOVDB_HLSL)
529 pnanovdb_vec3_t pnanovdb_vec3_uniform(float a) { return float3(a, a, a); }
530 pnanovdb_vec3_t pnanovdb_vec3_add(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return a + b; }
531 pnanovdb_vec3_t pnanovdb_vec3_sub(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return a - b; }
532 pnanovdb_vec3_t pnanovdb_vec3_mul(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return a * b; }
533 pnanovdb_vec3_t pnanovdb_vec3_div(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return a / b; }
534 pnanovdb_vec3_t pnanovdb_vec3_min(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return min(a, b); }
535 pnanovdb_vec3_t pnanovdb_vec3_max(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return max(a, b); }
536 pnanovdb_vec3_t pnanovdb_coord_to_vec3(pnanovdb_coord_t coord) { return float3(coord); }
537 pnanovdb_coord_t pnanovdb_coord_uniform(pnanovdb_int32_t a) { return int3(a, a, a); }
538 pnanovdb_coord_t pnanovdb_coord_add(pnanovdb_coord_t a, pnanovdb_coord_t b) { return a + b; }
539 #elif defined(PNANOVDB_GLSL)
540 pnanovdb_vec3_t pnanovdb_vec3_uniform(float a) { return vec3(a, a, a); }
541 pnanovdb_vec3_t pnanovdb_vec3_add(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return a + b; }
542 pnanovdb_vec3_t pnanovdb_vec3_sub(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return a - b; }
543 pnanovdb_vec3_t pnanovdb_vec3_mul(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return a * b; }
544 pnanovdb_vec3_t pnanovdb_vec3_div(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return a / b; }
545 pnanovdb_vec3_t pnanovdb_vec3_min(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return min(a, b); }
546 pnanovdb_vec3_t pnanovdb_vec3_max(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return max(a, b); }
547 pnanovdb_vec3_t pnanovdb_coord_to_vec3(const pnanovdb_coord_t coord) { return vec3(coord); }
548 pnanovdb_coord_t pnanovdb_coord_uniform(pnanovdb_int32_t a) { return ivec3(a, a, a); }
549 pnanovdb_coord_t pnanovdb_coord_add(pnanovdb_coord_t a, pnanovdb_coord_t b) { return a + b; }
550 #endif
551 
552 // ------------------------------------------------ Uint64 Utils -----------------------------------------------------------
553 
554 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_uint32_countbits(pnanovdb_uint32_t value)
555 {
556 #if defined(PNANOVDB_C)
557 #if defined(_MSC_VER) && (_MSC_VER >= 1928) && defined(PNANOVDB_USE_INTRINSICS)
558  return __popcnt(value);
559 #elif (defined(__GNUC__) || defined(__clang__)) && defined(PNANOVDB_USE_INTRINSICS)
560  return __builtin_popcount(value);
561 #else
562  value = value - ((value >> 1) & 0x55555555);
563  value = (value & 0x33333333) + ((value >> 2) & 0x33333333);
564  value = (value + (value >> 4)) & 0x0F0F0F0F;
565  return (value * 0x01010101) >> 24;
566 #endif
567 #elif defined(PNANOVDB_HLSL)
568  return countbits(value);
569 #elif defined(PNANOVDB_GLSL)
570  return bitCount(value);
571 #endif
572 }
573 
574 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_uint64_countbits(pnanovdb_uint64_t value)
575 {
576  return pnanovdb_uint32_countbits(pnanovdb_uint64_low(value)) + pnanovdb_uint32_countbits(pnanovdb_uint64_high(value));
577 }
578 
579 #if defined(PNANOVDB_ADDRESS_32)
580 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_uint64_offset(pnanovdb_uint64_t a, pnanovdb_uint32_t b)
581 {
582  pnanovdb_uint32_t low = pnanovdb_uint64_low(a);
583  pnanovdb_uint32_t high = pnanovdb_uint64_high(a);
584  low += b;
585  if (low < b)
586  {
587  high += 1u;
588  }
589  return pnanovdb_uint32_as_uint64(low, high);
590 }
591 
592 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_uint64_dec(pnanovdb_uint64_t a)
593 {
594  pnanovdb_uint32_t low = pnanovdb_uint64_low(a);
595  pnanovdb_uint32_t high = pnanovdb_uint64_high(a);
596  if (low == 0u)
597  {
598  high -= 1u;
599  }
600  low -= 1u;
601  return pnanovdb_uint32_as_uint64(low, high);
602 }
603 
604 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_uint64_to_uint32_lsr(pnanovdb_uint64_t a, pnanovdb_uint32_t b)
605 {
606  pnanovdb_uint32_t low = pnanovdb_uint64_low(a);
607  pnanovdb_uint32_t high = pnanovdb_uint64_high(a);
608  return (b >= 32u) ?
609  (high >> (b - 32)) :
610  ((low >> b) | ((b > 0) ? (high << (32u - b)) : 0u));
611 }
612 
613 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_uint64_bit_mask(pnanovdb_uint32_t bit_idx)
614 {
615  pnanovdb_uint32_t mask_low = bit_idx < 32u ? 1u << bit_idx : 0u;
616  pnanovdb_uint32_t mask_high = bit_idx >= 32u ? 1u << (bit_idx - 32u) : 0u;
617  return pnanovdb_uint32_as_uint64(mask_low, mask_high);
618 }
619 
620 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_uint64_and(pnanovdb_uint64_t a, pnanovdb_uint64_t b)
621 {
622  return pnanovdb_uint32_as_uint64(
623  pnanovdb_uint64_low(a) & pnanovdb_uint64_low(b),
624  pnanovdb_uint64_high(a) & pnanovdb_uint64_high(b)
625  );
626 }
627 
628 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_uint64_any_bit(pnanovdb_uint64_t a)
629 {
630  return pnanovdb_uint64_low(a) != 0u || pnanovdb_uint64_high(a) != 0u;
631 }
632 
633 #else
634 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_uint64_offset(pnanovdb_uint64_t a, pnanovdb_uint32_t b)
635 {
636  return a + b;
637 }
638 
639 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_uint64_dec(pnanovdb_uint64_t a)
640 {
641  return a - 1u;
642 }
643 
644 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_uint64_to_uint32_lsr(pnanovdb_uint64_t a, pnanovdb_uint32_t b)
645 {
646  return pnanovdb_uint64_low(a >> b);
647 }
648 
649 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_uint64_bit_mask(pnanovdb_uint32_t bit_idx)
650 {
651  return 1llu << bit_idx;
652 }
653 
654 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_uint64_and(pnanovdb_uint64_t a, pnanovdb_uint64_t b)
655 {
656  return a & b;
657 }
658 
659 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_uint64_any_bit(pnanovdb_uint64_t a)
660 {
661  return a != 0llu;
662 }
663 #endif
664 
665 // ------------------------------------------------ Address Type -----------------------------------------------------------
666 
667 #if defined(PNANOVDB_ADDRESS_32)
668 struct pnanovdb_address_t
669 {
670  pnanovdb_uint32_t byte_offset;
671 };
672 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_address_t)
673 
674 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_offset(pnanovdb_address_t address, pnanovdb_uint32_t byte_offset)
675 {
676  pnanovdb_address_t ret = address;
677  ret.byte_offset += byte_offset;
678  return ret;
679 }
680 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_offset_neg(pnanovdb_address_t address, pnanovdb_uint32_t byte_offset)
681 {
682  pnanovdb_address_t ret = address;
683  ret.byte_offset -= byte_offset;
684  return ret;
685 }
686 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_offset_product(pnanovdb_address_t address, pnanovdb_uint32_t byte_offset, pnanovdb_uint32_t multiplier)
687 {
688  pnanovdb_address_t ret = address;
689  ret.byte_offset += byte_offset * multiplier;
690  return ret;
691 }
692 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_offset64(pnanovdb_address_t address, pnanovdb_uint64_t byte_offset)
693 {
694  pnanovdb_address_t ret = address;
695  // lose high bits on 32-bit
696  ret.byte_offset += pnanovdb_uint64_low(byte_offset);
697  return ret;
698 }
699 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_offset64_product(pnanovdb_address_t address, pnanovdb_uint64_t byte_offset, pnanovdb_uint32_t multiplier)
700 {
701  pnanovdb_address_t ret = address;
702  ret.byte_offset += pnanovdb_uint64_low(byte_offset) * multiplier;
703  return ret;
704 }
705 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_address_mask(pnanovdb_address_t address, pnanovdb_uint32_t mask)
706 {
707  return address.byte_offset & mask;
708 }
709 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_mask_inv(pnanovdb_address_t address, pnanovdb_uint32_t mask)
710 {
711  pnanovdb_address_t ret = address;
712  ret.byte_offset &= (~mask);
713  return ret;
714 }
715 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_null()
716 {
717  pnanovdb_address_t ret = { 0 };
718  return ret;
719 }
720 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_address_is_null(pnanovdb_address_t address)
721 {
722  return address.byte_offset == 0u;
723 }
724 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_address_in_interval(pnanovdb_address_t address, pnanovdb_address_t min_address, pnanovdb_address_t max_address)
725 {
726  return address.byte_offset >= min_address.byte_offset && address.byte_offset < max_address.byte_offset;
727 }
728 #elif defined(PNANOVDB_ADDRESS_64)
729 struct pnanovdb_address_t
730 {
731  pnanovdb_uint64_t byte_offset;
732 };
733 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_address_t)
734 
735 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_offset(pnanovdb_address_t address, pnanovdb_uint32_t byte_offset)
736 {
737  pnanovdb_address_t ret = address;
738  ret.byte_offset += byte_offset;
739  return ret;
740 }
741 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_offset_neg(pnanovdb_address_t address, pnanovdb_uint32_t byte_offset)
742 {
743  pnanovdb_address_t ret = address;
744  ret.byte_offset -= byte_offset;
745  return ret;
746 }
747 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_offset_product(pnanovdb_address_t address, pnanovdb_uint32_t byte_offset, pnanovdb_uint32_t multiplier)
748 {
749  pnanovdb_address_t ret = address;
750  ret.byte_offset += pnanovdb_uint32_as_uint64_low(byte_offset) * pnanovdb_uint32_as_uint64_low(multiplier);
751  return ret;
752 }
753 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_offset64(pnanovdb_address_t address, pnanovdb_uint64_t byte_offset)
754 {
755  pnanovdb_address_t ret = address;
756  ret.byte_offset += byte_offset;
757  return ret;
758 }
759 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_offset64_product(pnanovdb_address_t address, pnanovdb_uint64_t byte_offset, pnanovdb_uint32_t multiplier)
760 {
761  pnanovdb_address_t ret = address;
762  ret.byte_offset += byte_offset * pnanovdb_uint32_as_uint64_low(multiplier);
763  return ret;
764 }
765 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_address_mask(pnanovdb_address_t address, pnanovdb_uint32_t mask)
766 {
767  return pnanovdb_uint64_low(address.byte_offset) & mask;
768 }
769 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_mask_inv(pnanovdb_address_t address, pnanovdb_uint32_t mask)
770 {
771  pnanovdb_address_t ret = address;
772  ret.byte_offset &= (~pnanovdb_uint32_as_uint64_low(mask));
773  return ret;
774 }
775 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_null()
776 {
777  pnanovdb_address_t ret = { 0 };
778  return ret;
779 }
780 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_address_is_null(pnanovdb_address_t address)
781 {
782  return address.byte_offset == 0llu;
783 }
784 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_address_in_interval(pnanovdb_address_t address, pnanovdb_address_t min_address, pnanovdb_address_t max_address)
785 {
786  return address.byte_offset >= min_address.byte_offset && address.byte_offset < max_address.byte_offset;
787 }
788 #endif
789 
790 // ------------------------------------------------ High Level Buffer Read -----------------------------------------------------------
791 
792 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_read_uint32(pnanovdb_buf_t buf, pnanovdb_address_t address)
793 {
794  return pnanovdb_buf_read_uint32(buf, address.byte_offset);
795 }
796 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_read_uint64(pnanovdb_buf_t buf, pnanovdb_address_t address)
797 {
798  return pnanovdb_buf_read_uint64(buf, address.byte_offset);
799 }
800 PNANOVDB_FORCE_INLINE pnanovdb_int32_t pnanovdb_read_int32(pnanovdb_buf_t buf, pnanovdb_address_t address)
801 {
802  return pnanovdb_uint32_as_int32(pnanovdb_read_uint32(buf, address));
803 }
804 PNANOVDB_FORCE_INLINE float pnanovdb_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address)
805 {
806  return pnanovdb_uint32_as_float(pnanovdb_read_uint32(buf, address));
807 }
808 PNANOVDB_FORCE_INLINE pnanovdb_int64_t pnanovdb_read_int64(pnanovdb_buf_t buf, pnanovdb_address_t address)
809 {
810  return pnanovdb_uint64_as_int64(pnanovdb_read_uint64(buf, address));
811 }
812 PNANOVDB_FORCE_INLINE double pnanovdb_read_double(pnanovdb_buf_t buf, pnanovdb_address_t address)
813 {
814  return pnanovdb_uint64_as_double(pnanovdb_read_uint64(buf, address));
815 }
816 PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_read_coord(pnanovdb_buf_t buf, pnanovdb_address_t address)
817 {
818  pnanovdb_coord_t ret;
819  ret.x = pnanovdb_uint32_as_int32(pnanovdb_read_uint32(buf, pnanovdb_address_offset(address, 0u)));
820  ret.y = pnanovdb_uint32_as_int32(pnanovdb_read_uint32(buf, pnanovdb_address_offset(address, 4u)));
821  ret.z = pnanovdb_uint32_as_int32(pnanovdb_read_uint32(buf, pnanovdb_address_offset(address, 8u)));
822  return ret;
823 }
824 PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_read_vec3(pnanovdb_buf_t buf, pnanovdb_address_t address)
825 {
826  pnanovdb_vec3_t ret;
827  ret.x = pnanovdb_read_float(buf, pnanovdb_address_offset(address, 0u));
828  ret.y = pnanovdb_read_float(buf, pnanovdb_address_offset(address, 4u));
829  ret.z = pnanovdb_read_float(buf, pnanovdb_address_offset(address, 8u));
830  return ret;
831 }
832 
833 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_read_uint16(pnanovdb_buf_t buf, pnanovdb_address_t address)
834 {
835  pnanovdb_uint32_t raw = pnanovdb_read_uint32(buf, pnanovdb_address_mask_inv(address, 3u));
836  return (raw >> (pnanovdb_address_mask(address, 2) << 3));
837 }
838 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_read_uint8(pnanovdb_buf_t buf, pnanovdb_address_t address)
839 {
840  pnanovdb_uint32_t raw = pnanovdb_read_uint32(buf, pnanovdb_address_mask_inv(address, 3u));
841  return (raw >> (pnanovdb_address_mask(address, 3) << 3)) & 255;
842 }
843 PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_read_vec3u16(pnanovdb_buf_t buf, pnanovdb_address_t address)
844 {
845  pnanovdb_vec3_t ret;
846  const float scale = 1.f / 65535.f;
847  ret.x = scale * pnanovdb_uint32_to_float(pnanovdb_read_uint16(buf, pnanovdb_address_offset(address, 0u))) - 0.5f;
848  ret.y = scale * pnanovdb_uint32_to_float(pnanovdb_read_uint16(buf, pnanovdb_address_offset(address, 2u))) - 0.5f;
849  ret.z = scale * pnanovdb_uint32_to_float(pnanovdb_read_uint16(buf, pnanovdb_address_offset(address, 4u))) - 0.5f;
850  return ret;
851 }
852 PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_read_vec3u8(pnanovdb_buf_t buf, pnanovdb_address_t address)
853 {
854  pnanovdb_vec3_t ret;
855  const float scale = 1.f / 255.f;
856  ret.x = scale * pnanovdb_uint32_to_float(pnanovdb_read_uint8(buf, pnanovdb_address_offset(address, 0u))) - 0.5f;
857  ret.y = scale * pnanovdb_uint32_to_float(pnanovdb_read_uint8(buf, pnanovdb_address_offset(address, 1u))) - 0.5f;
858  ret.z = scale * pnanovdb_uint32_to_float(pnanovdb_read_uint8(buf, pnanovdb_address_offset(address, 2u))) - 0.5f;
859  return ret;
860 }
861 
862 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_read_bit(pnanovdb_buf_t buf, pnanovdb_address_t address, pnanovdb_uint32_t bit_offset)
863 {
864  pnanovdb_address_t word_address = pnanovdb_address_mask_inv(address, 3u);
865  pnanovdb_uint32_t bit_index = (pnanovdb_address_mask(address, 3u) << 3u) + bit_offset;
866  pnanovdb_uint32_t value_word = pnanovdb_buf_read_uint32(buf, word_address.byte_offset);
867  return ((value_word >> bit_index) & 1) != 0u;
868 }
869 
870 #if defined(PNANOVDB_C)
871 PNANOVDB_FORCE_INLINE short pnanovdb_read_half(pnanovdb_buf_t buf, pnanovdb_address_t address)
872 {
873  pnanovdb_uint32_t raw = pnanovdb_read_uint32(buf, address);
874  return (short)(raw >> (pnanovdb_address_mask(address, 2) << 3));
875 }
876 #elif defined(PNANOVDB_HLSL)
877 PNANOVDB_FORCE_INLINE float pnanovdb_read_half(pnanovdb_buf_t buf, pnanovdb_address_t address)
878 {
879  pnanovdb_uint32_t raw = pnanovdb_read_uint32(buf, address);
880  return f16tof32(raw >> (pnanovdb_address_mask(address, 2) << 3));
881 }
882 #elif defined(PNANOVDB_GLSL)
883 PNANOVDB_FORCE_INLINE float pnanovdb_read_half(pnanovdb_buf_t buf, pnanovdb_address_t address)
884 {
885  pnanovdb_uint32_t raw = pnanovdb_read_uint32(buf, address);
886  return unpackHalf2x16(raw >> (pnanovdb_address_mask(address, 2) << 3)).x;
887 }
888 #endif
889 
890 // ------------------------------------------------ High Level Buffer Write -----------------------------------------------------------
891 
892 PNANOVDB_FORCE_INLINE void pnanovdb_write_uint32(pnanovdb_buf_t buf, pnanovdb_address_t address, pnanovdb_uint32_t value)
893 {
894  pnanovdb_buf_write_uint32(buf, address.byte_offset, value);
895 }
896 PNANOVDB_FORCE_INLINE void pnanovdb_write_uint64(pnanovdb_buf_t buf, pnanovdb_address_t address, pnanovdb_uint64_t value)
897 {
898  pnanovdb_buf_write_uint64(buf, address.byte_offset, value);
899 }
900 PNANOVDB_FORCE_INLINE void pnanovdb_write_int32(pnanovdb_buf_t buf, pnanovdb_address_t address, pnanovdb_int32_t value)
901 {
902  pnanovdb_write_uint32(buf, address, pnanovdb_int32_as_uint32(value));
903 }
904 PNANOVDB_FORCE_INLINE void pnanovdb_write_int64(pnanovdb_buf_t buf, pnanovdb_address_t address, pnanovdb_int64_t value)
905 {
906  pnanovdb_buf_write_uint64(buf, address.byte_offset, pnanovdb_int64_as_uint64(value));
907 }
908 PNANOVDB_FORCE_INLINE void pnanovdb_write_float(pnanovdb_buf_t buf, pnanovdb_address_t address, float value)
909 {
910  pnanovdb_write_uint32(buf, address, pnanovdb_float_as_uint32(value));
911 }
912 PNANOVDB_FORCE_INLINE void pnanovdb_write_double(pnanovdb_buf_t buf, pnanovdb_address_t address, double value)
913 {
914  pnanovdb_write_uint64(buf, address, pnanovdb_double_as_uint64(value));
915 }
916 PNANOVDB_FORCE_INLINE void pnanovdb_write_coord(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) value)
917 {
918  pnanovdb_write_uint32(buf, pnanovdb_address_offset(address, 0u), pnanovdb_int32_as_uint32(PNANOVDB_DEREF(value).x));
919  pnanovdb_write_uint32(buf, pnanovdb_address_offset(address, 4u), pnanovdb_int32_as_uint32(PNANOVDB_DEREF(value).y));
920  pnanovdb_write_uint32(buf, pnanovdb_address_offset(address, 8u), pnanovdb_int32_as_uint32(PNANOVDB_DEREF(value).z));
921 }
922 PNANOVDB_FORCE_INLINE void pnanovdb_write_vec3(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_vec3_t) value)
923 {
924  pnanovdb_write_float(buf, pnanovdb_address_offset(address, 0u), PNANOVDB_DEREF(value).x);
925  pnanovdb_write_float(buf, pnanovdb_address_offset(address, 4u), PNANOVDB_DEREF(value).y);
926  pnanovdb_write_float(buf, pnanovdb_address_offset(address, 8u), PNANOVDB_DEREF(value).z);
927 }
928 
929 // ------------------------------------------------ Core Structures -----------------------------------------------------------
930 
931 #define PNANOVDB_MAGIC_NUMBER 0x304244566f6e614eUL// "NanoVDB0" in hex - little endian (uint64_t)
932 #define PNANOVDB_MAGIC_GRID 0x314244566f6e614eUL// "NanoVDB1" in hex - little endian (uint64_t)
933 #define PNANOVDB_MAGIC_FILE 0x324244566f6e614eUL// "NanoVDB2" in hex - little endian (uint64_t)
934 
935 #define PNANOVDB_MAJOR_VERSION_NUMBER 32// reflects changes to the ABI
936 #define PNANOVDB_MINOR_VERSION_NUMBER 7// reflects changes to the API but not ABI
937 #define PNANOVDB_PATCH_VERSION_NUMBER 0// reflects bug-fixes with no ABI or API changes
938 
939 #define PNANOVDB_GRID_TYPE_UNKNOWN 0
940 #define PNANOVDB_GRID_TYPE_FLOAT 1
941 #define PNANOVDB_GRID_TYPE_DOUBLE 2
942 #define PNANOVDB_GRID_TYPE_INT16 3
943 #define PNANOVDB_GRID_TYPE_INT32 4
944 #define PNANOVDB_GRID_TYPE_INT64 5
945 #define PNANOVDB_GRID_TYPE_VEC3F 6
946 #define PNANOVDB_GRID_TYPE_VEC3D 7
947 #define PNANOVDB_GRID_TYPE_MASK 8
948 #define PNANOVDB_GRID_TYPE_HALF 9
949 #define PNANOVDB_GRID_TYPE_UINT32 10
950 #define PNANOVDB_GRID_TYPE_BOOLEAN 11
951 #define PNANOVDB_GRID_TYPE_RGBA8 12
952 #define PNANOVDB_GRID_TYPE_FP4 13
953 #define PNANOVDB_GRID_TYPE_FP8 14
954 #define PNANOVDB_GRID_TYPE_FP16 15
955 #define PNANOVDB_GRID_TYPE_FPN 16
956 #define PNANOVDB_GRID_TYPE_VEC4F 17
957 #define PNANOVDB_GRID_TYPE_VEC4D 18
958 #define PNANOVDB_GRID_TYPE_INDEX 19
959 #define PNANOVDB_GRID_TYPE_ONINDEX 20
960 #define PNANOVDB_GRID_TYPE_INDEXMASK 21
961 #define PNANOVDB_GRID_TYPE_ONINDEXMASK 22
962 #define PNANOVDB_GRID_TYPE_POINTINDEX 23
963 #define PNANOVDB_GRID_TYPE_VEC3U8 24
964 #define PNANOVDB_GRID_TYPE_VEC3U16 25
965 #define PNANOVDB_GRID_TYPE_UINT8 26
966 #define PNANOVDB_GRID_TYPE_END 27
967 
968 #define PNANOVDB_GRID_CLASS_UNKNOWN 0
969 #define PNANOVDB_GRID_CLASS_LEVEL_SET 1 // narrow band level set, e.g. SDF
970 #define PNANOVDB_GRID_CLASS_FOG_VOLUME 2 // fog volume, e.g. density
971 #define PNANOVDB_GRID_CLASS_STAGGERED 3 // staggered MAC grid, e.g. velocity
972 #define PNANOVDB_GRID_CLASS_POINT_INDEX 4 // point index grid
973 #define PNANOVDB_GRID_CLASS_POINT_DATA 5 // point data grid
974 #define PNANOVDB_GRID_CLASS_TOPOLOGY 6 // grid with active states only (no values)
975 #define PNANOVDB_GRID_CLASS_VOXEL_VOLUME 7 // volume of geometric cubes, e.g. minecraft
976 #define PNANOVDB_GRID_CLASS_INDEX_GRID 8 // grid whose values are offsets, e.g. into an external array
977 #define PNANOVDB_GRID_CLASS_TENSOR_GRID 9 // grid which can have extra metadata and features
978 #define PNANOVDB_GRID_CLASS_END 10
979 
980 #define PNANOVDB_GRID_FLAGS_HAS_LONG_GRID_NAME (1 << 0)
981 #define PNANOVDB_GRID_FLAGS_HAS_BBOX (1 << 1)
982 #define PNANOVDB_GRID_FLAGS_HAS_MIN_MAX (1 << 2)
983 #define PNANOVDB_GRID_FLAGS_HAS_AVERAGE (1 << 3)
984 #define PNANOVDB_GRID_FLAGS_HAS_STD_DEVIATION (1 << 4)
985 #define PNANOVDB_GRID_FLAGS_IS_BREADTH_FIRST (1 << 5)
986 #define PNANOVDB_GRID_FLAGS_END (1 << 6)
987 
988 #define PNANOVDB_LEAF_TYPE_DEFAULT 0
989 #define PNANOVDB_LEAF_TYPE_LITE 1
990 #define PNANOVDB_LEAF_TYPE_FP 2
991 #define PNANOVDB_LEAF_TYPE_INDEX 3
992 #define PNANOVDB_LEAF_TYPE_INDEXMASK 4
993 #define PNANOVDB_LEAF_TYPE_POINTINDEX 5
994 
995 // BuildType = Unknown, float, double, int16_t, int32_t, int64_t, Vec3f, Vec3d, Mask, ...
996 // bit count of values in leaf nodes, i.e. 8*sizeof(*nanovdb::LeafNode<BuildType>::mValues) or zero if no values are stored
997 PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_value_strides_bits[PNANOVDB_GRID_TYPE_END] = { 0, 32, 64, 16, 32, 64, 96, 192, 0, 16, 32, 1, 32, 4, 8, 16, 0, 128, 256, 0, 0, 0, 0, 16, 24, 48, 8 };
998 // bit count of the Tile union in InternalNodes, i.e. 8*sizeof(nanovdb::InternalData::Tile)
999 PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_table_strides_bits[PNANOVDB_GRID_TYPE_END] = { 64, 64, 64, 64, 64, 64, 128, 192, 64, 64, 64, 64, 64, 64, 64, 64, 64, 128, 256, 64, 64, 64, 64, 64, 64, 64, 64 };
1000 // bit count of min/max values, i.e. 8*sizeof(nanovdb::LeafData::mMinimum) or zero if no min/max exists
1001 PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_minmax_strides_bits[PNANOVDB_GRID_TYPE_END] = { 0, 32, 64, 16, 32, 64, 96, 192, 8, 16, 32, 8, 32, 32, 32, 32, 32, 128, 256, 64, 64, 64, 64, 64, 24, 48, 8 };
1002 // bit alignment of the value type, controlled by the smallest native type, which is why it is always 0, 8, 16, 32, or 64, e.g. for Vec3f it is 32
1003 PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_minmax_aligns_bits[PNANOVDB_GRID_TYPE_END] = { 0, 32, 64, 16, 32, 64, 32, 64, 8, 16, 32, 8, 32, 32, 32, 32, 32, 32, 64, 64, 64, 64, 64, 64, 8, 16, 8 };
1004 // bit alignment of the stats (avg/std-dev) types, e.g. 8*sizeof(nanovdb::LeafData::mAverage)
1005 PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_stat_strides_bits[PNANOVDB_GRID_TYPE_END] = { 0, 32, 64, 32, 32, 64, 32, 64, 8, 32, 32, 8, 32, 32, 32, 32, 32, 32, 64, 64, 64, 64, 64, 64, 32, 32, 32 };
1006 // one of the 4 leaf types defined above, e.g. PNANOVDB_LEAF_TYPE_INDEX = 3
1007 PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_leaf_type[PNANOVDB_GRID_TYPE_END] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 2, 2, 2, 2, 0, 0, 3, 3, 4, 4, 5, 0, 0, 0 };
1008 
1010 {
1011  float matf[9];
1012  float invmatf[9];
1013  float vecf[3];
1014  float taperf;
1015  double matd[9];
1016  double invmatd[9];
1017  double vecd[3];
1018  double taperd;
1019 };
1020 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_map_t)
1021 struct pnanovdb_map_handle_t { pnanovdb_address_t address; };
1022 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_map_handle_t)
1023 
1024 #define PNANOVDB_MAP_SIZE 264
1025 
1026 #define PNANOVDB_MAP_OFF_MATF 0
1027 #define PNANOVDB_MAP_OFF_INVMATF 36
1028 #define PNANOVDB_MAP_OFF_VECF 72
1029 #define PNANOVDB_MAP_OFF_TAPERF 84
1030 #define PNANOVDB_MAP_OFF_MATD 88
1031 #define PNANOVDB_MAP_OFF_INVMATD 160
1032 #define PNANOVDB_MAP_OFF_VECD 232
1033 #define PNANOVDB_MAP_OFF_TAPERD 256
1034 
1035 PNANOVDB_FORCE_INLINE float pnanovdb_map_get_matf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index) {
1036  return pnanovdb_read_float(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_MATF + 4u * index));
1037 }
1038 PNANOVDB_FORCE_INLINE float pnanovdb_map_get_invmatf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index) {
1039  return pnanovdb_read_float(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_INVMATF + 4u * index));
1040 }
1041 PNANOVDB_FORCE_INLINE float pnanovdb_map_get_vecf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index) {
1042  return pnanovdb_read_float(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_VECF + 4u * index));
1043 }
1044 PNANOVDB_FORCE_INLINE float pnanovdb_map_get_taperf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index) {
1045  return pnanovdb_read_float(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_TAPERF));
1046 }
1047 PNANOVDB_FORCE_INLINE double pnanovdb_map_get_matd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index) {
1048  return pnanovdb_read_double(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_MATD + 8u * index));
1049 }
1050 PNANOVDB_FORCE_INLINE double pnanovdb_map_get_invmatd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index) {
1051  return pnanovdb_read_double(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_INVMATD + 8u * index));
1052 }
1053 PNANOVDB_FORCE_INLINE double pnanovdb_map_get_vecd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index) {
1054  return pnanovdb_read_double(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_VECD + 8u * index));
1055 }
1056 PNANOVDB_FORCE_INLINE double pnanovdb_map_get_taperd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index) {
1057  return pnanovdb_read_double(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_TAPERD));
1058 }
1059 
1060 PNANOVDB_FORCE_INLINE void pnanovdb_map_set_matf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index, float matf) {
1061  pnanovdb_write_float(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_MATF + 4u * index), matf);
1062 }
1063 PNANOVDB_FORCE_INLINE void pnanovdb_map_set_invmatf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index, float invmatf) {
1064  pnanovdb_write_float(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_INVMATF + 4u * index), invmatf);
1065 }
1066 PNANOVDB_FORCE_INLINE void pnanovdb_map_set_vecf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index, float vecf) {
1067  pnanovdb_write_float(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_VECF + 4u * index), vecf);
1068 }
1069 PNANOVDB_FORCE_INLINE void pnanovdb_map_set_taperf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index, float taperf) {
1070  pnanovdb_write_float(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_TAPERF), taperf);
1071 }
1072 PNANOVDB_FORCE_INLINE void pnanovdb_map_set_matd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index, double matd) {
1073  pnanovdb_write_double(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_MATD + 8u * index), matd);
1074 }
1075 PNANOVDB_FORCE_INLINE void pnanovdb_map_set_invmatd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index, double invmatd) {
1076  pnanovdb_write_double(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_INVMATD + 8u * index), invmatd);
1077 }
1078 PNANOVDB_FORCE_INLINE void pnanovdb_map_set_vecd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index, double vecd) {
1079  pnanovdb_write_double(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_VECD + 8u * index), vecd);
1080 }
1081 PNANOVDB_FORCE_INLINE void pnanovdb_map_set_taperd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index, double taperd) {
1082  pnanovdb_write_double(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_TAPERD), taperd);
1083 }
1084 
1086 {
1087  pnanovdb_uint64_t magic; // 8 bytes, 0
1088  pnanovdb_uint64_t checksum; // 8 bytes, 8
1089  pnanovdb_uint32_t version; // 4 bytes, 16
1090  pnanovdb_uint32_t flags; // 4 bytes, 20
1091  pnanovdb_uint32_t grid_index; // 4 bytes, 24
1092  pnanovdb_uint32_t grid_count; // 4 bytes, 28
1093  pnanovdb_uint64_t grid_size; // 8 bytes, 32
1094  pnanovdb_uint32_t grid_name[256 / 4]; // 256 bytes, 40
1095  pnanovdb_map_t map; // 264 bytes, 296
1096  double world_bbox[6]; // 48 bytes, 560
1097  double voxel_size[3]; // 24 bytes, 608
1098  pnanovdb_uint32_t grid_class; // 4 bytes, 632
1099  pnanovdb_uint32_t grid_type; // 4 bytes, 636
1100  pnanovdb_int64_t blind_metadata_offset; // 8 bytes, 640
1101  pnanovdb_uint32_t blind_metadata_count; // 4 bytes, 648
1102  pnanovdb_uint32_t pad[5]; // 20 bytes, 652
1103 };
1104 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_grid_t)
1105 struct pnanovdb_grid_handle_t { pnanovdb_address_t address; };
1106 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_grid_handle_t)
1107 
1108 #define PNANOVDB_GRID_SIZE 672
1109 
1110 #define PNANOVDB_GRID_OFF_MAGIC 0
1111 #define PNANOVDB_GRID_OFF_CHECKSUM 8
1112 #define PNANOVDB_GRID_OFF_VERSION 16
1113 #define PNANOVDB_GRID_OFF_FLAGS 20
1114 #define PNANOVDB_GRID_OFF_GRID_INDEX 24
1115 #define PNANOVDB_GRID_OFF_GRID_COUNT 28
1116 #define PNANOVDB_GRID_OFF_GRID_SIZE 32
1117 #define PNANOVDB_GRID_OFF_GRID_NAME 40
1118 #define PNANOVDB_GRID_OFF_MAP 296
1119 #define PNANOVDB_GRID_OFF_WORLD_BBOX 560
1120 #define PNANOVDB_GRID_OFF_VOXEL_SIZE 608
1121 #define PNANOVDB_GRID_OFF_GRID_CLASS 632
1122 #define PNANOVDB_GRID_OFF_GRID_TYPE 636
1123 #define PNANOVDB_GRID_OFF_BLIND_METADATA_OFFSET 640
1124 #define PNANOVDB_GRID_OFF_BLIND_METADATA_COUNT 648
1125 
1126 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_grid_get_magic(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
1127  return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_MAGIC));
1128 }
1129 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_grid_get_checksum(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
1130  return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_CHECKSUM));
1131 }
1132 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_version(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
1133  return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_VERSION));
1134 }
1135 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_flags(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
1136  return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_FLAGS));
1137 }
1138 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_grid_index(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
1139  return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_GRID_INDEX));
1140 }
1141 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_grid_count(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
1142  return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_GRID_COUNT));
1143 }
1144 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_grid_get_grid_size(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
1145  return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_GRID_SIZE));
1146 }
1147 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_grid_name(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t index) {
1148  return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_GRID_NAME + 4u * index));
1149 }
1150 PNANOVDB_FORCE_INLINE pnanovdb_map_handle_t pnanovdb_grid_get_map(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
1152  ret.address = pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_MAP);
1153  return ret;
1154 }
1155 PNANOVDB_FORCE_INLINE double pnanovdb_grid_get_world_bbox(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t index) {
1156  return pnanovdb_read_double(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_WORLD_BBOX + 8u * index));
1157 }
1158 PNANOVDB_FORCE_INLINE double pnanovdb_grid_get_voxel_size(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t index) {
1159  return pnanovdb_read_double(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_VOXEL_SIZE + 8u * index));
1160 }
1161 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_grid_class(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
1162  return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_GRID_CLASS));
1163 }
1164 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_grid_type(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
1165  return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_GRID_TYPE));
1166 }
1167 PNANOVDB_FORCE_INLINE pnanovdb_int64_t pnanovdb_grid_get_blind_metadata_offset(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
1168  return pnanovdb_read_int64(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_BLIND_METADATA_OFFSET));
1169 }
1170 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_blind_metadata_count(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
1171  return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_BLIND_METADATA_COUNT));
1172 }
1173 
1174 PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_magic(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint64_t magic) {
1175  pnanovdb_write_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_MAGIC), magic);
1176 }
1177 PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_checksum(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint64_t checksum) {
1178  pnanovdb_write_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_CHECKSUM), checksum);
1179 }
1180 PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_version(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t version) {
1181  pnanovdb_write_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_VERSION), version);
1182 }
1183 PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_flags(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t flags) {
1184  pnanovdb_write_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_FLAGS), flags);
1185 }
1186 PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_grid_index(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t grid_index) {
1187  pnanovdb_write_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_GRID_INDEX), grid_index);
1188 }
1189 PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_grid_count(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t grid_count) {
1190  pnanovdb_write_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_GRID_COUNT), grid_count);
1191 }
1192 PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_grid_size(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint64_t grid_size) {
1193  pnanovdb_write_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_GRID_SIZE), grid_size);
1194 }
1195 PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_grid_name(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t index, pnanovdb_uint32_t grid_name) {
1196  pnanovdb_write_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_GRID_NAME + 4u * index), grid_name);
1197 }
1198 PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_world_bbox(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t index, double world_bbox) {
1199  pnanovdb_write_double(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_WORLD_BBOX + 8u * index), world_bbox);
1200 }
1201 PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_voxel_size(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t index, double voxel_size) {
1202  pnanovdb_write_double(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_VOXEL_SIZE + 8u * index), voxel_size);
1203 }
1204 PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_grid_class(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t grid_class) {
1205  pnanovdb_write_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_GRID_CLASS), grid_class);
1206 }
1207 PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_grid_type(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t grid_type) {
1208  pnanovdb_write_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_GRID_TYPE), grid_type);
1209 }
1210 PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_blind_metadata_offset(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint64_t blind_metadata_offset) {
1211  pnanovdb_write_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_BLIND_METADATA_OFFSET), blind_metadata_offset);
1212 }
1213 PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_blind_metadata_count(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t metadata_count) {
1214  pnanovdb_write_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_BLIND_METADATA_COUNT), metadata_count);
1215 }
1216 
1217 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_make_version(pnanovdb_uint32_t major, pnanovdb_uint32_t minor, pnanovdb_uint32_t patch_num)
1218 {
1219  return (major << 21u) | (minor << 10u) | patch_num;
1220 }
1221 
1222 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_version_get_major(pnanovdb_uint32_t version)
1223 {
1224  return (version >> 21u) & ((1u << 11u) - 1u);
1225 }
1226 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_version_get_minor(pnanovdb_uint32_t version)
1227 {
1228  return (version >> 10u) & ((1u << 11u) - 1u);
1229 }
1230 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_version_get_patch(pnanovdb_uint32_t version)
1231 {
1232  return version & ((1u << 10u) - 1u);
1233 }
1234 
1236 {
1237  pnanovdb_int64_t data_offset; // 8 bytes, 0
1238  pnanovdb_uint64_t value_count; // 8 bytes, 8
1239  pnanovdb_uint32_t value_size; // 4 bytes, 16
1240  pnanovdb_uint32_t semantic; // 4 bytes, 20
1241  pnanovdb_uint32_t data_class; // 4 bytes, 24
1242  pnanovdb_uint32_t data_type; // 4 bytes, 28
1243  pnanovdb_uint32_t name[256 / 4]; // 256 bytes, 32
1244 };
1245 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_gridblindmetadata_t)
1246 struct pnanovdb_gridblindmetadata_handle_t { pnanovdb_address_t address; };
1247 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_gridblindmetadata_handle_t)
1248 
1249 #define PNANOVDB_GRIDBLINDMETADATA_SIZE 288
1250 
1251 #define PNANOVDB_GRIDBLINDMETADATA_OFF_DATA_OFFSET 0
1252 #define PNANOVDB_GRIDBLINDMETADATA_OFF_VALUE_COUNT 8
1253 #define PNANOVDB_GRIDBLINDMETADATA_OFF_VALUE_SIZE 16
1254 #define PNANOVDB_GRIDBLINDMETADATA_OFF_SEMANTIC 20
1255 #define PNANOVDB_GRIDBLINDMETADATA_OFF_DATA_CLASS 24
1256 #define PNANOVDB_GRIDBLINDMETADATA_OFF_DATA_TYPE 28
1257 #define PNANOVDB_GRIDBLINDMETADATA_OFF_NAME 32
1258 
1259 PNANOVDB_FORCE_INLINE pnanovdb_int64_t pnanovdb_gridblindmetadata_get_data_offset(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p) {
1260  return pnanovdb_read_int64(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRIDBLINDMETADATA_OFF_DATA_OFFSET));
1261 }
1262 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_gridblindmetadata_get_value_count(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p) {
1263  return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRIDBLINDMETADATA_OFF_VALUE_COUNT));
1264 }
1265 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_gridblindmetadata_get_value_size(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p) {
1266  return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRIDBLINDMETADATA_OFF_VALUE_SIZE));
1267 }
1268 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_gridblindmetadata_get_semantic(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p) {
1269  return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRIDBLINDMETADATA_OFF_SEMANTIC));
1270 }
1271 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_gridblindmetadata_get_data_class(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p) {
1272  return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRIDBLINDMETADATA_OFF_DATA_CLASS));
1273 }
1274 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_gridblindmetadata_get_data_type(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p) {
1275  return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRIDBLINDMETADATA_OFF_DATA_TYPE));
1276 }
1277 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_gridblindmetadata_get_name(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p, pnanovdb_uint32_t index) {
1278  return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRIDBLINDMETADATA_OFF_NAME + 4u * index));
1279 }
1280 
1282 {
1283  pnanovdb_uint64_t node_offset_leaf;
1284  pnanovdb_uint64_t node_offset_lower;
1285  pnanovdb_uint64_t node_offset_upper;
1286  pnanovdb_uint64_t node_offset_root;
1287  pnanovdb_uint32_t node_count_leaf;
1288  pnanovdb_uint32_t node_count_lower;
1289  pnanovdb_uint32_t node_count_upper;
1290  pnanovdb_uint32_t tile_count_leaf;
1291  pnanovdb_uint32_t tile_count_lower;
1292  pnanovdb_uint32_t tile_count_upper;
1293  pnanovdb_uint64_t voxel_count;
1294 };
1295 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_tree_t)
1296 struct pnanovdb_tree_handle_t { pnanovdb_address_t address; };
1297 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_tree_handle_t)
1298 
1299 #define PNANOVDB_TREE_SIZE 64
1300 
1301 #define PNANOVDB_TREE_OFF_NODE_OFFSET_LEAF 0
1302 #define PNANOVDB_TREE_OFF_NODE_OFFSET_LOWER 8
1303 #define PNANOVDB_TREE_OFF_NODE_OFFSET_UPPER 16
1304 #define PNANOVDB_TREE_OFF_NODE_OFFSET_ROOT 24
1305 #define PNANOVDB_TREE_OFF_NODE_COUNT_LEAF 32
1306 #define PNANOVDB_TREE_OFF_NODE_COUNT_LOWER 36
1307 #define PNANOVDB_TREE_OFF_NODE_COUNT_UPPER 40
1308 #define PNANOVDB_TREE_OFF_TILE_COUNT_LEAF 44
1309 #define PNANOVDB_TREE_OFF_TILE_COUNT_LOWER 48
1310 #define PNANOVDB_TREE_OFF_TILE_COUNT_UPPER 52
1311 #define PNANOVDB_TREE_OFF_VOXEL_COUNT 56
1312 
1313 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_tree_get_node_offset_leaf(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p) {
1314  return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_NODE_OFFSET_LEAF));
1315 }
1316 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_tree_get_node_offset_lower(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p) {
1317  return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_NODE_OFFSET_LOWER));
1318 }
1319 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_tree_get_node_offset_upper(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p) {
1320  return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_NODE_OFFSET_UPPER));
1321 }
1322 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_tree_get_node_offset_root(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p) {
1323  return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_NODE_OFFSET_ROOT));
1324 }
1325 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_node_count_leaf(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p) {
1326  return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_NODE_COUNT_LEAF));
1327 }
1328 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_node_count_lower(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p) {
1329  return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_NODE_COUNT_LOWER));
1330 }
1331 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_node_count_upper(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p) {
1332  return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_NODE_COUNT_UPPER));
1333 }
1334 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_tile_count_leaf(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p) {
1335  return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_TILE_COUNT_LEAF));
1336 }
1337 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_tile_count_lower(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p) {
1338  return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_TILE_COUNT_LOWER));
1339 }
1340 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_tile_count_upper(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p) {
1341  return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_TILE_COUNT_UPPER));
1342 }
1343 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_tree_get_voxel_count(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p) {
1344  return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_VOXEL_COUNT));
1345 }
1346 
1347 PNANOVDB_FORCE_INLINE void pnanovdb_tree_set_node_offset_leaf(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p, pnanovdb_uint64_t node_offset_leaf) {
1348  pnanovdb_write_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_NODE_OFFSET_LEAF), node_offset_leaf);
1349 }
1350 PNANOVDB_FORCE_INLINE void pnanovdb_tree_set_node_offset_lower(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p, pnanovdb_uint64_t node_offset_lower) {
1351  pnanovdb_write_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_NODE_OFFSET_LOWER), node_offset_lower);
1352 }
1353 PNANOVDB_FORCE_INLINE void pnanovdb_tree_set_node_offset_upper(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p, pnanovdb_uint64_t node_offset_upper) {
1354  pnanovdb_write_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_NODE_OFFSET_UPPER), node_offset_upper);
1355 }
1356 PNANOVDB_FORCE_INLINE void pnanovdb_tree_set_node_offset_root(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p, pnanovdb_uint64_t node_offset_root) {
1357  pnanovdb_write_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_NODE_OFFSET_ROOT), node_offset_root);
1358 }
1359 PNANOVDB_FORCE_INLINE void pnanovdb_tree_set_node_count_leaf(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p, pnanovdb_uint32_t node_count_leaf) {
1360  pnanovdb_write_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_NODE_COUNT_LEAF), node_count_leaf);
1361 }
1362 PNANOVDB_FORCE_INLINE void pnanovdb_tree_set_node_count_lower(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p, pnanovdb_uint32_t node_count_lower) {
1363  pnanovdb_write_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_NODE_COUNT_LOWER), node_count_lower);
1364 }
1365 PNANOVDB_FORCE_INLINE void pnanovdb_tree_set_node_count_upper(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p, pnanovdb_uint32_t node_count_upper) {
1366  pnanovdb_write_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_NODE_COUNT_UPPER), node_count_upper);
1367 }
1368 PNANOVDB_FORCE_INLINE void pnanovdb_tree_set_tile_count_leaf(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p, pnanovdb_uint32_t tile_count_leaf) {
1369  pnanovdb_write_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_TILE_COUNT_LEAF), tile_count_leaf);
1370 }
1371 PNANOVDB_FORCE_INLINE void pnanovdb_tree_set_tile_count_lower(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p, pnanovdb_uint32_t tile_count_lower) {
1372  pnanovdb_write_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_TILE_COUNT_LOWER), tile_count_lower);
1373 }
1374 PNANOVDB_FORCE_INLINE void pnanovdb_tree_set_tile_count_upper(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p, pnanovdb_uint32_t tile_count_upper) {
1375  pnanovdb_write_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_TILE_COUNT_UPPER), tile_count_upper);
1376 }
1377 PNANOVDB_FORCE_INLINE void pnanovdb_tree_set_voxel_count(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p, pnanovdb_uint64_t voxel_count) {
1378  pnanovdb_write_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_VOXEL_COUNT), voxel_count);
1379 }
1380 
1382 {
1383  pnanovdb_coord_t bbox_min;
1384  pnanovdb_coord_t bbox_max;
1385  pnanovdb_uint32_t table_size;
1386  pnanovdb_uint32_t pad1; // background can start here
1387  // background, min, max
1388 };
1389 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_root_t)
1390 struct pnanovdb_root_handle_t { pnanovdb_address_t address; };
1391 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_root_handle_t)
1392 
1393 #define PNANOVDB_ROOT_BASE_SIZE 28
1394 
1395 #define PNANOVDB_ROOT_OFF_BBOX_MIN 0
1396 #define PNANOVDB_ROOT_OFF_BBOX_MAX 12
1397 #define PNANOVDB_ROOT_OFF_TABLE_SIZE 24
1398 
1399 PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_root_get_bbox_min(pnanovdb_buf_t buf, pnanovdb_root_handle_t p) {
1400  return pnanovdb_read_coord(buf, pnanovdb_address_offset(p.address, PNANOVDB_ROOT_OFF_BBOX_MIN));
1401 }
1402 PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_root_get_bbox_max(pnanovdb_buf_t buf, pnanovdb_root_handle_t p) {
1403  return pnanovdb_read_coord(buf, pnanovdb_address_offset(p.address, PNANOVDB_ROOT_OFF_BBOX_MAX));
1404 }
1405 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_root_get_tile_count(pnanovdb_buf_t buf, pnanovdb_root_handle_t p) {
1406  return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_ROOT_OFF_TABLE_SIZE));
1407 }
1408 
1409 PNANOVDB_FORCE_INLINE void pnanovdb_root_set_bbox_min(pnanovdb_buf_t buf, pnanovdb_root_handle_t p, PNANOVDB_IN(pnanovdb_coord_t) bbox_min) {
1410  pnanovdb_write_coord(buf, pnanovdb_address_offset(p.address, PNANOVDB_ROOT_OFF_BBOX_MIN), bbox_min);
1411 }
1412 PNANOVDB_FORCE_INLINE void pnanovdb_root_set_bbox_max(pnanovdb_buf_t buf, pnanovdb_root_handle_t p, PNANOVDB_IN(pnanovdb_coord_t) bbox_max) {
1413  pnanovdb_write_coord(buf, pnanovdb_address_offset(p.address, PNANOVDB_ROOT_OFF_BBOX_MAX), bbox_max);
1414 }
1415 PNANOVDB_FORCE_INLINE void pnanovdb_root_set_tile_count(pnanovdb_buf_t buf, pnanovdb_root_handle_t p, pnanovdb_uint32_t tile_count) {
1416  pnanovdb_write_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_ROOT_OFF_TABLE_SIZE), tile_count);
1417 }
1418 
1420 {
1421  pnanovdb_uint64_t key;
1422  pnanovdb_int64_t child; // signed byte offset from root to the child node, 0 means it is a constant tile, so use value
1423  pnanovdb_uint32_t state;
1424  pnanovdb_uint32_t pad1; // value can start here
1425  // value
1426 };
1427 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_root_tile_t)
1428 struct pnanovdb_root_tile_handle_t { pnanovdb_address_t address; };
1429 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_root_tile_handle_t)
1430 
1431 #define PNANOVDB_ROOT_TILE_BASE_SIZE 20
1432 
1433 #define PNANOVDB_ROOT_TILE_OFF_KEY 0
1434 #define PNANOVDB_ROOT_TILE_OFF_CHILD 8
1435 #define PNANOVDB_ROOT_TILE_OFF_STATE 16
1436 
1437 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_root_tile_get_key(pnanovdb_buf_t buf, pnanovdb_root_tile_handle_t p) {
1438  return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_ROOT_TILE_OFF_KEY));
1439 }
1440 PNANOVDB_FORCE_INLINE pnanovdb_int64_t pnanovdb_root_tile_get_child(pnanovdb_buf_t buf, pnanovdb_root_tile_handle_t p) {
1441  return pnanovdb_read_int64(buf, pnanovdb_address_offset(p.address, PNANOVDB_ROOT_TILE_OFF_CHILD));
1442 }
1443 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_root_tile_get_state(pnanovdb_buf_t buf, pnanovdb_root_tile_handle_t p) {
1444  return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_ROOT_TILE_OFF_STATE));
1445 }
1446 
1447 PNANOVDB_FORCE_INLINE void pnanovdb_root_tile_set_key(pnanovdb_buf_t buf, pnanovdb_root_tile_handle_t p, pnanovdb_uint64_t key) {
1448  pnanovdb_write_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_ROOT_TILE_OFF_KEY), key);
1449 }
1450 PNANOVDB_FORCE_INLINE void pnanovdb_root_tile_set_child(pnanovdb_buf_t buf, pnanovdb_root_tile_handle_t p, pnanovdb_int64_t child) {
1451  pnanovdb_write_int64(buf, pnanovdb_address_offset(p.address, PNANOVDB_ROOT_TILE_OFF_CHILD), child);
1452 }
1453 PNANOVDB_FORCE_INLINE void pnanovdb_root_tile_set_state(pnanovdb_buf_t buf, pnanovdb_root_tile_handle_t p, pnanovdb_uint32_t state) {
1454  pnanovdb_write_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_ROOT_TILE_OFF_STATE), state);
1455 }
1456 
1458 {
1459  pnanovdb_coord_t bbox_min;
1460  pnanovdb_coord_t bbox_max;
1461  pnanovdb_uint64_t flags;
1462  pnanovdb_uint32_t value_mask[1024];
1463  pnanovdb_uint32_t child_mask[1024];
1464  // min, max
1465  // alignas(32) pnanovdb_uint32_t table[];
1466 };
1467 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_upper_t)
1468 struct pnanovdb_upper_handle_t { pnanovdb_address_t address; };
1469 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_upper_handle_t)
1470 
1471 #define PNANOVDB_UPPER_TABLE_COUNT 32768
1472 #define PNANOVDB_UPPER_BASE_SIZE 8224
1473 
1474 #define PNANOVDB_UPPER_OFF_BBOX_MIN 0
1475 #define PNANOVDB_UPPER_OFF_BBOX_MAX 12
1476 #define PNANOVDB_UPPER_OFF_FLAGS 24
1477 #define PNANOVDB_UPPER_OFF_VALUE_MASK 32
1478 #define PNANOVDB_UPPER_OFF_CHILD_MASK 4128
1479 
1480 PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_upper_get_bbox_min(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p) {
1481  return pnanovdb_read_coord(buf, pnanovdb_address_offset(p.address, PNANOVDB_UPPER_OFF_BBOX_MIN));
1482 }
1483 PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_upper_get_bbox_max(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p) {
1484  return pnanovdb_read_coord(buf, pnanovdb_address_offset(p.address, PNANOVDB_UPPER_OFF_BBOX_MAX));
1485 }
1486 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_upper_get_flags(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p) {
1487  return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_UPPER_OFF_FLAGS));
1488 }
1489 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_upper_get_value_mask(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p, pnanovdb_uint32_t bit_index) {
1490  pnanovdb_uint32_t value = pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_UPPER_OFF_VALUE_MASK + 4u * (bit_index >> 5u)));
1491  return ((value >> (bit_index & 31u)) & 1) != 0u;
1492 }
1493 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_upper_get_child_mask(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p, pnanovdb_uint32_t bit_index) {
1494  pnanovdb_uint32_t value = pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_UPPER_OFF_CHILD_MASK + 4u * (bit_index >> 5u)));
1495  return ((value >> (bit_index & 31u)) & 1) != 0u;
1496 }
1497 
1498 PNANOVDB_FORCE_INLINE void pnanovdb_upper_set_bbox_min(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p, PNANOVDB_IN(pnanovdb_coord_t) bbox_min) {
1499  pnanovdb_write_coord(buf, pnanovdb_address_offset(p.address, PNANOVDB_UPPER_OFF_BBOX_MIN), bbox_min);
1500 }
1501 PNANOVDB_FORCE_INLINE void pnanovdb_upper_set_bbox_max(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p, PNANOVDB_IN(pnanovdb_coord_t) bbox_max) {
1502  pnanovdb_write_coord(buf, pnanovdb_address_offset(p.address, PNANOVDB_UPPER_OFF_BBOX_MAX), bbox_max);
1503 }
1504 PNANOVDB_FORCE_INLINE void pnanovdb_upper_set_child_mask(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p, pnanovdb_uint32_t bit_index, pnanovdb_bool_t value) {
1505  pnanovdb_address_t addr = pnanovdb_address_offset(p.address, PNANOVDB_UPPER_OFF_CHILD_MASK + 4u * (bit_index >> 5u));
1506  pnanovdb_uint32_t valueMask = pnanovdb_read_uint32(buf, addr);
1507  if (!value) { valueMask &= ~(1u << (bit_index & 31u)); }
1508  if (value) valueMask |= (1u << (bit_index & 31u));
1509  pnanovdb_write_uint32(buf, addr, valueMask);
1510 }
1511 
1513 {
1514  pnanovdb_coord_t bbox_min;
1515  pnanovdb_coord_t bbox_max;
1516  pnanovdb_uint64_t flags;
1517  pnanovdb_uint32_t value_mask[128];
1518  pnanovdb_uint32_t child_mask[128];
1519  // min, max
1520  // alignas(32) pnanovdb_uint32_t table[];
1521 };
1522 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_lower_t)
1523 struct pnanovdb_lower_handle_t { pnanovdb_address_t address; };
1524 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_lower_handle_t)
1525 
1526 #define PNANOVDB_LOWER_TABLE_COUNT 4096
1527 #define PNANOVDB_LOWER_BASE_SIZE 1056
1528 
1529 #define PNANOVDB_LOWER_OFF_BBOX_MIN 0
1530 #define PNANOVDB_LOWER_OFF_BBOX_MAX 12
1531 #define PNANOVDB_LOWER_OFF_FLAGS 24
1532 #define PNANOVDB_LOWER_OFF_VALUE_MASK 32
1533 #define PNANOVDB_LOWER_OFF_CHILD_MASK 544
1534 
1535 PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_lower_get_bbox_min(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p) {
1536  return pnanovdb_read_coord(buf, pnanovdb_address_offset(p.address, PNANOVDB_LOWER_OFF_BBOX_MIN));
1537 }
1538 PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_lower_get_bbox_max(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p) {
1539  return pnanovdb_read_coord(buf, pnanovdb_address_offset(p.address, PNANOVDB_LOWER_OFF_BBOX_MAX));
1540 }
1541 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_lower_get_flags(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p) {
1542  return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_LOWER_OFF_FLAGS));
1543 }
1544 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_lower_get_value_mask(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p, pnanovdb_uint32_t bit_index) {
1545  pnanovdb_uint32_t value = pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_LOWER_OFF_VALUE_MASK + 4u * (bit_index >> 5u)));
1546  return ((value >> (bit_index & 31u)) & 1) != 0u;
1547 }
1548 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_lower_get_child_mask(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p, pnanovdb_uint32_t bit_index) {
1549  pnanovdb_uint32_t value = pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_LOWER_OFF_CHILD_MASK + 4u * (bit_index >> 5u)));
1550  return ((value >> (bit_index & 31u)) & 1) != 0u;
1551 }
1552 
1553 PNANOVDB_FORCE_INLINE void pnanovdb_lower_set_bbox_min(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p, PNANOVDB_IN(pnanovdb_coord_t) bbox_min) {
1554  pnanovdb_write_coord(buf, pnanovdb_address_offset(p.address, PNANOVDB_LOWER_OFF_BBOX_MIN), bbox_min);
1555 }
1556 PNANOVDB_FORCE_INLINE void pnanovdb_lower_set_bbox_max(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p, PNANOVDB_IN(pnanovdb_coord_t) bbox_max) {
1557  pnanovdb_write_coord(buf, pnanovdb_address_offset(p.address, PNANOVDB_LOWER_OFF_BBOX_MAX), bbox_max);
1558 }
1559 PNANOVDB_FORCE_INLINE void pnanovdb_lower_set_child_mask(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p, pnanovdb_uint32_t bit_index, pnanovdb_bool_t value) {
1560  pnanovdb_address_t addr = pnanovdb_address_offset(p.address, PNANOVDB_LOWER_OFF_CHILD_MASK + 4u * (bit_index >> 5u));
1561  pnanovdb_uint32_t valueMask = pnanovdb_read_uint32(buf, addr);
1562  if (!value) { valueMask &= ~(1u << (bit_index & 31u)); }
1563  if (value) valueMask |= (1u << (bit_index & 31u));
1564  pnanovdb_write_uint32(buf, addr, valueMask);
1565 }
1566 
1568 {
1569  pnanovdb_coord_t bbox_min;
1570  pnanovdb_uint32_t bbox_dif_and_flags;
1571  pnanovdb_uint32_t value_mask[16];
1572  // min, max
1573  // alignas(32) pnanovdb_uint32_t values[];
1574 };
1575 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_leaf_t)
1576 struct pnanovdb_leaf_handle_t { pnanovdb_address_t address; };
1577 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_leaf_handle_t)
1578 
1579 #define PNANOVDB_LEAF_TABLE_COUNT 512
1580 #define PNANOVDB_LEAF_BASE_SIZE 80
1581 
1582 #define PNANOVDB_LEAF_OFF_BBOX_MIN 0
1583 #define PNANOVDB_LEAF_OFF_BBOX_DIF_AND_FLAGS 12
1584 #define PNANOVDB_LEAF_OFF_VALUE_MASK 16
1585 
1586 #define PNANOVDB_LEAF_TABLE_NEG_OFF_BBOX_DIF_AND_FLAGS 84
1587 #define PNANOVDB_LEAF_TABLE_NEG_OFF_MINIMUM 16
1588 #define PNANOVDB_LEAF_TABLE_NEG_OFF_QUANTUM 12
1589 
1590 PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_leaf_get_bbox_min(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t p) {
1591  return pnanovdb_read_coord(buf, pnanovdb_address_offset(p.address, PNANOVDB_LEAF_OFF_BBOX_MIN));
1592 }
1593 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_leaf_get_bbox_dif_and_flags(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t p) {
1594  return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_LEAF_OFF_BBOX_DIF_AND_FLAGS));
1595 }
1596 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_leaf_get_value_mask(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t p, pnanovdb_uint32_t bit_index) {
1597  pnanovdb_uint32_t value = pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_LEAF_OFF_VALUE_MASK + 4u * (bit_index >> 5u)));
1598  return ((value >> (bit_index & 31u)) & 1) != 0u;
1599 }
1600 
1601 PNANOVDB_FORCE_INLINE void pnanovdb_leaf_set_bbox_min(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t p, PNANOVDB_IN(pnanovdb_coord_t) bbox_min) {
1602  pnanovdb_write_coord(buf, pnanovdb_address_offset(p.address, PNANOVDB_LEAF_OFF_BBOX_MIN), bbox_min);
1603 }
1604 PNANOVDB_FORCE_INLINE void pnanovdb_leaf_set_bbox_dif_and_flags(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t p, pnanovdb_uint32_t bbox_dif_and_flags) {
1605  pnanovdb_write_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_LEAF_OFF_BBOX_DIF_AND_FLAGS), bbox_dif_and_flags);
1606 }
1607 
1609 {
1610  pnanovdb_uint32_t root_off_background;
1611  pnanovdb_uint32_t root_off_min;
1612  pnanovdb_uint32_t root_off_max;
1613  pnanovdb_uint32_t root_off_ave;
1614  pnanovdb_uint32_t root_off_stddev;
1615  pnanovdb_uint32_t root_size;
1616  pnanovdb_uint32_t value_stride_bits;
1617  pnanovdb_uint32_t table_stride;
1618  pnanovdb_uint32_t root_tile_off_value;
1619  pnanovdb_uint32_t root_tile_size;
1620  pnanovdb_uint32_t upper_off_min;
1621  pnanovdb_uint32_t upper_off_max;
1622  pnanovdb_uint32_t upper_off_ave;
1623  pnanovdb_uint32_t upper_off_stddev;
1624  pnanovdb_uint32_t upper_off_table;
1625  pnanovdb_uint32_t upper_size;
1626  pnanovdb_uint32_t lower_off_min;
1627  pnanovdb_uint32_t lower_off_max;
1628  pnanovdb_uint32_t lower_off_ave;
1629  pnanovdb_uint32_t lower_off_stddev;
1630  pnanovdb_uint32_t lower_off_table;
1631  pnanovdb_uint32_t lower_size;
1632  pnanovdb_uint32_t leaf_off_min;
1633  pnanovdb_uint32_t leaf_off_max;
1634  pnanovdb_uint32_t leaf_off_ave;
1635  pnanovdb_uint32_t leaf_off_stddev;
1636  pnanovdb_uint32_t leaf_off_table;
1637  pnanovdb_uint32_t leaf_size;
1638 };
1639 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_grid_type_constants_t)
1640 
1641 // The following table with offsets will nedd to be updates as new GridTypes are added in NanoVDB.h
1643 {
1644 {28, 28, 28, 28, 28, 32, 0, 8, 20, 32, 8224, 8224, 8224, 8224, 8224, 270368, 1056, 1056, 1056, 1056, 1056, 33824, 80, 80, 80, 80, 96, 96},
1645 {28, 32, 36, 40, 44, 64, 32, 8, 20, 32, 8224, 8228, 8232, 8236, 8256, 270400, 1056, 1060, 1064, 1068, 1088, 33856, 80, 84, 88, 92, 96, 2144},
1646 {32, 40, 48, 56, 64, 96, 64, 8, 24, 32, 8224, 8232, 8240, 8248, 8256, 270400, 1056, 1064, 1072, 1080, 1088, 33856, 80, 88, 96, 104, 128, 4224},
1647 {28, 30, 32, 36, 40, 64, 16, 8, 20, 32, 8224, 8226, 8228, 8232, 8256, 270400, 1056, 1058, 1060, 1064, 1088, 33856, 80, 82, 84, 88, 96, 1120},
1648 {28, 32, 36, 40, 44, 64, 32, 8, 20, 32, 8224, 8228, 8232, 8236, 8256, 270400, 1056, 1060, 1064, 1068, 1088, 33856, 80, 84, 88, 92, 96, 2144},
1649 {32, 40, 48, 56, 64, 96, 64, 8, 24, 32, 8224, 8232, 8240, 8248, 8256, 270400, 1056, 1064, 1072, 1080, 1088, 33856, 80, 88, 96, 104, 128, 4224},
1650 {28, 40, 52, 64, 68, 96, 96, 16, 20, 32, 8224, 8236, 8248, 8252, 8256, 532544, 1056, 1068, 1080, 1084, 1088, 66624, 80, 92, 104, 108, 128, 6272},
1651 {32, 56, 80, 104, 112, 128, 192, 24, 24, 64, 8224, 8248, 8272, 8280, 8288, 794720, 1056, 1080, 1104, 1112, 1120, 99424, 80, 104, 128, 136, 160, 12448},
1652 {28, 29, 30, 31, 32, 64, 0, 8, 20, 32, 8224, 8225, 8226, 8227, 8256, 270400, 1056, 1057, 1058, 1059, 1088, 33856, 80, 80, 80, 80, 96, 96},
1653 {28, 30, 32, 36, 40, 64, 16, 8, 20, 32, 8224, 8226, 8228, 8232, 8256, 270400, 1056, 1058, 1060, 1064, 1088, 33856, 80, 82, 84, 88, 96, 1120},
1654 {28, 32, 36, 40, 44, 64, 32, 8, 20, 32, 8224, 8228, 8232, 8236, 8256, 270400, 1056, 1060, 1064, 1068, 1088, 33856, 80, 84, 88, 92, 96, 2144},
1655 {28, 29, 30, 31, 32, 64, 1, 8, 20, 32, 8224, 8225, 8226, 8227, 8256, 270400, 1056, 1057, 1058, 1059, 1088, 33856, 80, 80, 80, 80, 96, 160},
1656 {28, 32, 36, 40, 44, 64, 32, 8, 20, 32, 8224, 8228, 8232, 8236, 8256, 270400, 1056, 1060, 1064, 1068, 1088, 33856, 80, 84, 88, 92, 96, 2144},
1657 {28, 32, 36, 40, 44, 64, 0, 8, 20, 32, 8224, 8228, 8232, 8236, 8256, 270400, 1056, 1060, 1064, 1068, 1088, 33856, 88, 90, 92, 94, 96, 352},
1658 {28, 32, 36, 40, 44, 64, 0, 8, 20, 32, 8224, 8228, 8232, 8236, 8256, 270400, 1056, 1060, 1064, 1068, 1088, 33856, 88, 90, 92, 94, 96, 608},
1659 {28, 32, 36, 40, 44, 64, 0, 8, 20, 32, 8224, 8228, 8232, 8236, 8256, 270400, 1056, 1060, 1064, 1068, 1088, 33856, 88, 90, 92, 94, 96, 1120},
1660 {28, 32, 36, 40, 44, 64, 0, 8, 20, 32, 8224, 8228, 8232, 8236, 8256, 270400, 1056, 1060, 1064, 1068, 1088, 33856, 88, 90, 92, 94, 96, 96},
1661 {28, 44, 60, 76, 80, 96, 128, 16, 20, 64, 8224, 8240, 8256, 8260, 8288, 532576, 1056, 1072, 1088, 1092, 1120, 66656, 80, 96, 112, 116, 128, 8320},
1662 {32, 64, 96, 128, 136, 160, 256, 32, 24, 64, 8224, 8256, 8288, 8296, 8320, 1056896, 1056, 1088, 1120, 1128, 1152, 132224, 80, 112, 144, 152, 160, 16544},
1663 {32, 40, 48, 56, 64, 96, 0, 8, 24, 32, 8224, 8232, 8240, 8248, 8256, 270400, 1056, 1064, 1072, 1080, 1088, 33856, 80, 80, 80, 80, 80, 96},
1664 {32, 40, 48, 56, 64, 96, 0, 8, 24, 32, 8224, 8232, 8240, 8248, 8256, 270400, 1056, 1064, 1072, 1080, 1088, 33856, 80, 80, 80, 80, 80, 96},
1665 {32, 40, 48, 56, 64, 96, 0, 8, 24, 32, 8224, 8232, 8240, 8248, 8256, 270400, 1056, 1064, 1072, 1080, 1088, 33856, 80, 80, 80, 80, 80, 160},
1666 {32, 40, 48, 56, 64, 96, 0, 8, 24, 32, 8224, 8232, 8240, 8248, 8256, 270400, 1056, 1064, 1072, 1080, 1088, 33856, 80, 80, 80, 80, 80, 160},
1667 {32, 40, 48, 56, 64, 96, 16, 8, 24, 32, 8224, 8232, 8240, 8248, 8256, 270400, 1056, 1064, 1072, 1080, 1088, 33856, 80, 88, 96, 96, 96, 1120},
1668 {28, 31, 34, 40, 44, 64, 24, 8, 20, 32, 8224, 8227, 8232, 8236, 8256, 270400, 1056, 1059, 1064, 1068, 1088, 33856, 80, 83, 88, 92, 96, 1632},
1669 {28, 34, 40, 48, 52, 64, 48, 8, 20, 32, 8224, 8230, 8236, 8240, 8256, 270400, 1056, 1062, 1068, 1072, 1088, 33856, 80, 86, 92, 96, 128, 3200},
1670 {28, 29, 30, 32, 36, 64, 8, 8, 20, 32, 8224, 8225, 8228, 8232, 8256, 270400, 1056, 1057, 1060, 1064, 1088, 33856, 80, 81, 84, 88, 96, 608},
1671 };
1672 
1673 // ------------------------------------------------ Basic Lookup -----------------------------------------------------------
1674 
1675 PNANOVDB_FORCE_INLINE pnanovdb_gridblindmetadata_handle_t pnanovdb_grid_get_gridblindmetadata(pnanovdb_buf_t buf, pnanovdb_grid_handle_t grid, pnanovdb_uint32_t index)
1676 {
1678  pnanovdb_uint64_t byte_offset = pnanovdb_grid_get_blind_metadata_offset(buf, grid);
1679  meta.address = pnanovdb_address_offset64(meta.address, byte_offset);
1680  meta.address = pnanovdb_address_offset_product(meta.address, PNANOVDB_GRIDBLINDMETADATA_SIZE, index);
1681  return meta;
1682 }
1683 
1684 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_grid_get_gridblindmetadata_value_address(pnanovdb_buf_t buf, pnanovdb_grid_handle_t grid, pnanovdb_uint32_t index)
1685 {
1687  pnanovdb_int64_t byte_offset = pnanovdb_gridblindmetadata_get_data_offset(buf, meta);
1688  pnanovdb_address_t address = pnanovdb_address_offset64(meta.address, pnanovdb_int64_as_uint64(byte_offset));
1689  return address;
1690 }
1691 
1692 PNANOVDB_FORCE_INLINE pnanovdb_tree_handle_t pnanovdb_grid_get_tree(pnanovdb_buf_t buf, pnanovdb_grid_handle_t grid)
1693 {
1694  pnanovdb_tree_handle_t tree = { grid.address };
1695  tree.address = pnanovdb_address_offset(tree.address, PNANOVDB_GRID_SIZE);
1696  return tree;
1697 }
1698 
1699 PNANOVDB_FORCE_INLINE pnanovdb_root_handle_t pnanovdb_tree_get_root(pnanovdb_buf_t buf, pnanovdb_tree_handle_t tree)
1700 {
1701  pnanovdb_root_handle_t root = { tree.address };
1702  pnanovdb_uint64_t byte_offset = pnanovdb_tree_get_node_offset_root(buf, tree);
1703  root.address = pnanovdb_address_offset64(root.address, byte_offset);
1704  return root;
1705 }
1706 
1707 PNANOVDB_FORCE_INLINE pnanovdb_root_tile_handle_t pnanovdb_root_get_tile(pnanovdb_grid_type_t grid_type, pnanovdb_root_handle_t root, pnanovdb_uint32_t n)
1708 {
1709  pnanovdb_root_tile_handle_t tile = { root.address };
1710  tile.address = pnanovdb_address_offset(tile.address, PNANOVDB_GRID_TYPE_GET(grid_type, root_size));
1711  tile.address = pnanovdb_address_offset_product(tile.address, PNANOVDB_GRID_TYPE_GET(grid_type, root_tile_size), n);
1712  return tile;
1713 }
1714 
1715 PNANOVDB_FORCE_INLINE pnanovdb_root_tile_handle_t pnanovdb_root_get_tile_zero(pnanovdb_grid_type_t grid_type, pnanovdb_root_handle_t root)
1716 {
1717  pnanovdb_root_tile_handle_t tile = { root.address };
1718  tile.address = pnanovdb_address_offset(tile.address, PNANOVDB_GRID_TYPE_GET(grid_type, root_size));
1719  return tile;
1720 }
1721 
1722 PNANOVDB_FORCE_INLINE pnanovdb_upper_handle_t pnanovdb_root_get_child(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root, pnanovdb_root_tile_handle_t tile)
1723 {
1724  pnanovdb_upper_handle_t upper = { root.address };
1725  upper.address = pnanovdb_address_offset64(upper.address, pnanovdb_int64_as_uint64(pnanovdb_root_tile_get_child(buf, tile)));
1726  return upper;
1727 }
1728 
1729 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_coord_to_key(PNANOVDB_IN(pnanovdb_coord_t) ijk)
1730 {
1731 #if defined(PNANOVDB_NATIVE_64)
1732  pnanovdb_uint64_t iu = pnanovdb_int32_as_uint32(PNANOVDB_DEREF(ijk).x) >> 12u;
1733  pnanovdb_uint64_t ju = pnanovdb_int32_as_uint32(PNANOVDB_DEREF(ijk).y) >> 12u;
1734  pnanovdb_uint64_t ku = pnanovdb_int32_as_uint32(PNANOVDB_DEREF(ijk).z) >> 12u;
1735  return (ku) | (ju << 21u) | (iu << 42u);
1736 #else
1737  pnanovdb_uint32_t iu = pnanovdb_int32_as_uint32(PNANOVDB_DEREF(ijk).x) >> 12u;
1738  pnanovdb_uint32_t ju = pnanovdb_int32_as_uint32(PNANOVDB_DEREF(ijk).y) >> 12u;
1739  pnanovdb_uint32_t ku = pnanovdb_int32_as_uint32(PNANOVDB_DEREF(ijk).z) >> 12u;
1740  pnanovdb_uint32_t key_x = ku | (ju << 21);
1741  pnanovdb_uint32_t key_y = (iu << 10) | (ju >> 11);
1742  return pnanovdb_uint32_as_uint64(key_x, key_y);
1743 #endif
1744 }
1745 
1746 PNANOVDB_FORCE_INLINE pnanovdb_root_tile_handle_t pnanovdb_root_find_tile(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root, PNANOVDB_IN(pnanovdb_coord_t) ijk)
1747 {
1748  pnanovdb_uint32_t tile_count = pnanovdb_uint32_as_int32(pnanovdb_root_get_tile_count(buf, root));
1750  pnanovdb_uint64_t key = pnanovdb_coord_to_key(ijk);
1751  for (pnanovdb_uint32_t i = 0u; i < tile_count; i++)
1752  {
1753  if (pnanovdb_uint64_is_equal(key, pnanovdb_root_tile_get_key(buf, tile)))
1754  {
1755  return tile;
1756  }
1757  tile.address = pnanovdb_address_offset(tile.address, PNANOVDB_GRID_TYPE_GET(grid_type, root_tile_size));
1758  }
1759  pnanovdb_root_tile_handle_t null_handle = { pnanovdb_address_null() };
1760  return null_handle;
1761 }
1762 
1763 // ----------------------------- Leaf Node ---------------------------------------
1764 
1765 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_leaf_coord_to_offset(PNANOVDB_IN(pnanovdb_coord_t) ijk)
1766 {
1767  return (((PNANOVDB_DEREF(ijk).x & 7) >> 0) << (2 * 3)) +
1768  (((PNANOVDB_DEREF(ijk).y & 7) >> 0) << (3)) +
1769  ((PNANOVDB_DEREF(ijk).z & 7) >> 0);
1770 }
1771 
1772 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_leaf_get_min_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_leaf_handle_t node)
1773 {
1774  pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, leaf_off_min);
1775  return pnanovdb_address_offset(node.address, byte_offset);
1776 }
1777 
1778 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_leaf_get_max_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_leaf_handle_t node)
1779 {
1780  pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, leaf_off_max);
1781  return pnanovdb_address_offset(node.address, byte_offset);
1782 }
1783 
1784 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_leaf_get_ave_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_leaf_handle_t node)
1785 {
1786  pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, leaf_off_ave);
1787  return pnanovdb_address_offset(node.address, byte_offset);
1788 }
1789 
1790 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_leaf_get_stddev_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_leaf_handle_t node)
1791 {
1792  pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, leaf_off_stddev);
1793  return pnanovdb_address_offset(node.address, byte_offset);
1794 }
1795 
1796 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_leaf_get_table_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_leaf_handle_t node, pnanovdb_uint32_t n)
1797 {
1798  pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, leaf_off_table) + ((PNANOVDB_GRID_TYPE_GET(grid_type, value_stride_bits) * n) >> 3u);
1799  return pnanovdb_address_offset(node.address, byte_offset);
1800 }
1801 
1802 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_leaf_get_value_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, PNANOVDB_IN(pnanovdb_coord_t) ijk)
1803 {
1804  pnanovdb_uint32_t n = pnanovdb_leaf_coord_to_offset(ijk);
1805  return pnanovdb_leaf_get_table_address(grid_type, buf, leaf, n);
1806 }
1807 
1808 // ----------------------------- Leaf FP Types Specialization ---------------------------------------
1809 
1810 PNANOVDB_FORCE_INLINE float pnanovdb_leaf_fp_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk, pnanovdb_uint32_t value_log_bits)
1811 {
1812  // value_log_bits // 2 3 4
1813  pnanovdb_uint32_t value_bits = 1u << value_log_bits; // 4 8 16
1814  pnanovdb_uint32_t value_mask = (1u << value_bits) - 1u; // 0xF 0xFF 0xFFFF
1815  pnanovdb_uint32_t values_per_word_bits = 5u - value_log_bits; // 3 2 1
1816  pnanovdb_uint32_t values_per_word_mask = (1u << values_per_word_bits) - 1u; // 7 3 1
1817 
1818  pnanovdb_uint32_t n = pnanovdb_leaf_coord_to_offset(ijk);
1819  float minimum = pnanovdb_read_float(buf, pnanovdb_address_offset_neg(address, PNANOVDB_LEAF_TABLE_NEG_OFF_MINIMUM));
1820  float quantum = pnanovdb_read_float(buf, pnanovdb_address_offset_neg(address, PNANOVDB_LEAF_TABLE_NEG_OFF_QUANTUM));
1821  pnanovdb_uint32_t raw = pnanovdb_read_uint32(buf, pnanovdb_address_offset(address, ((n >> values_per_word_bits) << 2u)));
1822  pnanovdb_uint32_t value_compressed = (raw >> ((n & values_per_word_mask) << value_log_bits)) & value_mask;
1823  return pnanovdb_uint32_to_float(value_compressed) * quantum + minimum;
1824 }
1825 
1826 PNANOVDB_FORCE_INLINE float pnanovdb_leaf_fp4_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk)
1827 {
1828  return pnanovdb_leaf_fp_read_float(buf, address, ijk, 2u);
1829 }
1830 
1831 PNANOVDB_FORCE_INLINE float pnanovdb_leaf_fp8_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk)
1832 {
1833  return pnanovdb_leaf_fp_read_float(buf, address, ijk, 3u);
1834 }
1835 
1836 PNANOVDB_FORCE_INLINE float pnanovdb_leaf_fp16_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk)
1837 {
1838  return pnanovdb_leaf_fp_read_float(buf, address, ijk, 4u);
1839 }
1840 
1841 PNANOVDB_FORCE_INLINE float pnanovdb_leaf_fpn_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk)
1842 {
1843  pnanovdb_uint32_t bbox_dif_and_flags = pnanovdb_read_uint32(buf, pnanovdb_address_offset_neg(address, PNANOVDB_LEAF_TABLE_NEG_OFF_BBOX_DIF_AND_FLAGS));
1844  pnanovdb_uint32_t flags = bbox_dif_and_flags >> 24u;
1845  pnanovdb_uint32_t value_log_bits = flags >> 5; // b = 0, 1, 2, 3, 4 corresponding to 1, 2, 4, 8, 16 bits
1846  return pnanovdb_leaf_fp_read_float(buf, address, ijk, value_log_bits);
1847 }
1848 
1849 // ----------------------------- Leaf Index Specialization ---------------------------------------
1850 
1851 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_leaf_index_has_stats(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf)
1852 {
1853  return (pnanovdb_leaf_get_bbox_dif_and_flags(buf, leaf) & (1u << 28u)) != 0u;
1854 }
1855 
1856 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_index_get_min_index(pnanovdb_buf_t buf, pnanovdb_address_t min_address)
1857 {
1858  return pnanovdb_uint64_offset(pnanovdb_read_uint64(buf, min_address), 512u);
1859 }
1860 
1861 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_index_get_max_index(pnanovdb_buf_t buf, pnanovdb_address_t max_address)
1862 {
1863  return pnanovdb_uint64_offset(pnanovdb_read_uint64(buf, max_address), 513u);
1864 }
1865 
1866 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_index_get_ave_index(pnanovdb_buf_t buf, pnanovdb_address_t ave_address)
1867 {
1868  return pnanovdb_uint64_offset(pnanovdb_read_uint64(buf, ave_address), 514u);
1869 }
1870 
1871 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_index_get_dev_index(pnanovdb_buf_t buf, pnanovdb_address_t dev_address)
1872 {
1873  return pnanovdb_uint64_offset(pnanovdb_read_uint64(buf, dev_address), 515u);
1874 }
1875 
1876 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_index_get_value_index(pnanovdb_buf_t buf, pnanovdb_address_t value_address, PNANOVDB_IN(pnanovdb_coord_t) ijk)
1877 {
1878  pnanovdb_uint32_t n = pnanovdb_leaf_coord_to_offset(ijk);
1879  pnanovdb_uint64_t offset = pnanovdb_read_uint64(buf, value_address);
1880  return pnanovdb_uint64_offset(offset, n);
1881 }
1882 
1883 // ----------------------------- Leaf IndexMask Specialization ---------------------------------------
1884 
1885 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_leaf_indexmask_has_stats(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf)
1886 {
1887  return pnanovdb_leaf_index_has_stats(buf, leaf);
1888 }
1889 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_indexmask_get_min_index(pnanovdb_buf_t buf, pnanovdb_address_t min_address)
1890 {
1891  return pnanovdb_leaf_index_get_min_index(buf, min_address);
1892 }
1893 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_indexmask_get_max_index(pnanovdb_buf_t buf, pnanovdb_address_t max_address)
1894 {
1895  return pnanovdb_leaf_index_get_max_index(buf, max_address);
1896 }
1897 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_indexmask_get_ave_index(pnanovdb_buf_t buf, pnanovdb_address_t ave_address)
1898 {
1899  return pnanovdb_leaf_index_get_ave_index(buf, ave_address);
1900 }
1901 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_indexmask_get_dev_index(pnanovdb_buf_t buf, pnanovdb_address_t dev_address)
1902 {
1903  return pnanovdb_leaf_index_get_dev_index(buf, dev_address);
1904 }
1905 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_indexmask_get_value_index(pnanovdb_buf_t buf, pnanovdb_address_t value_address, PNANOVDB_IN(pnanovdb_coord_t) ijk)
1906 {
1907  return pnanovdb_leaf_index_get_value_index(buf, value_address, ijk);
1908 }
1909 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_leaf_indexmask_get_mask_bit(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, pnanovdb_uint32_t n)
1910 {
1911  pnanovdb_uint32_t word_idx = n >> 5;
1912  pnanovdb_uint32_t bit_idx = n & 31;
1913  pnanovdb_uint32_t val_mask =
1914  pnanovdb_read_uint32(buf, pnanovdb_address_offset(leaf.address, 96u + 4u * word_idx));
1915  return (val_mask & (1u << bit_idx)) != 0u;
1916 }
1917 PNANOVDB_FORCE_INLINE void pnanovdb_leaf_indexmask_set_mask_bit(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, pnanovdb_uint32_t n, pnanovdb_bool_t v)
1918 {
1919  pnanovdb_uint32_t word_idx = n >> 5;
1920  pnanovdb_uint32_t bit_idx = n & 31;
1921  pnanovdb_uint32_t val_mask =
1922  pnanovdb_read_uint32(buf, pnanovdb_address_offset(leaf.address, 96u + 4u * word_idx));
1923  if (v)
1924  {
1925  val_mask = val_mask | (1u << bit_idx);
1926  }
1927  else
1928  {
1929  val_mask = val_mask & ~(1u << bit_idx);
1930  }
1931  pnanovdb_write_uint32(buf, pnanovdb_address_offset(leaf.address, 96u + 4u * word_idx), val_mask);
1932 }
1933 
1934 // ----------------------------- Leaf OnIndex Specialization ---------------------------------------
1935 
1936 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_leaf_onindex_get_value_count(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf)
1937 {
1938  pnanovdb_uint64_t val_mask = pnanovdb_read_uint64(buf, pnanovdb_address_offset(leaf.address, PNANOVDB_LEAF_OFF_VALUE_MASK + 8u * 7u));
1939  pnanovdb_uint64_t prefix_sum = pnanovdb_read_uint64(
1940  buf, pnanovdb_address_offset(leaf.address, PNANOVDB_GRID_TYPE_GET(PNANOVDB_GRID_TYPE_ONINDEX, leaf_off_table) + 8u));
1941  return pnanovdb_uint64_countbits(val_mask) + (pnanovdb_uint64_to_uint32_lsr(prefix_sum, 54u) & 511u);
1942 }
1943 
1944 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindex_get_last_offset(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf)
1945 {
1946  return pnanovdb_uint64_offset(
1947  pnanovdb_read_uint64(buf, pnanovdb_address_offset(leaf.address, PNANOVDB_GRID_TYPE_GET(PNANOVDB_GRID_TYPE_ONINDEX, leaf_off_table))),
1948  pnanovdb_leaf_onindex_get_value_count(buf, leaf) - 1u);
1949 }
1950 
1951 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_leaf_onindex_has_stats(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf)
1952 {
1953  return (pnanovdb_leaf_get_bbox_dif_and_flags(buf, leaf) & (1u << 28u)) != 0u;
1954 }
1955 
1956 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindex_get_min_index(pnanovdb_buf_t buf, pnanovdb_address_t min_address)
1957 {
1958  pnanovdb_leaf_handle_t leaf = { pnanovdb_address_offset_neg(min_address, PNANOVDB_GRID_TYPE_GET(PNANOVDB_GRID_TYPE_ONINDEX, leaf_off_table)) };
1959  pnanovdb_uint64_t idx = pnanovdb_uint32_as_uint64_low(0u);
1960  if (pnanovdb_leaf_onindex_has_stats(buf, leaf))
1961  {
1963  }
1964  return idx;
1965 }
1966 
1967 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindex_get_max_index(pnanovdb_buf_t buf, pnanovdb_address_t max_address)
1968 {
1969  pnanovdb_leaf_handle_t leaf = { pnanovdb_address_offset_neg(max_address, PNANOVDB_GRID_TYPE_GET(PNANOVDB_GRID_TYPE_ONINDEX, leaf_off_table)) };
1970  pnanovdb_uint64_t idx = pnanovdb_uint32_as_uint64_low(0u);
1971  if (pnanovdb_leaf_onindex_has_stats(buf, leaf))
1972  {
1974  }
1975  return idx;
1976 }
1977 
1978 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindex_get_ave_index(pnanovdb_buf_t buf, pnanovdb_address_t ave_address)
1979 {
1980  pnanovdb_leaf_handle_t leaf = { pnanovdb_address_offset_neg(ave_address, PNANOVDB_GRID_TYPE_GET(PNANOVDB_GRID_TYPE_ONINDEX, leaf_off_table)) };
1981  pnanovdb_uint64_t idx = pnanovdb_uint32_as_uint64_low(0u);
1982  if (pnanovdb_leaf_onindex_has_stats(buf, leaf))
1983  {
1985  }
1986  return idx;
1987 }
1988 
1989 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindex_get_dev_index(pnanovdb_buf_t buf, pnanovdb_address_t dev_address)
1990 {
1991  pnanovdb_leaf_handle_t leaf = { pnanovdb_address_offset_neg(dev_address, PNANOVDB_GRID_TYPE_GET(PNANOVDB_GRID_TYPE_ONINDEX, leaf_off_table)) };
1992  pnanovdb_uint64_t idx = pnanovdb_uint32_as_uint64_low(0u);
1993  if (pnanovdb_leaf_onindex_has_stats(buf, leaf))
1994  {
1996  }
1997  return idx;
1998 }
1999 
2000 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindex_get_value_index(pnanovdb_buf_t buf, pnanovdb_address_t value_address, PNANOVDB_IN(pnanovdb_coord_t) ijk)
2001 {
2002  pnanovdb_uint32_t n = pnanovdb_leaf_coord_to_offset(ijk);
2003  pnanovdb_leaf_handle_t leaf = { pnanovdb_address_offset_neg(value_address, PNANOVDB_GRID_TYPE_GET(PNANOVDB_GRID_TYPE_ONINDEX, leaf_off_table)) };
2004 
2005  pnanovdb_uint32_t word_idx = n >> 6u;
2006  pnanovdb_uint32_t bit_idx = n & 63u;
2007  pnanovdb_uint64_t val_mask = pnanovdb_read_uint64(buf, pnanovdb_address_offset(leaf.address, PNANOVDB_LEAF_OFF_VALUE_MASK + 8u * word_idx));
2008  pnanovdb_uint64_t mask = pnanovdb_uint64_bit_mask(bit_idx);
2009  pnanovdb_uint64_t value_index = pnanovdb_uint32_as_uint64_low(0u);
2010  if (pnanovdb_uint64_any_bit(pnanovdb_uint64_and(val_mask, mask)))
2011  {
2012  pnanovdb_uint32_t sum = 0u;
2014  if (word_idx > 0u)
2015  {
2016  pnanovdb_uint64_t prefix_sum = pnanovdb_read_uint64(buf, pnanovdb_address_offset(value_address, 8u));
2017  sum += pnanovdb_uint64_to_uint32_lsr(prefix_sum, 9u * (word_idx - 1u)) & 511u;
2018  }
2019  pnanovdb_uint64_t offset = pnanovdb_read_uint64(buf, value_address);
2020  value_index = pnanovdb_uint64_offset(offset, sum);
2021  }
2022  return value_index;
2023 }
2024 
2025 // ----------------------------- Leaf OnIndexMask Specialization ---------------------------------------
2026 
2027 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_leaf_onindexmask_get_value_count(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf)
2028 {
2029  return pnanovdb_leaf_onindex_get_value_count(buf, leaf);
2030 }
2031 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindexmask_get_last_offset(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf)
2032 {
2033  return pnanovdb_leaf_onindex_get_last_offset(buf, leaf);
2034 }
2035 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_leaf_onindexmask_has_stats(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf)
2036 {
2037  return pnanovdb_leaf_onindex_has_stats(buf, leaf);
2038 }
2039 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindexmask_get_min_index(pnanovdb_buf_t buf, pnanovdb_address_t min_address)
2040 {
2041  return pnanovdb_leaf_onindex_get_min_index(buf, min_address);
2042 }
2043 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindexmask_get_max_index(pnanovdb_buf_t buf, pnanovdb_address_t max_address)
2044 {
2045  return pnanovdb_leaf_onindex_get_max_index(buf, max_address);
2046 }
2047 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindexmask_get_ave_index(pnanovdb_buf_t buf, pnanovdb_address_t ave_address)
2048 {
2049  return pnanovdb_leaf_onindex_get_ave_index(buf, ave_address);
2050 }
2051 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindexmask_get_dev_index(pnanovdb_buf_t buf, pnanovdb_address_t dev_address)
2052 {
2053  return pnanovdb_leaf_onindex_get_dev_index(buf, dev_address);
2054 }
2055 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindexmask_get_value_index(pnanovdb_buf_t buf, pnanovdb_address_t value_address, PNANOVDB_IN(pnanovdb_coord_t) ijk)
2056 {
2057  return pnanovdb_leaf_onindex_get_value_index(buf, value_address, ijk);
2058 }
2059 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_leaf_onindexmask_get_mask_bit(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, pnanovdb_uint32_t n)
2060 {
2061  pnanovdb_uint32_t word_idx = n >> 5;
2062  pnanovdb_uint32_t bit_idx = n & 31;
2063  pnanovdb_uint32_t val_mask =
2064  pnanovdb_read_uint32(buf, pnanovdb_address_offset(leaf.address, 96u + 4u * word_idx));
2065  return (val_mask & (1u << bit_idx)) != 0u;
2066 }
2067 PNANOVDB_FORCE_INLINE void pnanovdb_leaf_onindexmask_set_mask_bit(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, pnanovdb_uint32_t n, pnanovdb_bool_t v)
2068 {
2069  pnanovdb_uint32_t word_idx = n >> 5;
2070  pnanovdb_uint32_t bit_idx = n & 31;
2071  pnanovdb_uint32_t val_mask =
2072  pnanovdb_read_uint32(buf, pnanovdb_address_offset(leaf.address, 96u + 4u * word_idx));
2073  if (v)
2074  {
2075  val_mask = val_mask | (1u << bit_idx);
2076  }
2077  else
2078  {
2079  val_mask = val_mask & ~(1u << bit_idx);
2080  }
2081  pnanovdb_write_uint32(buf, pnanovdb_address_offset(leaf.address, 96u + 4u * word_idx), val_mask);
2082 }
2083 
2084 // ----------------------------- Leaf PointIndex Specialization ---------------------------------------
2085 
2086 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_pointindex_get_offset(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf)
2087 {
2089 }
2090 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_pointindex_get_point_count(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf)
2091 {
2093 }
2094 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_pointindex_get_first(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, pnanovdb_uint32_t i)
2095 {
2097  (i == 0u ? 0u : pnanovdb_read_uint16(buf, pnanovdb_leaf_get_table_address(PNANOVDB_GRID_TYPE_POINTINDEX, buf, leaf, i - 1u))));
2098 }
2099 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_pointindex_get_last(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, pnanovdb_uint32_t i)
2100 {
2103 }
2104 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_pointindex_get_value(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, pnanovdb_uint32_t i)
2105 {
2106  return pnanovdb_uint32_as_uint64_low(pnanovdb_read_uint16(buf, pnanovdb_leaf_get_table_address(PNANOVDB_GRID_TYPE_POINTINDEX, buf, leaf, i)));
2107 }
2108 PNANOVDB_FORCE_INLINE void pnanovdb_leaf_pointindex_set_value_only(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, pnanovdb_uint32_t i, pnanovdb_uint32_t value)
2109 {
2110  pnanovdb_address_t addr = pnanovdb_leaf_get_table_address(PNANOVDB_GRID_TYPE_POINTINDEX, buf, leaf, i);
2111  pnanovdb_uint32_t raw32 = pnanovdb_read_uint32(buf, pnanovdb_address_mask_inv(addr, 3u));
2112  if ((i & 1) == 0u)
2113  {
2114  raw32 = (raw32 & 0xFFFF0000) | (value & 0x0000FFFF);
2115  }
2116  else
2117  {
2118  raw32 = (raw32 & 0x0000FFFF) | (value << 16u);
2119  }
2120  pnanovdb_write_uint32(buf, addr, raw32);
2121 }
2122 PNANOVDB_FORCE_INLINE void pnanovdb_leaf_pointindex_set_on(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, pnanovdb_uint32_t i)
2123 {
2124  pnanovdb_uint32_t word_idx = i >> 5;
2125  pnanovdb_uint32_t bit_idx = i & 31;
2126  pnanovdb_address_t addr = pnanovdb_address_offset(leaf.address, PNANOVDB_LEAF_OFF_VALUE_MASK + 4u * word_idx);
2127  pnanovdb_uint32_t val_mask = pnanovdb_read_uint32(buf, addr);
2128  val_mask = val_mask | (1u << bit_idx);
2129  pnanovdb_write_uint32(buf, addr, val_mask);
2130 }
2131 PNANOVDB_FORCE_INLINE void pnanovdb_leaf_pointindex_set_value(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, pnanovdb_uint32_t i, pnanovdb_uint32_t value)
2132 {
2133  pnanovdb_leaf_pointindex_set_on(buf, leaf, i);
2134  pnanovdb_leaf_pointindex_set_value_only(buf, leaf, i, value);
2135 }
2136 
2137 // ------------------------------------------------ Lower Node -----------------------------------------------------------
2138 
2139 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_lower_coord_to_offset(PNANOVDB_IN(pnanovdb_coord_t) ijk)
2140 {
2141  return (((PNANOVDB_DEREF(ijk).x & 127) >> 3) << (2 * 4)) +
2142  (((PNANOVDB_DEREF(ijk).y & 127) >> 3) << (4)) +
2143  ((PNANOVDB_DEREF(ijk).z & 127) >> 3);
2144 }
2145 
2146 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_lower_get_min_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t node)
2147 {
2148  pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, lower_off_min);
2149  return pnanovdb_address_offset(node.address, byte_offset);
2150 }
2151 
2152 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_lower_get_max_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t node)
2153 {
2154  pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, lower_off_max);
2155  return pnanovdb_address_offset(node.address, byte_offset);
2156 }
2157 
2158 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_lower_get_ave_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t node)
2159 {
2160  pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, lower_off_ave);
2161  return pnanovdb_address_offset(node.address, byte_offset);
2162 }
2163 
2164 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_lower_get_stddev_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t node)
2165 {
2166  pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, lower_off_stddev);
2167  return pnanovdb_address_offset(node.address, byte_offset);
2168 }
2169 
2170 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_lower_get_table_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t node, pnanovdb_uint32_t n)
2171 {
2172  pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, lower_off_table) + PNANOVDB_GRID_TYPE_GET(grid_type, table_stride) * n;
2173  return pnanovdb_address_offset(node.address, byte_offset);
2174 }
2175 
2176 PNANOVDB_FORCE_INLINE pnanovdb_int64_t pnanovdb_lower_get_table_child(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t node, pnanovdb_uint32_t n)
2177 {
2178  pnanovdb_address_t table_address = pnanovdb_lower_get_table_address(grid_type, buf, node, n);
2179  return pnanovdb_read_int64(buf, table_address);
2180 }
2181 
2182 PNANOVDB_FORCE_INLINE pnanovdb_leaf_handle_t pnanovdb_lower_get_child(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t lower, pnanovdb_uint32_t n)
2183 {
2184  pnanovdb_leaf_handle_t leaf = { lower.address };
2185  leaf.address = pnanovdb_address_offset64(leaf.address, pnanovdb_int64_as_uint64(pnanovdb_lower_get_table_child(grid_type, buf, lower, n)));
2186  return leaf;
2187 }
2188 
2189 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_lower_get_value_address_and_level(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t lower, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_uint32_t) level)
2190 {
2191  pnanovdb_uint32_t n = pnanovdb_lower_coord_to_offset(ijk);
2192  pnanovdb_address_t value_address;
2193  if (pnanovdb_lower_get_child_mask(buf, lower, n))
2194  {
2195  pnanovdb_leaf_handle_t child = pnanovdb_lower_get_child(grid_type, buf, lower, n);
2196  value_address = pnanovdb_leaf_get_value_address(grid_type, buf, child, ijk);
2197  PNANOVDB_DEREF(level) = 0u;
2198  }
2199  else
2200  {
2201  value_address = pnanovdb_lower_get_table_address(grid_type, buf, lower, n);
2202  PNANOVDB_DEREF(level) = 1u;
2203  }
2204  return value_address;
2205 }
2206 
2207 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_lower_get_value_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t lower, PNANOVDB_IN(pnanovdb_coord_t) ijk)
2208 {
2209  pnanovdb_uint32_t level;
2210  return pnanovdb_lower_get_value_address_and_level(grid_type, buf, lower, ijk, PNANOVDB_REF(level));
2211 }
2212 
2213 // ------------------------------------------------ Upper Node -----------------------------------------------------------
2214 
2215 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_upper_coord_to_offset(PNANOVDB_IN(pnanovdb_coord_t) ijk)
2216 {
2217  return (((PNANOVDB_DEREF(ijk).x & 4095) >> 7) << (2 * 5)) +
2218  (((PNANOVDB_DEREF(ijk).y & 4095) >> 7) << (5)) +
2219  ((PNANOVDB_DEREF(ijk).z & 4095) >> 7);
2220 }
2221 
2222 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_upper_get_min_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t node)
2223 {
2224  pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, upper_off_min);
2225  return pnanovdb_address_offset(node.address, byte_offset);
2226 }
2227 
2228 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_upper_get_max_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t node)
2229 {
2230  pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, upper_off_max);
2231  return pnanovdb_address_offset(node.address, byte_offset);
2232 }
2233 
2234 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_upper_get_ave_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t node)
2235 {
2236  pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, upper_off_ave);
2237  return pnanovdb_address_offset(node.address, byte_offset);
2238 }
2239 
2240 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_upper_get_stddev_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t node)
2241 {
2242  pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, upper_off_stddev);
2243  return pnanovdb_address_offset(node.address, byte_offset);
2244 }
2245 
2246 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_upper_get_table_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t node, pnanovdb_uint32_t n)
2247 {
2248  pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, upper_off_table) + PNANOVDB_GRID_TYPE_GET(grid_type, table_stride) * n;
2249  return pnanovdb_address_offset(node.address, byte_offset);
2250 }
2251 
2252 PNANOVDB_FORCE_INLINE pnanovdb_int64_t pnanovdb_upper_get_table_child(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t node, pnanovdb_uint32_t n)
2253 {
2254  pnanovdb_address_t bufAddress = pnanovdb_upper_get_table_address(grid_type, buf, node, n);
2255  return pnanovdb_read_int64(buf, bufAddress);
2256 }
2257 
2258 PNANOVDB_FORCE_INLINE pnanovdb_lower_handle_t pnanovdb_upper_get_child(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t upper, pnanovdb_uint32_t n)
2259 {
2260  pnanovdb_lower_handle_t lower = { upper.address };
2261  lower.address = pnanovdb_address_offset64(lower.address, pnanovdb_int64_as_uint64(pnanovdb_upper_get_table_child(grid_type, buf, upper, n)));
2262  return lower;
2263 }
2264 
2265 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_upper_get_value_address_and_level(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t upper, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_uint32_t) level)
2266 {
2267  pnanovdb_uint32_t n = pnanovdb_upper_coord_to_offset(ijk);
2268  pnanovdb_address_t value_address;
2269  if (pnanovdb_upper_get_child_mask(buf, upper, n))
2270  {
2271  pnanovdb_lower_handle_t child = pnanovdb_upper_get_child(grid_type, buf, upper, n);
2272  value_address = pnanovdb_lower_get_value_address_and_level(grid_type, buf, child, ijk, level);
2273  }
2274  else
2275  {
2276  value_address = pnanovdb_upper_get_table_address(grid_type, buf, upper, n);
2277  PNANOVDB_DEREF(level) = 2u;
2278  }
2279  return value_address;
2280 }
2281 
2282 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_upper_get_value_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t upper, PNANOVDB_IN(pnanovdb_coord_t) ijk)
2283 {
2284  pnanovdb_uint32_t level;
2285  return pnanovdb_upper_get_value_address_and_level(grid_type, buf, upper, ijk, PNANOVDB_REF(level));
2286 }
2287 
2288 PNANOVDB_FORCE_INLINE void pnanovdb_upper_set_table_child(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t node, pnanovdb_uint32_t n, pnanovdb_int64_t child)
2289 {
2290  pnanovdb_address_t bufAddress = pnanovdb_upper_get_table_address(grid_type, buf, node, n);
2291  pnanovdb_write_int64(buf, bufAddress, child);
2292 }
2293 
2294 // ------------------------------------------------ Root -----------------------------------------------------------
2295 
2296 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_root_get_min_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root)
2297 {
2298  pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, root_off_min);
2299  return pnanovdb_address_offset(root.address, byte_offset);
2300 }
2301 
2302 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_root_get_max_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root)
2303 {
2304  pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, root_off_max);
2305  return pnanovdb_address_offset(root.address, byte_offset);
2306 }
2307 
2308 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_root_get_ave_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root)
2309 {
2310  pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, root_off_ave);
2311  return pnanovdb_address_offset(root.address, byte_offset);
2312 }
2313 
2314 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_root_get_stddev_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root)
2315 {
2316  pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, root_off_stddev);
2317  return pnanovdb_address_offset(root.address, byte_offset);
2318 }
2319 
2320 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_root_tile_get_value_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_tile_handle_t root_tile)
2321 {
2322  pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, root_tile_off_value);
2323  return pnanovdb_address_offset(root_tile.address, byte_offset);
2324 }
2325 
2326 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_root_get_value_address_and_level(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_uint32_t) level)
2327 {
2328  pnanovdb_root_tile_handle_t tile = pnanovdb_root_find_tile(grid_type, buf, root, ijk);
2329  pnanovdb_address_t ret;
2330  if (pnanovdb_address_is_null(tile.address))
2331  {
2332  ret = pnanovdb_address_offset(root.address, PNANOVDB_GRID_TYPE_GET(grid_type, root_off_background));
2333  PNANOVDB_DEREF(level) = 4u;
2334  }
2335  else if (pnanovdb_int64_is_zero(pnanovdb_root_tile_get_child(buf, tile)))
2336  {
2337  ret = pnanovdb_address_offset(tile.address, PNANOVDB_GRID_TYPE_GET(grid_type, root_tile_off_value));
2338  PNANOVDB_DEREF(level) = 3u;
2339  }
2340  else
2341  {
2342  pnanovdb_upper_handle_t child = pnanovdb_root_get_child(grid_type, buf, root, tile);
2343  ret = pnanovdb_upper_get_value_address_and_level(grid_type, buf, child, ijk, level);
2344  }
2345  return ret;
2346 }
2347 
2348 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_root_get_value_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root, PNANOVDB_IN(pnanovdb_coord_t) ijk)
2349 {
2350  pnanovdb_uint32_t level;
2351  return pnanovdb_root_get_value_address_and_level(grid_type, buf, root, ijk, PNANOVDB_REF(level));
2352 }
2353 
2354 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_root_get_value_address_bit(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_uint32_t) bit_index)
2355 {
2356  pnanovdb_uint32_t level;
2357  pnanovdb_address_t address = pnanovdb_root_get_value_address_and_level(grid_type, buf, root, ijk, PNANOVDB_REF(level));
2358  PNANOVDB_DEREF(bit_index) = level == 0u ? pnanovdb_int32_as_uint32(PNANOVDB_DEREF(ijk).x & 7) : 0u;
2359  return address;
2360 }
2361 
2362 PNANOVDB_FORCE_INLINE float pnanovdb_root_fp4_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk, pnanovdb_uint32_t level)
2363 {
2364  float ret;
2365  if (level == 0)
2366  {
2367  ret = pnanovdb_leaf_fp4_read_float(buf, address, ijk);
2368  }
2369  else
2370  {
2371  ret = pnanovdb_read_float(buf, address);
2372  }
2373  return ret;
2374 }
2375 
2376 PNANOVDB_FORCE_INLINE float pnanovdb_root_fp8_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk, pnanovdb_uint32_t level)
2377 {
2378  float ret;
2379  if (level == 0)
2380  {
2381  ret = pnanovdb_leaf_fp8_read_float(buf, address, ijk);
2382  }
2383  else
2384  {
2385  ret = pnanovdb_read_float(buf, address);
2386  }
2387  return ret;
2388 }
2389 
2390 PNANOVDB_FORCE_INLINE float pnanovdb_root_fp16_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk, pnanovdb_uint32_t level)
2391 {
2392  float ret;
2393  if (level == 0)
2394  {
2395  ret = pnanovdb_leaf_fp16_read_float(buf, address, ijk);
2396  }
2397  else
2398  {
2399  ret = pnanovdb_read_float(buf, address);
2400  }
2401  return ret;
2402 }
2403 
2404 PNANOVDB_FORCE_INLINE float pnanovdb_root_fpn_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk, pnanovdb_uint32_t level)
2405 {
2406  float ret;
2407  if (level == 0)
2408  {
2409  ret = pnanovdb_leaf_fpn_read_float(buf, address, ijk);
2410  }
2411  else
2412  {
2413  ret = pnanovdb_read_float(buf, address);
2414  }
2415  return ret;
2416 }
2417 
2418 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_root_index_get_value_index(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk, pnanovdb_uint32_t level)
2419 {
2420  pnanovdb_uint64_t ret;
2421  if (level == 0)
2422  {
2423  ret = pnanovdb_leaf_index_get_value_index(buf, address, ijk);
2424  }
2425  else
2426  {
2427  ret = pnanovdb_read_uint64(buf, address);
2428  }
2429  return ret;
2430 }
2431 
2432 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_root_onindex_get_value_index(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk, pnanovdb_uint32_t level)
2433 {
2434  pnanovdb_uint64_t ret;
2435  if (level == 0)
2436  {
2437  ret = pnanovdb_leaf_onindex_get_value_index(buf, address, ijk);
2438  }
2439  else
2440  {
2441  ret = pnanovdb_read_uint64(buf, address);
2442  }
2443  return ret;
2444 }
2445 
2446 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_root_pointindex_get_point_range(
2447  pnanovdb_buf_t buf,
2448  pnanovdb_address_t value_address,
2449  PNANOVDB_IN(pnanovdb_coord_t) ijk,
2450  pnanovdb_uint32_t level,
2451  PNANOVDB_INOUT(pnanovdb_uint64_t)range_begin,
2452  PNANOVDB_INOUT(pnanovdb_uint64_t)range_end
2453 )
2454 {
2455  pnanovdb_uint32_t local_range_begin = 0u;
2456  pnanovdb_uint32_t local_range_end = 0u;
2457  pnanovdb_uint64_t offset = pnanovdb_uint32_as_uint64_low(0u);
2458  if (level == 0)
2459  {
2460  pnanovdb_uint32_t n = pnanovdb_leaf_coord_to_offset(ijk);
2461  // recover leaf address
2462  pnanovdb_leaf_handle_t leaf = { pnanovdb_address_offset_neg(value_address, PNANOVDB_GRID_TYPE_GET(PNANOVDB_GRID_TYPE_POINTINDEX, leaf_off_table) + 2u * n) };
2463  if (n > 0u)
2464  {
2465  local_range_begin = pnanovdb_read_uint16(buf, pnanovdb_address_offset_neg(value_address, 2u));
2466  }
2467  local_range_end = pnanovdb_read_uint16(buf, value_address);
2468  offset = pnanovdb_leaf_pointindex_get_offset(buf, leaf);
2469  }
2470  PNANOVDB_DEREF(range_begin) = pnanovdb_uint64_offset(offset, local_range_begin);
2471  PNANOVDB_DEREF(range_end) = pnanovdb_uint64_offset(offset, local_range_end);
2472  return pnanovdb_uint32_as_uint64_low(local_range_end - local_range_begin);
2473 }
2474 
2475 PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_root_pointindex_get_point_address_range(
2476  pnanovdb_buf_t buf,
2477  pnanovdb_grid_type_t value_type,
2478  pnanovdb_address_t value_address,
2479  pnanovdb_address_t blindmetadata_value_address,
2480  PNANOVDB_IN(pnanovdb_coord_t) ijk,
2481  pnanovdb_uint32_t level,
2482  PNANOVDB_INOUT(pnanovdb_address_t)address_begin,
2483  PNANOVDB_INOUT(pnanovdb_address_t)address_end
2484 )
2485 {
2486  pnanovdb_uint64_t range_begin;
2487  pnanovdb_uint64_t range_end;
2488  pnanovdb_uint64_t range_size = pnanovdb_root_pointindex_get_point_range(buf, value_address, ijk, level, PNANOVDB_REF(range_begin), PNANOVDB_REF(range_end));
2489 
2490  pnanovdb_uint32_t stride = 12u; // vec3f
2491  if (value_type == PNANOVDB_GRID_TYPE_VEC3U8)
2492  {
2493  stride = 3u;
2494  }
2495  else if (value_type == PNANOVDB_GRID_TYPE_VEC3U16)
2496  {
2497  stride = 6u;
2498  }
2499  PNANOVDB_DEREF(address_begin) = pnanovdb_address_offset64_product(blindmetadata_value_address, range_begin, stride);
2500  PNANOVDB_DEREF(address_end) = pnanovdb_address_offset64_product(blindmetadata_value_address, range_end, stride);
2501  return range_size;
2502 }
2503 
2504 // ------------------------------------------------ ReadAccessor -----------------------------------------------------------
2505 
2507 {
2508  pnanovdb_coord_t key;
2513 };
2514 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_readaccessor_t)
2515 
2516 PNANOVDB_FORCE_INLINE void pnanovdb_readaccessor_init(PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, pnanovdb_root_handle_t root)
2517 {
2518  PNANOVDB_DEREF(acc).key.x = 0x7FFFFFFF;
2519  PNANOVDB_DEREF(acc).key.y = 0x7FFFFFFF;
2520  PNANOVDB_DEREF(acc).key.z = 0x7FFFFFFF;
2521  PNANOVDB_DEREF(acc).leaf.address = pnanovdb_address_null();
2522  PNANOVDB_DEREF(acc).lower.address = pnanovdb_address_null();
2523  PNANOVDB_DEREF(acc).upper.address = pnanovdb_address_null();
2524  PNANOVDB_DEREF(acc).root = root;
2525 }
2526 
2527 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_readaccessor_iscached0(PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, int dirty)
2528 {
2529  if (pnanovdb_address_is_null(PNANOVDB_DEREF(acc).leaf.address)) { return PNANOVDB_FALSE; }
2530  if ((dirty & ~((1u << 3) - 1u)) != 0)
2531  {
2532  PNANOVDB_DEREF(acc).leaf.address = pnanovdb_address_null();
2533  return PNANOVDB_FALSE;
2534  }
2535  return PNANOVDB_TRUE;
2536 }
2537 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_readaccessor_iscached1(PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, int dirty)
2538 {
2539  if (pnanovdb_address_is_null(PNANOVDB_DEREF(acc).lower.address)) { return PNANOVDB_FALSE; }
2540  if ((dirty & ~((1u << 7) - 1u)) != 0)
2541  {
2542  PNANOVDB_DEREF(acc).lower.address = pnanovdb_address_null();
2543  return PNANOVDB_FALSE;
2544  }
2545  return PNANOVDB_TRUE;
2546 }
2547 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_readaccessor_iscached2(PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, int dirty)
2548 {
2549  if (pnanovdb_address_is_null(PNANOVDB_DEREF(acc).upper.address)) { return PNANOVDB_FALSE; }
2550  if ((dirty & ~((1u << 12) - 1u)) != 0)
2551  {
2552  PNANOVDB_DEREF(acc).upper.address = pnanovdb_address_null();
2553  return PNANOVDB_FALSE;
2554  }
2555  return PNANOVDB_TRUE;
2556 }
2557 PNANOVDB_FORCE_INLINE int pnanovdb_readaccessor_computedirty(PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, PNANOVDB_IN(pnanovdb_coord_t) ijk)
2558 {
2559  return (PNANOVDB_DEREF(ijk).x ^ PNANOVDB_DEREF(acc).key.x) | (PNANOVDB_DEREF(ijk).y ^ PNANOVDB_DEREF(acc).key.y) | (PNANOVDB_DEREF(ijk).z ^ PNANOVDB_DEREF(acc).key.z);
2560 }
2561 
2562 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_leaf_get_value_address_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
2563 {
2564  pnanovdb_uint32_t n = pnanovdb_leaf_coord_to_offset(ijk);
2565  return pnanovdb_leaf_get_table_address(grid_type, buf, leaf, n);
2566 }
2567 
2568 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_lower_get_value_address_and_level_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t lower, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, PNANOVDB_INOUT(pnanovdb_uint32_t) level)
2569 {
2570  pnanovdb_uint32_t n = pnanovdb_lower_coord_to_offset(ijk);
2571  pnanovdb_address_t value_address;
2572  if (pnanovdb_lower_get_child_mask(buf, lower, n))
2573  {
2574  pnanovdb_leaf_handle_t child = pnanovdb_lower_get_child(grid_type, buf, lower, n);
2575  PNANOVDB_DEREF(acc).leaf = child;
2576  PNANOVDB_DEREF(acc).key = PNANOVDB_DEREF(ijk);
2577  value_address = pnanovdb_leaf_get_value_address_and_cache(grid_type, buf, child, ijk, acc);
2578  PNANOVDB_DEREF(level) = 0u;
2579  }
2580  else
2581  {
2582  value_address = pnanovdb_lower_get_table_address(grid_type, buf, lower, n);
2583  PNANOVDB_DEREF(level) = 1u;
2584  }
2585  return value_address;
2586 }
2587 
2588 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_lower_get_value_address_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t lower, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
2589 {
2590  pnanovdb_uint32_t level;
2591  return pnanovdb_lower_get_value_address_and_level_and_cache(grid_type, buf, lower, ijk, acc, PNANOVDB_REF(level));
2592 }
2593 
2594 PNANOVDB_FORCE_INLINE void pnanovdb_lower_set_table_child(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t node, pnanovdb_uint32_t n, pnanovdb_int64_t child)
2595 {
2596  pnanovdb_address_t table_address = pnanovdb_lower_get_table_address(grid_type, buf, node, n);
2597  pnanovdb_write_int64(buf, table_address, child);
2598 }
2599 
2600 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_upper_get_value_address_and_level_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t upper, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, PNANOVDB_INOUT(pnanovdb_uint32_t) level)
2601 {
2602  pnanovdb_uint32_t n = pnanovdb_upper_coord_to_offset(ijk);
2603  pnanovdb_address_t value_address;
2604  if (pnanovdb_upper_get_child_mask(buf, upper, n))
2605  {
2606  pnanovdb_lower_handle_t child = pnanovdb_upper_get_child(grid_type, buf, upper, n);
2607  PNANOVDB_DEREF(acc).lower = child;
2608  PNANOVDB_DEREF(acc).key = PNANOVDB_DEREF(ijk);
2609  value_address = pnanovdb_lower_get_value_address_and_level_and_cache(grid_type, buf, child, ijk, acc, level);
2610  }
2611  else
2612  {
2613  value_address = pnanovdb_upper_get_table_address(grid_type, buf, upper, n);
2614  PNANOVDB_DEREF(level) = 2u;
2615  }
2616  return value_address;
2617 }
2618 
2619 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_upper_get_value_address_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t upper, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
2620 {
2621  pnanovdb_uint32_t level;
2622  return pnanovdb_upper_get_value_address_and_level_and_cache(grid_type, buf, upper, ijk, acc, PNANOVDB_REF(level));
2623 }
2624 
2625 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_root_get_value_address_and_level_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, PNANOVDB_INOUT(pnanovdb_uint32_t) level)
2626 {
2627  pnanovdb_root_tile_handle_t tile = pnanovdb_root_find_tile(grid_type, buf, root, ijk);
2628  pnanovdb_address_t ret;
2629  if (pnanovdb_address_is_null(tile.address))
2630  {
2631  ret = pnanovdb_address_offset(root.address, PNANOVDB_GRID_TYPE_GET(grid_type, root_off_background));
2632  PNANOVDB_DEREF(level) = 4u;
2633  }
2634  else if (pnanovdb_int64_is_zero(pnanovdb_root_tile_get_child(buf, tile)))
2635  {
2636  ret = pnanovdb_address_offset(tile.address, PNANOVDB_GRID_TYPE_GET(grid_type, root_tile_off_value));
2637  PNANOVDB_DEREF(level) = 3u;
2638  }
2639  else
2640  {
2641  pnanovdb_upper_handle_t child = pnanovdb_root_get_child(grid_type, buf, root, tile);
2642  PNANOVDB_DEREF(acc).upper = child;
2643  PNANOVDB_DEREF(acc).key = PNANOVDB_DEREF(ijk);
2644  ret = pnanovdb_upper_get_value_address_and_level_and_cache(grid_type, buf, child, ijk, acc, level);
2645  }
2646  return ret;
2647 }
2648 
2649 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_root_get_value_address_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
2650 {
2651  pnanovdb_uint32_t level;
2652  return pnanovdb_root_get_value_address_and_level_and_cache(grid_type, buf, root, ijk, acc, PNANOVDB_REF(level));
2653 }
2654 
2655 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_readaccessor_get_value_address_and_level(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_uint32_t) level)
2656 {
2657  int dirty = pnanovdb_readaccessor_computedirty(acc, ijk);
2658 
2659  pnanovdb_address_t value_address;
2660  if (pnanovdb_readaccessor_iscached0(acc, dirty))
2661  {
2662  value_address = pnanovdb_leaf_get_value_address_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).leaf, ijk, acc);
2663  PNANOVDB_DEREF(level) = 0u;
2664  }
2665  else if (pnanovdb_readaccessor_iscached1(acc, dirty))
2666  {
2667  value_address = pnanovdb_lower_get_value_address_and_level_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).lower, ijk, acc, level);
2668  }
2669  else if (pnanovdb_readaccessor_iscached2(acc, dirty))
2670  {
2671  value_address = pnanovdb_upper_get_value_address_and_level_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).upper, ijk, acc, level);
2672  }
2673  else
2674  {
2675  value_address = pnanovdb_root_get_value_address_and_level_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).root, ijk, acc, level);
2676  }
2677  return value_address;
2678 }
2679 
2680 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_readaccessor_get_value_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, PNANOVDB_IN(pnanovdb_coord_t) ijk)
2681 {
2682  pnanovdb_uint32_t level;
2683  return pnanovdb_readaccessor_get_value_address_and_level(grid_type, buf, acc, ijk, PNANOVDB_REF(level));
2684 }
2685 
2686 PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_readaccessor_get_value_address_bit(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_uint32_t) bit_index)
2687 {
2688  pnanovdb_uint32_t level;
2689  pnanovdb_address_t address = pnanovdb_readaccessor_get_value_address_and_level(grid_type, buf, acc, ijk, PNANOVDB_REF(level));
2690  PNANOVDB_DEREF(bit_index) = level == 0u ? pnanovdb_int32_as_uint32(PNANOVDB_DEREF(ijk).x & 7) : 0u;
2691  return address;
2692 }
2693 
2694 // ------------------------------------------------ ReadAccessor GetDim -----------------------------------------------------------
2695 
2696 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_leaf_get_dim_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
2697 {
2698  return 1u;
2699 }
2700 
2701 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_lower_get_dim_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t lower, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
2702 {
2703  pnanovdb_uint32_t n = pnanovdb_lower_coord_to_offset(ijk);
2704  pnanovdb_uint32_t ret;
2705  if (pnanovdb_lower_get_child_mask(buf, lower, n))
2706  {
2707  pnanovdb_leaf_handle_t child = pnanovdb_lower_get_child(grid_type, buf, lower, n);
2708  PNANOVDB_DEREF(acc).leaf = child;
2709  PNANOVDB_DEREF(acc).key = PNANOVDB_DEREF(ijk);
2710  ret = pnanovdb_leaf_get_dim_and_cache(grid_type, buf, child, ijk, acc);
2711  }
2712  else
2713  {
2714  ret = (1u << (3u)); // node 0 dim
2715  }
2716  return ret;
2717 }
2718 
2719 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_upper_get_dim_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t upper, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
2720 {
2721  pnanovdb_uint32_t n = pnanovdb_upper_coord_to_offset(ijk);
2722  pnanovdb_uint32_t ret;
2723  if (pnanovdb_upper_get_child_mask(buf, upper, n))
2724  {
2725  pnanovdb_lower_handle_t child = pnanovdb_upper_get_child(grid_type, buf, upper, n);
2726  PNANOVDB_DEREF(acc).lower = child;
2727  PNANOVDB_DEREF(acc).key = PNANOVDB_DEREF(ijk);
2728  ret = pnanovdb_lower_get_dim_and_cache(grid_type, buf, child, ijk, acc);
2729  }
2730  else
2731  {
2732  ret = (1u << (4u + 3u)); // node 1 dim
2733  }
2734  return ret;
2735 }
2736 
2737 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_root_get_dim_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
2738 {
2739  pnanovdb_root_tile_handle_t tile = pnanovdb_root_find_tile(grid_type, buf, root, ijk);
2740  pnanovdb_uint32_t ret;
2741  if (pnanovdb_address_is_null(tile.address))
2742  {
2743  ret = 1u << (5u + 4u + 3u); // background, node 2 dim
2744  }
2745  else if (pnanovdb_int64_is_zero(pnanovdb_root_tile_get_child(buf, tile)))
2746  {
2747  ret = 1u << (5u + 4u + 3u); // tile value, node 2 dim
2748  }
2749  else
2750  {
2751  pnanovdb_upper_handle_t child = pnanovdb_root_get_child(grid_type, buf, root, tile);
2752  PNANOVDB_DEREF(acc).upper = child;
2753  PNANOVDB_DEREF(acc).key = PNANOVDB_DEREF(ijk);
2754  ret = pnanovdb_upper_get_dim_and_cache(grid_type, buf, child, ijk, acc);
2755  }
2756  return ret;
2757 }
2758 
2759 PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_readaccessor_get_dim(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, PNANOVDB_IN(pnanovdb_coord_t) ijk)
2760 {
2761  int dirty = pnanovdb_readaccessor_computedirty(acc, ijk);
2762 
2763  pnanovdb_uint32_t dim;
2764  if (pnanovdb_readaccessor_iscached0(acc, dirty))
2765  {
2766  dim = pnanovdb_leaf_get_dim_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).leaf, ijk, acc);
2767  }
2768  else if (pnanovdb_readaccessor_iscached1(acc, dirty))
2769  {
2770  dim = pnanovdb_lower_get_dim_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).lower, ijk, acc);
2771  }
2772  else if (pnanovdb_readaccessor_iscached2(acc, dirty))
2773  {
2774  dim = pnanovdb_upper_get_dim_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).upper, ijk, acc);
2775  }
2776  else
2777  {
2778  dim = pnanovdb_root_get_dim_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).root, ijk, acc);
2779  }
2780  return dim;
2781 }
2782 
2783 // ------------------------------------------------ ReadAccessor IsActive -----------------------------------------------------------
2784 
2785 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_leaf_is_active_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
2786 {
2787  pnanovdb_uint32_t n = pnanovdb_leaf_coord_to_offset(ijk);
2788  return pnanovdb_leaf_get_value_mask(buf, leaf, n);
2789 }
2790 
2791 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_lower_is_active_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t lower, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
2792 {
2793  pnanovdb_uint32_t n = pnanovdb_lower_coord_to_offset(ijk);
2794  pnanovdb_bool_t is_active;
2795  if (pnanovdb_lower_get_child_mask(buf, lower, n))
2796  {
2797  pnanovdb_leaf_handle_t child = pnanovdb_lower_get_child(grid_type, buf, lower, n);
2798  PNANOVDB_DEREF(acc).leaf = child;
2799  PNANOVDB_DEREF(acc).key = PNANOVDB_DEREF(ijk);
2800  is_active = pnanovdb_leaf_is_active_and_cache(grid_type, buf, child, ijk, acc);
2801  }
2802  else
2803  {
2804  is_active = pnanovdb_lower_get_value_mask(buf, lower, n);
2805  }
2806  return is_active;
2807 }
2808 
2809 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_upper_is_active_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t upper, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
2810 {
2811  pnanovdb_uint32_t n = pnanovdb_upper_coord_to_offset(ijk);
2812  pnanovdb_bool_t is_active;
2813  if (pnanovdb_upper_get_child_mask(buf, upper, n))
2814  {
2815  pnanovdb_lower_handle_t child = pnanovdb_upper_get_child(grid_type, buf, upper, n);
2816  PNANOVDB_DEREF(acc).lower = child;
2817  PNANOVDB_DEREF(acc).key = PNANOVDB_DEREF(ijk);
2818  is_active = pnanovdb_lower_is_active_and_cache(grid_type, buf, child, ijk, acc);
2819  }
2820  else
2821  {
2822  is_active = pnanovdb_upper_get_value_mask(buf, upper, n);
2823  }
2824  return is_active;
2825 }
2826 
2827 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_root_is_active_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
2828 {
2829  pnanovdb_root_tile_handle_t tile = pnanovdb_root_find_tile(grid_type, buf, root, ijk);
2830  pnanovdb_bool_t is_active;
2831  if (pnanovdb_address_is_null(tile.address))
2832  {
2833  is_active = PNANOVDB_FALSE; // background
2834  }
2835  else if (pnanovdb_int64_is_zero(pnanovdb_root_tile_get_child(buf, tile)))
2836  {
2837  pnanovdb_uint32_t state = pnanovdb_root_tile_get_state(buf, tile);
2838  is_active = state != 0u; // tile value
2839  }
2840  else
2841  {
2842  pnanovdb_upper_handle_t child = pnanovdb_root_get_child(grid_type, buf, root, tile);
2843  PNANOVDB_DEREF(acc).upper = child;
2844  PNANOVDB_DEREF(acc).key = PNANOVDB_DEREF(ijk);
2845  is_active = pnanovdb_upper_is_active_and_cache(grid_type, buf, child, ijk, acc);
2846  }
2847  return is_active;
2848 }
2849 
2850 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_readaccessor_is_active(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, PNANOVDB_IN(pnanovdb_coord_t) ijk)
2851 {
2852  int dirty = pnanovdb_readaccessor_computedirty(acc, ijk);
2853 
2854  pnanovdb_bool_t is_active;
2855  if (pnanovdb_readaccessor_iscached0(acc, dirty))
2856  {
2857  is_active = pnanovdb_leaf_is_active_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).leaf, ijk, acc);
2858  }
2859  else if (pnanovdb_readaccessor_iscached1(acc, dirty))
2860  {
2861  is_active = pnanovdb_lower_is_active_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).lower, ijk, acc);
2862  }
2863  else if (pnanovdb_readaccessor_iscached2(acc, dirty))
2864  {
2865  is_active = pnanovdb_upper_is_active_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).upper, ijk, acc);
2866  }
2867  else
2868  {
2869  is_active = pnanovdb_root_is_active_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).root, ijk, acc);
2870  }
2871  return is_active;
2872 }
2873 
2874 // ------------------------------------------------ Map Transforms -----------------------------------------------------------
2875 
2876 PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_map_apply(pnanovdb_buf_t buf, pnanovdb_map_handle_t map, PNANOVDB_IN(pnanovdb_vec3_t) src)
2877 {
2878  pnanovdb_vec3_t dst;
2879  float sx = PNANOVDB_DEREF(src).x;
2880  float sy = PNANOVDB_DEREF(src).y;
2881  float sz = PNANOVDB_DEREF(src).z;
2882  dst.x = sx * pnanovdb_map_get_matf(buf, map, 0) + sy * pnanovdb_map_get_matf(buf, map, 1) + sz * pnanovdb_map_get_matf(buf, map, 2) + pnanovdb_map_get_vecf(buf, map, 0);
2883  dst.y = sx * pnanovdb_map_get_matf(buf, map, 3) + sy * pnanovdb_map_get_matf(buf, map, 4) + sz * pnanovdb_map_get_matf(buf, map, 5) + pnanovdb_map_get_vecf(buf, map, 1);
2884  dst.z = sx * pnanovdb_map_get_matf(buf, map, 6) + sy * pnanovdb_map_get_matf(buf, map, 7) + sz * pnanovdb_map_get_matf(buf, map, 8) + pnanovdb_map_get_vecf(buf, map, 2);
2885  return dst;
2886 }
2887 
2888 PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_map_apply_inverse(pnanovdb_buf_t buf, pnanovdb_map_handle_t map, PNANOVDB_IN(pnanovdb_vec3_t) src)
2889 {
2890  pnanovdb_vec3_t dst;
2891  float sx = PNANOVDB_DEREF(src).x - pnanovdb_map_get_vecf(buf, map, 0);
2892  float sy = PNANOVDB_DEREF(src).y - pnanovdb_map_get_vecf(buf, map, 1);
2893  float sz = PNANOVDB_DEREF(src).z - pnanovdb_map_get_vecf(buf, map, 2);
2894  dst.x = sx * pnanovdb_map_get_invmatf(buf, map, 0) + sy * pnanovdb_map_get_invmatf(buf, map, 1) + sz * pnanovdb_map_get_invmatf(buf, map, 2);
2895  dst.y = sx * pnanovdb_map_get_invmatf(buf, map, 3) + sy * pnanovdb_map_get_invmatf(buf, map, 4) + sz * pnanovdb_map_get_invmatf(buf, map, 5);
2896  dst.z = sx * pnanovdb_map_get_invmatf(buf, map, 6) + sy * pnanovdb_map_get_invmatf(buf, map, 7) + sz * pnanovdb_map_get_invmatf(buf, map, 8);
2897  return dst;
2898 }
2899 
2900 PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_map_apply_jacobi(pnanovdb_buf_t buf, pnanovdb_map_handle_t map, PNANOVDB_IN(pnanovdb_vec3_t) src)
2901 {
2902  pnanovdb_vec3_t dst;
2903  float sx = PNANOVDB_DEREF(src).x;
2904  float sy = PNANOVDB_DEREF(src).y;
2905  float sz = PNANOVDB_DEREF(src).z;
2906  dst.x = sx * pnanovdb_map_get_matf(buf, map, 0) + sy * pnanovdb_map_get_matf(buf, map, 1) + sz * pnanovdb_map_get_matf(buf, map, 2);
2907  dst.y = sx * pnanovdb_map_get_matf(buf, map, 3) + sy * pnanovdb_map_get_matf(buf, map, 4) + sz * pnanovdb_map_get_matf(buf, map, 5);
2908  dst.z = sx * pnanovdb_map_get_matf(buf, map, 6) + sy * pnanovdb_map_get_matf(buf, map, 7) + sz * pnanovdb_map_get_matf(buf, map, 8);
2909  return dst;
2910 }
2911 
2912 PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_map_apply_inverse_jacobi(pnanovdb_buf_t buf, pnanovdb_map_handle_t map, PNANOVDB_IN(pnanovdb_vec3_t) src)
2913 {
2914  pnanovdb_vec3_t dst;
2915  float sx = PNANOVDB_DEREF(src).x;
2916  float sy = PNANOVDB_DEREF(src).y;
2917  float sz = PNANOVDB_DEREF(src).z;
2918  dst.x = sx * pnanovdb_map_get_invmatf(buf, map, 0) + sy * pnanovdb_map_get_invmatf(buf, map, 1) + sz * pnanovdb_map_get_invmatf(buf, map, 2);
2919  dst.y = sx * pnanovdb_map_get_invmatf(buf, map, 3) + sy * pnanovdb_map_get_invmatf(buf, map, 4) + sz * pnanovdb_map_get_invmatf(buf, map, 5);
2920  dst.z = sx * pnanovdb_map_get_invmatf(buf, map, 6) + sy * pnanovdb_map_get_invmatf(buf, map, 7) + sz * pnanovdb_map_get_invmatf(buf, map, 8);
2921  return dst;
2922 }
2923 
2924 PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_grid_world_to_indexf(pnanovdb_buf_t buf, pnanovdb_grid_handle_t grid, PNANOVDB_IN(pnanovdb_vec3_t) src)
2925 {
2927  return pnanovdb_map_apply_inverse(buf, map, src);
2928 }
2929 
2930 PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_grid_index_to_worldf(pnanovdb_buf_t buf, pnanovdb_grid_handle_t grid, PNANOVDB_IN(pnanovdb_vec3_t) src)
2931 {
2933  return pnanovdb_map_apply(buf, map, src);
2934 }
2935 
2936 PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_grid_world_to_index_dirf(pnanovdb_buf_t buf, pnanovdb_grid_handle_t grid, PNANOVDB_IN(pnanovdb_vec3_t) src)
2937 {
2939  return pnanovdb_map_apply_inverse_jacobi(buf, map, src);
2940 }
2941 
2942 PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_grid_index_to_world_dirf(pnanovdb_buf_t buf, pnanovdb_grid_handle_t grid, PNANOVDB_IN(pnanovdb_vec3_t) src)
2943 {
2945  return pnanovdb_map_apply_jacobi(buf, map, src);
2946 }
2947 
2948 // ------------------------------------------------ DitherLUT -----------------------------------------------------------
2949 
2950 // This table was generated with
2951 /**************
2952 
2953 static constexpr inline uint32
2954 SYSwang_inthash(uint32 key)
2955 {
2956  // From http://www.concentric.net/~Ttwang/tech/inthash.htm
2957  key += ~(key << 16);
2958  key ^= (key >> 5);
2959  key += (key << 3);
2960  key ^= (key >> 13);
2961  key += ~(key << 9);
2962  key ^= (key >> 17);
2963  return key;
2964 }
2965 
2966 static void
2967 ut_initDitherR(float *pattern, float offset,
2968  int x, int y, int z, int res, int goalres)
2969 {
2970  // These offsets are designed to maximize the difference between
2971  // dither values in nearby voxels within a given 2x2x2 cell, without
2972  // producing axis-aligned artifacts. The are organized in row-major
2973  // order.
2974  static const float theDitherOffset[] = {0,4,6,2,5,1,3,7};
2975  static const float theScale = 0.125F;
2976  int key = (((z << res) + y) << res) + x;
2977 
2978  if (res == goalres)
2979  {
2980  pattern[key] = offset;
2981  return;
2982  }
2983 
2984  // Randomly flip (on each axis) the dithering patterns used by the
2985  // subcells. This key is xor'd with the subcell index below before
2986  // looking up in the dither offset list.
2987  key = SYSwang_inthash(key) & 7;
2988 
2989  x <<= 1;
2990  y <<= 1;
2991  z <<= 1;
2992 
2993  offset *= theScale;
2994  for (int i = 0; i < 8; i++)
2995  ut_initDitherR(pattern, offset+theDitherOffset[i ^ key]*theScale,
2996  x+(i&1), y+((i&2)>>1), z+((i&4)>>2), res+1, goalres);
2997 }
2998 
2999 // This is a compact algorithm that accomplishes essentially the same thing
3000 // as ut_initDither() above. We should eventually switch to use this and
3001 // clean the dead code.
3002 static fpreal32 *
3003 ut_initDitherRecursive(int goalres)
3004 {
3005  const int nfloat = 1 << (goalres*3);
3006  float *pattern = new float[nfloat];
3007  ut_initDitherR(pattern, 1.0F, 0, 0, 0, 0, goalres);
3008 
3009  // This has built an even spacing from 1/nfloat to 1.0.
3010  // however, our dither pattern should be 1/(nfloat+1) to nfloat/(nfloat+1)
3011  // So we do a correction here. Note that the earlier calculations are
3012  // done with powers of 2 so are exact, so it does make sense to delay
3013  // the renormalization to this pass.
3014  float correctionterm = nfloat / (nfloat+1.0F);
3015  for (int i = 0; i < nfloat; i++)
3016  pattern[i] *= correctionterm;
3017  return pattern;
3018 }
3019 
3020  theDitherMatrix = ut_initDitherRecursive(3);
3021 
3022  for (int i = 0; i < 512/8; i ++)
3023  {
3024  for (int j = 0; j < 8; j ++)
3025  std::cout << theDitherMatrix[i*8+j] << "f, ";
3026  std::cout << std::endl;
3027  }
3028 
3029  **************/
3030 
3031 PNANOVDB_STATIC_CONST float pnanovdb_dither_lut[512] =
3032 {
3033  0.14425f, 0.643275f, 0.830409f, 0.331384f, 0.105263f, 0.604289f, 0.167641f, 0.666667f,
3034  0.892788f, 0.393762f, 0.0818713f, 0.580897f, 0.853801f, 0.354776f, 0.916179f, 0.417154f,
3035  0.612086f, 0.11306f, 0.79922f, 0.300195f, 0.510721f, 0.0116959f, 0.947368f, 0.448343f,
3036  0.362573f, 0.861598f, 0.0506823f, 0.549708f, 0.261209f, 0.760234f, 0.19883f, 0.697856f,
3037  0.140351f, 0.639376f, 0.576998f, 0.0779727f, 0.522417f, 0.0233918f, 0.460039f, 0.959064f,
3038  0.888889f, 0.389864f, 0.327485f, 0.826511f, 0.272904f, 0.77193f, 0.709552f, 0.210526f,
3039  0.483431f, 0.982456f, 0.296296f, 0.795322f, 0.116959f, 0.615984f, 0.0545809f, 0.553606f,
3040  0.732943f, 0.233918f, 0.545809f, 0.0467836f, 0.865497f, 0.366472f, 0.803119f, 0.304094f,
3041  0.518519f, 0.0194932f, 0.45614f, 0.955166f, 0.729045f, 0.230019f, 0.54191f, 0.042885f,
3042  0.269006f, 0.768031f, 0.705653f, 0.206628f, 0.479532f, 0.978558f, 0.292398f, 0.791423f,
3043  0.237817f, 0.736842f, 0.424951f, 0.923977f, 0.136452f, 0.635478f, 0.323587f, 0.822612f,
3044  0.986355f, 0.487329f, 0.674464f, 0.175439f, 0.88499f, 0.385965f, 0.573099f, 0.0740741f,
3045  0.51462f, 0.0155945f, 0.202729f, 0.701754f, 0.148148f, 0.647174f, 0.834308f, 0.335283f,
3046  0.265107f, 0.764133f, 0.951267f, 0.452242f, 0.896686f, 0.397661f, 0.08577f, 0.584795f,
3047  0.8577f, 0.358674f, 0.920078f, 0.421053f, 0.740741f, 0.241715f, 0.678363f, 0.179337f,
3048  0.109162f, 0.608187f, 0.17154f, 0.670565f, 0.491228f, 0.990253f, 0.42885f, 0.927875f,
3049  0.0662768f, 0.565302f, 0.62768f, 0.128655f, 0.183236f, 0.682261f, 0.744639f, 0.245614f,
3050  0.814815f, 0.315789f, 0.378168f, 0.877193f, 0.931774f, 0.432749f, 0.495127f, 0.994152f,
3051  0.0350877f, 0.534113f, 0.97076f, 0.471735f, 0.214425f, 0.71345f, 0.526316f, 0.0272904f,
3052  0.783626f, 0.2846f, 0.222222f, 0.721248f, 0.962963f, 0.463938f, 0.276803f, 0.775828f,
3053  0.966862f, 0.467836f, 0.405458f, 0.904483f, 0.0701754f, 0.569201f, 0.881092f, 0.382066f,
3054  0.218324f, 0.717349f, 0.654971f, 0.155945f, 0.818713f, 0.319688f, 0.132554f, 0.631579f,
3055  0.0623782f, 0.561404f, 0.748538f, 0.249513f, 0.912281f, 0.413255f, 0.974659f, 0.475634f,
3056  0.810916f, 0.311891f, 0.499025f, 0.998051f, 0.163743f, 0.662768f, 0.226121f, 0.725146f,
3057  0.690058f, 0.191033f, 0.00389864f, 0.502924f, 0.557505f, 0.0584795f, 0.120858f, 0.619883f,
3058  0.440546f, 0.939571f, 0.752437f, 0.253411f, 0.307992f, 0.807018f, 0.869396f, 0.37037f,
3059  0.658869f, 0.159844f, 0.346979f, 0.846004f, 0.588694f, 0.0896686f, 0.152047f, 0.651072f,
3060  0.409357f, 0.908382f, 0.596491f, 0.0974659f, 0.339181f, 0.838207f, 0.900585f, 0.401559f,
3061  0.34308f, 0.842105f, 0.779727f, 0.280702f, 0.693957f, 0.194932f, 0.25731f, 0.756335f,
3062  0.592593f, 0.0935673f, 0.0311891f, 0.530214f, 0.444444f, 0.94347f, 0.506823f, 0.00779727f,
3063  0.68616f, 0.187135f, 0.124756f, 0.623782f, 0.288499f, 0.787524f, 0.350877f, 0.849903f,
3064  0.436647f, 0.935673f, 0.873294f, 0.374269f, 0.538012f, 0.0389864f, 0.60039f, 0.101365f,
3065  0.57115f, 0.0721248f, 0.758285f, 0.259259f, 0.719298f, 0.220273f, 0.532164f, 0.0331384f,
3066  0.321637f, 0.820663f, 0.00974659f, 0.508772f, 0.469786f, 0.968811f, 0.282651f, 0.781676f,
3067  0.539961f, 0.0409357f, 0.727096f, 0.22807f, 0.500975f, 0.00194932f, 0.563353f, 0.0643275f,
3068  0.290448f, 0.789474f, 0.477583f, 0.976608f, 0.251462f, 0.750487f, 0.31384f, 0.812865f,
3069  0.94152f, 0.442495f, 0.879142f, 0.380117f, 0.37232f, 0.871345f, 0.309942f, 0.808967f,
3070  0.192982f, 0.692008f, 0.130604f, 0.62963f, 0.621832f, 0.122807f, 0.559454f, 0.0604289f,
3071  0.660819f, 0.161793f, 0.723197f, 0.224172f, 0.403509f, 0.902534f, 0.840156f, 0.341131f,
3072  0.411306f, 0.910331f, 0.473684f, 0.97271f, 0.653021f, 0.153996f, 0.0916179f, 0.590643f,
3073  0.196881f, 0.695906f, 0.384016f, 0.883041f, 0.0955166f, 0.594542f, 0.157895f, 0.65692f,
3074  0.945419f, 0.446394f, 0.633528f, 0.134503f, 0.844055f, 0.345029f, 0.906433f, 0.407407f,
3075  0.165692f, 0.664717f, 0.103314f, 0.602339f, 0.126706f, 0.625731f, 0.189084f, 0.688109f,
3076  0.91423f, 0.415205f, 0.851852f, 0.352827f, 0.875244f, 0.376218f, 0.937622f, 0.438596f,
3077  0.317739f, 0.816764f, 0.255361f, 0.754386f, 0.996101f, 0.497076f, 0.933723f, 0.434698f,
3078  0.567251f, 0.0682261f, 0.504873f, 0.00584795f, 0.247563f, 0.746589f, 0.185185f, 0.684211f,
3079  0.037037f, 0.536062f, 0.0994152f, 0.598441f, 0.777778f, 0.278752f, 0.465887f, 0.964912f,
3080  0.785575f, 0.28655f, 0.847953f, 0.348928f, 0.0292398f, 0.528265f, 0.7154f, 0.216374f,
3081  0.39961f, 0.898636f, 0.961014f, 0.461988f, 0.0487329f, 0.547758f, 0.111111f, 0.610136f,
3082  0.649123f, 0.150097f, 0.212476f, 0.711501f, 0.797271f, 0.298246f, 0.859649f, 0.360624f,
3083  0.118908f, 0.617934f, 0.0565302f, 0.555556f, 0.329435f, 0.82846f, 0.516569f, 0.0175439f,
3084  0.867446f, 0.368421f, 0.805068f, 0.306043f, 0.578947f, 0.079922f, 0.267057f, 0.766082f,
3085  0.270955f, 0.76998f, 0.707602f, 0.208577f, 0.668616f, 0.169591f, 0.606238f, 0.107212f,
3086  0.520468f, 0.0214425f, 0.45809f, 0.957115f, 0.419103f, 0.918129f, 0.356725f, 0.855751f,
3087  0.988304f, 0.489279f, 0.426901f, 0.925926f, 0.450292f, 0.949318f, 0.512671f, 0.0136452f,
3088  0.239766f, 0.738791f, 0.676413f, 0.177388f, 0.699805f, 0.20078f, 0.263158f, 0.762183f,
3089  0.773879f, 0.274854f, 0.337232f, 0.836257f, 0.672515f, 0.173489f, 0.734893f, 0.235867f,
3090  0.0253411f, 0.524366f, 0.586745f, 0.0877193f, 0.423002f, 0.922027f, 0.48538f, 0.984405f,
3091  0.74269f, 0.243665f, 0.680312f, 0.181287f, 0.953216f, 0.454191f, 0.1423f, 0.641326f,
3092  0.493177f, 0.992203f, 0.430799f, 0.929825f, 0.204678f, 0.703704f, 0.890838f, 0.391813f,
3093  0.894737f, 0.395712f, 0.0838207f, 0.582846f, 0.0448343f, 0.54386f, 0.231969f, 0.730994f,
3094  0.146199f, 0.645224f, 0.832359f, 0.333333f, 0.793372f, 0.294347f, 0.980507f, 0.481481f,
3095  0.364522f, 0.863548f, 0.80117f, 0.302144f, 0.824561f, 0.325536f, 0.138402f, 0.637427f,
3096  0.614035f, 0.11501f, 0.0526316f, 0.551657f, 0.0760234f, 0.575049f, 0.88694f, 0.387914f,
3097 };
3098 
3099 PNANOVDB_FORCE_INLINE float pnanovdb_dither_lookup(pnanovdb_bool_t enabled, int offset)
3100 {
3101  return enabled ? pnanovdb_dither_lut[offset & 511] : 0.5f;
3102 }
3103 
3104 // ------------------------------------------------ HDDA -----------------------------------------------------------
3105 
3106 #ifdef PNANOVDB_HDDA
3107 
3108 // Comment out to disable this explicit round-off check
3109 #define PNANOVDB_ENFORCE_FORWARD_STEPPING
3110 
3111 #define PNANOVDB_HDDA_FLOAT_MAX 1e38f
3112 
3113 struct pnanovdb_hdda_t
3114 {
3115  pnanovdb_int32_t dim;
3116  float tmin;
3117  float tmax;
3118  pnanovdb_coord_t voxel;
3119  pnanovdb_coord_t step;
3120  pnanovdb_vec3_t delta;
3121  pnanovdb_vec3_t next;
3122 };
3123 PNANOVDB_STRUCT_TYPEDEF(pnanovdb_hdda_t)
3124 
3125 PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_hdda_pos_to_ijk(PNANOVDB_IN(pnanovdb_vec3_t) pos)
3126 {
3127  pnanovdb_coord_t voxel;
3128  voxel.x = pnanovdb_float_to_int32(pnanovdb_floor(PNANOVDB_DEREF(pos).x));
3129  voxel.y = pnanovdb_float_to_int32(pnanovdb_floor(PNANOVDB_DEREF(pos).y));
3130  voxel.z = pnanovdb_float_to_int32(pnanovdb_floor(PNANOVDB_DEREF(pos).z));
3131  return voxel;
3132 }
3133 
3134 PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_hdda_pos_to_voxel(PNANOVDB_IN(pnanovdb_vec3_t) pos, int dim)
3135 {
3136  pnanovdb_coord_t voxel;
3137  voxel.x = pnanovdb_float_to_int32(pnanovdb_floor(PNANOVDB_DEREF(pos).x)) & (~(dim - 1));
3138  voxel.y = pnanovdb_float_to_int32(pnanovdb_floor(PNANOVDB_DEREF(pos).y)) & (~(dim - 1));
3139  voxel.z = pnanovdb_float_to_int32(pnanovdb_floor(PNANOVDB_DEREF(pos).z)) & (~(dim - 1));
3140  return voxel;
3141 }
3142 
3143 PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_hdda_ray_start(PNANOVDB_IN(pnanovdb_vec3_t) origin, float tmin, PNANOVDB_IN(pnanovdb_vec3_t) direction)
3144 {
3145  pnanovdb_vec3_t pos = pnanovdb_vec3_add(
3146  pnanovdb_vec3_mul(PNANOVDB_DEREF(direction), pnanovdb_vec3_uniform(tmin)),
3147  PNANOVDB_DEREF(origin)
3148  );
3149  return pos;
3150 }
3151 
3152 PNANOVDB_FORCE_INLINE void pnanovdb_hdda_init(PNANOVDB_INOUT(pnanovdb_hdda_t) hdda, PNANOVDB_IN(pnanovdb_vec3_t) origin, float tmin, PNANOVDB_IN(pnanovdb_vec3_t) direction, float tmax, int dim)
3153 {
3154  PNANOVDB_DEREF(hdda).dim = dim;
3155  PNANOVDB_DEREF(hdda).tmin = tmin;
3156  PNANOVDB_DEREF(hdda).tmax = tmax;
3157 
3158  pnanovdb_vec3_t pos = pnanovdb_hdda_ray_start(origin, tmin, direction);
3159  pnanovdb_vec3_t dir_inv = pnanovdb_vec3_div(pnanovdb_vec3_uniform(1.f), PNANOVDB_DEREF(direction));
3160 
3161  PNANOVDB_DEREF(hdda).voxel = pnanovdb_hdda_pos_to_voxel(PNANOVDB_REF(pos), dim);
3162 
3163  // x
3164  if (PNANOVDB_DEREF(direction).x == 0.f)
3165  {
3166  PNANOVDB_DEREF(hdda).next.x = PNANOVDB_HDDA_FLOAT_MAX;
3167  PNANOVDB_DEREF(hdda).step.x = 0;
3168  PNANOVDB_DEREF(hdda).delta.x = 0.f;
3169  }
3170  else if (dir_inv.x > 0.f)
3171  {
3172  PNANOVDB_DEREF(hdda).step.x = 1;
3173  PNANOVDB_DEREF(hdda).next.x = PNANOVDB_DEREF(hdda).tmin + (PNANOVDB_DEREF(hdda).voxel.x + dim - pos.x) * dir_inv.x;
3174  PNANOVDB_DEREF(hdda).delta.x = dir_inv.x;
3175  }
3176  else
3177  {
3178  PNANOVDB_DEREF(hdda).step.x = -1;
3179  PNANOVDB_DEREF(hdda).next.x = PNANOVDB_DEREF(hdda).tmin + (PNANOVDB_DEREF(hdda).voxel.x - pos.x) * dir_inv.x;
3180  PNANOVDB_DEREF(hdda).delta.x = -dir_inv.x;
3181  }
3182 
3183  // y
3184  if (PNANOVDB_DEREF(direction).y == 0.f)
3185  {
3186  PNANOVDB_DEREF(hdda).next.y = PNANOVDB_HDDA_FLOAT_MAX;
3187  PNANOVDB_DEREF(hdda).step.y = 0;
3188  PNANOVDB_DEREF(hdda).delta.y = 0.f;
3189  }
3190  else if (dir_inv.y > 0.f)
3191  {
3192  PNANOVDB_DEREF(hdda).step.y = 1;
3193  PNANOVDB_DEREF(hdda).next.y = PNANOVDB_DEREF(hdda).tmin + (PNANOVDB_DEREF(hdda).voxel.y + dim - pos.y) * dir_inv.y;
3194  PNANOVDB_DEREF(hdda).delta.y = dir_inv.y;
3195  }
3196  else
3197  {
3198  PNANOVDB_DEREF(hdda).step.y = -1;
3199  PNANOVDB_DEREF(hdda).next.y = PNANOVDB_DEREF(hdda).tmin + (PNANOVDB_DEREF(hdda).voxel.y - pos.y) * dir_inv.y;
3200  PNANOVDB_DEREF(hdda).delta.y = -dir_inv.y;
3201  }
3202 
3203  // z
3204  if (PNANOVDB_DEREF(direction).z == 0.f)
3205  {
3206  PNANOVDB_DEREF(hdda).next.z = PNANOVDB_HDDA_FLOAT_MAX;
3207  PNANOVDB_DEREF(hdda).step.z = 0;
3208  PNANOVDB_DEREF(hdda).delta.z = 0.f;
3209  }
3210  else if (dir_inv.z > 0.f)
3211  {
3212  PNANOVDB_DEREF(hdda).step.z = 1;
3213  PNANOVDB_DEREF(hdda).next.z = PNANOVDB_DEREF(hdda).tmin + (PNANOVDB_DEREF(hdda).voxel.z + dim - pos.z) * dir_inv.z;
3214  PNANOVDB_DEREF(hdda).delta.z = dir_inv.z;
3215  }
3216  else
3217  {
3218  PNANOVDB_DEREF(hdda).step.z = -1;
3219  PNANOVDB_DEREF(hdda).next.z = PNANOVDB_DEREF(hdda).tmin + (PNANOVDB_DEREF(hdda).voxel.z - pos.z) * dir_inv.z;
3220  PNANOVDB_DEREF(hdda).delta.z = -dir_inv.z;
3221  }
3222 }
3223 
3224 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_hdda_update(PNANOVDB_INOUT(pnanovdb_hdda_t) hdda, PNANOVDB_IN(pnanovdb_vec3_t) origin, PNANOVDB_IN(pnanovdb_vec3_t) direction, int dim)
3225 {
3226  if (PNANOVDB_DEREF(hdda).dim == dim)
3227  {
3228  return PNANOVDB_FALSE;
3229  }
3230  PNANOVDB_DEREF(hdda).dim = dim;
3231 
3232  pnanovdb_vec3_t pos = pnanovdb_vec3_add(
3233  pnanovdb_vec3_mul(PNANOVDB_DEREF(direction), pnanovdb_vec3_uniform(PNANOVDB_DEREF(hdda).tmin)),
3234  PNANOVDB_DEREF(origin)
3235  );
3236  pnanovdb_vec3_t dir_inv = pnanovdb_vec3_div(pnanovdb_vec3_uniform(1.f), PNANOVDB_DEREF(direction));
3237 
3238  PNANOVDB_DEREF(hdda).voxel = pnanovdb_hdda_pos_to_voxel(PNANOVDB_REF(pos), dim);
3239 
3240  if (PNANOVDB_DEREF(hdda).step.x != 0)
3241  {
3242  PNANOVDB_DEREF(hdda).next.x = PNANOVDB_DEREF(hdda).tmin + (PNANOVDB_DEREF(hdda).voxel.x - pos.x) * dir_inv.x;
3243  if (PNANOVDB_DEREF(hdda).step.x > 0)
3244  {
3245  PNANOVDB_DEREF(hdda).next.x += dim * dir_inv.x;
3246  }
3247  }
3248  if (PNANOVDB_DEREF(hdda).step.y != 0)
3249  {
3250  PNANOVDB_DEREF(hdda).next.y = PNANOVDB_DEREF(hdda).tmin + (PNANOVDB_DEREF(hdda).voxel.y - pos.y) * dir_inv.y;
3251  if (PNANOVDB_DEREF(hdda).step.y > 0)
3252  {
3253  PNANOVDB_DEREF(hdda).next.y += dim * dir_inv.y;
3254  }
3255  }
3256  if (PNANOVDB_DEREF(hdda).step.z != 0)
3257  {
3258  PNANOVDB_DEREF(hdda).next.z = PNANOVDB_DEREF(hdda).tmin + (PNANOVDB_DEREF(hdda).voxel.z - pos.z) * dir_inv.z;
3259  if (PNANOVDB_DEREF(hdda).step.z > 0)
3260  {
3261  PNANOVDB_DEREF(hdda).next.z += dim * dir_inv.z;
3262  }
3263  }
3264 
3265  return PNANOVDB_TRUE;
3266 }
3267 
3268 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_hdda_step(PNANOVDB_INOUT(pnanovdb_hdda_t) hdda)
3269 {
3270  pnanovdb_bool_t ret;
3271  if (PNANOVDB_DEREF(hdda).next.x < PNANOVDB_DEREF(hdda).next.y && PNANOVDB_DEREF(hdda).next.x < PNANOVDB_DEREF(hdda).next.z)
3272  {
3273 #ifdef PNANOVDB_ENFORCE_FORWARD_STEPPING
3274  if (PNANOVDB_DEREF(hdda).next.x <= PNANOVDB_DEREF(hdda).tmin)
3275  {
3276  PNANOVDB_DEREF(hdda).next.x += PNANOVDB_DEREF(hdda).tmin - 0.999999f * PNANOVDB_DEREF(hdda).next.x + 1.0e-6f;
3277  }
3278 #endif
3279  PNANOVDB_DEREF(hdda).tmin = PNANOVDB_DEREF(hdda).next.x;
3280  PNANOVDB_DEREF(hdda).next.x += PNANOVDB_DEREF(hdda).dim * PNANOVDB_DEREF(hdda).delta.x;
3281  PNANOVDB_DEREF(hdda).voxel.x += PNANOVDB_DEREF(hdda).dim * PNANOVDB_DEREF(hdda).step.x;
3282  ret = PNANOVDB_DEREF(hdda).tmin <= PNANOVDB_DEREF(hdda).tmax;
3283  }
3284  else if (PNANOVDB_DEREF(hdda).next.y < PNANOVDB_DEREF(hdda).next.z)
3285  {
3286 #ifdef PNANOVDB_ENFORCE_FORWARD_STEPPING
3287  if (PNANOVDB_DEREF(hdda).next.y <= PNANOVDB_DEREF(hdda).tmin)
3288  {
3289  PNANOVDB_DEREF(hdda).next.y += PNANOVDB_DEREF(hdda).tmin - 0.999999f * PNANOVDB_DEREF(hdda).next.y + 1.0e-6f;
3290  }
3291 #endif
3292  PNANOVDB_DEREF(hdda).tmin = PNANOVDB_DEREF(hdda).next.y;
3293  PNANOVDB_DEREF(hdda).next.y += PNANOVDB_DEREF(hdda).dim * PNANOVDB_DEREF(hdda).delta.y;
3294  PNANOVDB_DEREF(hdda).voxel.y += PNANOVDB_DEREF(hdda).dim * PNANOVDB_DEREF(hdda).step.y;
3295  ret = PNANOVDB_DEREF(hdda).tmin <= PNANOVDB_DEREF(hdda).tmax;
3296  }
3297  else
3298  {
3299 #ifdef PNANOVDB_ENFORCE_FORWARD_STEPPING
3300  if (PNANOVDB_DEREF(hdda).next.z <= PNANOVDB_DEREF(hdda).tmin)
3301  {
3302  PNANOVDB_DEREF(hdda).next.z += PNANOVDB_DEREF(hdda).tmin - 0.999999f * PNANOVDB_DEREF(hdda).next.z + 1.0e-6f;
3303  }
3304 #endif
3305  PNANOVDB_DEREF(hdda).tmin = PNANOVDB_DEREF(hdda).next.z;
3306  PNANOVDB_DEREF(hdda).next.z += PNANOVDB_DEREF(hdda).dim * PNANOVDB_DEREF(hdda).delta.z;
3307  PNANOVDB_DEREF(hdda).voxel.z += PNANOVDB_DEREF(hdda).dim * PNANOVDB_DEREF(hdda).step.z;
3308  ret = PNANOVDB_DEREF(hdda).tmin <= PNANOVDB_DEREF(hdda).tmax;
3309  }
3310  return ret;
3311 }
3312 
3313 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_hdda_ray_clip(
3314  PNANOVDB_IN(pnanovdb_vec3_t) bbox_min,
3315  PNANOVDB_IN(pnanovdb_vec3_t) bbox_max,
3316  PNANOVDB_IN(pnanovdb_vec3_t) origin, PNANOVDB_INOUT(float) tmin,
3317  PNANOVDB_IN(pnanovdb_vec3_t) direction, PNANOVDB_INOUT(float) tmax
3318 )
3319 {
3320  pnanovdb_vec3_t dir_inv = pnanovdb_vec3_div(pnanovdb_vec3_uniform(1.f), PNANOVDB_DEREF(direction));
3321  pnanovdb_vec3_t t0 = pnanovdb_vec3_mul(pnanovdb_vec3_sub(PNANOVDB_DEREF(bbox_min), PNANOVDB_DEREF(origin)), dir_inv);
3322  pnanovdb_vec3_t t1 = pnanovdb_vec3_mul(pnanovdb_vec3_sub(PNANOVDB_DEREF(bbox_max), PNANOVDB_DEREF(origin)), dir_inv);
3323  pnanovdb_vec3_t tmin3 = pnanovdb_vec3_min(t0, t1);
3324  pnanovdb_vec3_t tmax3 = pnanovdb_vec3_max(t0, t1);
3325  float tnear = pnanovdb_max(tmin3.x, pnanovdb_max(tmin3.y, tmin3.z));
3326  float tfar = pnanovdb_min(tmax3.x, pnanovdb_min(tmax3.y, tmax3.z));
3327  pnanovdb_bool_t hit = tnear <= tfar;
3328  PNANOVDB_DEREF(tmin) = pnanovdb_max(PNANOVDB_DEREF(tmin), tnear);
3329  PNANOVDB_DEREF(tmax) = pnanovdb_min(PNANOVDB_DEREF(tmax), tfar);
3330  return hit;
3331 }
3332 
3333 PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_hdda_zero_crossing(
3334  pnanovdb_grid_type_t grid_type,
3335  pnanovdb_buf_t buf,
3336  PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc,
3337  PNANOVDB_IN(pnanovdb_vec3_t) origin, float tmin,
3338  PNANOVDB_IN(pnanovdb_vec3_t) direction, float tmax,
3339  PNANOVDB_INOUT(float) thit,
3340  PNANOVDB_INOUT(float) v
3341 )
3342 {
3343  pnanovdb_coord_t bbox_min = pnanovdb_root_get_bbox_min(buf, PNANOVDB_DEREF(acc).root);
3344  pnanovdb_coord_t bbox_max = pnanovdb_root_get_bbox_max(buf, PNANOVDB_DEREF(acc).root);
3345  pnanovdb_vec3_t bbox_minf = pnanovdb_coord_to_vec3(bbox_min);
3346  pnanovdb_vec3_t bbox_maxf = pnanovdb_coord_to_vec3(pnanovdb_coord_add(bbox_max, pnanovdb_coord_uniform(1)));
3347 
3348  pnanovdb_bool_t hit = pnanovdb_hdda_ray_clip(PNANOVDB_REF(bbox_minf), PNANOVDB_REF(bbox_maxf), origin, PNANOVDB_REF(tmin), direction, PNANOVDB_REF(tmax));
3349  if (!hit || tmax > 1.0e20f)
3350  {
3351  return PNANOVDB_FALSE;
3352  }
3353 
3354  pnanovdb_vec3_t pos = pnanovdb_hdda_ray_start(origin, tmin, direction);
3355  pnanovdb_coord_t ijk = pnanovdb_hdda_pos_to_ijk(PNANOVDB_REF(pos));
3356 
3357  pnanovdb_address_t address = pnanovdb_readaccessor_get_value_address(PNANOVDB_GRID_TYPE_FLOAT, buf, acc, PNANOVDB_REF(ijk));
3358  float v0 = pnanovdb_read_float(buf, address);
3359 
3360  pnanovdb_int32_t dim = pnanovdb_uint32_as_int32(pnanovdb_readaccessor_get_dim(PNANOVDB_GRID_TYPE_FLOAT, buf, acc, PNANOVDB_REF(ijk)));
3361  pnanovdb_hdda_t hdda;
3362  pnanovdb_hdda_init(PNANOVDB_REF(hdda), origin, tmin, direction, tmax, dim);
3363  while (pnanovdb_hdda_step(PNANOVDB_REF(hdda)))
3364  {
3365  pnanovdb_vec3_t pos_start = pnanovdb_hdda_ray_start(origin, hdda.tmin + 1.0001f, direction);
3366  ijk = pnanovdb_hdda_pos_to_ijk(PNANOVDB_REF(pos_start));
3367  dim = pnanovdb_uint32_as_int32(pnanovdb_readaccessor_get_dim(PNANOVDB_GRID_TYPE_FLOAT, buf, acc, PNANOVDB_REF(ijk)));
3368  pnanovdb_hdda_update(PNANOVDB_REF(hdda), origin, direction, dim);
3369  if (hdda.dim > 1 || !pnanovdb_readaccessor_is_active(grid_type, buf, acc, PNANOVDB_REF(ijk)))
3370  {
3371  continue;
3372  }
3373  while (pnanovdb_hdda_step(PNANOVDB_REF(hdda)) && pnanovdb_readaccessor_is_active(grid_type, buf, acc, PNANOVDB_REF(hdda.voxel)))
3374  {
3375  ijk = hdda.voxel;
3376  pnanovdb_address_t address = pnanovdb_readaccessor_get_value_address(PNANOVDB_GRID_TYPE_FLOAT, buf, acc, PNANOVDB_REF(ijk));
3377  PNANOVDB_DEREF(v) = pnanovdb_read_float(buf, address);
3378  if (PNANOVDB_DEREF(v) * v0 < 0.f)
3379  {
3380  PNANOVDB_DEREF(thit) = hdda.tmin;
3381  return PNANOVDB_TRUE;
3382  }
3383  }
3384  }
3385  return PNANOVDB_FALSE;
3386 }
3387 
3388 #endif
3389 
3390 #endif // end of NANOVDB_PNANOVDB_H_HAS_BEEN_INCLUDED
pnanovdb_map_t map
Definition: PNanoVDB.h:1095
PNANOVDB_FORCE_INLINE float pnanovdb_root_fp4_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk, pnanovdb_uint32_t level)
Definition: PNanoVDB.h:2362
#define PNANOVDB_GRID_TYPE_END
Definition: PNanoVDB.h:966
pnanovdb_uint32_t node_count_lower
Definition: PNanoVDB.h:1288
PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_grid_world_to_index_dirf(pnanovdb_buf_t buf, pnanovdb_grid_handle_t grid, PNANOVDB_IN(pnanovdb_vec3_t) src)
Definition: PNanoVDB.h:2936
PNANOVDB_FORCE_INLINE double pnanovdb_map_get_taperd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:1056
PNANOVDB_FORCE_INLINE float pnanovdb_leaf_fp4_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:1826
PNANOVDB_FORCE_INLINE float pnanovdb_root_fp16_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk, pnanovdb_uint32_t level)
Definition: PNanoVDB.h:2390
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_tile_count_leaf(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p)
Definition: PNanoVDB.h:1334
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_upper_get_stddev_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t node)
Definition: PNanoVDB.h:2240
pnanovdb_coord_t bbox_max
Definition: PNanoVDB.h:1515
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_node_count_lower(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p)
Definition: PNanoVDB.h:1328
PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_read_vec3u16(pnanovdb_buf_t buf, pnanovdb_address_t address)
Definition: PNanoVDB.h:843
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_pointindex_get_offset(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf)
Definition: PNanoVDB.h:2086
#define PNANOVDB_ROOT_TILE_OFF_KEY
Definition: PNanoVDB.h:1433
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindexmask_get_last_offset(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf)
Definition: PNanoVDB.h:2031
PNANOVDB_FORCE_INLINE void pnanovdb_lower_set_bbox_max(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p, PNANOVDB_IN(pnanovdb_coord_t) bbox_max)
Definition: PNanoVDB.h:1556
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_readaccessor_is_active(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:2850
#define PNANOVDB_GRID_SIZE
Definition: PNanoVDB.h:1108
PNANOVDB_FORCE_INLINE pnanovdb_root_handle_t pnanovdb_tree_get_root(pnanovdb_buf_t buf, pnanovdb_tree_handle_t tree)
Definition: PNanoVDB.h:1699
pnanovdb_uint32_t grid_type
Definition: PNanoVDB.h:1099
pnanovdb_uint32_t root_tile_size
Definition: PNanoVDB.h:1619
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_gridblindmetadata_get_data_type(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p)
Definition: PNanoVDB.h:1274
#define PNANOVDB_GRID_TYPE_VEC3U16
Definition: PNanoVDB.h:964
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_read_uint32(pnanovdb_buf_t buf, pnanovdb_address_t address)
Definition: PNanoVDB.h:792
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_index_get_min_index(pnanovdb_buf_t buf, pnanovdb_address_t min_address)
Definition: PNanoVDB.h:1856
Definition: PNanoVDB.h:1608
pnanovdb_int64_t data_offset
Definition: PNanoVDB.h:1237
pnanovdb_lower_handle_t lower
Definition: PNanoVDB.h:2510
#define PNANOVDB_LEAF_OFF_BBOX_MIN
Definition: PNanoVDB.h:1582
#define PNANOVDB_UPPER_OFF_FLAGS
Definition: PNanoVDB.h:1476
PNANOVDB_FORCE_INLINE void pnanovdb_write_int32(pnanovdb_buf_t buf, pnanovdb_address_t address, pnanovdb_int32_t value)
Definition: PNanoVDB.h:900
Definition: PNanoVDB.h:1296
Definition: PNanoVDB.h:1085
#define PNANOVDB_MAP_OFF_MATF
Definition: PNanoVDB.h:1026
#define PNANOVDB_UPPER_OFF_BBOX_MAX
Definition: PNanoVDB.h:1475
pnanovdb_upper_handle_t upper
Definition: PNanoVDB.h:2511
#define PNANOVDB_LOWER_OFF_BBOX_MAX
Definition: PNanoVDB.h:1530
Definition: PNanoVDB.h:1523
PNANOVDB_FORCE_INLINE void pnanovdb_root_tile_set_state(pnanovdb_buf_t buf, pnanovdb_root_tile_handle_t p, pnanovdb_uint32_t state)
Definition: PNanoVDB.h:1453
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_indexmask_get_ave_index(pnanovdb_buf_t buf, pnanovdb_address_t ave_address)
Definition: PNanoVDB.h:1897
PNANOVDB_FORCE_INLINE void pnanovdb_leaf_pointindex_set_value(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, pnanovdb_uint32_t i, pnanovdb_uint32_t value)
Definition: PNanoVDB.h:2131
#define PNANOVDB_GRID_OFF_MAGIC
Definition: PNanoVDB.h:1110
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_root_get_stddev_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root)
Definition: PNanoVDB.h:2314
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_index_get_ave_index(pnanovdb_buf_t buf, pnanovdb_address_t ave_address)
Definition: PNanoVDB.h:1866
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_uint64_any_bit(pnanovdb_uint64_t a)
Definition: PNanoVDB.h:659
pnanovdb_uint32_t lower_off_max
Definition: PNanoVDB.h:1627
pnanovdb_coord_t key
Definition: PNanoVDB.h:2508
pnanovdb_uint32_t value_size
Definition: PNanoVDB.h:1239
PNANOVDB_FORCE_INLINE void pnanovdb_lower_set_table_child(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t node, pnanovdb_uint32_t n, pnanovdb_int64_t child)
Definition: PNanoVDB.h:2594
PNANOVDB_FORCE_INLINE void pnanovdb_root_set_bbox_min(pnanovdb_buf_t buf, pnanovdb_root_handle_t p, PNANOVDB_IN(pnanovdb_coord_t) bbox_min)
Definition: PNanoVDB.h:1409
pnanovdb_address_t address
Definition: PNanoVDB.h:1428
PNANOVDB_FORCE_INLINE pnanovdb_lower_handle_t pnanovdb_upper_get_child(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t upper, pnanovdb_uint32_t n)
Definition: PNanoVDB.h:2258
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_read_uint64(pnanovdb_buf_t buf, pnanovdb_address_t address)
Definition: PNanoVDB.h:796
#define PNANOVDB_UPPER_OFF_VALUE_MASK
Definition: PNanoVDB.h:1477
PNANOVDB_FORCE_INLINE pnanovdb_tree_handle_t pnanovdb_grid_get_tree(pnanovdb_buf_t buf, pnanovdb_grid_handle_t grid)
Definition: PNanoVDB.h:1692
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_leaf_onindexmask_get_value_count(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf)
Definition: PNanoVDB.h:2027
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_tree_get_node_offset_upper(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p)
Definition: PNanoVDB.h:1319
#define PNANOVDB_MAP_OFF_INVMATD
Definition: PNanoVDB.h:1031
PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_checksum(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint64_t checksum)
Definition: PNanoVDB.h:1177
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_grid_count(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:1141
pnanovdb_uint32_t value_stride_bits
Definition: PNanoVDB.h:1616
pnanovdb_uint32_t root_off_max
Definition: PNanoVDB.h:1612
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_readaccessor_iscached2(PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, int dirty)
Definition: PNanoVDB.h:2547
PNANOVDB_FORCE_INLINE float pnanovdb_leaf_fp8_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:1831
pnanovdb_uint32_t root_size
Definition: PNanoVDB.h:1615
pnanovdb_uint32_t lower_off_min
Definition: PNanoVDB.h:1626
PNANOVDB_FORCE_INLINE void pnanovdb_root_tile_set_key(pnanovdb_buf_t buf, pnanovdb_root_tile_handle_t p, pnanovdb_uint64_t key)
Definition: PNanoVDB.h:1447
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_upper_get_value_address_and_level_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t upper, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, PNANOVDB_INOUT(pnanovdb_uint32_t) level)
Definition: PNanoVDB.h:2600
#define PNANOVDB_UPPER_OFF_CHILD_MASK
Definition: PNanoVDB.h:1478
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_index_get_dev_index(pnanovdb_buf_t buf, pnanovdb_address_t dev_address)
Definition: PNanoVDB.h:1871
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_upper_get_flags(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p)
Definition: PNanoVDB.h:1486
pnanovdb_address_t address
Definition: PNanoVDB.h:1390
pnanovdb_uint64_t voxel_count
Definition: PNanoVDB.h:1293
#define PNANOVDB_TREE_OFF_TILE_COUNT_LOWER
Definition: PNanoVDB.h:1309
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_grid_index(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:1138
PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_upper_get_bbox_min(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p)
Definition: PNanoVDB.h:1480
pnanovdb_uint32_t leaf_off_max
Definition: PNanoVDB.h:1633
PNANOVDB_FORCE_INLINE void pnanovdb_write_double(pnanovdb_buf_t buf, pnanovdb_address_t address, double value)
Definition: PNanoVDB.h:912
pnanovdb_address_t address
Definition: PNanoVDB.h:1523
PNANOVDB_FORCE_INLINE int pnanovdb_readaccessor_computedirty(PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:2557
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindex_get_dev_index(pnanovdb_buf_t buf, pnanovdb_address_t dev_address)
Definition: PNanoVDB.h:1989
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_readaccessor_get_dim(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:2759
PNANOVDB_FORCE_INLINE void pnanovdb_tree_set_node_offset_leaf(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p, pnanovdb_uint64_t node_offset_leaf)
Definition: PNanoVDB.h:1347
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_upper_is_active_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t upper, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
Definition: PNanoVDB.h:2809
PNANOVDB_FORCE_INLINE pnanovdb_int64_t pnanovdb_lower_get_table_child(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t node, pnanovdb_uint32_t n)
Definition: PNanoVDB.h:2176
Definition: PNanoVDB.h:1281
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_readaccessor_iscached0(PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, int dirty)
Definition: PNanoVDB.h:2527
PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_read_vec3u8(pnanovdb_buf_t buf, pnanovdb_address_t address)
Definition: PNanoVDB.h:852
#define PNANOVDB_ROOT_OFF_BBOX_MIN
Definition: PNanoVDB.h:1395
#define PNANOVDB_GRID_OFF_VOXEL_SIZE
Definition: PNanoVDB.h:1120
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_leaf_get_table_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_leaf_handle_t node, pnanovdb_uint32_t n)
Definition: PNanoVDB.h:1796
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_lower_get_value_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t lower, PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:2207
#define PNANOVDB_GRID_TYPE_VEC3U8
Definition: PNanoVDB.h:963
pnanovdb_uint32_t upper_off_table
Definition: PNanoVDB.h:1624
pnanovdb_uint64_t grid_size
Definition: PNanoVDB.h:1093
PNANOVDB_STATIC_CONST pnanovdb_grid_type_constants_t pnanovdb_grid_type_constants[27]
Definition: PNanoVDB.h:1642
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_root_pointindex_get_point_range(pnanovdb_buf_t buf, pnanovdb_address_t value_address, PNANOVDB_IN(pnanovdb_coord_t) ijk, pnanovdb_uint32_t level, PNANOVDB_INOUT(pnanovdb_uint64_t) range_begin, PNANOVDB_INOUT(pnanovdb_uint64_t) range_end)
Definition: PNanoVDB.h:2446
#define PNANOVDB_ROOT_OFF_BBOX_MAX
Definition: PNanoVDB.h:1396
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_leaf_onindexmask_get_mask_bit(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, pnanovdb_uint32_t n)
Definition: PNanoVDB.h:2059
PNANOVDB_FORCE_INLINE void pnanovdb_root_tile_set_child(pnanovdb_buf_t buf, pnanovdb_root_tile_handle_t p, pnanovdb_int64_t child)
Definition: PNanoVDB.h:1450
#define PNANOVDB_GRIDBLINDMETADATA_OFF_DATA_CLASS
Definition: PNanoVDB.h:1255
pnanovdb_uint32_t leaf_size
Definition: PNanoVDB.h:1637
#define PNANOVDB_GRID_OFF_FLAGS
Definition: PNanoVDB.h:1113
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_tree_get_voxel_count(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p)
Definition: PNanoVDB.h:1343
PNANOVDB_FORCE_INLINE void pnanovdb_tree_set_tile_count_lower(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p, pnanovdb_uint32_t tile_count_lower)
Definition: PNanoVDB.h:1371
pnanovdb_uint32_t upper_size
Definition: PNanoVDB.h:1625
PNANOVDB_FORCE_INLINE void pnanovdb_leaf_onindexmask_set_mask_bit(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, pnanovdb_uint32_t n, pnanovdb_bool_t v)
Definition: PNanoVDB.h:2067
PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_read_coord(pnanovdb_buf_t buf, pnanovdb_address_t address)
Definition: PNanoVDB.h:816
pnanovdb_uint32_t root_off_stddev
Definition: PNanoVDB.h:1614
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_lower_get_child_mask(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p, pnanovdb_uint32_t bit_index)
Definition: PNanoVDB.h:1548
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_gridblindmetadata_get_value_size(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p)
Definition: PNanoVDB.h:1265
PNANOVDB_FORCE_INLINE void pnanovdb_lower_set_child_mask(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p, pnanovdb_uint32_t bit_index, pnanovdb_bool_t value)
Definition: PNanoVDB.h:1559
#define PNANOVDB_MAP_OFF_VECF
Definition: PNanoVDB.h:1028
pnanovdb_int64_t blind_metadata_offset
Definition: PNanoVDB.h:1100
PNANOVDB_FORCE_INLINE double pnanovdb_map_get_vecd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:1053
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindex_get_min_index(pnanovdb_buf_t buf, pnanovdb_address_t min_address)
Definition: PNanoVDB.h:1956
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindexmask_get_ave_index(pnanovdb_buf_t buf, pnanovdb_address_t ave_address)
Definition: PNanoVDB.h:2047
PNANOVDB_FORCE_INLINE pnanovdb_gridblindmetadata_handle_t pnanovdb_grid_get_gridblindmetadata(pnanovdb_buf_t buf, pnanovdb_grid_handle_t grid, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:1675
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_node_count_leaf(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p)
Definition: PNanoVDB.h:1325
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindexmask_get_value_index(pnanovdb_buf_t buf, pnanovdb_address_t value_address, PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:2055
PNANOVDB_FORCE_INLINE void pnanovdb_tree_set_node_offset_root(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p, pnanovdb_uint64_t node_offset_root)
Definition: PNanoVDB.h:1356
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_uint32_countbits(pnanovdb_uint32_t value)
Definition: PNanoVDB.h:554
PNANOVDB_FORCE_INLINE pnanovdb_int64_t pnanovdb_grid_get_blind_metadata_offset(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:1167
PNANOVDB_FORCE_INLINE double pnanovdb_grid_get_world_bbox(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:1155
pnanovdb_coord_t bbox_min
Definition: PNanoVDB.h:1514
pnanovdb_uint32_t version
Definition: PNanoVDB.h:1089
#define PNANOVDB_LOWER_OFF_FLAGS
Definition: PNanoVDB.h:1531
#define PNANOVDB_TREE_OFF_NODE_OFFSET_LOWER
Definition: PNanoVDB.h:1302
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_version_get_minor(pnanovdb_uint32_t version)
Definition: PNanoVDB.h:1226
Definition: PNanoVDB.h:1567
PNANOVDB_FORCE_INLINE double pnanovdb_map_get_invmatd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:1050
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_uint64_countbits(pnanovdb_uint64_t value)
Definition: PNanoVDB.h:574
#define PNANOVDB_UPPER_OFF_BBOX_MIN
Definition: PNanoVDB.h:1474
Definition: PNanoVDB.h:1419
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_lower_get_stddev_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t node)
Definition: PNanoVDB.h:2164
#define PNANOVDB_TREE_OFF_TILE_COUNT_UPPER
Definition: PNanoVDB.h:1310
PNANOVDB_FORCE_INLINE void pnanovdb_upper_set_child_mask(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p, pnanovdb_uint32_t bit_index, pnanovdb_bool_t value)
Definition: PNanoVDB.h:1504
#define PNANOVDB_TREE_OFF_NODE_OFFSET_ROOT
Definition: PNanoVDB.h:1304
#define PNANOVDB_ROOT_TILE_OFF_STATE
Definition: PNanoVDB.h:1435
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_pointindex_get_value(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, pnanovdb_uint32_t i)
Definition: PNanoVDB.h:2104
#define PNANOVDB_MAP_OFF_TAPERF
Definition: PNanoVDB.h:1029
pnanovdb_uint32_t grid_index
Definition: PNanoVDB.h:1091
pnanovdb_uint64_t node_offset_lower
Definition: PNanoVDB.h:1284
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_tile_count_upper(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p)
Definition: PNanoVDB.h:1340
pnanovdb_uint32_t node_count_leaf
Definition: PNanoVDB.h:1287
#define PNANOVDB_LOWER_OFF_VALUE_MASK
Definition: PNanoVDB.h:1532
Definition: PNanoVDB.h:1235
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_grid_name(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:1147
pnanovdb_uint64_t checksum
Definition: PNanoVDB.h:1088
PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_upper_get_bbox_max(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p)
Definition: PNanoVDB.h:1483
#define PNANOVDB_TREE_OFF_TILE_COUNT_LEAF
Definition: PNanoVDB.h:1308
pnanovdb_uint32_t pad1
Definition: PNanoVDB.h:1424
const std::enable_if<!VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:110
pnanovdb_uint32_t grid_count
Definition: PNanoVDB.h:1092
float taperf
Definition: PNanoVDB.h:1014
pnanovdb_uint64_t flags
Definition: PNanoVDB.h:1516
PNANOVDB_FORCE_INLINE void pnanovdb_write_vec3(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_vec3_t) value)
Definition: PNanoVDB.h:922
#define PNANOVDB_LOWER_OFF_CHILD_MASK
Definition: PNanoVDB.h:1533
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_tile_count_lower(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p)
Definition: PNanoVDB.h:1337
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_upper_get_value_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t upper, PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:2282
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindex_get_ave_index(pnanovdb_buf_t buf, pnanovdb_address_t ave_address)
Definition: PNanoVDB.h:1978
pnanovdb_uint32_t lower_off_ave
Definition: PNanoVDB.h:1628
pnanovdb_uint32_t bbox_dif_and_flags
Definition: PNanoVDB.h:1570
PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_lower_get_bbox_max(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p)
Definition: PNanoVDB.h:1538
#define PNANOVDB_GRIDBLINDMETADATA_OFF_VALUE_COUNT
Definition: PNanoVDB.h:1252
if(shared)
Definition: ValueTransformer.h:596
pnanovdb_address_t address
Definition: PNanoVDB.h:1105
PNANOVDB_FORCE_INLINE float pnanovdb_dither_lookup(pnanovdb_bool_t enabled, int offset)
Definition: PNanoVDB.h:3099
pnanovdb_coord_t bbox_min
Definition: PNanoVDB.h:1569
PNANOVDB_FORCE_INLINE float pnanovdb_root_fpn_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk, pnanovdb_uint32_t level)
Definition: PNanoVDB.h:2404
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_lower_get_value_address_and_level(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t lower, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_uint32_t) level)
Definition: PNanoVDB.h:2189
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_index_get_value_index(pnanovdb_buf_t buf, pnanovdb_address_t value_address, PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:1876
PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_leaf_get_bbox_min(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t p)
Definition: PNanoVDB.h:1590
pnanovdb_uint32_t blind_metadata_count
Definition: PNanoVDB.h:1101
PNANOVDB_FORCE_INLINE void pnanovdb_map_set_taperd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index, double taperd)
Definition: PNanoVDB.h:1081
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_upper_get_value_address_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t upper, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
Definition: PNanoVDB.h:2619
PNANOVDB_FORCE_INLINE void pnanovdb_tree_set_node_count_upper(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p, pnanovdb_uint32_t node_count_upper)
Definition: PNanoVDB.h:1365
pnanovdb_uint32_t leaf_off_min
Definition: PNanoVDB.h:1632
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_leaf_get_dim_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
Definition: PNanoVDB.h:2696
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_root_get_max_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root)
Definition: PNanoVDB.h:2302
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_gridblindmetadata_get_value_count(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p)
Definition: PNanoVDB.h:1262
#define PNANOVDB_TREE_OFF_NODE_COUNT_LEAF
Definition: PNanoVDB.h:1305
PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_grid_index(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t grid_index)
Definition: PNanoVDB.h:1186
pnanovdb_uint32_t semantic
Definition: PNanoVDB.h:1240
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_lower_is_active_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t lower, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
Definition: PNanoVDB.h:2791
pnanovdb_uint32_t upper_off_min
Definition: PNanoVDB.h:1620
PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_flags(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t flags)
Definition: PNanoVDB.h:1183
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_readaccessor_iscached1(PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, int dirty)
Definition: PNanoVDB.h:2537
pnanovdb_uint32_t table_stride
Definition: PNanoVDB.h:1617
PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_stat_strides_bits[27]
Definition: PNanoVDB.h:1005
#define PNANOVDB_GRID_OFF_GRID_COUNT
Definition: PNanoVDB.h:1115
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_readaccessor_get_value_address_bit(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_uint32_t) bit_index)
Definition: PNanoVDB.h:2686
pnanovdb_uint32_t upper_off_max
Definition: PNanoVDB.h:1621
PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_root_get_bbox_max(pnanovdb_buf_t buf, pnanovdb_root_handle_t p)
Definition: PNanoVDB.h:1402
#define PNANOVDB_GRIDBLINDMETADATA_OFF_DATA_TYPE
Definition: PNanoVDB.h:1256
Definition: PNanoVDB.h:1381
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_grid_get_magic(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:1126
pnanovdb_address_t address
Definition: PNanoVDB.h:1246
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_root_get_dim_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
Definition: PNanoVDB.h:2737
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_version_get_major(pnanovdb_uint32_t version)
Definition: PNanoVDB.h:1222
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_root_get_ave_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root)
Definition: PNanoVDB.h:2308
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_root_pointindex_get_point_address_range(pnanovdb_buf_t buf, pnanovdb_grid_type_t value_type, pnanovdb_address_t value_address, pnanovdb_address_t blindmetadata_value_address, PNANOVDB_IN(pnanovdb_coord_t) ijk, pnanovdb_uint32_t level, PNANOVDB_INOUT(pnanovdb_address_t) address_begin, PNANOVDB_INOUT(pnanovdb_address_t) address_end)
Definition: PNanoVDB.h:2475
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_lower_get_flags(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p)
Definition: PNanoVDB.h:1541
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_tree_get_node_offset_leaf(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p)
Definition: PNanoVDB.h:1313
PNANOVDB_FORCE_INLINE pnanovdb_leaf_handle_t pnanovdb_lower_get_child(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t lower, pnanovdb_uint32_t n)
Definition: PNanoVDB.h:2182
#define PNANOVDB_LEAF_OFF_BBOX_DIF_AND_FLAGS
Definition: PNanoVDB.h:1583
PNANOVDB_FORCE_INLINE void pnanovdb_map_set_taperf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index, float taperf)
Definition: PNanoVDB.h:1069
PNANOVDB_FORCE_INLINE void pnanovdb_map_set_invmatd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index, double invmatd)
Definition: PNanoVDB.h:1075
PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_value_strides_bits[27]
Definition: PNanoVDB.h:997
PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_minmax_strides_bits[27]
Definition: PNanoVDB.h:1001
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_root_tile_get_key(pnanovdb_buf_t buf, pnanovdb_root_tile_handle_t p)
Definition: PNanoVDB.h:1437
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_upper_get_min_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t node)
Definition: PNanoVDB.h:2222
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindexmask_get_max_index(pnanovdb_buf_t buf, pnanovdb_address_t max_address)
Definition: PNanoVDB.h:2043
PNANOVDB_FORCE_INLINE void pnanovdb_upper_set_table_child(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t node, pnanovdb_uint32_t n, pnanovdb_int64_t child)
Definition: PNanoVDB.h:2288
pnanovdb_leaf_handle_t leaf
Definition: PNanoVDB.h:2509
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_leaf_get_max_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_leaf_handle_t node)
Definition: PNanoVDB.h:1778
pnanovdb_address_t address
Definition: PNanoVDB.h:1021
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_readaccessor_get_value_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:2680
PNANOVDB_FORCE_INLINE pnanovdb_root_tile_handle_t pnanovdb_root_get_tile(pnanovdb_grid_type_t grid_type, pnanovdb_root_handle_t root, pnanovdb_uint32_t n)
Definition: PNanoVDB.h:1707
Definition: PNanoVDB.h:1576
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_leaf_indexmask_has_stats(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf)
Definition: PNanoVDB.h:1885
PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_map_apply_inverse(pnanovdb_buf_t buf, pnanovdb_map_handle_t map, PNANOVDB_IN(pnanovdb_vec3_t) src)
Definition: PNanoVDB.h:2888
PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_map_apply_jacobi(pnanovdb_buf_t buf, pnanovdb_map_handle_t map, PNANOVDB_IN(pnanovdb_vec3_t) src)
Definition: PNanoVDB.h:2900
#define PNANOVDB_GRID_TYPE_FLOAT
Definition: PNanoVDB.h:940
pnanovdb_uint32_t lower_off_table
Definition: PNanoVDB.h:1630
PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_world_bbox(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t index, double world_bbox)
Definition: PNanoVDB.h:1198
pnanovdb_uint32_t data_class
Definition: PNanoVDB.h:1241
#define PNANOVDB_GRIDBLINDMETADATA_OFF_NAME
Definition: PNanoVDB.h:1257
#define PNANOVDB_GRIDBLINDMETADATA_SIZE
Definition: PNanoVDB.h:1249
PNANOVDB_FORCE_INLINE float pnanovdb_leaf_fp_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk, pnanovdb_uint32_t value_log_bits)
Definition: PNanoVDB.h:1810
pnanovdb_uint32_t table_size
Definition: PNanoVDB.h:1385
MatType scale(const Vec3< typename MatType::value_type > &s)
Return a matrix that scales by s.
Definition: Mat.h:615
PNANOVDB_FORCE_INLINE float pnanovdb_map_get_matf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:1035
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_upper_get_child_mask(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p, pnanovdb_uint32_t bit_index)
Definition: PNanoVDB.h:1493
PNANOVDB_FORCE_INLINE void pnanovdb_write_uint64(pnanovdb_buf_t buf, pnanovdb_address_t address, pnanovdb_uint64_t value)
Definition: PNanoVDB.h:896
PNANOVDB_FORCE_INLINE void pnanovdb_write_uint32(pnanovdb_buf_t buf, pnanovdb_address_t address, pnanovdb_uint32_t value)
Definition: PNanoVDB.h:892
PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_leaf_type[27]
Definition: PNanoVDB.h:1007
#define PNANOVDB_GRIDBLINDMETADATA_OFF_DATA_OFFSET
Definition: PNanoVDB.h:1251
PNANOVDB_FORCE_INLINE void pnanovdb_tree_set_node_count_leaf(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p, pnanovdb_uint32_t node_count_leaf)
Definition: PNanoVDB.h:1359
PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_voxel_size(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t index, double voxel_size)
Definition: PNanoVDB.h:1201
PNANOVDB_FORCE_INLINE void pnanovdb_lower_set_bbox_min(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p, PNANOVDB_IN(pnanovdb_coord_t) bbox_min)
Definition: PNanoVDB.h:1553
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_grid_get_checksum(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:1129
#define PNANOVDB_LEAF_TABLE_NEG_OFF_BBOX_DIF_AND_FLAGS
Definition: PNanoVDB.h:1586
#define PNANOVDB_GRID_OFF_GRID_TYPE
Definition: PNanoVDB.h:1122
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_pointindex_get_last(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, pnanovdb_uint32_t i)
Definition: PNanoVDB.h:2099
#define PNANOVDB_LOWER_OFF_BBOX_MIN
Definition: PNanoVDB.h:1529
Definition: PNanoVDB.h:1390
pnanovdb_address_t address
Definition: PNanoVDB.h:1468
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_lower_get_ave_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t node)
Definition: PNanoVDB.h:2158
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindex_get_max_index(pnanovdb_buf_t buf, pnanovdb_address_t max_address)
Definition: PNanoVDB.h:1967
PNANOVDB_FORCE_INLINE void pnanovdb_tree_set_voxel_count(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p, pnanovdb_uint64_t voxel_count)
Definition: PNanoVDB.h:1377
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_readaccessor_get_value_address_and_level(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_uint32_t) level)
Definition: PNanoVDB.h:2655
PNANOVDB_FORCE_INLINE void pnanovdb_write_int64(pnanovdb_buf_t buf, pnanovdb_address_t address, pnanovdb_int64_t value)
Definition: PNanoVDB.h:904
PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_version(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t version)
Definition: PNanoVDB.h:1180
#define PNANOVDB_LEAF_TABLE_NEG_OFF_MINIMUM
Definition: PNanoVDB.h:1587
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindexmask_get_dev_index(pnanovdb_buf_t buf, pnanovdb_address_t dev_address)
Definition: PNanoVDB.h:2051
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_uint64_to_uint32_lsr(pnanovdb_uint64_t a, pnanovdb_uint32_t b)
Definition: PNanoVDB.h:644
#define PNANOVDB_GRID_OFF_VERSION
Definition: PNanoVDB.h:1112
pnanovdb_uint32_t leaf_off_table
Definition: PNanoVDB.h:1636
pnanovdb_coord_t bbox_min
Definition: PNanoVDB.h:1459
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_root_tile_get_state(pnanovdb_buf_t buf, pnanovdb_root_tile_handle_t p)
Definition: PNanoVDB.h:1443
pnanovdb_uint32_t root_off_background
Definition: PNanoVDB.h:1610
PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_lower_get_bbox_min(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p)
Definition: PNanoVDB.h:1535
PNANOVDB_FORCE_INLINE pnanovdb_int32_t pnanovdb_read_int32(pnanovdb_buf_t buf, pnanovdb_address_t address)
Definition: PNanoVDB.h:800
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_version(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:1132
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_upper_get_max_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t node)
Definition: PNanoVDB.h:2228
Definition: PNanoVDB.h:1105
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_leaf_is_active_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
Definition: PNanoVDB.h:2785
Definition: PNanoVDB.h:1021
PNANOVDB_FORCE_INLINE float pnanovdb_root_fp8_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk, pnanovdb_uint32_t level)
Definition: PNanoVDB.h:2376
pnanovdb_uint32_t data_type
Definition: PNanoVDB.h:1242
PNANOVDB_FORCE_INLINE void pnanovdb_tree_set_node_offset_upper(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p, pnanovdb_uint64_t node_offset_upper)
Definition: PNanoVDB.h:1353
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_node_count_upper(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p)
Definition: PNanoVDB.h:1331
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_upper_get_value_mask(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p, pnanovdb_uint32_t bit_index)
Definition: PNanoVDB.h:1489
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_leaf_index_has_stats(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf)
Definition: PNanoVDB.h:1851
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_root_get_min_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root)
Definition: PNanoVDB.h:2296
pnanovdb_uint32_t upper_off_stddev
Definition: PNanoVDB.h:1623
#define PNANOVDB_GRIDBLINDMETADATA_OFF_VALUE_SIZE
Definition: PNanoVDB.h:1253
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_upper_get_ave_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t node)
Definition: PNanoVDB.h:2234
PNANOVDB_FORCE_INLINE void pnanovdb_map_set_invmatf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index, float invmatf)
Definition: PNanoVDB.h:1063
PNANOVDB_FORCE_INLINE pnanovdb_int64_t pnanovdb_gridblindmetadata_get_data_offset(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p)
Definition: PNanoVDB.h:1259
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_pointindex_get_first(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, pnanovdb_uint32_t i)
Definition: PNanoVDB.h:2094
#define PNANOVDB_ROOT_TILE_OFF_CHILD
Definition: PNanoVDB.h:1434
PNANOVDB_FORCE_INLINE void pnanovdb_upper_set_bbox_max(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p, PNANOVDB_IN(pnanovdb_coord_t) bbox_max)
Definition: PNanoVDB.h:1501
PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_read_vec3(pnanovdb_buf_t buf, pnanovdb_address_t address)
Definition: PNanoVDB.h:824
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_indexmask_get_dev_index(pnanovdb_buf_t buf, pnanovdb_address_t dev_address)
Definition: PNanoVDB.h:1901
pnanovdb_uint32_t root_tile_off_value
Definition: PNanoVDB.h:1618
PNANOVDB_FORCE_INLINE double pnanovdb_grid_get_voxel_size(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:1158
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_indexmask_get_max_index(pnanovdb_buf_t buf, pnanovdb_address_t max_address)
Definition: PNanoVDB.h:1893
PNANOVDB_FORCE_INLINE void pnanovdb_leaf_pointindex_set_value_only(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, pnanovdb_uint32_t i, pnanovdb_uint32_t value)
Definition: PNanoVDB.h:2108
PNANOVDB_FORCE_INLINE void pnanovdb_tree_set_node_count_lower(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p, pnanovdb_uint32_t node_count_lower)
Definition: PNanoVDB.h:1362
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_leaf_onindexmask_has_stats(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf)
Definition: PNanoVDB.h:2035
#define PNANOVDB_LEAF_OFF_VALUE_MASK
Definition: PNanoVDB.h:1584
PNANOVDB_FORCE_INLINE void pnanovdb_leaf_set_bbox_dif_and_flags(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t p, pnanovdb_uint32_t bbox_dif_and_flags)
Definition: PNanoVDB.h:1604
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_read_uint16(pnanovdb_buf_t buf, pnanovdb_address_t address)
Definition: PNanoVDB.h:833
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindex_get_value_index(pnanovdb_buf_t buf, pnanovdb_address_t value_address, PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:2000
#define PNANOVDB_GRID_OFF_BLIND_METADATA_OFFSET
Definition: PNanoVDB.h:1123
PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_table_strides_bits[27]
Definition: PNanoVDB.h:999
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_tree_get_node_offset_root(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p)
Definition: PNanoVDB.h:1322
pnanovdb_uint32_t tile_count_upper
Definition: PNanoVDB.h:1292
Definition: PNanoVDB.h:1457
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_pointindex_get_point_count(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf)
Definition: PNanoVDB.h:2090
PNANOVDB_FORCE_INLINE float pnanovdb_leaf_fp16_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:1836
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_leaf_onindex_get_value_count(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf)
Definition: PNanoVDB.h:1936
pnanovdb_uint64_t node_offset_leaf
Definition: PNanoVDB.h:1283
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_root_get_value_address_bit(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_uint32_t) bit_index)
Definition: PNanoVDB.h:2354
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_uint64_offset(pnanovdb_uint64_t a, pnanovdb_uint32_t b)
Definition: PNanoVDB.h:634
PNANOVDB_FORCE_INLINE pnanovdb_int64_t pnanovdb_upper_get_table_child(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t node, pnanovdb_uint32_t n)
Definition: PNanoVDB.h:2252
pnanovdb_uint32_t tile_count_leaf
Definition: PNanoVDB.h:1290
#define PNANOVDB_MAP_OFF_VECD
Definition: PNanoVDB.h:1032
#define PNANOVDB_ROOT_OFF_TABLE_SIZE
Definition: PNanoVDB.h:1397
pnanovdb_uint64_t node_offset_root
Definition: PNanoVDB.h:1286
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_leaf_get_value_mask(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t p, pnanovdb_uint32_t bit_index)
Definition: PNanoVDB.h:1596
#define PNANOVDB_TREE_OFF_NODE_COUNT_LOWER
Definition: PNanoVDB.h:1306
PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_magic(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint64_t magic)
Definition: PNanoVDB.h:1174
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_gridblindmetadata_get_data_class(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p)
Definition: PNanoVDB.h:1271
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_upper_get_value_address_and_level(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t upper, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_uint32_t) level)
Definition: PNanoVDB.h:2265
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_uint64_bit_mask(pnanovdb_uint32_t bit_idx)
Definition: PNanoVDB.h:649
PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_minmax_aligns_bits[27]
Definition: PNanoVDB.h:1003
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_leaf_onindex_has_stats(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf)
Definition: PNanoVDB.h:1951
Definition: PNanoVDB.h:1468
PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_root_get_bbox_min(pnanovdb_buf_t buf, pnanovdb_root_handle_t p)
Definition: PNanoVDB.h:1399
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_root_get_value_address_and_level_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, PNANOVDB_INOUT(pnanovdb_uint32_t) level)
Definition: PNanoVDB.h:2625
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_root_is_active_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
Definition: PNanoVDB.h:2827
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_root_index_get_value_index(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk, pnanovdb_uint32_t level)
Definition: PNanoVDB.h:2418
pnanovdb_uint32_t upper_off_ave
Definition: PNanoVDB.h:1622
#define PNANOVDB_LEAF_TABLE_NEG_OFF_QUANTUM
Definition: PNanoVDB.h:1588
pnanovdb_uint32_t root_off_min
Definition: PNanoVDB.h:1611
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_indexmask_get_value_index(pnanovdb_buf_t buf, pnanovdb_address_t value_address, PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:1905
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_upper_coord_to_offset(PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:2215
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_upper_get_table_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t node, pnanovdb_uint32_t n)
Definition: PNanoVDB.h:2246
pnanovdb_coord_t bbox_min
Definition: PNanoVDB.h:1383
PNANOVDB_FORCE_INLINE void pnanovdb_map_set_vecf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index, float vecf)
Definition: PNanoVDB.h:1066
#define PNANOVDB_TREE_OFF_NODE_COUNT_UPPER
Definition: PNanoVDB.h:1307
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_root_onindex_get_value_index(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk, pnanovdb_uint32_t level)
Definition: PNanoVDB.h:2432
PNANOVDB_FORCE_INLINE float pnanovdb_map_get_taperf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:1044
pnanovdb_address_t address
Definition: PNanoVDB.h:1576
PNANOVDB_FORCE_INLINE void pnanovdb_upper_set_bbox_min(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p, PNANOVDB_IN(pnanovdb_coord_t) bbox_min)
Definition: PNanoVDB.h:1498
#define PNANOVDB_GRID_OFF_GRID_CLASS
Definition: PNanoVDB.h:1121
pnanovdb_uint64_t value_count
Definition: PNanoVDB.h:1238
PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_grid_size(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint64_t grid_size)
Definition: PNanoVDB.h:1192
#define PNANOVDB_GRID_TYPE_ONINDEX
Definition: PNanoVDB.h:959
PNANOVDB_FORCE_INLINE void pnanovdb_write_float(pnanovdb_buf_t buf, pnanovdb_address_t address, float value)
Definition: PNanoVDB.h:908
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_gridblindmetadata_get_name(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:1277
#define PNANOVDB_MAP_OFF_MATD
Definition: PNanoVDB.h:1030
Definition: PNanoVDB.h:1246
PNANOVDB_FORCE_INLINE void pnanovdb_leaf_pointindex_set_on(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, pnanovdb_uint32_t i)
Definition: PNanoVDB.h:2122
PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_grid_index_to_world_dirf(pnanovdb_buf_t buf, pnanovdb_grid_handle_t grid, PNANOVDB_IN(pnanovdb_vec3_t) src)
Definition: PNanoVDB.h:2942
#define PNANOVDB_GRID_OFF_GRID_NAME
Definition: PNanoVDB.h:1117
PNANOVDB_FORCE_INLINE void pnanovdb_tree_set_tile_count_leaf(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p, pnanovdb_uint32_t tile_count_leaf)
Definition: PNanoVDB.h:1368
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_blind_metadata_count(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:1170
PNANOVDB_FORCE_INLINE void pnanovdb_map_set_vecd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index, double vecd)
Definition: PNanoVDB.h:1078
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindex_get_last_offset(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf)
Definition: PNanoVDB.h:1944
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_gridblindmetadata_get_semantic(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p)
Definition: PNanoVDB.h:1268
PNANOVDB_FORCE_INLINE float pnanovdb_map_get_invmatf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:1038
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_lower_get_value_mask(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p, pnanovdb_uint32_t bit_index)
Definition: PNanoVDB.h:1544
pnanovdb_uint32_t leaf_off_stddev
Definition: PNanoVDB.h:1635
PNANOVDB_FORCE_INLINE pnanovdb_int64_t pnanovdb_root_tile_get_child(pnanovdb_buf_t buf, pnanovdb_root_tile_handle_t p)
Definition: PNanoVDB.h:1440
pnanovdb_uint32_t tile_count_lower
Definition: PNanoVDB.h:1291
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_leaf_get_min_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_leaf_handle_t node)
Definition: PNanoVDB.h:1772
#define PNANOVDB_GRID_OFF_MAP
Definition: PNanoVDB.h:1118
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_uint64_and(pnanovdb_uint64_t a, pnanovdb_uint64_t b)
Definition: PNanoVDB.h:654
PNANOVDB_FORCE_INLINE double pnanovdb_read_double(pnanovdb_buf_t buf, pnanovdb_address_t address)
Definition: PNanoVDB.h:812
#define PNANOVDB_TREE_OFF_NODE_OFFSET_UPPER
Definition: PNanoVDB.h:1303
pnanovdb_coord_t bbox_max
Definition: PNanoVDB.h:1384
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_root_get_value_address_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
Definition: PNanoVDB.h:2649
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_grid_get_grid_size(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:1144
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_root_get_value_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root, PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:2348
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_leaf_get_bbox_dif_and_flags(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t p)
Definition: PNanoVDB.h:1593
Definition: PNanoVDB.h:1009
PNANOVDB_FORCE_INLINE void pnanovdb_write_coord(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) value)
Definition: PNanoVDB.h:916
pnanovdb_uint64_t magic
Definition: PNanoVDB.h:1087
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_leaf_get_stddev_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_leaf_handle_t node)
Definition: PNanoVDB.h:1790
PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_blind_metadata_count(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t metadata_count)
Definition: PNanoVDB.h:1213
PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_grid_type(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t grid_type)
Definition: PNanoVDB.h:1207
pnanovdb_uint32_t node_count_upper
Definition: PNanoVDB.h:1289
PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_grid_count(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t grid_count)
Definition: PNanoVDB.h:1189
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_root_get_tile_count(pnanovdb_buf_t buf, pnanovdb_root_handle_t p)
Definition: PNanoVDB.h:1405
pnanovdb_uint32_t lower_off_stddev
Definition: PNanoVDB.h:1629
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_make_version(pnanovdb_uint32_t major, pnanovdb_uint32_t minor, pnanovdb_uint32_t patch_num)
Definition: PNanoVDB.h:1217
#define PNANOVDB_GRID_OFF_CHECKSUM
Definition: PNanoVDB.h:1111
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_index_get_max_index(pnanovdb_buf_t buf, pnanovdb_address_t max_address)
Definition: PNanoVDB.h:1861
PNANOVDB_FORCE_INLINE float pnanovdb_leaf_fpn_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:1841
Definition: PNanoVDB.h:1512
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_tree_get_node_offset_lower(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p)
Definition: PNanoVDB.h:1316
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_grid_type(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:1164
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_lower_get_dim_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t lower, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
Definition: PNanoVDB.h:2701
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_lower_get_value_address_and_level_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t lower, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, PNANOVDB_INOUT(pnanovdb_uint32_t) level)
Definition: PNanoVDB.h:2568
#define PNANOVDB_GRID_TYPE_POINTINDEX
Definition: PNanoVDB.h:962
PNANOVDB_FORCE_INLINE void pnanovdb_leaf_set_bbox_min(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t p, PNANOVDB_IN(pnanovdb_coord_t) bbox_min)
Definition: PNanoVDB.h:1601
pnanovdb_uint64_t flags
Definition: PNanoVDB.h:1461
PNANOVDB_FORCE_INLINE pnanovdb_map_handle_t pnanovdb_grid_get_map(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:1150
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_lower_get_max_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t node)
Definition: PNanoVDB.h:2152
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_grid_get_gridblindmetadata_value_address(pnanovdb_buf_t buf, pnanovdb_grid_handle_t grid, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:1684
PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_blind_metadata_offset(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint64_t blind_metadata_offset)
Definition: PNanoVDB.h:1210
PNANOVDB_FORCE_INLINE void pnanovdb_root_set_tile_count(pnanovdb_buf_t buf, pnanovdb_root_handle_t p, pnanovdb_uint32_t tile_count)
Definition: PNanoVDB.h:1415
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_lower_get_table_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t node, pnanovdb_uint32_t n)
Definition: PNanoVDB.h:2170
PNANOVDB_STATIC_CONST float pnanovdb_dither_lut[512]
Definition: PNanoVDB.h:3031
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_onindexmask_get_min_index(pnanovdb_buf_t buf, pnanovdb_address_t min_address)
Definition: PNanoVDB.h:2039
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_upper_get_dim_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_upper_handle_t upper, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
Definition: PNanoVDB.h:2719
PNANOVDB_FORCE_INLINE void pnanovdb_readaccessor_init(PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, pnanovdb_root_handle_t root)
Definition: PNanoVDB.h:2516
PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_grid_index_to_worldf(pnanovdb_buf_t buf, pnanovdb_grid_handle_t grid, PNANOVDB_IN(pnanovdb_vec3_t) src)
Definition: PNanoVDB.h:2930
PNANOVDB_FORCE_INLINE void pnanovdb_root_set_bbox_max(pnanovdb_buf_t buf, pnanovdb_root_handle_t p, PNANOVDB_IN(pnanovdb_coord_t) bbox_max)
Definition: PNanoVDB.h:1412
pnanovdb_uint32_t pad1
Definition: PNanoVDB.h:1386
PNANOVDB_FORCE_INLINE pnanovdb_upper_handle_t pnanovdb_root_get_child(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root, pnanovdb_root_tile_handle_t tile)
Definition: PNanoVDB.h:1722
pnanovdb_uint64_t node_offset_upper
Definition: PNanoVDB.h:1285
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_lower_coord_to_offset(PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:2139
const std::enable_if<!VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:106
#define PNANOVDB_GRIDBLINDMETADATA_OFF_SEMANTIC
Definition: PNanoVDB.h:1254
#define PNANOVDB_TREE_OFF_VOXEL_COUNT
Definition: PNanoVDB.h:1311
pnanovdb_coord_t bbox_max
Definition: PNanoVDB.h:1460
#define PNANOVDB_GRID_OFF_GRID_SIZE
Definition: PNanoVDB.h:1116
PNANOVDB_FORCE_INLINE void pnanovdb_map_set_matd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index, double matd)
Definition: PNanoVDB.h:1072
PNANOVDB_FORCE_INLINE double pnanovdb_map_get_matd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:1047
Definition: PNanoVDB.h:1428
PNANOVDB_FORCE_INLINE pnanovdb_root_tile_handle_t pnanovdb_root_get_tile_zero(pnanovdb_grid_type_t grid_type, pnanovdb_root_handle_t root)
Definition: PNanoVDB.h:1715
pnanovdb_uint32_t flags
Definition: PNanoVDB.h:1090
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_leaf_get_value_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:1802
pnanovdb_uint32_t grid_class
Definition: PNanoVDB.h:1098
Definition: PNanoVDB.h:2506
PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_grid_name(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t index, pnanovdb_uint32_t grid_name)
Definition: PNanoVDB.h:1195
#define PNANOVDB_GRID_OFF_GRID_INDEX
Definition: PNanoVDB.h:1114
#define PNANOVDB_TREE_OFF_NODE_OFFSET_LEAF
Definition: PNanoVDB.h:1301
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_flags(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:1135
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_leaf_get_ave_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_leaf_handle_t node)
Definition: PNanoVDB.h:1784
PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_map_apply(pnanovdb_buf_t buf, pnanovdb_map_handle_t map, PNANOVDB_IN(pnanovdb_vec3_t) src)
Definition: PNanoVDB.h:2876
PNANOVDB_FORCE_INLINE void pnanovdb_grid_set_grid_class(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t grid_class)
Definition: PNanoVDB.h:1204
#define PNANOVDB_GRID_OFF_BLIND_METADATA_COUNT
Definition: PNanoVDB.h:1124
#define PNANOVDB_MAP_OFF_TAPERD
Definition: PNanoVDB.h:1033
#define PNANOVDB_GRID_OFF_WORLD_BBOX
Definition: PNanoVDB.h:1119
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_root_get_value_address_and_level(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_uint32_t) level)
Definition: PNanoVDB.h:2326
pnanovdb_uint64_t key
Definition: PNanoVDB.h:1421
PNANOVDB_FORCE_INLINE void pnanovdb_map_set_matf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index, float matf)
Definition: PNanoVDB.h:1060
PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_map_apply_inverse_jacobi(pnanovdb_buf_t buf, pnanovdb_map_handle_t map, PNANOVDB_IN(pnanovdb_vec3_t) src)
Definition: PNanoVDB.h:2912
PNANOVDB_FORCE_INLINE pnanovdb_int64_t pnanovdb_read_int64(pnanovdb_buf_t buf, pnanovdb_address_t address)
Definition: PNanoVDB.h:808
PNANOVDB_FORCE_INLINE void pnanovdb_leaf_indexmask_set_mask_bit(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, pnanovdb_uint32_t n, pnanovdb_bool_t v)
Definition: PNanoVDB.h:1917
PNANOVDB_FORCE_INLINE pnanovdb_root_tile_handle_t pnanovdb_root_find_tile(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_handle_t root, PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:1746
pnanovdb_uint32_t leaf_off_ave
Definition: PNanoVDB.h:1634
PNANOVDB_FORCE_INLINE float pnanovdb_map_get_vecf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:1041
pnanovdb_uint32_t root_off_ave
Definition: PNanoVDB.h:1613
pnanovdb_uint32_t lower_size
Definition: PNanoVDB.h:1631
pnanovdb_int64_t child
Definition: PNanoVDB.h:1422
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_indexmask_get_min_index(pnanovdb_buf_t buf, pnanovdb_address_t min_address)
Definition: PNanoVDB.h:1889
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_version_get_patch(pnanovdb_uint32_t version)
Definition: PNanoVDB.h:1230
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_leaf_coord_to_offset(PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:1765
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_lower_get_min_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t node)
Definition: PNanoVDB.h:2146
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_grid_class(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:1161
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_coord_to_key(PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:1729
#define PNANOVDB_MAP_OFF_INVMATF
Definition: PNanoVDB.h:1027
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_lower_get_value_address_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_lower_handle_t lower, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
Definition: PNanoVDB.h:2588
PNANOVDB_FORCE_INLINE void pnanovdb_tree_set_node_offset_lower(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p, pnanovdb_uint64_t node_offset_lower)
Definition: PNanoVDB.h:1350
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_read_bit(pnanovdb_buf_t buf, pnanovdb_address_t address, pnanovdb_uint32_t bit_offset)
Definition: PNanoVDB.h:862
pnanovdb_uint32_t state
Definition: PNanoVDB.h:1423
double taperd
Definition: PNanoVDB.h:1018
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_leaf_indexmask_get_mask_bit(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, pnanovdb_uint32_t n)
Definition: PNanoVDB.h:1909
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_uint64_dec(pnanovdb_uint64_t a)
Definition: PNanoVDB.h:639
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_leaf_get_value_address_and_cache(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, PNANOVDB_IN(pnanovdb_coord_t) ijk, PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc)
Definition: PNanoVDB.h:2562
pnanovdb_root_handle_t root
Definition: PNanoVDB.h:2512
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_root_tile_get_value_address(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_root_tile_handle_t root_tile)
Definition: PNanoVDB.h:2320
PNANOVDB_FORCE_INLINE float pnanovdb_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address)
Definition: PNanoVDB.h:804
PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_grid_world_to_indexf(pnanovdb_buf_t buf, pnanovdb_grid_handle_t grid, PNANOVDB_IN(pnanovdb_vec3_t) src)
Definition: PNanoVDB.h:2924
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_read_uint8(pnanovdb_buf_t buf, pnanovdb_address_t address)
Definition: PNanoVDB.h:838
PNANOVDB_FORCE_INLINE void pnanovdb_tree_set_tile_count_upper(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p, pnanovdb_uint32_t tile_count_upper)
Definition: PNanoVDB.h:1374
pnanovdb_address_t address
Definition: PNanoVDB.h:1296