OpenVDB: nanovdb/PNanoVDB.h Source File

OpenVDB 10.0.1

PNanoVDB.h
Go to the documentation of this file.
1
2// Copyright Contributors to the OpenVDB Project
3// SPDX-License-Identifier: MPL-2.0
4
5/*!
6 \file 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#include <math.h>
60#endif
61
62// ------------------------------------------------ Buffer -----------------------------------------------------------
63
64#if defined(PNANOVDB_BUF_CUSTOM)
65// NOP
66#elif defined(PNANOVDB_C)
67#define PNANOVDB_BUF_C
68#elif defined(PNANOVDB_HLSL)
69#define PNANOVDB_BUF_HLSL
70#elif defined(PNANOVDB_GLSL)
71#define PNANOVDB_BUF_GLSL
72#endif
73
74#if defined(PNANOVDB_BUF_C)
75#include <stdint.h>
76#if defined(_WIN32)
77#define PNANOVDB_BUF_FORCE_INLINE static inline __forceinline
78#else
79#define PNANOVDB_BUF_FORCE_INLINE static inline __attribute__((always_inline))
80#endif
81typedef struct pnanovdb_buf_t
82{
83 uint32_t* data;
84#ifdef PNANOVDB_BUF_BOUNDS_CHECK
85 uint64_t size_in_words;
86#endif
87}pnanovdb_buf_t;
88PNANOVDB_BUF_FORCE_INLINE pnanovdb_buf_t pnanovdb_make_buf(uint32_t* data, uint64_t size_in_words)
89{
90 pnanovdb_buf_t ret;
91 ret.data = data;
92#ifdef PNANOVDB_BUF_BOUNDS_CHECK
93 ret.size_in_words = size_in_words;
94#endif
95 return ret;
96}
97#if defined(PNANOVDB_ADDRESS_32)
98PNANOVDB_BUF_FORCE_INLINE uint32_t pnanovdb_buf_read_uint32(pnanovdb_buf_t buf, uint32_t byte_offset)
99{
100 uint32_t wordaddress = (byte_offset >> 2u);
101#ifdef PNANOVDB_BUF_BOUNDS_CHECK
102 return wordaddress < buf.size_in_words ? buf.data[wordaddress] : 0u;
103#else
104 return buf.data[wordaddress];
105#endif
106}
107PNANOVDB_BUF_FORCE_INLINE uint64_t pnanovdb_buf_read_uint64(pnanovdb_buf_t buf, uint32_t byte_offset)
108{
109 uint64_t* data64 = (uint64_t*)buf.data;
110 uint32_t wordaddress64 = (byte_offset >> 3u);
111#ifdef PNANOVDB_BUF_BOUNDS_CHECK
112 uint64_t size_in_words64 = buf.size_in_words >> 1u;
113 return wordaddress64 < size_in_words64 ? data64[wordaddress64] : 0llu;
114#else
115 return data64[wordaddress64];
116#endif
117}
118#elif defined(PNANOVDB_ADDRESS_64)
119PNANOVDB_BUF_FORCE_INLINE uint32_t pnanovdb_buf_read_uint32(pnanovdb_buf_t buf, uint64_t byte_offset)
120{
121 uint64_t wordaddress = (byte_offset >> 2u);
122#ifdef PNANOVDB_BUF_BOUNDS_CHECK
123 return wordaddress < buf.size_in_words ? buf.data[wordaddress] : 0u;
124#else
125 return buf.data[wordaddress];
126#endif
127}
128PNANOVDB_BUF_FORCE_INLINE uint64_t pnanovdb_buf_read_uint64(pnanovdb_buf_t buf, uint64_t byte_offset)
129{
130 uint64_t* data64 = (uint64_t*)buf.data;
131 uint64_t wordaddress64 = (byte_offset >> 3u);
132#ifdef PNANOVDB_BUF_BOUNDS_CHECK
133 uint64_t size_in_words64 = buf.size_in_words >> 1u;
134 return wordaddress64 < size_in_words64 ? data64[wordaddress64] : 0llu;
135#else
136 return data64[wordaddress64];
137#endif
138}
139#endif
140typedef uint32_t pnanovdb_grid_type_t;
141#define PNANOVDB_GRID_TYPE_GET(grid_typeIn, nameIn) pnanovdb_grid_type_constants[grid_typeIn].nameIn
142#elif defined(PNANOVDB_BUF_HLSL)
143#if defined(PNANOVDB_ADDRESS_32)
144#define pnanovdb_buf_t StructuredBuffer<uint>
145uint pnanovdb_buf_read_uint32(pnanovdb_buf_t buf, uint byte_offset)
146{
147 return buf[(byte_offset >> 2u)];
148}
149uint2 pnanovdb_buf_read_uint64(pnanovdb_buf_t buf, uint byte_offset)
150{
151 uint2 ret;
152 ret.x = pnanovdb_buf_read_uint32(buf, byte_offset + 0u);
153 ret.y = pnanovdb_buf_read_uint32(buf, byte_offset + 4u);
154 return ret;
155}
156#elif defined(PNANOVDB_ADDRESS_64)
157#define pnanovdb_buf_t StructuredBuffer<uint>
158uint pnanovdb_buf_read_uint32(pnanovdb_buf_t buf, uint64_t byte_offset)
159{
160 return buf[uint(byte_offset >> 2u)];
161}
162uint64_t pnanovdb_buf_read_uint64(pnanovdb_buf_t buf, uint64_t byte_offset)
163{
164 uint64_t ret;
165 ret = pnanovdb_buf_read_uint32(buf, byte_offset + 0u);
166 ret = ret + (uint64_t(pnanovdb_buf_read_uint32(buf, byte_offset + 4u)) << 32u);
167 return ret;
168}
169#endif
170#define pnanovdb_grid_type_t uint
171#define PNANOVDB_GRID_TYPE_GET(grid_typeIn, nameIn) pnanovdb_grid_type_constants[grid_typeIn].nameIn
172#elif defined(PNANOVDB_BUF_GLSL)
173struct pnanovdb_buf_t
174{
175 uint unused; // to satisfy min struct size?
176};
177uint pnanovdb_buf_read_uint32(pnanovdb_buf_t buf, uint byte_offset)
178{
179 return pnanovdb_buf_data[(byte_offset >> 2u)];
180}
181uvec2 pnanovdb_buf_read_uint64(pnanovdb_buf_t buf, uint byte_offset)
182{
183 uvec2 ret;
184 ret.x = pnanovdb_buf_read_uint32(buf, byte_offset + 0u);
185 ret.y = pnanovdb_buf_read_uint32(buf, byte_offset + 4u);
186 return ret;
187}
188#define pnanovdb_grid_type_t uint
189#define PNANOVDB_GRID_TYPE_GET(grid_typeIn, nameIn) pnanovdb_grid_type_constants[grid_typeIn].nameIn
190#endif
191
192// ------------------------------------------------ Basic Types -----------------------------------------------------------
193
194// force inline
195#if defined(PNANOVDB_C)
196#if defined(_WIN32)
197#define PNANOVDB_FORCE_INLINE static inline __forceinline
198#else
199#define PNANOVDB_FORCE_INLINE static inline __attribute__((always_inline))
200#endif
201#elif defined(PNANOVDB_HLSL)
202#define PNANOVDB_FORCE_INLINE
203#elif defined(PNANOVDB_GLSL)
204#define PNANOVDB_FORCE_INLINE
205#endif
206
207// struct typedef, static const, inout
208#if defined(PNANOVDB_C)
209#define PNANOVDB_STRUCT_TYPEDEF(X) typedef struct X X;
210#define PNANOVDB_STATIC_CONST static const
211#define PNANOVDB_INOUT(X) X*
212#define PNANOVDB_IN(X) const X*
213#define PNANOVDB_DEREF(X) (*X)
214#define PNANOVDB_REF(X) &X
215#elif defined(PNANOVDB_HLSL)
216#define PNANOVDB_STRUCT_TYPEDEF(X)
217#define PNANOVDB_STATIC_CONST static const
218#define PNANOVDB_INOUT(X) inout X
219#define PNANOVDB_IN(X) X
220#define PNANOVDB_DEREF(X) X
221#define PNANOVDB_REF(X) X
222#elif defined(PNANOVDB_GLSL)
223#define PNANOVDB_STRUCT_TYPEDEF(X)
224#define PNANOVDB_STATIC_CONST const
225#define PNANOVDB_INOUT(X) inout X
226#define PNANOVDB_IN(X) X
227#define PNANOVDB_DEREF(X) X
228#define PNANOVDB_REF(X) X
229#endif
230
231// basic types, type conversion
232#if defined(PNANOVDB_C)
233#define PNANOVDB_NATIVE_64
234#include <stdint.h>
235#if !defined(PNANOVDB_MEMCPY_CUSTOM)
236#include <string.h>
237#define pnanovdb_memcpy memcpy
238#endif
239typedef uint32_t pnanovdb_uint32_t;
240typedef int32_t pnanovdb_int32_t;
241typedef int32_t pnanovdb_bool_t;
242#define PNANOVDB_FALSE 0
243#define PNANOVDB_TRUE 1
244typedef uint64_t pnanovdb_uint64_t;
245typedef int64_t pnanovdb_int64_t;
246typedef struct pnanovdb_coord_t
247{
248 pnanovdb_int32_t x, y, z;
249}pnanovdb_coord_t;
250typedef struct pnanovdb_vec3_t
251{
252 float x, y, z;
253}pnanovdb_vec3_t;
254PNANOVDB_FORCE_INLINE pnanovdb_int32_t pnanovdb_uint32_as_int32(pnanovdb_uint32_t v) { return (pnanovdb_int32_t)v; }
255PNANOVDB_FORCE_INLINE pnanovdb_int64_t pnanovdb_uint64_as_int64(pnanovdb_uint64_t v) { return (pnanovdb_int64_t)v; }
256PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_int64_as_uint64(pnanovdb_int64_t v) { return (pnanovdb_uint64_t)v; }
257PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_int32_as_uint32(pnanovdb_int32_t v) { return (pnanovdb_uint32_t)v; }
258PNANOVDB_FORCE_INLINE float pnanovdb_uint32_as_float(pnanovdb_uint32_t v) { float vf; pnanovdb_memcpy(&vf, &v, sizeof(vf)); return vf; }
259PNANOVDB_FORCE_INLINE double pnanovdb_uint64_as_double(pnanovdb_uint64_t v) { double vf; pnanovdb_memcpy(&vf, &v, sizeof(vf)); return vf; }
260PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_uint64_low(pnanovdb_uint64_t v) { return (pnanovdb_uint32_t)v; }
261PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_uint64_high(pnanovdb_uint64_t v) { return (pnanovdb_uint32_t)(v >> 32u); }
262PNANOVDB_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); }
263PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_uint32_as_uint64_low(pnanovdb_uint32_t x) { return ((pnanovdb_uint64_t)x); }
264PNANOVDB_FORCE_INLINE pnanovdb_int32_t pnanovdb_uint64_is_equal(pnanovdb_uint64_t a, pnanovdb_uint64_t b) { return a == b; }
265PNANOVDB_FORCE_INLINE pnanovdb_int32_t pnanovdb_int64_is_zero(pnanovdb_int64_t a) { return a == 0; }
266#ifdef PNANOVDB_CMATH
267PNANOVDB_FORCE_INLINE float pnanovdb_floor(float v) { return floorf(v); }
268#endif
269PNANOVDB_FORCE_INLINE pnanovdb_int32_t pnanovdb_float_to_int32(float v) { return (pnanovdb_int32_t)v; }
270PNANOVDB_FORCE_INLINE float pnanovdb_int32_to_float(pnanovdb_int32_t v) { return (float)v; }
271PNANOVDB_FORCE_INLINE float pnanovdb_uint32_to_float(pnanovdb_uint32_t v) { return (float)v; }
272PNANOVDB_FORCE_INLINE float pnanovdb_min(float a, float b) { return a < b ? a : b; }
273PNANOVDB_FORCE_INLINE float pnanovdb_max(float a, float b) { return a > b ? a : b; }
274#elif defined(PNANOVDB_HLSL)
275typedef uint pnanovdb_uint32_t;
276typedef int pnanovdb_int32_t;
277typedef bool pnanovdb_bool_t;
278#define PNANOVDB_FALSE false
279#define PNANOVDB_TRUE true
280typedef int3 pnanovdb_coord_t;
281typedef float3 pnanovdb_vec3_t;
282pnanovdb_int32_t pnanovdb_uint32_as_int32(pnanovdb_uint32_t v) { return int(v); }
283pnanovdb_uint32_t pnanovdb_int32_as_uint32(pnanovdb_int32_t v) { return uint(v); }
284float pnanovdb_uint32_as_float(pnanovdb_uint32_t v) { return asfloat(v); }
285float pnanovdb_floor(float v) { return floor(v); }
286pnanovdb_int32_t pnanovdb_float_to_int32(float v) { return int(v); }
287float pnanovdb_int32_to_float(pnanovdb_int32_t v) { return float(v); }
288float pnanovdb_uint32_to_float(pnanovdb_uint32_t v) { return float(v); }
289float pnanovdb_min(float a, float b) { return min(a, b); }
290float pnanovdb_max(float a, float b) { return max(a, b); }
291#if defined(PNANOVDB_ADDRESS_32)
292typedef uint2 pnanovdb_uint64_t;
293typedef int2 pnanovdb_int64_t;
294pnanovdb_int64_t pnanovdb_uint64_as_int64(pnanovdb_uint64_t v) { return int2(v); }
295pnanovdb_uint64_t pnanovdb_int64_as_uint64(pnanovdb_int64_t v) { return uint2(v); }
296double pnanovdb_uint64_as_double(pnanovdb_uint64_t v) { return asdouble(v.x, v.y); }
297pnanovdb_uint32_t pnanovdb_uint64_low(pnanovdb_uint64_t v) { return v.x; }
298pnanovdb_uint32_t pnanovdb_uint64_high(pnanovdb_uint64_t v) { return v.y; }
299pnanovdb_uint64_t pnanovdb_uint32_as_uint64(pnanovdb_uint32_t x, pnanovdb_uint32_t y) { return uint2(x, y); }
300pnanovdb_uint64_t pnanovdb_uint32_as_uint64_low(pnanovdb_uint32_t x) { return uint2(x, 0); }
301bool pnanovdb_uint64_is_equal(pnanovdb_uint64_t a, pnanovdb_uint64_t b) { return (a.x == b.x) && (a.y == b.y); }
302bool pnanovdb_int64_is_zero(pnanovdb_int64_t a) { return a.x == 0 && a.y == 0; }
303#else
304typedef uint64_t pnanovdb_uint64_t;
305typedef int64_t pnanovdb_int64_t;
306pnanovdb_int64_t pnanovdb_uint64_as_int64(pnanovdb_uint64_t v) { return int64_t(v); }
307pnanovdb_uint64_t pnanovdb_int64_as_uint64(pnanovdb_int64_t v) { return uint64_t(v); }
308double pnanovdb_uint64_as_double(pnanovdb_uint64_t v) { return asdouble(uint(v), uint(v >> 32u)); }
309pnanovdb_uint32_t pnanovdb_uint64_low(pnanovdb_uint64_t v) { return uint(v); }
310pnanovdb_uint32_t pnanovdb_uint64_high(pnanovdb_uint64_t v) { return uint(v >> 32u); }
311pnanovdb_uint64_t pnanovdb_uint32_as_uint64(pnanovdb_uint32_t x, pnanovdb_uint32_t y) { return uint64_t(x) + (uint64_t(y) << 32u); }
312pnanovdb_uint64_t pnanovdb_uint32_as_uint64_low(pnanovdb_uint32_t x) { return uint64_t(x); }
313bool pnanovdb_uint64_is_equal(pnanovdb_uint64_t a, pnanovdb_uint64_t b) { return a == b; }
314bool pnanovdb_int64_is_zero(pnanovdb_int64_t a) { return a == 0; }
315#endif
316#elif defined(PNANOVDB_GLSL)
317#define pnanovdb_uint32_t uint
318#define pnanovdb_int32_t int
319#define pnanovdb_bool_t bool
320#define PNANOVDB_FALSE false
321#define PNANOVDB_TRUE true
322#define pnanovdb_uint64_t uvec2
323#define pnanovdb_int64_t ivec2
324#define pnanovdb_coord_t ivec3
325#define pnanovdb_vec3_t vec3
326pnanovdb_int32_t pnanovdb_uint32_as_int32(pnanovdb_uint32_t v) { return int(v); }
327pnanovdb_int64_t pnanovdb_uint64_as_int64(pnanovdb_uint64_t v) { return ivec2(v); }
328pnanovdb_uint64_t pnanovdb_int64_as_uint64(pnanovdb_int64_t v) { return uvec2(v); }
329pnanovdb_uint32_t pnanovdb_int32_as_uint32(pnanovdb_int32_t v) { return uint(v); }
330float pnanovdb_uint32_as_float(pnanovdb_uint32_t v) { return uintBitsToFloat(v); }
331double pnanovdb_uint64_as_double(pnanovdb_uint64_t v) { return packDouble2x32(uvec2(v.x, v.y)); }
332pnanovdb_uint32_t pnanovdb_uint64_low(pnanovdb_uint64_t v) { return v.x; }
333pnanovdb_uint32_t pnanovdb_uint64_high(pnanovdb_uint64_t v) { return v.y; }
334pnanovdb_uint64_t pnanovdb_uint32_as_uint64(pnanovdb_uint32_t x, pnanovdb_uint32_t y) { return uvec2(x, y); }
335pnanovdb_uint64_t pnanovdb_uint32_as_uint64_low(pnanovdb_uint32_t x) { return uvec2(x, 0); }
336bool pnanovdb_uint64_is_equal(pnanovdb_uint64_t a, pnanovdb_uint64_t b) { return (a.x == b.x) && (a.y == b.y); }
337bool pnanovdb_int64_is_zero(pnanovdb_int64_t a) { return a.x == 0 && a.y == 0; }
338float pnanovdb_floor(float v) { return floor(v); }
339pnanovdb_int32_t pnanovdb_float_to_int32(float v) { return int(v); }
340float pnanovdb_int32_to_float(pnanovdb_int32_t v) { return float(v); }
341float pnanovdb_uint32_to_float(pnanovdb_uint32_t v) { return float(v); }
342float pnanovdb_min(float a, float b) { return min(a, b); }
343float pnanovdb_max(float a, float b) { return max(a, b); }
344#endif
345
346// ------------------------------------------------ Coord/Vec3 Utilties -----------------------------------------------------------
347
348#if defined(PNANOVDB_C)
349PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_vec3_uniform(float a)
350{
351 pnanovdb_vec3_t v;
352 v.x = a;
353 v.y = a;
354 v.z = a;
355 return v;
356}
357PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_vec3_add(const pnanovdb_vec3_t a, const pnanovdb_vec3_t b)
358{
359 pnanovdb_vec3_t v;
360 v.x = a.x + b.x;
361 v.y = a.y + b.y;
362 v.z = a.z + b.z;
363 return v;
364}
365PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_vec3_sub(const pnanovdb_vec3_t a, const pnanovdb_vec3_t b)
366{
367 pnanovdb_vec3_t v;
368 v.x = a.x - b.x;
369 v.y = a.y - b.y;
370 v.z = a.z - b.z;
371 return v;
372}
373PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_vec3_mul(const pnanovdb_vec3_t a, const pnanovdb_vec3_t b)
374{
375 pnanovdb_vec3_t v;
376 v.x = a.x * b.x;
377 v.y = a.y * b.y;
378 v.z = a.z * b.z;
379 return v;
380}
381PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_vec3_div(const pnanovdb_vec3_t a, const pnanovdb_vec3_t b)
382{
383 pnanovdb_vec3_t v;
384 v.x = a.x / b.x;
385 v.y = a.y / b.y;
386 v.z = a.z / b.z;
387 return v;
388}
389PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_vec3_min(const pnanovdb_vec3_t a, const pnanovdb_vec3_t b)
390{
391 pnanovdb_vec3_t v;
392 v.x = a.x < b.x ? a.x : b.x;
393 v.y = a.y < b.y ? a.y : b.y;
394 v.z = a.z < b.z ? a.z : b.z;
395 return v;
396}
397PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_vec3_max(const pnanovdb_vec3_t a, const pnanovdb_vec3_t b)
398{
399 pnanovdb_vec3_t v;
400 v.x = a.x > b.x ? a.x : b.x;
401 v.y = a.y > b.y ? a.y : b.y;
402 v.z = a.z > b.z ? a.z : b.z;
403 return v;
404}
405PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_coord_to_vec3(const pnanovdb_coord_t coord)
406{
407 pnanovdb_vec3_t v;
408 v.x = pnanovdb_int32_to_float(coord.x);
409 v.y = pnanovdb_int32_to_float(coord.y);
410 v.z = pnanovdb_int32_to_float(coord.z);
411 return v;
412}
413PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_coord_uniform(const pnanovdb_int32_t a)
414{
415 pnanovdb_coord_t v;
416 v.x = a;
417 v.y = a;
418 v.z = a;
419 return v;
420}
421PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_coord_add(pnanovdb_coord_t a, pnanovdb_coord_t b)
422{
423 pnanovdb_coord_t v;
424 v.x = a.x + b.x;
425 v.y = a.y + b.y;
426 v.z = a.z + b.z;
427 return v;
428}
429#elif defined(PNANOVDB_HLSL)
430pnanovdb_vec3_t pnanovdb_vec3_uniform(float a) { return float3(a, a, a); }
431pnanovdb_vec3_t pnanovdb_vec3_add(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return a + b; }
432pnanovdb_vec3_t pnanovdb_vec3_sub(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return a - b; }
433pnanovdb_vec3_t pnanovdb_vec3_mul(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return a * b; }
434pnanovdb_vec3_t pnanovdb_vec3_div(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return a / b; }
435pnanovdb_vec3_t pnanovdb_vec3_min(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return min(a, b); }
436pnanovdb_vec3_t pnanovdb_vec3_max(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return max(a, b); }
437pnanovdb_vec3_t pnanovdb_coord_to_vec3(pnanovdb_coord_t coord) { return float3(coord); }
438pnanovdb_coord_t pnanovdb_coord_uniform(pnanovdb_int32_t a) { return int3(a, a, a); }
439pnanovdb_coord_t pnanovdb_coord_add(pnanovdb_coord_t a, pnanovdb_coord_t b) { return a + b; }
440#elif defined(PNANOVDB_GLSL)
441pnanovdb_vec3_t pnanovdb_vec3_uniform(float a) { return vec3(a, a, a); }
442pnanovdb_vec3_t pnanovdb_vec3_add(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return a + b; }
443pnanovdb_vec3_t pnanovdb_vec3_sub(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return a - b; }
444pnanovdb_vec3_t pnanovdb_vec3_mul(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return a * b; }
445pnanovdb_vec3_t pnanovdb_vec3_div(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return a / b; }
446pnanovdb_vec3_t pnanovdb_vec3_min(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return min(a, b); }
447pnanovdb_vec3_t pnanovdb_vec3_max(pnanovdb_vec3_t a, pnanovdb_vec3_t b) { return max(a, b); }
448pnanovdb_vec3_t pnanovdb_coord_to_vec3(const pnanovdb_coord_t coord) { return vec3(coord); }
449pnanovdb_coord_t pnanovdb_coord_uniform(pnanovdb_int32_t a) { return ivec3(a, a, a); }
450pnanovdb_coord_t pnanovdb_coord_add(pnanovdb_coord_t a, pnanovdb_coord_t b) { return a + b; }
451#endif
452
453// ------------------------------------------------ Address Type -----------------------------------------------------------
454
455#if defined(PNANOVDB_ADDRESS_32)
456struct pnanovdb_address_t
457{
458 pnanovdb_uint32_t byte_offset;
459};
460PNANOVDB_STRUCT_TYPEDEF(pnanovdb_address_t)
461
462PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_offset(pnanovdb_address_t address, pnanovdb_uint32_t byte_offset)
463{
464 pnanovdb_address_t ret = address;
465 ret.byte_offset += byte_offset;
466 return ret;
467}
468PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_offset_neg(pnanovdb_address_t address, pnanovdb_uint32_t byte_offset)
469{
470 pnanovdb_address_t ret = address;
471 ret.byte_offset -= byte_offset;
472 return ret;
473}
474PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_offset_product(pnanovdb_address_t address, pnanovdb_uint32_t byte_offset, pnanovdb_uint32_t multiplier)
475{
476 pnanovdb_address_t ret = address;
477 ret.byte_offset += byte_offset * multiplier;
478 return ret;
479}
480PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_offset64(pnanovdb_address_t address, pnanovdb_uint64_t byte_offset)
481{
482 pnanovdb_address_t ret = address;
483 // lose high bits on 32-bit
484 ret.byte_offset += pnanovdb_uint64_low(byte_offset);
485 return ret;
486}
487PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_address_mask(pnanovdb_address_t address, pnanovdb_uint32_t mask)
488{
489 return address.byte_offset & mask;
490}
491PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_mask_inv(pnanovdb_address_t address, pnanovdb_uint32_t mask)
492{
493 pnanovdb_address_t ret = address;
494 ret.byte_offset &= (~mask);
495 return ret;
496}
497PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_null()
498{
499 pnanovdb_address_t ret = { 0 };
500 return ret;
501}
502PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_address_is_null(pnanovdb_address_t address)
503{
504 return address.byte_offset == 0u;
505}
506PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_address_in_interval(pnanovdb_address_t address, pnanovdb_address_t min_address, pnanovdb_address_t max_address)
507{
508 return address.byte_offset >= min_address.byte_offset && address.byte_offset < max_address.byte_offset;
509}
510#elif defined(PNANOVDB_ADDRESS_64)
511struct pnanovdb_address_t
512{
513 pnanovdb_uint64_t byte_offset;
514};
515PNANOVDB_STRUCT_TYPEDEF(pnanovdb_address_t)
516
517PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_offset(pnanovdb_address_t address, pnanovdb_uint32_t byte_offset)
518{
519 pnanovdb_address_t ret = address;
520 ret.byte_offset += byte_offset;
521 return ret;
522}
523PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_offset_neg(pnanovdb_address_t address, pnanovdb_uint32_t byte_offset)
524{
525 pnanovdb_address_t ret = address;
526 ret.byte_offset -= byte_offset;
527 return ret;
528}
529PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_offset_product(pnanovdb_address_t address, pnanovdb_uint32_t byte_offset, pnanovdb_uint32_t multiplier)
530{
531 pnanovdb_address_t ret = address;
532 ret.byte_offset += pnanovdb_uint32_as_uint64_low(byte_offset) * pnanovdb_uint32_as_uint64_low(multiplier);
533 return ret;
534}
535PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_offset64(pnanovdb_address_t address, pnanovdb_uint64_t byte_offset)
536{
537 pnanovdb_address_t ret = address;
538 ret.byte_offset += byte_offset;
539 return ret;
540}
541PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_address_mask(pnanovdb_address_t address, pnanovdb_uint32_t mask)
542{
543 return pnanovdb_uint64_low(address.byte_offset) & mask;
544}
545PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_mask_inv(pnanovdb_address_t address, pnanovdb_uint32_t mask)
546{
547 pnanovdb_address_t ret = address;
548 ret.byte_offset &= (~pnanovdb_uint32_as_uint64_low(mask));
549 return ret;
550}
551PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanovdb_address_null()
552{
553 pnanovdb_address_t ret = { 0 };
554 return ret;
555}
556PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_address_is_null(pnanovdb_address_t address)
557{
558 return address.byte_offset == 0llu;
559}
560PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_address_in_interval(pnanovdb_address_t address, pnanovdb_address_t min_address, pnanovdb_address_t max_address)
561{
562 return address.byte_offset >= min_address.byte_offset && address.byte_offset < max_address.byte_offset;
563}
564#endif
565
566// ------------------------------------------------ High Level Buffer Read -----------------------------------------------------------
567
568PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_read_uint32(pnanovdb_buf_t buf, pnanovdb_address_t address)
569{
570 return pnanovdb_buf_read_uint32(buf, address.byte_offset);
571}
572PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_read_uint64(pnanovdb_buf_t buf, pnanovdb_address_t address)
573{
574 return pnanovdb_buf_read_uint64(buf, address.byte_offset);
575}
576PNANOVDB_FORCE_INLINE pnanovdb_int32_t pnanovdb_read_int32(pnanovdb_buf_t buf, pnanovdb_address_t address)
577{
578 return pnanovdb_uint32_as_int32(pnanovdb_read_uint32(buf, address));
579}
580PNANOVDB_FORCE_INLINE float pnanovdb_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address)
581{
582 return pnanovdb_uint32_as_float(pnanovdb_read_uint32(buf, address));
583}
584PNANOVDB_FORCE_INLINE pnanovdb_int64_t pnanovdb_read_int64(pnanovdb_buf_t buf, pnanovdb_address_t address)
585{
586 return pnanovdb_uint64_as_int64(pnanovdb_read_uint64(buf, address));
587}
588PNANOVDB_FORCE_INLINE double pnanovdb_read_double(pnanovdb_buf_t buf, pnanovdb_address_t address)
589{
590 return pnanovdb_uint64_as_double(pnanovdb_read_uint64(buf, address));
591}
592PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_read_coord(pnanovdb_buf_t buf, pnanovdb_address_t address)
593{
594 pnanovdb_coord_t ret;
595 ret.x = pnanovdb_uint32_as_int32(pnanovdb_read_uint32(buf, pnanovdb_address_offset(address, 0u)));
596 ret.y = pnanovdb_uint32_as_int32(pnanovdb_read_uint32(buf, pnanovdb_address_offset(address, 4u)));
597 ret.z = pnanovdb_uint32_as_int32(pnanovdb_read_uint32(buf, pnanovdb_address_offset(address, 8u)));
598 return ret;
599}
600
601PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_read_bit(pnanovdb_buf_t buf, pnanovdb_address_t address, pnanovdb_uint32_t bit_offset)
602{
603 pnanovdb_address_t word_address = pnanovdb_address_mask_inv(address, 3u);
604 pnanovdb_uint32_t bit_index = (pnanovdb_address_mask(address, 3u) << 3u) + bit_offset;
605 pnanovdb_uint32_t value_word = pnanovdb_buf_read_uint32(buf, word_address.byte_offset);
606 return ((value_word >> bit_index) & 1) != 0u;
607}
608
609#if defined(PNANOVDB_C)
610PNANOVDB_FORCE_INLINE short pnanovdb_read_half(pnanovdb_buf_t buf, pnanovdb_address_t address)
611{
612 pnanovdb_uint32_t raw = pnanovdb_read_uint32(buf, address);
613 return (short)(raw >> (pnanovdb_address_mask(address, 2) << 3));
614}
615#elif defined(PNANOVDB_HLSL)
616PNANOVDB_FORCE_INLINE float pnanovdb_read_half(pnanovdb_buf_t buf, pnanovdb_address_t address)
617{
618 pnanovdb_uint32_t raw = pnanovdb_read_uint32(buf, address);
619 return f16tof32(raw >> (pnanovdb_address_mask(address, 2) << 3));
620}
621#elif defined(PNANOVDB_GLSL)
622PNANOVDB_FORCE_INLINE float pnanovdb_read_half(pnanovdb_buf_t buf, pnanovdb_address_t address)
623{
624 pnanovdb_uint32_t raw = pnanovdb_read_uint32(buf, address);
625 return unpackHalf2x16(raw >> (pnanovdb_address_mask(address, 2) << 3)).x;
626}
627#endif
628
629// ------------------------------------------------ Core Structures -----------------------------------------------------------
630
631#define PNANOVDB_MAGIC_NUMBER 0x304244566f6e614eUL// "NanoVDB0" in hex - little endian (uint64_t)
632
633#define PNANOVDB_MAJOR_VERSION_NUMBER 32// reflects changes to the ABI
634#define PNANOVDB_MINOR_VERSION_NUMBER 4// reflects changes to the API but not ABI
635#define PNANOVDB_PATCH_VERSION_NUMBER 2// reflects bug-fixes with no ABI or API changes
636
637#define PNANOVDB_GRID_TYPE_UNKNOWN 0
638#define PNANOVDB_GRID_TYPE_FLOAT 1
639#define PNANOVDB_GRID_TYPE_DOUBLE 2
640#define PNANOVDB_GRID_TYPE_INT16 3
641#define PNANOVDB_GRID_TYPE_INT32 4
642#define PNANOVDB_GRID_TYPE_INT64 5
643#define PNANOVDB_GRID_TYPE_VEC3F 6
644#define PNANOVDB_GRID_TYPE_VEC3D 7
645#define PNANOVDB_GRID_TYPE_MASK 8
646#define PNANOVDB_GRID_TYPE_HALF 9
647#define PNANOVDB_GRID_TYPE_UINT32 10
648#define PNANOVDB_GRID_TYPE_BOOLEAN 11
649#define PNANOVDB_GRID_TYPE_RGBA8 12
650#define PNANOVDB_GRID_TYPE_FP4 13
651#define PNANOVDB_GRID_TYPE_FP8 14
652#define PNANOVDB_GRID_TYPE_FP16 15
653#define PNANOVDB_GRID_TYPE_FPN 16
654#define PNANOVDB_GRID_TYPE_VEC4F 17
655#define PNANOVDB_GRID_TYPE_VEC4D 18
656#define PNANOVDB_GRID_TYPE_INDEX 19
657#define PNANOVDB_GRID_TYPE_END 20
658
659#define PNANOVDB_GRID_CLASS_UNKNOWN 0
660#define PNANOVDB_GRID_CLASS_LEVEL_SET 1 // narrow band levelset, e.g. SDF
661#define PNANOVDB_GRID_CLASS_FOG_VOLUME 2 // fog volume, e.g. density
662#define PNANOVDB_GRID_CLASS_STAGGERED 3 // staggered MAC grid, e.g. velocity
663#define PNANOVDB_GRID_CLASS_POINT_INDEX 4 // point index grid
664#define PNANOVDB_GRID_CLASS_POINT_DATA 5 // point data grid
665#define PNANOVDB_GRID_CLASS_TOPOLOGY 6 // grid with active states only (no values)
666#define PNANOVDB_GRID_CLASS_VOXEL_VOLUME 7 // volume of geometric cubes, e.g. minecraft
667#define PNANOVDB_GRID_CLASS_INDEX_GRID 8 // grid whose values are offsets, e.g. into an external array
668#define PNANOVDB_GRID_CLASS_END 9
669
670#define PNANOVDB_GRID_FLAGS_HAS_LONG_GRID_NAME (1 << 0)
671#define PNANOVDB_GRID_FLAGS_HAS_BBOX (1 << 1)
672#define PNANOVDB_GRID_FLAGS_HAS_MIN_MAX (1 << 2)
673#define PNANOVDB_GRID_FLAGS_HAS_AVERAGE (1 << 3)
674#define PNANOVDB_GRID_FLAGS_HAS_STD_DEVIATION (1 << 4)
675#define PNANOVDB_GRID_FLAGS_IS_BREADTH_FIRST (1 << 5)
676#define PNANOVDB_GRID_FLAGS_END (1 << 6)
677
678#define PNANOVDB_LEAF_TYPE_DEFAULT 0
679#define PNANOVDB_LEAF_TYPE_LITE 1
680#define PNANOVDB_LEAF_TYPE_FP 2
681#define PNANOVDB_LEAF_TYPE_INDEX 3
682
683PNANOVDB_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 };
684PNANOVDB_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 };
685PNANOVDB_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 };
686PNANOVDB_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 };
687PNANOVDB_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 };
688PNANOVDB_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 };
689
690 struct pnanovdb_map_t
691{
692 float matf[9];
693 float invmatf[9];
694 float vecf[3];
695 float taperf;
696 double matd[9];
697 double invmatd[9];
698 double vecd[3];
699 double taperd;
700};
701PNANOVDB_STRUCT_TYPEDEF(pnanovdb_map_t)
702struct pnanovdb_map_handle_t { pnanovdb_address_t address; };
703PNANOVDB_STRUCT_TYPEDEF(pnanovdb_map_handle_t)
704
705#define PNANOVDB_MAP_SIZE 264
706
707#define PNANOVDB_MAP_OFF_MATF 0
708#define PNANOVDB_MAP_OFF_INVMATF 36
709#define PNANOVDB_MAP_OFF_VECF 72
710#define PNANOVDB_MAP_OFF_TAPERF 84
711#define PNANOVDB_MAP_OFF_MATD 88
712#define PNANOVDB_MAP_OFF_INVMATD 160
713#define PNANOVDB_MAP_OFF_VECD 232
714#define PNANOVDB_MAP_OFF_TAPERD 256
715
716PNANOVDB_FORCE_INLINE float pnanovdb_map_get_matf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index) {
717 return pnanovdb_read_float(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_MATF + 4u * index));
718}
719PNANOVDB_FORCE_INLINE float pnanovdb_map_get_invmatf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index) {
720 return pnanovdb_read_float(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_INVMATF + 4u * index));
721}
722PNANOVDB_FORCE_INLINE float pnanovdb_map_get_vecf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index) {
723 return pnanovdb_read_float(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_VECF + 4u * index));
724}
725PNANOVDB_FORCE_INLINE float pnanovdb_map_get_taperf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index) {
726 return pnanovdb_read_float(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_TAPERF));
727}
728PNANOVDB_FORCE_INLINE double pnanovdb_map_get_matd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index) {
729 return pnanovdb_read_double(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_MATD + 8u * index));
730}
731PNANOVDB_FORCE_INLINE double pnanovdb_map_get_invmatd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index) {
732 return pnanovdb_read_double(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_INVMATD + 8u * index));
733}
734PNANOVDB_FORCE_INLINE double pnanovdb_map_get_vecd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index) {
735 return pnanovdb_read_double(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_VECD + 8u * index));
736}
737PNANOVDB_FORCE_INLINE double pnanovdb_map_get_taperd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index) {
738 return pnanovdb_read_double(buf, pnanovdb_address_offset(p.address, PNANOVDB_MAP_OFF_TAPERD));
739}
740
741 struct pnanovdb_grid_t
742{
743 pnanovdb_uint64_t magic; // 8 bytes, 0
744 pnanovdb_uint64_t checksum; // 8 bytes, 8
745 pnanovdb_uint32_t version; // 4 bytes, 16
746 pnanovdb_uint32_t flags; // 4 bytes, 20
747 pnanovdb_uint32_t grid_index; // 4 bytes, 24
748 pnanovdb_uint32_t grid_count; // 4 bytes, 28
749 pnanovdb_uint64_t grid_size; // 8 bytes, 32
750 pnanovdb_uint32_t grid_name[256 / 4]; // 256 bytes, 40
751 pnanovdb_map_t map; // 264 bytes, 296
752 double world_bbox[6]; // 48 bytes, 560
753 double voxel_size[3]; // 24 bytes, 608
754 pnanovdb_uint32_t grid_class; // 4 bytes, 632
755 pnanovdb_uint32_t grid_type; // 4 bytes, 636
756 pnanovdb_int64_t blind_metadata_offset; // 8 bytes, 640
757 pnanovdb_uint32_t blind_metadata_count; // 4 bytes, 648
758 pnanovdb_uint32_t pad[5]; // 20 bytes, 652
759};
760PNANOVDB_STRUCT_TYPEDEF(pnanovdb_grid_t)
761struct pnanovdb_grid_handle_t { pnanovdb_address_t address; };
762PNANOVDB_STRUCT_TYPEDEF(pnanovdb_grid_handle_t)
763
764#define PNANOVDB_GRID_SIZE 672
765
766#define PNANOVDB_GRID_OFF_MAGIC 0
767#define PNANOVDB_GRID_OFF_CHECKSUM 8
768#define PNANOVDB_GRID_OFF_VERSION 16
769#define PNANOVDB_GRID_OFF_FLAGS 20
770#define PNANOVDB_GRID_OFF_GRID_INDEX 24
771#define PNANOVDB_GRID_OFF_GRID_COUNT 28
772#define PNANOVDB_GRID_OFF_GRID_SIZE 32
773#define PNANOVDB_GRID_OFF_GRID_NAME 40
774#define PNANOVDB_GRID_OFF_MAP 296
775#define PNANOVDB_GRID_OFF_WORLD_BBOX 560
776#define PNANOVDB_GRID_OFF_VOXEL_SIZE 608
777#define PNANOVDB_GRID_OFF_GRID_CLASS 632
778#define PNANOVDB_GRID_OFF_GRID_TYPE 636
779#define PNANOVDB_GRID_OFF_BLIND_METADATA_OFFSET 640
780#define PNANOVDB_GRID_OFF_BLIND_METADATA_COUNT 648
781
782PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_grid_get_magic(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
783 return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_MAGIC));
784}
785PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_grid_get_checksum(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
786 return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_CHECKSUM));
787}
788PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_version(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
789 return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_VERSION));
790}
791PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_flags(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
792 return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_FLAGS));
793}
794PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_grid_index(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
795 return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_GRID_INDEX));
796}
797PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_grid_count(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
798 return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_GRID_COUNT));
799}
800PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_grid_get_grid_size(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
801 return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_GRID_SIZE));
802}
803PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_grid_name(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t index) {
804 return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_GRID_NAME + 4u * index));
805}
806PNANOVDB_FORCE_INLINE pnanovdb_map_handle_t pnanovdb_grid_get_map(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
807 pnanovdb_map_handle_t ret;
808 ret.address = pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_MAP);
809 return ret;
810}
811PNANOVDB_FORCE_INLINE double pnanovdb_grid_get_world_bbox(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t index) {
812 return pnanovdb_read_double(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_WORLD_BBOX + 8u * index));
813}
814PNANOVDB_FORCE_INLINE double pnanovdb_grid_get_voxel_size(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p, pnanovdb_uint32_t index) {
815 return pnanovdb_read_double(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_VOXEL_SIZE + 8u * index));
816}
817PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_grid_class(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
818 return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_GRID_CLASS));
819}
820PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_grid_type(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
821 return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_GRID_TYPE));
822}
823PNANOVDB_FORCE_INLINE pnanovdb_int64_t pnanovdb_grid_get_blind_metadata_offset(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
824 return pnanovdb_read_int64(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_BLIND_METADATA_OFFSET));
825}
826PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_blind_metadata_count(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p) {
827 return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRID_OFF_BLIND_METADATA_COUNT));
828}
829
830PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_version_get_major(pnanovdb_uint32_t version)
831{
832 return (version >> 21u) & ((1u << 11u) - 1u);
833}
834PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_version_get_minor(pnanovdb_uint32_t version)
835{
836 return (version >> 10u) & ((1u << 11u) - 1u);
837}
838PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_version_get_patch(pnanovdb_uint32_t version)
839{
840 return version & ((1u << 10u) - 1u);
841}
842
843 struct pnanovdb_gridblindmetadata_t
844{
845 pnanovdb_int64_t byte_offset; // 8 bytes, 0
846 pnanovdb_uint64_t element_count; // 8 bytes, 8
847 pnanovdb_uint32_t flags; // 4 bytes, 16
848 pnanovdb_uint32_t semantic; // 4 bytes, 20
849 pnanovdb_uint32_t data_class; // 4 bytes, 24
850 pnanovdb_uint32_t data_type; // 4 bytes, 28
851 pnanovdb_uint32_t name[256 / 4]; // 256 bytes, 32
852};
853PNANOVDB_STRUCT_TYPEDEF(pnanovdb_gridblindmetadata_t)
854struct pnanovdb_gridblindmetadata_handle_t { pnanovdb_address_t address; };
855PNANOVDB_STRUCT_TYPEDEF(pnanovdb_gridblindmetadata_handle_t)
856
857#define PNANOVDB_GRIDBLINDMETADATA_SIZE 288
858
859#define PNANOVDB_GRIDBLINDMETADATA_OFF_BYTE_OFFSET 0
860#define PNANOVDB_GRIDBLINDMETADATA_OFF_ELEMENT_COUNT 8
861#define PNANOVDB_GRIDBLINDMETADATA_OFF_FLAGS 16
862#define PNANOVDB_GRIDBLINDMETADATA_OFF_SEMANTIC 20
863#define PNANOVDB_GRIDBLINDMETADATA_OFF_DATA_CLASS 24
864#define PNANOVDB_GRIDBLINDMETADATA_OFF_DATA_TYPE 28
865#define PNANOVDB_GRIDBLINDMETADATA_OFF_NAME 32
866
867PNANOVDB_FORCE_INLINE pnanovdb_int64_t pnanovdb_gridblindmetadata_get_byte_offset(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p) {
868 return pnanovdb_read_int64(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRIDBLINDMETADATA_OFF_BYTE_OFFSET));
869}
870PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_gridblindmetadata_get_element_count(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p) {
871 return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRIDBLINDMETADATA_OFF_ELEMENT_COUNT));
872}
873PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_gridblindmetadata_get_flags(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p) {
874 return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRIDBLINDMETADATA_OFF_FLAGS));
875}
876PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_gridblindmetadata_get_semantic(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p) {
877 return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRIDBLINDMETADATA_OFF_SEMANTIC));
878}
879PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_gridblindmetadata_get_data_class(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p) {
880 return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRIDBLINDMETADATA_OFF_DATA_CLASS));
881}
882PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_gridblindmetadata_get_data_type(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p) {
883 return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRIDBLINDMETADATA_OFF_DATA_TYPE));
884}
885PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_gridblindmetadata_get_name(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p, pnanovdb_uint32_t index) {
886 return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_GRIDBLINDMETADATA_OFF_NAME + 4u * index));
887}
888
889 struct pnanovdb_tree_t
890{
891 pnanovdb_uint64_t node_offset_leaf;
892 pnanovdb_uint64_t node_offset_lower;
893 pnanovdb_uint64_t node_offset_upper;
894 pnanovdb_uint64_t node_offset_root;
895 pnanovdb_uint32_t node_count_leaf;
896 pnanovdb_uint32_t node_count_lower;
897 pnanovdb_uint32_t node_count_upper;
898 pnanovdb_uint32_t tile_count_leaf;
899 pnanovdb_uint32_t tile_count_lower;
900 pnanovdb_uint32_t tile_count_upper;
901 pnanovdb_uint64_t voxel_count;
902};
903PNANOVDB_STRUCT_TYPEDEF(pnanovdb_tree_t)
904struct pnanovdb_tree_handle_t { pnanovdb_address_t address; };
905PNANOVDB_STRUCT_TYPEDEF(pnanovdb_tree_handle_t)
906
907#define PNANOVDB_TREE_SIZE 64
908
909#define PNANOVDB_TREE_OFF_NODE_OFFSET_LEAF 0
910#define PNANOVDB_TREE_OFF_NODE_OFFSET_LOWER 8
911#define PNANOVDB_TREE_OFF_NODE_OFFSET_UPPER 16
912#define PNANOVDB_TREE_OFF_NODE_OFFSET_ROOT 24
913#define PNANOVDB_TREE_OFF_NODE_COUNT_LEAF 32
914#define PNANOVDB_TREE_OFF_NODE_COUNT_LOWER 36
915#define PNANOVDB_TREE_OFF_NODE_COUNT_UPPER 40
916#define PNANOVDB_TREE_OFF_TILE_COUNT_LEAF 44
917#define PNANOVDB_TREE_OFF_TILE_COUNT_LOWER 48
918#define PNANOVDB_TREE_OFF_TILE_COUNT_UPPER 52
919#define PNANOVDB_TREE_OFF_VOXEL_COUNT 56
920
921PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_tree_get_node_offset_leaf(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p) {
922 return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_NODE_OFFSET_LEAF));
923}
924PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_tree_get_node_offset_lower(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p) {
925 return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_NODE_OFFSET_LOWER));
926}
927PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_tree_get_node_offset_upper(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p) {
928 return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_NODE_OFFSET_UPPER));
929}
930PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_tree_get_node_offset_root(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p) {
931 return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_NODE_OFFSET_ROOT));
932}
933PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_node_count_leaf(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p) {
934 return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_NODE_COUNT_LEAF));
935}
936PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_node_count_lower(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p) {
937 return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_NODE_COUNT_LOWER));
938}
939PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_node_count_upper(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p) {
940 return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_NODE_COUNT_UPPER));
941}
942PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_tile_count_leaf(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p) {
943 return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_TILE_COUNT_LEAF));
944}
945PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_tile_count_lower(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p) {
946 return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_TILE_COUNT_LOWER));
947}
948PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_tile_count_upper(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p) {
949 return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_TILE_COUNT_UPPER));
950}
951PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_tree_get_voxel_count(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p) {
952 return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_TREE_OFF_VOXEL_COUNT));
953}
954
955 struct pnanovdb_root_t
956{
957 pnanovdb_coord_t bbox_min;
958 pnanovdb_coord_t bbox_max;
959 pnanovdb_uint32_t table_size;
960 pnanovdb_uint32_t pad1; // background can start here
961 // background, min, max
962};
963PNANOVDB_STRUCT_TYPEDEF(pnanovdb_root_t)
964struct pnanovdb_root_handle_t { pnanovdb_address_t address; };
965PNANOVDB_STRUCT_TYPEDEF(pnanovdb_root_handle_t)
966
967#define PNANOVDB_ROOT_BASE_SIZE 28
968
969#define PNANOVDB_ROOT_OFF_BBOX_MIN 0
970#define PNANOVDB_ROOT_OFF_BBOX_MAX 12
971#define PNANOVDB_ROOT_OFF_TABLE_SIZE 24
972
973PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_root_get_bbox_min(pnanovdb_buf_t buf, pnanovdb_root_handle_t p) {
974 return pnanovdb_read_coord(buf, pnanovdb_address_offset(p.address, PNANOVDB_ROOT_OFF_BBOX_MIN));
975}
976PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_root_get_bbox_max(pnanovdb_buf_t buf, pnanovdb_root_handle_t p) {
977 return pnanovdb_read_coord(buf, pnanovdb_address_offset(p.address, PNANOVDB_ROOT_OFF_BBOX_MAX));
978}
979PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_root_get_tile_count(pnanovdb_buf_t buf, pnanovdb_root_handle_t p) {
980 return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_ROOT_OFF_TABLE_SIZE));
981}
982
983 struct pnanovdb_root_tile_t
984{
985 pnanovdb_uint64_t key;
986 pnanovdb_int64_t child; // signed byte offset from root to the child node, 0 means it is a constant tile, so use value
987 pnanovdb_uint32_t state;
988 pnanovdb_uint32_t pad1; // value can start here
989 // value
990};
991PNANOVDB_STRUCT_TYPEDEF(pnanovdb_root_tile_t)
992struct pnanovdb_root_tile_handle_t { pnanovdb_address_t address; };
993PNANOVDB_STRUCT_TYPEDEF(pnanovdb_root_tile_handle_t)
994
995#define PNANOVDB_ROOT_TILE_BASE_SIZE 20
996
997#define PNANOVDB_ROOT_TILE_OFF_KEY 0
998#define PNANOVDB_ROOT_TILE_OFF_CHILD 8
999#define PNANOVDB_ROOT_TILE_OFF_STATE 16
1000
1001PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_root_tile_get_key(pnanovdb_buf_t buf, pnanovdb_root_tile_handle_t p) {
1002 return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_ROOT_TILE_OFF_KEY));
1003}
1004PNANOVDB_FORCE_INLINE pnanovdb_int64_t pnanovdb_root_tile_get_child(pnanovdb_buf_t buf, pnanovdb_root_tile_handle_t p) {
1005 return pnanovdb_read_int64(buf, pnanovdb_address_offset(p.address, PNANOVDB_ROOT_TILE_OFF_CHILD));
1006}
1007PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_root_tile_get_state(pnanovdb_buf_t buf, pnanovdb_root_tile_handle_t p) {
1008 return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_ROOT_TILE_OFF_STATE));
1009}
1010
1011 struct pnanovdb_upper_t
1012{
1013 pnanovdb_coord_t bbox_min;
1014 pnanovdb_coord_t bbox_max;
1015 pnanovdb_uint64_t flags;
1016 pnanovdb_uint32_t value_mask[1024];
1017 pnanovdb_uint32_t child_mask[1024];
1018 // min, max
1019 // alignas(32) pnanovdb_uint32_t table[];
1020};
1021PNANOVDB_STRUCT_TYPEDEF(pnanovdb_upper_t)
1022struct pnanovdb_upper_handle_t { pnanovdb_address_t address; };
1023PNANOVDB_STRUCT_TYPEDEF(pnanovdb_upper_handle_t)
1024
1025#define PNANOVDB_UPPER_TABLE_COUNT 32768
1026#define PNANOVDB_UPPER_BASE_SIZE 8224
1027
1028#define PNANOVDB_UPPER_OFF_BBOX_MIN 0
1029#define PNANOVDB_UPPER_OFF_BBOX_MAX 12
1030#define PNANOVDB_UPPER_OFF_FLAGS 24
1031#define PNANOVDB_UPPER_OFF_VALUE_MASK 32
1032#define PNANOVDB_UPPER_OFF_CHILD_MASK 4128
1033
1034PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_upper_get_bbox_min(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p) {
1035 return pnanovdb_read_coord(buf, pnanovdb_address_offset(p.address, PNANOVDB_UPPER_OFF_BBOX_MIN));
1036}
1037PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_upper_get_bbox_max(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p) {
1038 return pnanovdb_read_coord(buf, pnanovdb_address_offset(p.address, PNANOVDB_UPPER_OFF_BBOX_MAX));
1039}
1040PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_upper_get_flags(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p) {
1041 return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_UPPER_OFF_FLAGS));
1042}
1043PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_upper_get_value_mask(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p, pnanovdb_uint32_t bit_index) {
1044 pnanovdb_uint32_t value = pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_UPPER_OFF_VALUE_MASK + 4u * (bit_index >> 5u)));
1045 return ((value >> (bit_index & 31u)) & 1) != 0u;
1046}
1047PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_upper_get_child_mask(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p, pnanovdb_uint32_t bit_index) {
1048 pnanovdb_uint32_t value = pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_UPPER_OFF_CHILD_MASK + 4u * (bit_index >> 5u)));
1049 return ((value >> (bit_index & 31u)) & 1) != 0u;
1050}
1051
1052 struct pnanovdb_lower_t
1053{
1054 pnanovdb_coord_t bbox_min;
1055 pnanovdb_coord_t bbox_max;
1056 pnanovdb_uint64_t flags;
1057 pnanovdb_uint32_t value_mask[128];
1058 pnanovdb_uint32_t child_mask[128];
1059 // min, max
1060 // alignas(32) pnanovdb_uint32_t table[];
1061};
1062PNANOVDB_STRUCT_TYPEDEF(pnanovdb_lower_t)
1063struct pnanovdb_lower_handle_t { pnanovdb_address_t address; };
1064PNANOVDB_STRUCT_TYPEDEF(pnanovdb_lower_handle_t)
1065
1066#define PNANOVDB_LOWER_TABLE_COUNT 4096
1067#define PNANOVDB_LOWER_BASE_SIZE 1056
1068
1069#define PNANOVDB_LOWER_OFF_BBOX_MIN 0
1070#define PNANOVDB_LOWER_OFF_BBOX_MAX 12
1071#define PNANOVDB_LOWER_OFF_FLAGS 24
1072#define PNANOVDB_LOWER_OFF_VALUE_MASK 32
1073#define PNANOVDB_LOWER_OFF_CHILD_MASK 544
1074
1075PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_lower_get_bbox_min(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p) {
1076 return pnanovdb_read_coord(buf, pnanovdb_address_offset(p.address, PNANOVDB_LOWER_OFF_BBOX_MIN));
1077}
1078PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_lower_get_bbox_max(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p) {
1079 return pnanovdb_read_coord(buf, pnanovdb_address_offset(p.address, PNANOVDB_LOWER_OFF_BBOX_MAX));
1080}
1081PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_lower_get_flags(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p) {
1082 return pnanovdb_read_uint64(buf, pnanovdb_address_offset(p.address, PNANOVDB_LOWER_OFF_FLAGS));
1083}
1084PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_lower_get_value_mask(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p, pnanovdb_uint32_t bit_index) {
1085 pnanovdb_uint32_t value = pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_LOWER_OFF_VALUE_MASK + 4u * (bit_index >> 5u)));
1086 return ((value >> (bit_index & 31u)) & 1) != 0u;
1087}
1088PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_lower_get_child_mask(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p, pnanovdb_uint32_t bit_index) {
1089 pnanovdb_uint32_t value = pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_LOWER_OFF_CHILD_MASK + 4u * (bit_index >> 5u)));
1090 return ((value >> (bit_index & 31u)) & 1) != 0u;
1091}
1092
1093 struct pnanovdb_leaf_t
1094{
1095 pnanovdb_coord_t bbox_min;
1096 pnanovdb_uint32_t bbox_dif_and_flags;
1097 pnanovdb_uint32_t value_mask[16];
1098 // min, max
1099 // alignas(32) pnanovdb_uint32_t values[];
1100};
1101PNANOVDB_STRUCT_TYPEDEF(pnanovdb_leaf_t)
1102struct pnanovdb_leaf_handle_t { pnanovdb_address_t address; };
1103PNANOVDB_STRUCT_TYPEDEF(pnanovdb_leaf_handle_t)
1104
1105#define PNANOVDB_LEAF_TABLE_COUNT 512
1106#define PNANOVDB_LEAF_BASE_SIZE 80
1107
1108#define PNANOVDB_LEAF_OFF_BBOX_MIN 0
1109#define PNANOVDB_LEAF_OFF_BBOX_DIF_AND_FLAGS 12
1110#define PNANOVDB_LEAF_OFF_VALUE_MASK 16
1111
1112#define PNANOVDB_LEAF_TABLE_NEG_OFF_BBOX_DIF_AND_FLAGS 84
1113#define PNANOVDB_LEAF_TABLE_NEG_OFF_MINIMUM 16
1114#define PNANOVDB_LEAF_TABLE_NEG_OFF_QUANTUM 12
1115
1116PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_leaf_get_bbox_min(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t p) {
1117 return pnanovdb_read_coord(buf, pnanovdb_address_offset(p.address, PNANOVDB_LEAF_OFF_BBOX_MIN));
1118}
1119PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_leaf_get_bbox_dif_and_flags(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t p) {
1120 return pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_LEAF_OFF_BBOX_DIF_AND_FLAGS));
1121}
1122PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_leaf_get_value_mask(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t p, pnanovdb_uint32_t bit_index) {
1123 pnanovdb_uint32_t value = pnanovdb_read_uint32(buf, pnanovdb_address_offset(p.address, PNANOVDB_LEAF_OFF_VALUE_MASK + 4u * (bit_index >> 5u)));
1124 return ((value >> (bit_index & 31u)) & 1) != 0u;
1125}
1126
1127 struct pnanovdb_grid_type_constants_t
1128{
1129 pnanovdb_uint32_t root_off_background;
1130 pnanovdb_uint32_t root_off_min;
1131 pnanovdb_uint32_t root_off_max;
1132 pnanovdb_uint32_t root_off_ave;
1133 pnanovdb_uint32_t root_off_stddev;
1134 pnanovdb_uint32_t root_size;
1135 pnanovdb_uint32_t value_stride_bits;
1136 pnanovdb_uint32_t table_stride;
1137 pnanovdb_uint32_t root_tile_off_value;
1138 pnanovdb_uint32_t root_tile_size;
1139 pnanovdb_uint32_t upper_off_min;
1140 pnanovdb_uint32_t upper_off_max;
1141 pnanovdb_uint32_t upper_off_ave;
1142 pnanovdb_uint32_t upper_off_stddev;
1143 pnanovdb_uint32_t upper_off_table;
1144 pnanovdb_uint32_t upper_size;
1145 pnanovdb_uint32_t lower_off_min;
1146 pnanovdb_uint32_t lower_off_max;
1147 pnanovdb_uint32_t lower_off_ave;
1148 pnanovdb_uint32_t lower_off_stddev;
1149 pnanovdb_uint32_t lower_off_table;
1150 pnanovdb_uint32_t lower_size;
1151 pnanovdb_uint32_t leaf_off_min;
1152 pnanovdb_uint32_t leaf_off_max;
1153 pnanovdb_uint32_t leaf_off_ave;
1154 pnanovdb_uint32_t leaf_off_stddev;
1155 pnanovdb_uint32_t leaf_off_table;
1156 pnanovdb_uint32_t leaf_size;
1157};
1158PNANOVDB_STRUCT_TYPEDEF(pnanovdb_grid_type_constants_t)
1159
1160PNANOVDB_STATIC_CONST pnanovdb_grid_type_constants_t pnanovdb_grid_type_constants[PNANOVDB_GRID_TYPE_END] =
1161{
1162 {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},
1163 {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},
1164 {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},
1165 {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},
1166 {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},
1167 {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},
1168 {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},
1169 {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},
1170 {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},
1171 {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},
1172 {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},
1173 {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},
1174 {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},
1175 {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},
1176 {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},
1177 {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},
1178 {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},
1179 {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},
1180 {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},
1181 {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, 88, 96},
1182};
1183
1184// ------------------------------------------------ Basic Lookup -----------------------------------------------------------
1185
1186PNANOVDB_FORCE_INLINE pnanovdb_gridblindmetadata_handle_t pnanovdb_grid_get_gridblindmetadata(pnanovdb_buf_t buf, pnanovdb_grid_handle_t grid, pnanovdb_uint32_t index)
1187{
1188 pnanovdb_gridblindmetadata_handle_t meta = { grid.address };
1189 pnanovdb_uint64_t byte_offset = pnanovdb_grid_get_blind_metadata_offset(buf, grid);
1190 meta.address = pnanovdb_address_offset64(meta.address, byte_offset);
1191 meta.address = pnanovdb_address_offset_product(meta.address, PNANOVDB_GRIDBLINDMETADATA_SIZE, index);
1192 return meta;
1193}
1194
1195PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanodvb_grid_get_gridblindmetadata_value_address(pnanovdb_buf_t buf, pnanovdb_grid_handle_t grid, pnanovdb_uint32_t index)
1196{
1197 pnanovdb_gridblindmetadata_handle_t meta = pnanovdb_grid_get_gridblindmetadata(buf, grid, index);
1198 pnanovdb_int64_t byte_offset = pnanovdb_gridblindmetadata_get_byte_offset(buf, meta);
1199 pnanovdb_address_t address = grid.address;
1200 address = pnanovdb_address_offset64(address, pnanovdb_int64_as_uint64(byte_offset));
1201 return address;
1202}
1203
1204PNANOVDB_FORCE_INLINE pnanovdb_tree_handle_t pnanovdb_grid_get_tree(pnanovdb_buf_t buf, pnanovdb_grid_handle_t grid)
1205{
1206 pnanovdb_tree_handle_t tree = { grid.address };
1207 tree.address = pnanovdb_address_offset(tree.address, PNANOVDB_GRID_SIZE);
1208 return tree;
1209}
1210
1211PNANOVDB_FORCE_INLINE pnanovdb_root_handle_t pnanovdb_tree_get_root(pnanovdb_buf_t buf, pnanovdb_tree_handle_t tree)
1212{
1213 pnanovdb_root_handle_t root = { tree.address };
1214 pnanovdb_uint64_t byte_offset = pnanovdb_tree_get_node_offset_root(buf, tree);
1215 root.address = pnanovdb_address_offset64(root.address, byte_offset);
1216 return root;
1217}
1218
1219PNANOVDB_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)
1220{
1221 pnanovdb_root_tile_handle_t tile = { root.address };
1222 tile.address = pnanovdb_address_offset(tile.address, PNANOVDB_GRID_TYPE_GET(grid_type, root_size));
1223 tile.address = pnanovdb_address_offset_product(tile.address, PNANOVDB_GRID_TYPE_GET(grid_type, root_tile_size), n);
1224 return tile;
1225}
1226
1227PNANOVDB_FORCE_INLINE pnanovdb_root_tile_handle_t pnanovdb_root_get_tile_zero(pnanovdb_grid_type_t grid_type, pnanovdb_root_handle_t root)
1228{
1229 pnanovdb_root_tile_handle_t tile = { root.address };
1230 tile.address = pnanovdb_address_offset(tile.address, PNANOVDB_GRID_TYPE_GET(grid_type, root_size));
1231 return tile;
1232}
1233
1234PNANOVDB_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)
1235{
1236 pnanovdb_upper_handle_t upper = { root.address };
1237 upper.address = pnanovdb_address_offset64(upper.address, pnanovdb_int64_as_uint64(pnanovdb_root_tile_get_child(buf, tile)));
1238 return upper;
1239}
1240
1241PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_coord_to_key(PNANOVDB_IN(pnanovdb_coord_t) ijk)
1242{
1243#if defined(PNANOVDB_NATIVE_64)
1244 pnanovdb_uint64_t iu = pnanovdb_int32_as_uint32(PNANOVDB_DEREF(ijk).x) >> 12u;
1245 pnanovdb_uint64_t ju = pnanovdb_int32_as_uint32(PNANOVDB_DEREF(ijk).y) >> 12u;
1246 pnanovdb_uint64_t ku = pnanovdb_int32_as_uint32(PNANOVDB_DEREF(ijk).z) >> 12u;
1247 return (ku) | (ju << 21u) | (iu << 42u);
1248#else
1249 pnanovdb_uint32_t iu = pnanovdb_int32_as_uint32(PNANOVDB_DEREF(ijk).x) >> 12u;
1250 pnanovdb_uint32_t ju = pnanovdb_int32_as_uint32(PNANOVDB_DEREF(ijk).y) >> 12u;
1251 pnanovdb_uint32_t ku = pnanovdb_int32_as_uint32(PNANOVDB_DEREF(ijk).z) >> 12u;
1252 pnanovdb_uint32_t key_x = ku | (ju << 21);
1253 pnanovdb_uint32_t key_y = (iu << 10) | (ju >> 11);
1254 return pnanovdb_uint32_as_uint64(key_x, key_y);
1255#endif
1256}
1257
1258PNANOVDB_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)
1259{
1260 pnanovdb_uint32_t tile_count = pnanovdb_uint32_as_int32(pnanovdb_root_get_tile_count(buf, root));
1261 pnanovdb_root_tile_handle_t tile = pnanovdb_root_get_tile_zero(grid_type, root);
1262 pnanovdb_uint64_t key = pnanovdb_coord_to_key(ijk);
1263 for (pnanovdb_uint32_t i = 0u; i < tile_count; i++)
1264 {
1265 if (pnanovdb_uint64_is_equal(key, pnanovdb_root_tile_get_key(buf, tile)))
1266 {
1267 return tile;
1268 }
1269 tile.address = pnanovdb_address_offset(tile.address, PNANOVDB_GRID_TYPE_GET(grid_type, root_tile_size));
1270 }
1271 pnanovdb_root_tile_handle_t null_handle = { pnanovdb_address_null() };
1272 return null_handle;
1273}
1274
1275PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_leaf_coord_to_offset(PNANOVDB_IN(pnanovdb_coord_t) ijk)
1276{
1277 return (((PNANOVDB_DEREF(ijk).x & 7) >> 0) << (2 * 3)) +
1278 (((PNANOVDB_DEREF(ijk).y & 7) >> 0) << (3)) +
1279 ((PNANOVDB_DEREF(ijk).z & 7) >> 0);
1280}
1281
1282PNANOVDB_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)
1283{
1284 pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, leaf_off_min);
1285 return pnanovdb_address_offset(node.address, byte_offset);
1286}
1287
1288PNANOVDB_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)
1289{
1290 pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, leaf_off_max);
1291 return pnanovdb_address_offset(node.address, byte_offset);
1292}
1293
1294PNANOVDB_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)
1295{
1296 pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, leaf_off_ave);
1297 return pnanovdb_address_offset(node.address, byte_offset);
1298}
1299
1300PNANOVDB_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)
1301{
1302 pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, leaf_off_stddev);
1303 return pnanovdb_address_offset(node.address, byte_offset);
1304}
1305
1306PNANOVDB_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)
1307{
1308 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);
1309 return pnanovdb_address_offset(node.address, byte_offset);
1310}
1311
1312PNANOVDB_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)
1313{
1314 pnanovdb_uint32_t n = pnanovdb_leaf_coord_to_offset(ijk);
1315 return pnanovdb_leaf_get_table_address(grid_type, buf, leaf, n);
1316}
1317
1318PNANOVDB_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)
1319{
1320 // value_log_bits // 2 3 4
1321 pnanovdb_uint32_t value_bits = 1u << value_log_bits; // 4 8 16
1322 pnanovdb_uint32_t value_mask = (1u << value_bits) - 1u; // 0xF 0xFF 0xFFFF
1323 pnanovdb_uint32_t values_per_word_bits = 5u - value_log_bits; // 3 2 1
1324 pnanovdb_uint32_t values_per_word_mask = (1u << values_per_word_bits) - 1u; // 7 3 1
1325
1326 pnanovdb_uint32_t n = pnanovdb_leaf_coord_to_offset(ijk);
1327 float minimum = pnanovdb_read_float(buf, pnanovdb_address_offset_neg(address, PNANOVDB_LEAF_TABLE_NEG_OFF_MINIMUM));
1328 float quantum = pnanovdb_read_float(buf, pnanovdb_address_offset_neg(address, PNANOVDB_LEAF_TABLE_NEG_OFF_QUANTUM));
1329 pnanovdb_uint32_t raw = pnanovdb_read_uint32(buf, pnanovdb_address_offset(address, ((n >> values_per_word_bits) << 2u)));
1330 pnanovdb_uint32_t value_compressed = (raw >> ((n & values_per_word_mask) << value_log_bits)) & value_mask;
1331 return pnanovdb_uint32_to_float(value_compressed) * quantum + minimum;
1332}
1333
1334PNANOVDB_FORCE_INLINE float pnanovdb_leaf_fp4_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk)
1335{
1336 return pnanovdb_leaf_fp_read_float(buf, address, ijk, 2u);
1337}
1338
1339PNANOVDB_FORCE_INLINE float pnanovdb_leaf_fp8_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk)
1340{
1341 return pnanovdb_leaf_fp_read_float(buf, address, ijk, 3u);
1342}
1343
1344PNANOVDB_FORCE_INLINE float pnanovdb_leaf_fp16_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk)
1345{
1346 return pnanovdb_leaf_fp_read_float(buf, address, ijk, 4u);
1347}
1348
1349PNANOVDB_FORCE_INLINE float pnanovdb_leaf_fpn_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address, PNANOVDB_IN(pnanovdb_coord_t) ijk)
1350{
1351 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));
1352 pnanovdb_uint32_t flags = bbox_dif_and_flags >> 24u;
1353 pnanovdb_uint32_t value_log_bits = flags >> 5; // b = 0, 1, 2, 3, 4 corresponding to 1, 2, 4, 8, 16 bits
1354 return pnanovdb_leaf_fp_read_float(buf, address, ijk, value_log_bits);
1355}
1356
1357PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_uint32_countbits(pnanovdb_uint32_t value)
1358{
1359#if defined(PNANOVDB_C)
1360#if defined(_MSC_VER) && (_MSC_VER >= 1928) && defined(PNANOVDB_USE_INTRINSICS)
1361 return __popcnt(value);
1362#elif (defined(__GNUC__) || defined(__clang__)) && defined(PNANOVDB_USE_INTRINSICS)
1363 return __builtin_popcount(value);
1364#else
1365 value = value - ((value >> 1) & 0x55555555);
1366 value = (value & 0x33333333) + ((value >> 2) & 0x33333333);
1367 value = (value + (value >> 4)) & 0x0F0F0F0F;
1368 return (value * 0x01010101) >> 24;
1369#endif
1370#elif defined(PNANOVDB_HLSL)
1371 return countbits(value);
1372#elif defined(PNANOVDB_GLSL)
1373 return bitCount(value);
1374#endif
1375}
1376
1377PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_leaf_count_on_range(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t p, pnanovdb_uint32_t max_index)
1378{
1379 pnanovdb_uint32_t mask_idx_max = max_index >> 5u;
1380 pnanovdb_uint32_t sum = 0u;
1381 pnanovdb_uint32_t mask_val = 0u;
1382 for (pnanovdb_uint32_t mask_idx = 0u; mask_idx < mask_idx_max; mask_idx++)
1383 {
1384 mask_val = pnanovdb_read_uint32(
1385 buf, pnanovdb_address_offset(p.address, PNANOVDB_LEAF_OFF_VALUE_MASK + 4u * mask_idx));
1386 sum += pnanovdb_uint32_countbits(mask_val);
1387 }
1388 mask_val = pnanovdb_read_uint32(
1389 buf, pnanovdb_address_offset(p.address, PNANOVDB_LEAF_OFF_VALUE_MASK + 4u * mask_idx_max));
1390 sum += pnanovdb_uint32_countbits(mask_val & ((1u << (max_index & 31u)) - 1u));
1391 return sum;
1392}
1393
1394PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_uint64_offset(pnanovdb_uint64_t a, pnanovdb_uint32_t b)
1395{
1396#if defined(PNANOVDB_ADDRESS_32)
1397 pnanovdb_uint32_t low = pnanovdb_uint64_low(a);
1398 pnanovdb_uint32_t high = pnanovdb_uint64_high(a);
1399 low += b;
1400 if (low < b)
1401 {
1402 high += 1u;
1403 }
1404 return pnanovdb_uint32_as_uint64(low, high);
1405#else
1406 return a + b;
1407#endif
1408}
1409
1410PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_index_get_min_index(pnanovdb_buf_t buf, pnanovdb_address_t min_address)
1411{
1412 return pnanovdb_read_uint64(buf, min_address);
1413}
1414
1415PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_index_get_max_index(pnanovdb_buf_t buf, pnanovdb_address_t max_address)
1416{
1417 return pnanovdb_uint64_offset(pnanovdb_read_uint64(buf, max_address), 1u);
1418}
1419
1420PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_index_get_ave_index(pnanovdb_buf_t buf, pnanovdb_address_t ave_address)
1421{
1422 return pnanovdb_uint64_offset(pnanovdb_read_uint64(buf, ave_address), 2u);
1423}
1424
1425PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_index_get_dev_index(pnanovdb_buf_t buf, pnanovdb_address_t dev_address)
1426{
1427 return pnanovdb_uint64_offset(pnanovdb_read_uint64(buf, dev_address), 3u);
1428}
1429
1430PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_index_get_value_index(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, PNANOVDB_IN(pnanovdb_coord_t) ijk)
1431{
1432 pnanovdb_uint32_t n = pnanovdb_leaf_coord_to_offset(ijk);
1433 pnanovdb_uint32_t bbox_dif_and_flags = pnanovdb_leaf_get_bbox_dif_and_flags(buf, leaf);
1434 pnanovdb_address_t value_address = pnanovdb_leaf_get_table_address(grid_type, buf, leaf, 0u);
1435 if ((bbox_dif_and_flags & 0x10000000) != 0u)
1436 {
1437 if (pnanovdb_leaf_get_value_mask(buf, leaf, n))
1438 {
1439 n = pnanovdb_leaf_count_on_range(buf, leaf, n);
1440 }
1441 else
1442 {
1443 value_address = pnanovdb_address_null();
1444 n = 0;
1445 }
1446 }
1447 return pnanovdb_uint64_offset(pnanovdb_read_uint64(buf, value_address), n);
1448}
1449
1450PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_lower_coord_to_offset(PNANOVDB_IN(pnanovdb_coord_t) ijk)
1451{
1452 return (((PNANOVDB_DEREF(ijk).x & 127) >> 3) << (2 * 4)) +
1453 (((PNANOVDB_DEREF(ijk).y & 127) >> 3) << (4)) +
1454 ((PNANOVDB_DEREF(ijk).z & 127) >> 3);
1455}
1456
1457PNANOVDB_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)
1458{
1459 pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, lower_off_min);
1460 return pnanovdb_address_offset(node.address, byte_offset);
1461}
1462
1463PNANOVDB_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)
1464{
1465 pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, lower_off_max);
1466 return pnanovdb_address_offset(node.address, byte_offset);
1467}
1468
1469PNANOVDB_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)
1470{
1471 pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, lower_off_ave);
1472 return pnanovdb_address_offset(node.address, byte_offset);
1473}
1474
1475PNANOVDB_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)
1476{
1477 pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, lower_off_stddev);
1478 return pnanovdb_address_offset(node.address, byte_offset);
1479}
1480
1481PNANOVDB_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)
1482{
1483 pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, lower_off_table) + PNANOVDB_GRID_TYPE_GET(grid_type, table_stride) * n;
1484 return pnanovdb_address_offset(node.address, byte_offset);
1485}
1486
1487PNANOVDB_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)
1488{
1489 pnanovdb_address_t table_address = pnanovdb_lower_get_table_address(grid_type, buf, node, n);
1490 return pnanovdb_read_int64(buf, table_address);
1491}
1492
1493PNANOVDB_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)
1494{
1495 pnanovdb_leaf_handle_t leaf = { lower.address };
1496 leaf.address = pnanovdb_address_offset64(leaf.address, pnanovdb_int64_as_uint64(pnanovdb_lower_get_table_child(grid_type, buf, lower, n)));
1497 return leaf;
1498}
1499
1500PNANOVDB_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)
1501{
1502 pnanovdb_uint32_t n = pnanovdb_lower_coord_to_offset(ijk);
1503 pnanovdb_address_t value_address;
1504 if (pnanovdb_lower_get_child_mask(buf, lower, n))
1505 {
1506 pnanovdb_leaf_handle_t child = pnanovdb_lower_get_child(grid_type, buf, lower, n);
1507 value_address = pnanovdb_leaf_get_value_address(grid_type, buf, child, ijk);
1508 PNANOVDB_DEREF(level) = 0u;
1509 }
1510 else
1511 {
1512 value_address = pnanovdb_lower_get_table_address(grid_type, buf, lower, n);
1513 PNANOVDB_DEREF(level) = 1u;
1514 }
1515 return value_address;
1516}
1517
1518PNANOVDB_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)
1519{
1520 pnanovdb_uint32_t level;
1521 return pnanovdb_lower_get_value_address_and_level(grid_type, buf, lower, ijk, PNANOVDB_REF(level));
1522}
1523
1524PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_upper_coord_to_offset(PNANOVDB_IN(pnanovdb_coord_t) ijk)
1525{
1526 return (((PNANOVDB_DEREF(ijk).x & 4095) >> 7) << (2 * 5)) +
1527 (((PNANOVDB_DEREF(ijk).y & 4095) >> 7) << (5)) +
1528 ((PNANOVDB_DEREF(ijk).z & 4095) >> 7);
1529}
1530
1531PNANOVDB_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)
1532{
1533 pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, upper_off_min);
1534 return pnanovdb_address_offset(node.address, byte_offset);
1535}
1536
1537PNANOVDB_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)
1538{
1539 pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, upper_off_max);
1540 return pnanovdb_address_offset(node.address, byte_offset);
1541}
1542
1543PNANOVDB_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)
1544{
1545 pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, upper_off_ave);
1546 return pnanovdb_address_offset(node.address, byte_offset);
1547}
1548
1549PNANOVDB_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)
1550{
1551 pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, upper_off_stddev);
1552 return pnanovdb_address_offset(node.address, byte_offset);
1553}
1554
1555PNANOVDB_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)
1556{
1557 pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, upper_off_table) + PNANOVDB_GRID_TYPE_GET(grid_type, table_stride) * n;
1558 return pnanovdb_address_offset(node.address, byte_offset);
1559}
1560
1561PNANOVDB_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)
1562{
1563 pnanovdb_address_t bufAddress = pnanovdb_upper_get_table_address(grid_type, buf, node, n);
1564 return pnanovdb_read_int64(buf, bufAddress);
1565}
1566
1567PNANOVDB_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)
1568{
1569 pnanovdb_lower_handle_t lower = { upper.address };
1570 lower.address = pnanovdb_address_offset64(lower.address, pnanovdb_int64_as_uint64(pnanovdb_upper_get_table_child(grid_type, buf, upper, n)));
1571 return lower;
1572}
1573
1574PNANOVDB_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)
1575{
1576 pnanovdb_uint32_t n = pnanovdb_upper_coord_to_offset(ijk);
1577 pnanovdb_address_t value_address;
1578 if (pnanovdb_upper_get_child_mask(buf, upper, n))
1579 {
1580 pnanovdb_lower_handle_t child = pnanovdb_upper_get_child(grid_type, buf, upper, n);
1581 value_address = pnanovdb_lower_get_value_address_and_level(grid_type, buf, child, ijk, level);
1582 }
1583 else
1584 {
1585 value_address = pnanovdb_upper_get_table_address(grid_type, buf, upper, n);
1586 PNANOVDB_DEREF(level) = 2u;
1587 }
1588 return value_address;
1589}
1590
1591PNANOVDB_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)
1592{
1593 pnanovdb_uint32_t level;
1594 return pnanovdb_upper_get_value_address_and_level(grid_type, buf, upper, ijk, PNANOVDB_REF(level));
1595}
1596
1597PNANOVDB_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)
1598{
1599 pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, root_off_min);
1600 return pnanovdb_address_offset(root.address, byte_offset);
1601}
1602
1603PNANOVDB_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)
1604{
1605 pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, root_off_max);
1606 return pnanovdb_address_offset(root.address, byte_offset);
1607}
1608
1609PNANOVDB_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)
1610{
1611 pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, root_off_ave);
1612 return pnanovdb_address_offset(root.address, byte_offset);
1613}
1614
1615PNANOVDB_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)
1616{
1617 pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, root_off_stddev);
1618 return pnanovdb_address_offset(root.address, byte_offset);
1619}
1620
1621PNANOVDB_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)
1622{
1623 pnanovdb_uint32_t byte_offset = PNANOVDB_GRID_TYPE_GET(grid_type, root_tile_off_value);
1624 return pnanovdb_address_offset(root_tile.address, byte_offset);
1625}
1626
1627PNANOVDB_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)
1628{
1629 pnanovdb_root_tile_handle_t tile = pnanovdb_root_find_tile(grid_type, buf, root, ijk);
1630 pnanovdb_address_t ret;
1631 if (pnanovdb_address_is_null(tile.address))
1632 {
1633 ret = pnanovdb_address_offset(root.address, PNANOVDB_GRID_TYPE_GET(grid_type, root_off_background));
1634 PNANOVDB_DEREF(level) = 4u;
1635 }
1636 else if (pnanovdb_int64_is_zero(pnanovdb_root_tile_get_child(buf, tile)))
1637 {
1638 ret = pnanovdb_address_offset(tile.address, PNANOVDB_GRID_TYPE_GET(grid_type, root_tile_off_value));
1639 PNANOVDB_DEREF(level) = 3u;
1640 }
1641 else
1642 {
1643 pnanovdb_upper_handle_t child = pnanovdb_root_get_child(grid_type, buf, root, tile);
1644 ret = pnanovdb_upper_get_value_address_and_level(grid_type, buf, child, ijk, level);
1645 }
1646 return ret;
1647}
1648
1649PNANOVDB_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)
1650{
1651 pnanovdb_uint32_t level;
1652 return pnanovdb_root_get_value_address_and_level(grid_type, buf, root, ijk, PNANOVDB_REF(level));
1653}
1654
1655PNANOVDB_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)
1656{
1657 pnanovdb_uint32_t level;
1658 pnanovdb_address_t address = pnanovdb_root_get_value_address_and_level(grid_type, buf, root, ijk, PNANOVDB_REF(level));
1659 PNANOVDB_DEREF(bit_index) = level == 0u ? pnanovdb_int32_as_uint32(PNANOVDB_DEREF(ijk).x & 7) : 0u;
1660 return address;
1661}
1662
1663PNANOVDB_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)
1664{
1665 float ret;
1666 if (level == 0)
1667 {
1668 ret = pnanovdb_leaf_fp4_read_float(buf, address, ijk);
1669 }
1670 else
1671 {
1672 ret = pnanovdb_read_float(buf, address);
1673 }
1674 return ret;
1675}
1676
1677PNANOVDB_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)
1678{
1679 float ret;
1680 if (level == 0)
1681 {
1682 ret = pnanovdb_leaf_fp8_read_float(buf, address, ijk);
1683 }
1684 else
1685 {
1686 ret = pnanovdb_read_float(buf, address);
1687 }
1688 return ret;
1689}
1690
1691PNANOVDB_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)
1692{
1693 float ret;
1694 if (level == 0)
1695 {
1696 ret = pnanovdb_leaf_fp16_read_float(buf, address, ijk);
1697 }
1698 else
1699 {
1700 ret = pnanovdb_read_float(buf, address);
1701 }
1702 return ret;
1703}
1704
1705PNANOVDB_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)
1706{
1707 float ret;
1708 if (level == 0)
1709 {
1710 ret = pnanovdb_leaf_fpn_read_float(buf, address, ijk);
1711 }
1712 else
1713 {
1714 ret = pnanovdb_read_float(buf, address);
1715 }
1716 return ret;
1717}
1718
1719// ------------------------------------------------ ReadAccessor -----------------------------------------------------------
1720
1721 struct pnanovdb_readaccessor_t
1722{
1723 pnanovdb_coord_t key;
1724 pnanovdb_leaf_handle_t leaf;
1725 pnanovdb_lower_handle_t lower;
1726 pnanovdb_upper_handle_t upper;
1727 pnanovdb_root_handle_t root;
1728};
1729PNANOVDB_STRUCT_TYPEDEF(pnanovdb_readaccessor_t)
1730
1731PNANOVDB_FORCE_INLINE void pnanovdb_readaccessor_init(PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, pnanovdb_root_handle_t root)
1732{
1733 PNANOVDB_DEREF(acc).key.x = 0x7FFFFFFF;
1734 PNANOVDB_DEREF(acc).key.y = 0x7FFFFFFF;
1735 PNANOVDB_DEREF(acc).key.z = 0x7FFFFFFF;
1736 PNANOVDB_DEREF(acc).leaf.address = pnanovdb_address_null();
1737 PNANOVDB_DEREF(acc).lower.address = pnanovdb_address_null();
1738 PNANOVDB_DEREF(acc).upper.address = pnanovdb_address_null();
1739 PNANOVDB_DEREF(acc).root = root;
1740}
1741
1742PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_readaccessor_iscached0(PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, int dirty)
1743{
1744 if (pnanovdb_address_is_null(PNANOVDB_DEREF(acc).leaf.address)) { return PNANOVDB_FALSE; }
1745 if ((dirty & ~((1u << 3) - 1u)) != 0)
1746 {
1747 PNANOVDB_DEREF(acc).leaf.address = pnanovdb_address_null();
1748 return PNANOVDB_FALSE;
1749 }
1750 return PNANOVDB_TRUE;
1751}
1752PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_readaccessor_iscached1(PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, int dirty)
1753{
1754 if (pnanovdb_address_is_null(PNANOVDB_DEREF(acc).lower.address)) { return PNANOVDB_FALSE; }
1755 if ((dirty & ~((1u << 7) - 1u)) != 0)
1756 {
1757 PNANOVDB_DEREF(acc).lower.address = pnanovdb_address_null();
1758 return PNANOVDB_FALSE;
1759 }
1760 return PNANOVDB_TRUE;
1761}
1762PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_readaccessor_iscached2(PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, int dirty)
1763{
1764 if (pnanovdb_address_is_null(PNANOVDB_DEREF(acc).upper.address)) { return PNANOVDB_FALSE; }
1765 if ((dirty & ~((1u << 12) - 1u)) != 0)
1766 {
1767 PNANOVDB_DEREF(acc).upper.address = pnanovdb_address_null();
1768 return PNANOVDB_FALSE;
1769 }
1770 return PNANOVDB_TRUE;
1771}
1772PNANOVDB_FORCE_INLINE int pnanovdb_readaccessor_computedirty(PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, PNANOVDB_IN(pnanovdb_coord_t) ijk)
1773{
1774 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);
1775}
1776
1777PNANOVDB_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)
1778{
1779 pnanovdb_uint32_t n = pnanovdb_leaf_coord_to_offset(ijk);
1780 return pnanovdb_leaf_get_table_address(grid_type, buf, leaf, n);
1781}
1782
1783PNANOVDB_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)
1784{
1785 pnanovdb_uint32_t n = pnanovdb_lower_coord_to_offset(ijk);
1786 pnanovdb_address_t value_address;
1787 if (pnanovdb_lower_get_child_mask(buf, lower, n))
1788 {
1789 pnanovdb_leaf_handle_t child = pnanovdb_lower_get_child(grid_type, buf, lower, n);
1790 PNANOVDB_DEREF(acc).leaf = child;
1791 PNANOVDB_DEREF(acc).key = PNANOVDB_DEREF(ijk);
1792 value_address = pnanovdb_leaf_get_value_address_and_cache(grid_type, buf, child, ijk, acc);
1793 PNANOVDB_DEREF(level) = 0u;
1794 }
1795 else
1796 {
1797 value_address = pnanovdb_lower_get_table_address(grid_type, buf, lower, n);
1798 PNANOVDB_DEREF(level) = 1u;
1799 }
1800 return value_address;
1801}
1802
1803PNANOVDB_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)
1804{
1805 pnanovdb_uint32_t level;
1806 return pnanovdb_lower_get_value_address_and_level_and_cache(grid_type, buf, lower, ijk, acc, PNANOVDB_REF(level));
1807}
1808
1809PNANOVDB_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)
1810{
1811 pnanovdb_uint32_t n = pnanovdb_upper_coord_to_offset(ijk);
1812 pnanovdb_address_t value_address;
1813 if (pnanovdb_upper_get_child_mask(buf, upper, n))
1814 {
1815 pnanovdb_lower_handle_t child = pnanovdb_upper_get_child(grid_type, buf, upper, n);
1816 PNANOVDB_DEREF(acc).lower = child;
1817 PNANOVDB_DEREF(acc).key = PNANOVDB_DEREF(ijk);
1818 value_address = pnanovdb_lower_get_value_address_and_level_and_cache(grid_type, buf, child, ijk, acc, level);
1819 }
1820 else
1821 {
1822 value_address = pnanovdb_upper_get_table_address(grid_type, buf, upper, n);
1823 PNANOVDB_DEREF(level) = 2u;
1824 }
1825 return value_address;
1826}
1827
1828PNANOVDB_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)
1829{
1830 pnanovdb_uint32_t level;
1831 return pnanovdb_upper_get_value_address_and_level_and_cache(grid_type, buf, upper, ijk, acc, PNANOVDB_REF(level));
1832}
1833
1834PNANOVDB_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)
1835{
1836 pnanovdb_root_tile_handle_t tile = pnanovdb_root_find_tile(grid_type, buf, root, ijk);
1837 pnanovdb_address_t ret;
1838 if (pnanovdb_address_is_null(tile.address))
1839 {
1840 ret = pnanovdb_address_offset(root.address, PNANOVDB_GRID_TYPE_GET(grid_type, root_off_background));
1841 PNANOVDB_DEREF(level) = 4u;
1842 }
1843 else if (pnanovdb_int64_is_zero(pnanovdb_root_tile_get_child(buf, tile)))
1844 {
1845 ret = pnanovdb_address_offset(tile.address, PNANOVDB_GRID_TYPE_GET(grid_type, root_tile_off_value));
1846 PNANOVDB_DEREF(level) = 3u;
1847 }
1848 else
1849 {
1850 pnanovdb_upper_handle_t child = pnanovdb_root_get_child(grid_type, buf, root, tile);
1851 PNANOVDB_DEREF(acc).upper = child;
1852 PNANOVDB_DEREF(acc).key = PNANOVDB_DEREF(ijk);
1853 ret = pnanovdb_upper_get_value_address_and_level_and_cache(grid_type, buf, child, ijk, acc, level);
1854 }
1855 return ret;
1856}
1857
1858PNANOVDB_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)
1859{
1860 pnanovdb_uint32_t level;
1861 return pnanovdb_root_get_value_address_and_level_and_cache(grid_type, buf, root, ijk, acc, PNANOVDB_REF(level));
1862}
1863
1864PNANOVDB_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)
1865{
1866 int dirty = pnanovdb_readaccessor_computedirty(acc, ijk);
1867
1868 pnanovdb_address_t value_address;
1869 if (pnanovdb_readaccessor_iscached0(acc, dirty))
1870 {
1871 value_address = pnanovdb_leaf_get_value_address_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).leaf, ijk, acc);
1872 PNANOVDB_DEREF(level) = 0u;
1873 }
1874 else if (pnanovdb_readaccessor_iscached1(acc, dirty))
1875 {
1876 value_address = pnanovdb_lower_get_value_address_and_level_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).lower, ijk, acc, level);
1877 }
1878 else if (pnanovdb_readaccessor_iscached2(acc, dirty))
1879 {
1880 value_address = pnanovdb_upper_get_value_address_and_level_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).upper, ijk, acc, level);
1881 }
1882 else
1883 {
1884 value_address = pnanovdb_root_get_value_address_and_level_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).root, ijk, acc, level);
1885 }
1886 return value_address;
1887}
1888
1889PNANOVDB_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)
1890{
1891 pnanovdb_uint32_t level;
1892 return pnanovdb_readaccessor_get_value_address_and_level(grid_type, buf, acc, ijk, PNANOVDB_REF(level));
1893}
1894
1895PNANOVDB_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)
1896{
1897 pnanovdb_uint32_t level;
1898 pnanovdb_address_t address = pnanovdb_readaccessor_get_value_address_and_level(grid_type, buf, acc, ijk, PNANOVDB_REF(level));
1899 PNANOVDB_DEREF(bit_index) = level == 0u ? pnanovdb_int32_as_uint32(PNANOVDB_DEREF(ijk).x & 7) : 0u;
1900 return address;
1901}
1902
1903// ------------------------------------------------ ReadAccessor GetDim -----------------------------------------------------------
1904
1905PNANOVDB_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)
1906{
1907 return 1u;
1908}
1909
1910PNANOVDB_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)
1911{
1912 pnanovdb_uint32_t n = pnanovdb_lower_coord_to_offset(ijk);
1913 pnanovdb_uint32_t ret;
1914 if (pnanovdb_lower_get_child_mask(buf, lower, n))
1915 {
1916 pnanovdb_leaf_handle_t child = pnanovdb_lower_get_child(grid_type, buf, lower, n);
1917 PNANOVDB_DEREF(acc).leaf = child;
1918 PNANOVDB_DEREF(acc).key = PNANOVDB_DEREF(ijk);
1919 ret = pnanovdb_leaf_get_dim_and_cache(grid_type, buf, child, ijk, acc);
1920 }
1921 else
1922 {
1923 ret = (1u << (3u)); // node 0 dim
1924 }
1925 return ret;
1926}
1927
1928PNANOVDB_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)
1929{
1930 pnanovdb_uint32_t n = pnanovdb_upper_coord_to_offset(ijk);
1931 pnanovdb_uint32_t ret;
1932 if (pnanovdb_upper_get_child_mask(buf, upper, n))
1933 {
1934 pnanovdb_lower_handle_t child = pnanovdb_upper_get_child(grid_type, buf, upper, n);
1935 PNANOVDB_DEREF(acc).lower = child;
1936 PNANOVDB_DEREF(acc).key = PNANOVDB_DEREF(ijk);
1937 ret = pnanovdb_lower_get_dim_and_cache(grid_type, buf, child, ijk, acc);
1938 }
1939 else
1940 {
1941 ret = (1u << (4u + 3u)); // node 1 dim
1942 }
1943 return ret;
1944}
1945
1946PNANOVDB_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)
1947{
1948 pnanovdb_root_tile_handle_t tile = pnanovdb_root_find_tile(grid_type, buf, root, ijk);
1949 pnanovdb_uint32_t ret;
1950 if (pnanovdb_address_is_null(tile.address))
1951 {
1952 ret = 1u << (5u + 4u + 3u); // background, node 2 dim
1953 }
1954 else if (pnanovdb_int64_is_zero(pnanovdb_root_tile_get_child(buf, tile)))
1955 {
1956 ret = 1u << (5u + 4u + 3u); // tile value, node 2 dim
1957 }
1958 else
1959 {
1960 pnanovdb_upper_handle_t child = pnanovdb_root_get_child(grid_type, buf, root, tile);
1961 PNANOVDB_DEREF(acc).upper = child;
1962 PNANOVDB_DEREF(acc).key = PNANOVDB_DEREF(ijk);
1963 ret = pnanovdb_upper_get_dim_and_cache(grid_type, buf, child, ijk, acc);
1964 }
1965 return ret;
1966}
1967
1968PNANOVDB_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)
1969{
1970 int dirty = pnanovdb_readaccessor_computedirty(acc, ijk);
1971
1972 pnanovdb_uint32_t dim;
1973 if (pnanovdb_readaccessor_iscached0(acc, dirty))
1974 {
1975 dim = pnanovdb_leaf_get_dim_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).leaf, ijk, acc);
1976 }
1977 else if (pnanovdb_readaccessor_iscached1(acc, dirty))
1978 {
1979 dim = pnanovdb_lower_get_dim_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).lower, ijk, acc);
1980 }
1981 else if (pnanovdb_readaccessor_iscached2(acc, dirty))
1982 {
1983 dim = pnanovdb_upper_get_dim_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).upper, ijk, acc);
1984 }
1985 else
1986 {
1987 dim = pnanovdb_root_get_dim_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).root, ijk, acc);
1988 }
1989 return dim;
1990}
1991
1992// ------------------------------------------------ ReadAccessor IsActive -----------------------------------------------------------
1993
1994PNANOVDB_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)
1995{
1996 pnanovdb_uint32_t n = pnanovdb_leaf_coord_to_offset(ijk);
1997 return pnanovdb_leaf_get_value_mask(buf, leaf, n);
1998}
1999
2000PNANOVDB_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)
2001{
2002 pnanovdb_uint32_t n = pnanovdb_lower_coord_to_offset(ijk);
2003 pnanovdb_bool_t is_active;
2004 if (pnanovdb_lower_get_child_mask(buf, lower, n))
2005 {
2006 pnanovdb_leaf_handle_t child = pnanovdb_lower_get_child(grid_type, buf, lower, n);
2007 PNANOVDB_DEREF(acc).leaf = child;
2008 PNANOVDB_DEREF(acc).key = PNANOVDB_DEREF(ijk);
2009 is_active = pnanovdb_leaf_is_active_and_cache(grid_type, buf, child, ijk, acc);
2010 }
2011 else
2012 {
2013 is_active = pnanovdb_lower_get_value_mask(buf, lower, n);
2014 }
2015 return is_active;
2016}
2017
2018PNANOVDB_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)
2019{
2020 pnanovdb_uint32_t n = pnanovdb_upper_coord_to_offset(ijk);
2021 pnanovdb_bool_t is_active;
2022 if (pnanovdb_upper_get_child_mask(buf, upper, n))
2023 {
2024 pnanovdb_lower_handle_t child = pnanovdb_upper_get_child(grid_type, buf, upper, n);
2025 PNANOVDB_DEREF(acc).lower = child;
2026 PNANOVDB_DEREF(acc).key = PNANOVDB_DEREF(ijk);
2027 is_active = pnanovdb_lower_is_active_and_cache(grid_type, buf, child, ijk, acc);
2028 }
2029 else
2030 {
2031 is_active = pnanovdb_upper_get_value_mask(buf, upper, n);
2032 }
2033 return is_active;
2034}
2035
2036PNANOVDB_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)
2037{
2038 pnanovdb_root_tile_handle_t tile = pnanovdb_root_find_tile(grid_type, buf, root, ijk);
2039 pnanovdb_bool_t is_active;
2040 if (pnanovdb_address_is_null(tile.address))
2041 {
2042 is_active = PNANOVDB_FALSE; // background
2043 }
2044 else if (pnanovdb_int64_is_zero(pnanovdb_root_tile_get_child(buf, tile)))
2045 {
2046 pnanovdb_uint32_t state = pnanovdb_root_tile_get_state(buf, tile);
2047 is_active = state != 0u; // tile value
2048 }
2049 else
2050 {
2051 pnanovdb_upper_handle_t child = pnanovdb_root_get_child(grid_type, buf, root, tile);
2052 PNANOVDB_DEREF(acc).upper = child;
2053 PNANOVDB_DEREF(acc).key = PNANOVDB_DEREF(ijk);
2054 is_active = pnanovdb_upper_is_active_and_cache(grid_type, buf, child, ijk, acc);
2055 }
2056 return is_active;
2057}
2058
2059PNANOVDB_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)
2060{
2061 int dirty = pnanovdb_readaccessor_computedirty(acc, ijk);
2062
2063 pnanovdb_bool_t is_active;
2064 if (pnanovdb_readaccessor_iscached0(acc, dirty))
2065 {
2066 is_active = pnanovdb_leaf_is_active_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).leaf, ijk, acc);
2067 }
2068 else if (pnanovdb_readaccessor_iscached1(acc, dirty))
2069 {
2070 is_active = pnanovdb_lower_is_active_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).lower, ijk, acc);
2071 }
2072 else if (pnanovdb_readaccessor_iscached2(acc, dirty))
2073 {
2074 is_active = pnanovdb_upper_is_active_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).upper, ijk, acc);
2075 }
2076 else
2077 {
2078 is_active = pnanovdb_root_is_active_and_cache(grid_type, buf, PNANOVDB_DEREF(acc).root, ijk, acc);
2079 }
2080 return is_active;
2081}
2082
2083// ------------------------------------------------ Map Transforms -----------------------------------------------------------
2084
2085PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_map_apply(pnanovdb_buf_t buf, pnanovdb_map_handle_t map, PNANOVDB_IN(pnanovdb_vec3_t) src)
2086{
2087 pnanovdb_vec3_t dst;
2088 float sx = PNANOVDB_DEREF(src).x;
2089 float sy = PNANOVDB_DEREF(src).y;
2090 float sz = PNANOVDB_DEREF(src).z;
2091 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);
2092 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);
2093 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);
2094 return dst;
2095}
2096
2097PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_map_apply_inverse(pnanovdb_buf_t buf, pnanovdb_map_handle_t map, PNANOVDB_IN(pnanovdb_vec3_t) src)
2098{
2099 pnanovdb_vec3_t dst;
2100 float sx = PNANOVDB_DEREF(src).x - pnanovdb_map_get_vecf(buf, map, 0);
2101 float sy = PNANOVDB_DEREF(src).y - pnanovdb_map_get_vecf(buf, map, 1);
2102 float sz = PNANOVDB_DEREF(src).z - pnanovdb_map_get_vecf(buf, map, 2);
2103 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);
2104 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);
2105 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);
2106 return dst;
2107}
2108
2109PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_map_apply_jacobi(pnanovdb_buf_t buf, pnanovdb_map_handle_t map, PNANOVDB_IN(pnanovdb_vec3_t) src)
2110{
2111 pnanovdb_vec3_t dst;
2112 float sx = PNANOVDB_DEREF(src).x;
2113 float sy = PNANOVDB_DEREF(src).y;
2114 float sz = PNANOVDB_DEREF(src).z;
2115 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);
2116 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);
2117 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);
2118 return dst;
2119}
2120
2121PNANOVDB_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)
2122{
2123 pnanovdb_vec3_t dst;
2124 float sx = PNANOVDB_DEREF(src).x;
2125 float sy = PNANOVDB_DEREF(src).y;
2126 float sz = PNANOVDB_DEREF(src).z;
2127 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);
2128 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);
2129 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);
2130 return dst;
2131}
2132
2133PNANOVDB_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)
2134{
2135 pnanovdb_map_handle_t map = pnanovdb_grid_get_map(buf, grid);
2136 return pnanovdb_map_apply_inverse(buf, map, src);
2137}
2138
2139PNANOVDB_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)
2140{
2141 pnanovdb_map_handle_t map = pnanovdb_grid_get_map(buf, grid);
2142 return pnanovdb_map_apply(buf, map, src);
2143}
2144
2145PNANOVDB_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)
2146{
2147 pnanovdb_map_handle_t map = pnanovdb_grid_get_map(buf, grid);
2148 return pnanovdb_map_apply_inverse_jacobi(buf, map, src);
2149}
2150
2151PNANOVDB_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)
2152{
2153 pnanovdb_map_handle_t map = pnanovdb_grid_get_map(buf, grid);
2154 return pnanovdb_map_apply_jacobi(buf, map, src);
2155}
2156
2157// ------------------------------------------------ DitherLUT -----------------------------------------------------------
2158
2159// This table was generated with
2160/**************
2161
2162static constexpr inline uint32
2163SYSwang_inthash(uint32 key)
2164{
2165 // From http://www.concentric.net/~Ttwang/tech/inthash.htm
2166 key += ~(key << 16);
2167 key ^= (key >> 5);
2168 key += (key << 3);
2169 key ^= (key >> 13);
2170 key += ~(key << 9);
2171 key ^= (key >> 17);
2172 return key;
2173}
2174
2175static void
2176ut_initDitherR(float *pattern, float offset,
2177 int x, int y, int z, int res, int goalres)
2178{
2179 // These offsets are designed to maximize the difference between
2180 // dither values in nearby voxels within a given 2x2x2 cell, without
2181 // producing axis-aligned artifacts. The are organized in row-major
2182 // order.
2183 static const float theDitherOffset[] = {0,4,6,2,5,1,3,7};
2184 static const float theScale = 0.125F;
2185 int key = (((z << res) + y) << res) + x;
2186
2187 if (res == goalres)
2188 {
2189 pattern[key] = offset;
2190 return;
2191 }
2192
2193 // Randomly flip (on each axis) the dithering patterns used by the
2194 // subcells. This key is xor'd with the subcell index below before
2195 // looking up in the dither offset list.
2196 key = SYSwang_inthash(key) & 7;
2197
2198 x <<= 1;
2199 y <<= 1;
2200 z <<= 1;
2201
2202 offset *= theScale;
2203 for (int i = 0; i < 8; i++)
2204 ut_initDitherR(pattern, offset+theDitherOffset[i ^ key]*theScale,
2205 x+(i&1), y+((i&2)>>1), z+((i&4)>>2), res+1, goalres);
2206}
2207
2208// This is a compact algorithm that accomplishes essentially the same thing
2209// as ut_initDither() above. We should eventually switch to use this and
2210// clean the dead code.
2211static fpreal32 *
2212ut_initDitherRecursive(int goalres)
2213{
2214 const int nfloat = 1 << (goalres*3);
2215 float *pattern = new float[nfloat];
2216 ut_initDitherR(pattern, 1.0F, 0, 0, 0, 0, goalres);
2217
2218 // This has built an even spacing from 1/nfloat to 1.0.
2219 // however, our dither pattern should be 1/(nfloat+1) to nfloat/(nfloat+1)
2220 // So we do a correction here. Note that the earlier calculations are
2221 // done with powers of 2 so are exact, so it does make sense to delay
2222 // the renormalization to this pass.
2223 float correctionterm = nfloat / (nfloat+1.0F);
2224 for (int i = 0; i < nfloat; i++)
2225 pattern[i] *= correctionterm;
2226 return pattern;
2227}
2228
2229 theDitherMatrix = ut_initDitherRecursive(3);
2230
2231 for (int i = 0; i < 512/8; i ++)
2232 {
2233 for (int j = 0; j < 8; j ++)
2234 std::cout << theDitherMatrix[i*8+j] << "f, ";
2235 std::cout << std::endl;
2236 }
2237
2238 **************/
2239
2240PNANOVDB_STATIC_CONST float pnanovdb_dither_lut[512] =
2241{
2242 0.14425f, 0.643275f, 0.830409f, 0.331384f, 0.105263f, 0.604289f, 0.167641f, 0.666667f,
2243 0.892788f, 0.393762f, 0.0818713f, 0.580897f, 0.853801f, 0.354776f, 0.916179f, 0.417154f,
2244 0.612086f, 0.11306f, 0.79922f, 0.300195f, 0.510721f, 0.0116959f, 0.947368f, 0.448343f,
2245 0.362573f, 0.861598f, 0.0506823f, 0.549708f, 0.261209f, 0.760234f, 0.19883f, 0.697856f,
2246 0.140351f, 0.639376f, 0.576998f, 0.0779727f, 0.522417f, 0.0233918f, 0.460039f, 0.959064f,
2247 0.888889f, 0.389864f, 0.327485f, 0.826511f, 0.272904f, 0.77193f, 0.709552f, 0.210526f,
2248 0.483431f, 0.982456f, 0.296296f, 0.795322f, 0.116959f, 0.615984f, 0.0545809f, 0.553606f,
2249 0.732943f, 0.233918f, 0.545809f, 0.0467836f, 0.865497f, 0.366472f, 0.803119f, 0.304094f,
2250 0.518519f, 0.0194932f, 0.45614f, 0.955166f, 0.729045f, 0.230019f, 0.54191f, 0.042885f,
2251 0.269006f, 0.768031f, 0.705653f, 0.206628f, 0.479532f, 0.978558f, 0.292398f, 0.791423f,
2252 0.237817f, 0.736842f, 0.424951f, 0.923977f, 0.136452f, 0.635478f, 0.323587f, 0.822612f,
2253 0.986355f, 0.487329f, 0.674464f, 0.175439f, 0.88499f, 0.385965f, 0.573099f, 0.0740741f,
2254 0.51462f, 0.0155945f, 0.202729f, 0.701754f, 0.148148f, 0.647174f, 0.834308f, 0.335283f,
2255 0.265107f, 0.764133f, 0.951267f, 0.452242f, 0.896686f, 0.397661f, 0.08577f, 0.584795f,
2256 0.8577f, 0.358674f, 0.920078f, 0.421053f, 0.740741f, 0.241715f, 0.678363f, 0.179337f,
2257 0.109162f, 0.608187f, 0.17154f, 0.670565f, 0.491228f, 0.990253f, 0.42885f, 0.927875f,
2258 0.0662768f, 0.565302f, 0.62768f, 0.128655f, 0.183236f, 0.682261f, 0.744639f, 0.245614f,
2259 0.814815f, 0.315789f, 0.378168f, 0.877193f, 0.931774f, 0.432749f, 0.495127f, 0.994152f,
2260 0.0350877f, 0.534113f, 0.97076f, 0.471735f, 0.214425f, 0.71345f, 0.526316f, 0.0272904f,
2261 0.783626f, 0.2846f, 0.222222f, 0.721248f, 0.962963f, 0.463938f, 0.276803f, 0.775828f,
2262 0.966862f, 0.467836f, 0.405458f, 0.904483f, 0.0701754f, 0.569201f, 0.881092f, 0.382066f,
2263 0.218324f, 0.717349f, 0.654971f, 0.155945f, 0.818713f, 0.319688f, 0.132554f, 0.631579f,
2264 0.0623782f, 0.561404f, 0.748538f, 0.249513f, 0.912281f, 0.413255f, 0.974659f, 0.475634f,
2265 0.810916f, 0.311891f, 0.499025f, 0.998051f, 0.163743f, 0.662768f, 0.226121f, 0.725146f,
2266 0.690058f, 0.191033f, 0.00389864f, 0.502924f, 0.557505f, 0.0584795f, 0.120858f, 0.619883f,
2267 0.440546f, 0.939571f, 0.752437f, 0.253411f, 0.307992f, 0.807018f, 0.869396f, 0.37037f,
2268 0.658869f, 0.159844f, 0.346979f, 0.846004f, 0.588694f, 0.0896686f, 0.152047f, 0.651072f,
2269 0.409357f, 0.908382f, 0.596491f, 0.0974659f, 0.339181f, 0.838207f, 0.900585f, 0.401559f,
2270 0.34308f, 0.842105f, 0.779727f, 0.280702f, 0.693957f, 0.194932f, 0.25731f, 0.756335f,
2271 0.592593f, 0.0935673f, 0.0311891f, 0.530214f, 0.444444f, 0.94347f, 0.506823f, 0.00779727f,
2272 0.68616f, 0.187135f, 0.124756f, 0.623782f, 0.288499f, 0.787524f, 0.350877f, 0.849903f,
2273 0.436647f, 0.935673f, 0.873294f, 0.374269f, 0.538012f, 0.0389864f, 0.60039f, 0.101365f,
2274 0.57115f, 0.0721248f, 0.758285f, 0.259259f, 0.719298f, 0.220273f, 0.532164f, 0.0331384f,
2275 0.321637f, 0.820663f, 0.00974659f, 0.508772f, 0.469786f, 0.968811f, 0.282651f, 0.781676f,
2276 0.539961f, 0.0409357f, 0.727096f, 0.22807f, 0.500975f, 0.00194932f, 0.563353f, 0.0643275f,
2277 0.290448f, 0.789474f, 0.477583f, 0.976608f, 0.251462f, 0.750487f, 0.31384f, 0.812865f,
2278 0.94152f, 0.442495f, 0.879142f, 0.380117f, 0.37232f, 0.871345f, 0.309942f, 0.808967f,
2279 0.192982f, 0.692008f, 0.130604f, 0.62963f, 0.621832f, 0.122807f, 0.559454f, 0.0604289f,
2280 0.660819f, 0.161793f, 0.723197f, 0.224172f, 0.403509f, 0.902534f, 0.840156f, 0.341131f,
2281 0.411306f, 0.910331f, 0.473684f, 0.97271f, 0.653021f, 0.153996f, 0.0916179f, 0.590643f,
2282 0.196881f, 0.695906f, 0.384016f, 0.883041f, 0.0955166f, 0.594542f, 0.157895f, 0.65692f,
2283 0.945419f, 0.446394f, 0.633528f, 0.134503f, 0.844055f, 0.345029f, 0.906433f, 0.407407f,
2284 0.165692f, 0.664717f, 0.103314f, 0.602339f, 0.126706f, 0.625731f, 0.189084f, 0.688109f,
2285 0.91423f, 0.415205f, 0.851852f, 0.352827f, 0.875244f, 0.376218f, 0.937622f, 0.438596f,
2286 0.317739f, 0.816764f, 0.255361f, 0.754386f, 0.996101f, 0.497076f, 0.933723f, 0.434698f,
2287 0.567251f, 0.0682261f, 0.504873f, 0.00584795f, 0.247563f, 0.746589f, 0.185185f, 0.684211f,
2288 0.037037f, 0.536062f, 0.0994152f, 0.598441f, 0.777778f, 0.278752f, 0.465887f, 0.964912f,
2289 0.785575f, 0.28655f, 0.847953f, 0.348928f, 0.0292398f, 0.528265f, 0.7154f, 0.216374f,
2290 0.39961f, 0.898636f, 0.961014f, 0.461988f, 0.0487329f, 0.547758f, 0.111111f, 0.610136f,
2291 0.649123f, 0.150097f, 0.212476f, 0.711501f, 0.797271f, 0.298246f, 0.859649f, 0.360624f,
2292 0.118908f, 0.617934f, 0.0565302f, 0.555556f, 0.329435f, 0.82846f, 0.516569f, 0.0175439f,
2293 0.867446f, 0.368421f, 0.805068f, 0.306043f, 0.578947f, 0.079922f, 0.267057f, 0.766082f,
2294 0.270955f, 0.76998f, 0.707602f, 0.208577f, 0.668616f, 0.169591f, 0.606238f, 0.107212f,
2295 0.520468f, 0.0214425f, 0.45809f, 0.957115f, 0.419103f, 0.918129f, 0.356725f, 0.855751f,
2296 0.988304f, 0.489279f, 0.426901f, 0.925926f, 0.450292f, 0.949318f, 0.512671f, 0.0136452f,
2297 0.239766f, 0.738791f, 0.676413f, 0.177388f, 0.699805f, 0.20078f, 0.263158f, 0.762183f,
2298 0.773879f, 0.274854f, 0.337232f, 0.836257f, 0.672515f, 0.173489f, 0.734893f, 0.235867f,
2299 0.0253411f, 0.524366f, 0.586745f, 0.0877193f, 0.423002f, 0.922027f, 0.48538f, 0.984405f,
2300 0.74269f, 0.243665f, 0.680312f, 0.181287f, 0.953216f, 0.454191f, 0.1423f, 0.641326f,
2301 0.493177f, 0.992203f, 0.430799f, 0.929825f, 0.204678f, 0.703704f, 0.890838f, 0.391813f,
2302 0.894737f, 0.395712f, 0.0838207f, 0.582846f, 0.0448343f, 0.54386f, 0.231969f, 0.730994f,
2303 0.146199f, 0.645224f, 0.832359f, 0.333333f, 0.793372f, 0.294347f, 0.980507f, 0.481481f,
2304 0.364522f, 0.863548f, 0.80117f, 0.302144f, 0.824561f, 0.325536f, 0.138402f, 0.637427f,
2305 0.614035f, 0.11501f, 0.0526316f, 0.551657f, 0.0760234f, 0.575049f, 0.88694f, 0.387914f,
2306};
2307
2308PNANOVDB_FORCE_INLINE float pnanovdb_dither_lookup(pnanovdb_bool_t enabled, int offset)
2309{
2310 return enabled ? pnanovdb_dither_lut[offset & 511] : 0.5f;
2311}
2312
2313// ------------------------------------------------ HDDA -----------------------------------------------------------
2314
2315#ifdef PNANOVDB_HDDA
2316
2317// Comment out to disable this explicit round-off check
2318#define PNANOVDB_ENFORCE_FORWARD_STEPPING
2319
2320#define PNANOVDB_HDDA_FLOAT_MAX 1e38f
2321
2322struct pnanovdb_hdda_t
2323{
2324 pnanovdb_int32_t dim;
2325 float tmin;
2326 float tmax;
2327 pnanovdb_coord_t voxel;
2328 pnanovdb_coord_t step;
2329 pnanovdb_vec3_t delta;
2330 pnanovdb_vec3_t next;
2331};
2332PNANOVDB_STRUCT_TYPEDEF(pnanovdb_hdda_t)
2333
2334PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_hdda_pos_to_ijk(PNANOVDB_IN(pnanovdb_vec3_t) pos)
2335{
2336 pnanovdb_coord_t voxel;
2337 voxel.x = pnanovdb_float_to_int32(pnanovdb_floor(PNANOVDB_DEREF(pos).x));
2338 voxel.y = pnanovdb_float_to_int32(pnanovdb_floor(PNANOVDB_DEREF(pos).y));
2339 voxel.z = pnanovdb_float_to_int32(pnanovdb_floor(PNANOVDB_DEREF(pos).z));
2340 return voxel;
2341}
2342
2343PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_hdda_pos_to_voxel(PNANOVDB_IN(pnanovdb_vec3_t) pos, int dim)
2344{
2345 pnanovdb_coord_t voxel;
2346 voxel.x = pnanovdb_float_to_int32(pnanovdb_floor(PNANOVDB_DEREF(pos).x)) & (~(dim - 1));
2347 voxel.y = pnanovdb_float_to_int32(pnanovdb_floor(PNANOVDB_DEREF(pos).y)) & (~(dim - 1));
2348 voxel.z = pnanovdb_float_to_int32(pnanovdb_floor(PNANOVDB_DEREF(pos).z)) & (~(dim - 1));
2349 return voxel;
2350}
2351
2352PNANOVDB_FORCE_INLINE pnanovdb_vec3_t pnanovdb_hdda_ray_start(PNANOVDB_IN(pnanovdb_vec3_t) origin, float tmin, PNANOVDB_IN(pnanovdb_vec3_t) direction)
2353{
2354 pnanovdb_vec3_t pos = pnanovdb_vec3_add(
2355 pnanovdb_vec3_mul(PNANOVDB_DEREF(direction), pnanovdb_vec3_uniform(tmin)),
2356 PNANOVDB_DEREF(origin)
2357 );
2358 return pos;
2359}
2360
2361PNANOVDB_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)
2362{
2363 PNANOVDB_DEREF(hdda).dim = dim;
2364 PNANOVDB_DEREF(hdda).tmin = tmin;
2365 PNANOVDB_DEREF(hdda).tmax = tmax;
2366
2367 pnanovdb_vec3_t pos = pnanovdb_hdda_ray_start(origin, tmin, direction);
2368 pnanovdb_vec3_t dir_inv = pnanovdb_vec3_div(pnanovdb_vec3_uniform(1.f), PNANOVDB_DEREF(direction));
2369
2370 PNANOVDB_DEREF(hdda).voxel = pnanovdb_hdda_pos_to_voxel(PNANOVDB_REF(pos), dim);
2371
2372 // x
2373 if (PNANOVDB_DEREF(direction).x == 0.f)
2374 {
2375 PNANOVDB_DEREF(hdda).next.x = PNANOVDB_HDDA_FLOAT_MAX;
2376 PNANOVDB_DEREF(hdda).step.x = 0;
2377 PNANOVDB_DEREF(hdda).delta.x = 0.f;
2378 }
2379 else if (dir_inv.x > 0.f)
2380 {
2381 PNANOVDB_DEREF(hdda).step.x = 1;
2382 PNANOVDB_DEREF(hdda).next.x = PNANOVDB_DEREF(hdda).tmin + (PNANOVDB_DEREF(hdda).voxel.x + dim - pos.x) * dir_inv.x;
2383 PNANOVDB_DEREF(hdda).delta.x = dir_inv.x;
2384 }
2385 else
2386 {
2387 PNANOVDB_DEREF(hdda).step.x = -1;
2388 PNANOVDB_DEREF(hdda).next.x = PNANOVDB_DEREF(hdda).tmin + (PNANOVDB_DEREF(hdda).voxel.x - pos.x) * dir_inv.x;
2389 PNANOVDB_DEREF(hdda).delta.x = -dir_inv.x;
2390 }
2391
2392 // y
2393 if (PNANOVDB_DEREF(direction).y == 0.f)
2394 {
2395 PNANOVDB_DEREF(hdda).next.y = PNANOVDB_HDDA_FLOAT_MAX;
2396 PNANOVDB_DEREF(hdda).step.y = 0;
2397 PNANOVDB_DEREF(hdda).delta.y = 0.f;
2398 }
2399 else if (dir_inv.y > 0.f)
2400 {
2401 PNANOVDB_DEREF(hdda).step.y = 1;
2402 PNANOVDB_DEREF(hdda).next.y = PNANOVDB_DEREF(hdda).tmin + (PNANOVDB_DEREF(hdda).voxel.y + dim - pos.y) * dir_inv.y;
2403 PNANOVDB_DEREF(hdda).delta.y = dir_inv.y;
2404 }
2405 else
2406 {
2407 PNANOVDB_DEREF(hdda).step.y = -1;
2408 PNANOVDB_DEREF(hdda).next.y = PNANOVDB_DEREF(hdda).tmin + (PNANOVDB_DEREF(hdda).voxel.y - pos.y) * dir_inv.y;
2409 PNANOVDB_DEREF(hdda).delta.y = -dir_inv.y;
2410 }
2411
2412 // z
2413 if (PNANOVDB_DEREF(direction).z == 0.f)
2414 {
2415 PNANOVDB_DEREF(hdda).next.z = PNANOVDB_HDDA_FLOAT_MAX;
2416 PNANOVDB_DEREF(hdda).step.z = 0;
2417 PNANOVDB_DEREF(hdda).delta.z = 0.f;
2418 }
2419 else if (dir_inv.z > 0.f)
2420 {
2421 PNANOVDB_DEREF(hdda).step.z = 1;
2422 PNANOVDB_DEREF(hdda).next.z = PNANOVDB_DEREF(hdda).tmin + (PNANOVDB_DEREF(hdda).voxel.z + dim - pos.z) * dir_inv.z;
2423 PNANOVDB_DEREF(hdda).delta.z = dir_inv.z;
2424 }
2425 else
2426 {
2427 PNANOVDB_DEREF(hdda).step.z = -1;
2428 PNANOVDB_DEREF(hdda).next.z = PNANOVDB_DEREF(hdda).tmin + (PNANOVDB_DEREF(hdda).voxel.z - pos.z) * dir_inv.z;
2429 PNANOVDB_DEREF(hdda).delta.z = -dir_inv.z;
2430 }
2431}
2432
2433PNANOVDB_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)
2434{
2435 if (PNANOVDB_DEREF(hdda).dim == dim)
2436 {
2437 return PNANOVDB_FALSE;
2438 }
2439 PNANOVDB_DEREF(hdda).dim = dim;
2440
2441 pnanovdb_vec3_t pos = pnanovdb_vec3_add(
2442 pnanovdb_vec3_mul(PNANOVDB_DEREF(direction), pnanovdb_vec3_uniform(PNANOVDB_DEREF(hdda).tmin)),
2443 PNANOVDB_DEREF(origin)
2444 );
2445 pnanovdb_vec3_t dir_inv = pnanovdb_vec3_div(pnanovdb_vec3_uniform(1.f), PNANOVDB_DEREF(direction));
2446
2447 PNANOVDB_DEREF(hdda).voxel = pnanovdb_hdda_pos_to_voxel(PNANOVDB_REF(pos), dim);
2448
2449 if (PNANOVDB_DEREF(hdda).step.x != 0)
2450 {
2451 PNANOVDB_DEREF(hdda).next.x = PNANOVDB_DEREF(hdda).tmin + (PNANOVDB_DEREF(hdda).voxel.x - pos.x) * dir_inv.x;
2452 if (PNANOVDB_DEREF(hdda).step.x > 0)
2453 {
2454 PNANOVDB_DEREF(hdda).next.x += dim * dir_inv.x;
2455 }
2456 }
2457 if (PNANOVDB_DEREF(hdda).step.y != 0)
2458 {
2459 PNANOVDB_DEREF(hdda).next.y = PNANOVDB_DEREF(hdda).tmin + (PNANOVDB_DEREF(hdda).voxel.y - pos.y) * dir_inv.y;
2460 if (PNANOVDB_DEREF(hdda).step.y > 0)
2461 {
2462 PNANOVDB_DEREF(hdda).next.y += dim * dir_inv.y;
2463 }
2464 }
2465 if (PNANOVDB_DEREF(hdda).step.z != 0)
2466 {
2467 PNANOVDB_DEREF(hdda).next.z = PNANOVDB_DEREF(hdda).tmin + (PNANOVDB_DEREF(hdda).voxel.z - pos.z) * dir_inv.z;
2468 if (PNANOVDB_DEREF(hdda).step.z > 0)
2469 {
2470 PNANOVDB_DEREF(hdda).next.z += dim * dir_inv.z;
2471 }
2472 }
2473
2474 return PNANOVDB_TRUE;
2475}
2476
2477PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_hdda_step(PNANOVDB_INOUT(pnanovdb_hdda_t) hdda)
2478{
2479 pnanovdb_bool_t ret;
2480 if (PNANOVDB_DEREF(hdda).next.x < PNANOVDB_DEREF(hdda).next.y && PNANOVDB_DEREF(hdda).next.x < PNANOVDB_DEREF(hdda).next.z)
2481 {
2482#ifdef PNANOVDB_ENFORCE_FORWARD_STEPPING
2483 if (PNANOVDB_DEREF(hdda).next.x <= PNANOVDB_DEREF(hdda).tmin)
2484 {
2485 PNANOVDB_DEREF(hdda).next.x += PNANOVDB_DEREF(hdda).tmin - 0.999999f * PNANOVDB_DEREF(hdda).next.x + 1.0e-6f;
2486 }
2487#endif
2488 PNANOVDB_DEREF(hdda).tmin = PNANOVDB_DEREF(hdda).next.x;
2489 PNANOVDB_DEREF(hdda).next.x += PNANOVDB_DEREF(hdda).dim * PNANOVDB_DEREF(hdda).delta.x;
2490 PNANOVDB_DEREF(hdda).voxel.x += PNANOVDB_DEREF(hdda).dim * PNANOVDB_DEREF(hdda).step.x;
2491 ret = PNANOVDB_DEREF(hdda).tmin <= PNANOVDB_DEREF(hdda).tmax;
2492 }
2493 else if (PNANOVDB_DEREF(hdda).next.y < PNANOVDB_DEREF(hdda).next.z)
2494 {
2495#ifdef PNANOVDB_ENFORCE_FORWARD_STEPPING
2496 if (PNANOVDB_DEREF(hdda).next.y <= PNANOVDB_DEREF(hdda).tmin)
2497 {
2498 PNANOVDB_DEREF(hdda).next.y += PNANOVDB_DEREF(hdda).tmin - 0.999999f * PNANOVDB_DEREF(hdda).next.y + 1.0e-6f;
2499 }
2500#endif
2501 PNANOVDB_DEREF(hdda).tmin = PNANOVDB_DEREF(hdda).next.y;
2502 PNANOVDB_DEREF(hdda).next.y += PNANOVDB_DEREF(hdda).dim * PNANOVDB_DEREF(hdda).delta.y;
2503 PNANOVDB_DEREF(hdda).voxel.y += PNANOVDB_DEREF(hdda).dim * PNANOVDB_DEREF(hdda).step.y;
2504 ret = PNANOVDB_DEREF(hdda).tmin <= PNANOVDB_DEREF(hdda).tmax;
2505 }
2506 else
2507 {
2508#ifdef PNANOVDB_ENFORCE_FORWARD_STEPPING
2509 if (PNANOVDB_DEREF(hdda).next.z <= PNANOVDB_DEREF(hdda).tmin)
2510 {
2511 PNANOVDB_DEREF(hdda).next.z += PNANOVDB_DEREF(hdda).tmin - 0.999999f * PNANOVDB_DEREF(hdda).next.z + 1.0e-6f;
2512 }
2513#endif
2514 PNANOVDB_DEREF(hdda).tmin = PNANOVDB_DEREF(hdda).next.z;
2515 PNANOVDB_DEREF(hdda).next.z += PNANOVDB_DEREF(hdda).dim * PNANOVDB_DEREF(hdda).delta.z;
2516 PNANOVDB_DEREF(hdda).voxel.z += PNANOVDB_DEREF(hdda).dim * PNANOVDB_DEREF(hdda).step.z;
2517 ret = PNANOVDB_DEREF(hdda).tmin <= PNANOVDB_DEREF(hdda).tmax;
2518 }
2519 return ret;
2520}
2521
2522PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_hdda_ray_clip(
2523 PNANOVDB_IN(pnanovdb_vec3_t) bbox_min,
2524 PNANOVDB_IN(pnanovdb_vec3_t) bbox_max,
2525 PNANOVDB_IN(pnanovdb_vec3_t) origin, PNANOVDB_INOUT(float) tmin,
2526 PNANOVDB_IN(pnanovdb_vec3_t) direction, PNANOVDB_INOUT(float) tmax
2527)
2528{
2529 pnanovdb_vec3_t dir_inv = pnanovdb_vec3_div(pnanovdb_vec3_uniform(1.f), PNANOVDB_DEREF(direction));
2530 pnanovdb_vec3_t t0 = pnanovdb_vec3_mul(pnanovdb_vec3_sub(PNANOVDB_DEREF(bbox_min), PNANOVDB_DEREF(origin)), dir_inv);
2531 pnanovdb_vec3_t t1 = pnanovdb_vec3_mul(pnanovdb_vec3_sub(PNANOVDB_DEREF(bbox_max), PNANOVDB_DEREF(origin)), dir_inv);
2532 pnanovdb_vec3_t tmin3 = pnanovdb_vec3_min(t0, t1);
2533 pnanovdb_vec3_t tmax3 = pnanovdb_vec3_max(t0, t1);
2534 float tnear = pnanovdb_max(tmin3.x, pnanovdb_max(tmin3.y, tmin3.z));
2535 float tfar = pnanovdb_min(tmax3.x, pnanovdb_min(tmax3.y, tmax3.z));
2536 pnanovdb_bool_t hit = tnear <= tfar;
2537 PNANOVDB_DEREF(tmin) = pnanovdb_max(PNANOVDB_DEREF(tmin), tnear);
2538 PNANOVDB_DEREF(tmax) = pnanovdb_min(PNANOVDB_DEREF(tmax), tfar);
2539 return hit;
2540}
2541
2542PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_hdda_zero_crossing(
2543 pnanovdb_grid_type_t grid_type,
2544 pnanovdb_buf_t buf,
2545 PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc,
2546 PNANOVDB_IN(pnanovdb_vec3_t) origin, float tmin,
2547 PNANOVDB_IN(pnanovdb_vec3_t) direction, float tmax,
2548 PNANOVDB_INOUT(float) thit,
2549 PNANOVDB_INOUT(float) v
2550)
2551{
2552 pnanovdb_coord_t bbox_min = pnanovdb_root_get_bbox_min(buf, PNANOVDB_DEREF(acc).root);
2553 pnanovdb_coord_t bbox_max = pnanovdb_root_get_bbox_max(buf, PNANOVDB_DEREF(acc).root);
2554 pnanovdb_vec3_t bbox_minf = pnanovdb_coord_to_vec3(bbox_min);
2555 pnanovdb_vec3_t bbox_maxf = pnanovdb_coord_to_vec3(pnanovdb_coord_add(bbox_max, pnanovdb_coord_uniform(1)));
2556
2557 pnanovdb_bool_t hit = pnanovdb_hdda_ray_clip(PNANOVDB_REF(bbox_minf), PNANOVDB_REF(bbox_maxf), origin, PNANOVDB_REF(tmin), direction, PNANOVDB_REF(tmax));
2558 if (!hit || tmax > 1.0e20f)
2559 {
2560 return PNANOVDB_FALSE;
2561 }
2562
2563 pnanovdb_vec3_t pos = pnanovdb_hdda_ray_start(origin, tmin, direction);
2564 pnanovdb_coord_t ijk = pnanovdb_hdda_pos_to_ijk(PNANOVDB_REF(pos));
2565
2566 pnanovdb_address_t address = pnanovdb_readaccessor_get_value_address(PNANOVDB_GRID_TYPE_FLOAT, buf, acc, PNANOVDB_REF(ijk));
2567 float v0 = pnanovdb_read_float(buf, address);
2568
2569 pnanovdb_int32_t dim = pnanovdb_uint32_as_int32(pnanovdb_readaccessor_get_dim(PNANOVDB_GRID_TYPE_FLOAT, buf, acc, PNANOVDB_REF(ijk)));
2570 pnanovdb_hdda_t hdda;
2571 pnanovdb_hdda_init(PNANOVDB_REF(hdda), origin, tmin, direction, tmax, dim);
2572 while (pnanovdb_hdda_step(PNANOVDB_REF(hdda)))
2573 {
2574 pnanovdb_vec3_t pos_start = pnanovdb_hdda_ray_start(origin, hdda.tmin + 1.0001f, direction);
2575 ijk = pnanovdb_hdda_pos_to_ijk(PNANOVDB_REF(pos_start));
2576 dim = pnanovdb_uint32_as_int32(pnanovdb_readaccessor_get_dim(PNANOVDB_GRID_TYPE_FLOAT, buf, acc, PNANOVDB_REF(ijk)));
2577 pnanovdb_hdda_update(PNANOVDB_REF(hdda), origin, direction, dim);
2578 if (hdda.dim > 1 || !pnanovdb_readaccessor_is_active(grid_type, buf, acc, PNANOVDB_REF(ijk)))
2579 {
2580 continue;
2581 }
2582 while (pnanovdb_hdda_step(PNANOVDB_REF(hdda)) && pnanovdb_readaccessor_is_active(grid_type, buf, acc, PNANOVDB_REF(hdda.voxel)))
2583 {
2584 ijk = hdda.voxel;
2585 pnanovdb_address_t address = pnanovdb_readaccessor_get_value_address(PNANOVDB_GRID_TYPE_FLOAT, buf, acc, PNANOVDB_REF(ijk));
2586 PNANOVDB_DEREF(v) = pnanovdb_read_float(buf, address);
2587 if (PNANOVDB_DEREF(v) * v0 < 0.f)
2588 {
2589 PNANOVDB_DEREF(thit) = hdda.tmin;
2590 return PNANOVDB_TRUE;
2591 }
2592 }
2593 }
2594 return PNANOVDB_FALSE;
2595}
2596
2597#endif
2598
2599#endif // end of NANOVDB_PNANOVDB_H_HAS_BEEN_INCLUDED
value
ValueT value
Definition: GridBuilder.h:1290
child
ChildT * child
Definition: GridBuilder.h:1289
pnanovdb_version_get_minor
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_version_get_minor(pnanovdb_uint32_t version)
Definition: PNanoVDB.h:834
pnanovdb_leaf_index_get_value_index
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_index_get_value_index(pnanovdb_grid_type_t grid_type, pnanovdb_buf_t buf, pnanovdb_leaf_handle_t leaf, PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:1430
PNANOVDB_GRID_OFF_VERSION
#define PNANOVDB_GRID_OFF_VERSION
Definition: PNanoVDB.h:768
pnanovdb_readaccessor_get_value_address_and_level
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:1864
pnanovdb_gridblindmetadata_get_semantic
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_gridblindmetadata_get_semantic(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p)
Definition: PNanoVDB.h:876
pnanovdb_root_get_value_address
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:1649
PNANOVDB_UPPER_OFF_VALUE_MASK
#define PNANOVDB_UPPER_OFF_VALUE_MASK
Definition: PNanoVDB.h:1031
pnanovdb_map_get_matf
PNANOVDB_FORCE_INLINE float pnanovdb_map_get_matf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:716
PNANOVDB_TREE_OFF_NODE_COUNT_LOWER
#define PNANOVDB_TREE_OFF_NODE_COUNT_LOWER
Definition: PNanoVDB.h:914
pnanovdb_dither_lut
PNANOVDB_STATIC_CONST float pnanovdb_dither_lut[512]
Definition: PNanoVDB.h:2240
pnanovdb_root_tile_get_state
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_root_tile_get_state(pnanovdb_buf_t buf, pnanovdb_root_tile_handle_t p)
Definition: PNanoVDB.h:1007
pnanovdb_root_get_tile_count
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_root_get_tile_count(pnanovdb_buf_t buf, pnanovdb_root_handle_t p)
Definition: PNanoVDB.h:979
PNANOVDB_TREE_OFF_TILE_COUNT_LEAF
#define PNANOVDB_TREE_OFF_TILE_COUNT_LEAF
Definition: PNanoVDB.h:916
pnanovdb_read_coord
PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_read_coord(pnanovdb_buf_t buf, pnanovdb_address_t address)
Definition: PNanoVDB.h:592
PNANOVDB_UPPER_OFF_FLAGS
#define PNANOVDB_UPPER_OFF_FLAGS
Definition: PNanoVDB.h:1030
PNANOVDB_GRID_TYPE_FLOAT
#define PNANOVDB_GRID_TYPE_FLOAT
Definition: PNanoVDB.h:638
pnanovdb_map_get_invmatf
PNANOVDB_FORCE_INLINE float pnanovdb_map_get_invmatf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:719
pnanovdb_dither_lookup
PNANOVDB_FORCE_INLINE float pnanovdb_dither_lookup(pnanovdb_bool_t enabled, int offset)
Definition: PNanoVDB.h:2308
pnanovdb_leaf_index_get_max_index
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_index_get_max_index(pnanovdb_buf_t buf, pnanovdb_address_t max_address)
Definition: PNanoVDB.h:1415
pnanovdb_gridblindmetadata_get_data_type
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_gridblindmetadata_get_data_type(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p)
Definition: PNanoVDB.h:882
pnanovdb_grid_type_value_strides_bits
PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_value_strides_bits[20]
Definition: PNanoVDB.h:683
pnanovdb_root_get_stddev_address
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:1615
pnanovdb_lower_get_value_mask
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:1084
PNANOVDB_GRID_OFF_BLIND_METADATA_OFFSET
#define PNANOVDB_GRID_OFF_BLIND_METADATA_OFFSET
Definition: PNanoVDB.h:779
PNANOVDB_MAP_OFF_MATF
#define PNANOVDB_MAP_OFF_MATF
Definition: PNanoVDB.h:707
pnanovdb_upper_get_flags
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_upper_get_flags(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p)
Definition: PNanoVDB.h:1040
pnanovdb_leaf_coord_to_offset
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_leaf_coord_to_offset(PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:1275
PNANOVDB_ROOT_OFF_BBOX_MIN
#define PNANOVDB_ROOT_OFF_BBOX_MIN
Definition: PNanoVDB.h:969
pnanovdb_lower_get_stddev_address
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:1475
pnanovdb_root_tile_get_value_address
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:1621
pnanovdb_upper_is_active_and_cache
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:2018
pnanovdb_gridblindmetadata_get_name
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:885
pnanovdb_root_is_active_and_cache
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:2036
PNANOVDB_ROOT_TILE_OFF_CHILD
#define PNANOVDB_ROOT_TILE_OFF_CHILD
Definition: PNanoVDB.h:998
pnanovdb_lower_get_value_address_and_level_and_cache
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:1783
PNANOVDB_GRID_OFF_GRID_COUNT
#define PNANOVDB_GRID_OFF_GRID_COUNT
Definition: PNanoVDB.h:771
pnanovdb_grid_get_grid_class
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_grid_class(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:817
pnanovdb_grid_type_minmax_aligns_bits
PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_minmax_aligns_bits[20]
Definition: PNanoVDB.h:686
pnanovdb_tree_get_node_offset_lower
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_tree_get_node_offset_lower(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p)
Definition: PNanoVDB.h:924
pnanovdb_lower_get_value_address
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:1518
PNANOVDB_LEAF_OFF_VALUE_MASK
#define PNANOVDB_LEAF_OFF_VALUE_MASK
Definition: PNanoVDB.h:1110
pnanovdb_lower_get_bbox_max
PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_lower_get_bbox_max(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p)
Definition: PNanoVDB.h:1078
pnanovdb_tree_get_tile_count_lower
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_tile_count_lower(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p)
Definition: PNanoVDB.h:945
pnanovdb_lower_get_value_address_and_cache
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:1803
pnanovdb_read_bit
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:601
pnanovdb_root_get_bbox_max
PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_root_get_bbox_max(pnanovdb_buf_t buf, pnanovdb_root_handle_t p)
Definition: PNanoVDB.h:976
pnanovdb_root_get_value_address_and_level
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:1627
pnanovdb_leaf_get_value_mask
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:1122
PNANOVDB_MAP_OFF_VECD
#define PNANOVDB_MAP_OFF_VECD
Definition: PNanoVDB.h:713
pnanovdb_lower_get_value_address_and_level
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:1500
PNANOVDB_ROOT_OFF_TABLE_SIZE
#define PNANOVDB_ROOT_OFF_TABLE_SIZE
Definition: PNanoVDB.h:971
pnanovdb_leaf_get_bbox_min
PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_leaf_get_bbox_min(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t p)
Definition: PNanoVDB.h:1116
PNANOVDB_LEAF_OFF_BBOX_DIF_AND_FLAGS
#define PNANOVDB_LEAF_OFF_BBOX_DIF_AND_FLAGS
Definition: PNanoVDB.h:1109
pnanovdb_uint64_offset
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_uint64_offset(pnanovdb_uint64_t a, pnanovdb_uint32_t b)
Definition: PNanoVDB.h:1394
pnanovdb_grid_get_gridblindmetadata
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:1186
pnanovdb_root_get_dim_and_cache
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:1946
pnanovdb_upper_get_bbox_max
PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_upper_get_bbox_max(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p)
Definition: PNanoVDB.h:1037
PNANOVDB_LOWER_OFF_FLAGS
#define PNANOVDB_LOWER_OFF_FLAGS
Definition: PNanoVDB.h:1071
pnanovdb_grid_get_version
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_version(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:788
pnanovdb_readaccessor_get_value_address_bit
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:1895
pnanovdb_map_get_taperf
PNANOVDB_FORCE_INLINE float pnanovdb_map_get_taperf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:725
pnanovdb_leaf_get_dim_and_cache
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:1905
pnanovdb_tree_get_node_offset_root
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_tree_get_node_offset_root(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p)
Definition: PNanoVDB.h:930
pnanovdb_grid_type_minmax_strides_bits
PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_minmax_strides_bits[20]
Definition: PNanoVDB.h:685
pnanovdb_tree_get_node_offset_leaf
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_tree_get_node_offset_leaf(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p)
Definition: PNanoVDB.h:921
pnanovdb_lower_get_min_address
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:1457
pnanovdb_map_apply
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:2085
pnanovdb_upper_get_stddev_address
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:1549
pnanovdb_uint32_countbits
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_uint32_countbits(pnanovdb_uint32_t value)
Definition: PNanoVDB.h:1357
pnanovdb_grid_world_to_index_dirf
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:2145
pnanovdb_lower_get_table_address
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:1481
pnanovdb_lower_get_flags
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_lower_get_flags(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p)
Definition: PNanoVDB.h:1081
pnanovdb_grid_index_to_worldf
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:2139
pnanovdb_upper_get_value_mask
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:1043
pnanovdb_root_get_child
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:1234
PNANOVDB_GRID_OFF_GRID_INDEX
#define PNANOVDB_GRID_OFF_GRID_INDEX
Definition: PNanoVDB.h:770
pnanovdb_grid_get_blind_metadata_count
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_blind_metadata_count(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:826
pnanovdb_lower_coord_to_offset
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_lower_coord_to_offset(PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:1450
PNANOVDB_UPPER_OFF_BBOX_MIN
#define PNANOVDB_UPPER_OFF_BBOX_MIN
Definition: PNanoVDB.h:1028
pnanovdb_lower_get_table_child
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:1487
PNANOVDB_GRID_OFF_MAP
#define PNANOVDB_GRID_OFF_MAP
Definition: PNanoVDB.h:774
PNANOVDB_LOWER_OFF_BBOX_MIN
#define PNANOVDB_LOWER_OFF_BBOX_MIN
Definition: PNanoVDB.h:1069
pnanovdb_leaf_fp16_read_float
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:1344
pnanovdb_readaccessor_iscached2
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_readaccessor_iscached2(PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, int dirty)
Definition: PNanoVDB.h:1762
PNANOVDB_GRIDBLINDMETADATA_OFF_SEMANTIC
#define PNANOVDB_GRIDBLINDMETADATA_OFF_SEMANTIC
Definition: PNanoVDB.h:862
PNANOVDB_GRID_OFF_WORLD_BBOX
#define PNANOVDB_GRID_OFF_WORLD_BBOX
Definition: PNanoVDB.h:775
PNANOVDB_TREE_OFF_NODE_OFFSET_UPPER
#define PNANOVDB_TREE_OFF_NODE_OFFSET_UPPER
Definition: PNanoVDB.h:911
pnanovdb_tree_get_voxel_count
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_tree_get_voxel_count(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p)
Definition: PNanoVDB.h:951
pnanovdb_grid_get_map
PNANOVDB_FORCE_INLINE pnanovdb_map_handle_t pnanovdb_grid_get_map(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:806
pnanovdb_leaf_get_value_address_and_cache
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:1777
PNANOVDB_LOWER_OFF_VALUE_MASK
#define PNANOVDB_LOWER_OFF_VALUE_MASK
Definition: PNanoVDB.h:1072
pnanovdb_map_get_matd
PNANOVDB_FORCE_INLINE double pnanovdb_map_get_matd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:728
pnanovdb_root_get_tile_zero
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:1227
pnanovdb_gridblindmetadata_get_element_count
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_gridblindmetadata_get_element_count(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p)
Definition: PNanoVDB.h:870
PNANOVDB_ROOT_OFF_BBOX_MAX
#define PNANOVDB_ROOT_OFF_BBOX_MAX
Definition: PNanoVDB.h:970
PNANOVDB_UPPER_OFF_CHILD_MASK
#define PNANOVDB_UPPER_OFF_CHILD_MASK
Definition: PNanoVDB.h:1032
PNANOVDB_MAP_OFF_VECF
#define PNANOVDB_MAP_OFF_VECF
Definition: PNanoVDB.h:709
pnanovdb_leaf_count_on_range
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_leaf_count_on_range(pnanovdb_buf_t buf, pnanovdb_leaf_handle_t p, pnanovdb_uint32_t max_index)
Definition: PNanoVDB.h:1377
pnanovdb_upper_get_value_address_and_cache
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:1828
PNANOVDB_TREE_OFF_VOXEL_COUNT
#define PNANOVDB_TREE_OFF_VOXEL_COUNT
Definition: PNanoVDB.h:919
pnanovdb_leaf_fp4_read_float
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:1334
pnanovdb_tree_get_tile_count_leaf
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_tile_count_leaf(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p)
Definition: PNanoVDB.h:942
pnanovdb_root_get_value_address_and_cache
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:1858
pnanovdb_upper_get_value_address_and_level
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:1574
PNANOVDB_LEAF_TABLE_NEG_OFF_QUANTUM
#define PNANOVDB_LEAF_TABLE_NEG_OFF_QUANTUM
Definition: PNanoVDB.h:1114
pnanovdb_upper_get_dim_and_cache
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:1928
pnanovdb_readaccessor_iscached1
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_readaccessor_iscached1(PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, int dirty)
Definition: PNanoVDB.h:1752
pnanovdb_upper_get_table_address
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:1555
PNANOVDB_MAP_OFF_TAPERF
#define PNANOVDB_MAP_OFF_TAPERF
Definition: PNanoVDB.h:710
PNANOVDB_TREE_OFF_NODE_OFFSET_LEAF
#define PNANOVDB_TREE_OFF_NODE_OFFSET_LEAF
Definition: PNanoVDB.h:909
pnanovdb_gridblindmetadata_get_byte_offset
PNANOVDB_FORCE_INLINE pnanovdb_int64_t pnanovdb_gridblindmetadata_get_byte_offset(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p)
Definition: PNanoVDB.h:867
pnanovdb_grid_get_magic
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_grid_get_magic(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:782
pnanovdb_leaf_fp8_read_float
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:1339
pnanovdb_grid_get_blind_metadata_offset
PNANOVDB_FORCE_INLINE pnanovdb_int64_t pnanovdb_grid_get_blind_metadata_offset(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:823
pnanovdb_tree_get_node_count_leaf
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_node_count_leaf(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p)
Definition: PNanoVDB.h:933
pnanovdb_grid_get_checksum
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_grid_get_checksum(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:785
pnanovdb_read_uint32
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_read_uint32(pnanovdb_buf_t buf, pnanovdb_address_t address)
Definition: PNanoVDB.h:568
PNANOVDB_GRID_OFF_CHECKSUM
#define PNANOVDB_GRID_OFF_CHECKSUM
Definition: PNanoVDB.h:767
PNANOVDB_MAP_OFF_INVMATD
#define PNANOVDB_MAP_OFF_INVMATD
Definition: PNanoVDB.h:712
PNANOVDB_TREE_OFF_NODE_OFFSET_ROOT
#define PNANOVDB_TREE_OFF_NODE_OFFSET_ROOT
Definition: PNanoVDB.h:912
PNANOVDB_GRIDBLINDMETADATA_OFF_DATA_CLASS
#define PNANOVDB_GRIDBLINDMETADATA_OFF_DATA_CLASS
Definition: PNanoVDB.h:863
PNANOVDB_GRIDBLINDMETADATA_OFF_FLAGS
#define PNANOVDB_GRIDBLINDMETADATA_OFF_FLAGS
Definition: PNanoVDB.h:861
pnanovdb_grid_get_grid_index
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_grid_index(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:794
pnanovdb_upper_get_value_address
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:1591
PNANOVDB_LEAF_TABLE_NEG_OFF_MINIMUM
#define PNANOVDB_LEAF_TABLE_NEG_OFF_MINIMUM
Definition: PNanoVDB.h:1113
pnanovdb_lower_get_bbox_min
PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_lower_get_bbox_min(pnanovdb_buf_t buf, pnanovdb_lower_handle_t p)
Definition: PNanoVDB.h:1075
pnanovdb_version_get_major
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_version_get_major(pnanovdb_uint32_t version)
Definition: PNanoVDB.h:830
pnanovdb_grid_get_grid_name
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:803
pnanovdb_tree_get_node_count_upper
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_node_count_upper(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p)
Definition: PNanoVDB.h:939
pnanovdb_lower_get_ave_address
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:1469
PNANOVDB_GRID_OFF_GRID_TYPE
#define PNANOVDB_GRID_OFF_GRID_TYPE
Definition: PNanoVDB.h:778
pnanovdb_root_get_min_address
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:1597
PNANOVDB_MAP_OFF_INVMATF
#define PNANOVDB_MAP_OFF_INVMATF
Definition: PNanoVDB.h:708
pnanovdb_root_fp8_read_float
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:1677
pnanovdb_read_int32
PNANOVDB_FORCE_INLINE pnanovdb_int32_t pnanovdb_read_int32(pnanovdb_buf_t buf, pnanovdb_address_t address)
Definition: PNanoVDB.h:576
PNANOVDB_GRIDBLINDMETADATA_OFF_BYTE_OFFSET
#define PNANOVDB_GRIDBLINDMETADATA_OFF_BYTE_OFFSET
Definition: PNanoVDB.h:859
PNANOVDB_GRID_SIZE
#define PNANOVDB_GRID_SIZE
Definition: PNanoVDB.h:764
PNANOVDB_ROOT_TILE_OFF_KEY
#define PNANOVDB_ROOT_TILE_OFF_KEY
Definition: PNanoVDB.h:997
PNANOVDB_TREE_OFF_NODE_OFFSET_LOWER
#define PNANOVDB_TREE_OFF_NODE_OFFSET_LOWER
Definition: PNanoVDB.h:910
pnanovdb_upper_get_value_address_and_level_and_cache
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:1809
pnanovdb_leaf_is_active_and_cache
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:1994
pnanovdb_tree_get_node_offset_upper
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_tree_get_node_offset_upper(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p)
Definition: PNanoVDB.h:927
pnanovdb_readaccessor_is_active
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:2059
PNANOVDB_UPPER_OFF_BBOX_MAX
#define PNANOVDB_UPPER_OFF_BBOX_MAX
Definition: PNanoVDB.h:1029
pnanovdb_lower_get_max_address
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:1463
pnanodvb_grid_get_gridblindmetadata_value_address
PNANOVDB_FORCE_INLINE pnanovdb_address_t pnanodvb_grid_get_gridblindmetadata_value_address(pnanovdb_buf_t buf, pnanovdb_grid_handle_t grid, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:1195
PNANOVDB_MAP_OFF_MATD
#define PNANOVDB_MAP_OFF_MATD
Definition: PNanoVDB.h:711
PNANOVDB_LOWER_OFF_BBOX_MAX
#define PNANOVDB_LOWER_OFF_BBOX_MAX
Definition: PNanoVDB.h:1070
pnanovdb_lower_get_dim_and_cache
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:1910
pnanovdb_tree_get_node_count_lower
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_node_count_lower(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p)
Definition: PNanoVDB.h:936
PNANOVDB_GRIDBLINDMETADATA_OFF_ELEMENT_COUNT
#define PNANOVDB_GRIDBLINDMETADATA_OFF_ELEMENT_COUNT
Definition: PNanoVDB.h:860
pnanovdb_readaccessor_get_dim
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:1968
pnanovdb_map_apply_jacobi
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:2109
pnanovdb_tree_get_root
PNANOVDB_FORCE_INLINE pnanovdb_root_handle_t pnanovdb_tree_get_root(pnanovdb_buf_t buf, pnanovdb_tree_handle_t tree)
Definition: PNanoVDB.h:1211
PNANOVDB_GRID_OFF_GRID_CLASS
#define PNANOVDB_GRID_OFF_GRID_CLASS
Definition: PNanoVDB.h:777
pnanovdb_read_double
PNANOVDB_FORCE_INLINE double pnanovdb_read_double(pnanovdb_buf_t buf, pnanovdb_address_t address)
Definition: PNanoVDB.h:588
PNANOVDB_GRID_TYPE_END
#define PNANOVDB_GRID_TYPE_END
Definition: PNanoVDB.h:657
pnanovdb_readaccessor_get_value_address
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:1889
pnanovdb_root_get_bbox_min
PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_root_get_bbox_min(pnanovdb_buf_t buf, pnanovdb_root_handle_t p)
Definition: PNanoVDB.h:973
pnanovdb_root_fp16_read_float
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:1691
pnanovdb_grid_get_grid_count
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_grid_count(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:797
pnanovdb_read_int64
PNANOVDB_FORCE_INLINE pnanovdb_int64_t pnanovdb_read_int64(pnanovdb_buf_t buf, pnanovdb_address_t address)
Definition: PNanoVDB.h:584
pnanovdb_map_get_vecd
PNANOVDB_FORCE_INLINE double pnanovdb_map_get_vecd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:734
pnanovdb_map_get_invmatd
PNANOVDB_FORCE_INLINE double pnanovdb_map_get_invmatd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:731
pnanovdb_root_tile_get_key
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_root_tile_get_key(pnanovdb_buf_t buf, pnanovdb_root_tile_handle_t p)
Definition: PNanoVDB.h:1001
pnanovdb_map_apply_inverse_jacobi
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:2121
pnanovdb_root_fpn_read_float
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:1705
pnanovdb_lower_is_active_and_cache
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:2000
pnanovdb_grid_type_stat_strides_bits
PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_stat_strides_bits[20]
Definition: PNanoVDB.h:687
pnanovdb_grid_type_table_strides_bits
PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_table_strides_bits[20]
Definition: PNanoVDB.h:684
pnanovdb_readaccessor_computedirty
PNANOVDB_FORCE_INLINE int pnanovdb_readaccessor_computedirty(PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:1772
PNANOVDB_GRIDBLINDMETADATA_OFF_NAME
#define PNANOVDB_GRIDBLINDMETADATA_OFF_NAME
Definition: PNanoVDB.h:865
pnanovdb_lower_get_child_mask
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:1088
pnanovdb_leaf_get_value_address
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:1312
PNANOVDB_GRID_OFF_GRID_NAME
#define PNANOVDB_GRID_OFF_GRID_NAME
Definition: PNanoVDB.h:773
pnanovdb_leaf_index_get_min_index
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_index_get_min_index(pnanovdb_buf_t buf, pnanovdb_address_t min_address)
Definition: PNanoVDB.h:1410
PNANOVDB_TREE_OFF_NODE_COUNT_LEAF
#define PNANOVDB_TREE_OFF_NODE_COUNT_LEAF
Definition: PNanoVDB.h:913
pnanovdb_upper_get_child
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:1567
pnanovdb_map_get_taperd
PNANOVDB_FORCE_INLINE double pnanovdb_map_get_taperd(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:737
pnanovdb_upper_get_table_child
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:1561
pnanovdb_leaf_get_max_address
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:1288
PNANOVDB_GRID_OFF_VOXEL_SIZE
#define PNANOVDB_GRID_OFF_VOXEL_SIZE
Definition: PNanoVDB.h:776
pnanovdb_grid_world_to_indexf
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:2133
pnanovdb_read_uint64
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_read_uint64(pnanovdb_buf_t buf, pnanovdb_address_t address)
Definition: PNanoVDB.h:572
pnanovdb_gridblindmetadata_get_data_class
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_gridblindmetadata_get_data_class(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p)
Definition: PNanoVDB.h:879
pnanovdb_grid_index_to_world_dirf
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:2151
pnanovdb_map_apply_inverse
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:2097
pnanovdb_tree_get_tile_count_upper
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_tree_get_tile_count_upper(pnanovdb_buf_t buf, pnanovdb_tree_handle_t p)
Definition: PNanoVDB.h:948
pnanovdb_upper_get_child_mask
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:1047
pnanovdb_upper_get_ave_address
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:1543
PNANOVDB_GRID_OFF_MAGIC
#define PNANOVDB_GRID_OFF_MAGIC
Definition: PNanoVDB.h:766
PNANOVDB_GRIDBLINDMETADATA_OFF_DATA_TYPE
#define PNANOVDB_GRIDBLINDMETADATA_OFF_DATA_TYPE
Definition: PNanoVDB.h:864
pnanovdb_grid_get_grid_size
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_grid_get_grid_size(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:800
pnanovdb_leaf_get_table_address
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:1306
PNANOVDB_LEAF_OFF_BBOX_MIN
#define PNANOVDB_LEAF_OFF_BBOX_MIN
Definition: PNanoVDB.h:1108
pnanovdb_grid_type_constants
PNANOVDB_STATIC_CONST pnanovdb_grid_type_constants_t pnanovdb_grid_type_constants[20]
Definition: PNanoVDB.h:1160
pnanovdb_upper_get_min_address
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:1531
pnanovdb_root_get_value_address_bit
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:1655
pnanovdb_lower_get_child
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:1493
pnanovdb_upper_get_bbox_min
PNANOVDB_FORCE_INLINE pnanovdb_coord_t pnanovdb_upper_get_bbox_min(pnanovdb_buf_t buf, pnanovdb_upper_handle_t p)
Definition: PNanoVDB.h:1034
pnanovdb_read_float
PNANOVDB_FORCE_INLINE float pnanovdb_read_float(pnanovdb_buf_t buf, pnanovdb_address_t address)
Definition: PNanoVDB.h:580
pnanovdb_coord_to_key
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_coord_to_key(PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:1241
pnanovdb_readaccessor_iscached0
PNANOVDB_FORCE_INLINE pnanovdb_bool_t pnanovdb_readaccessor_iscached0(PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, int dirty)
Definition: PNanoVDB.h:1742
PNANOVDB_GRID_OFF_BLIND_METADATA_COUNT
#define PNANOVDB_GRID_OFF_BLIND_METADATA_COUNT
Definition: PNanoVDB.h:780
PNANOVDB_LEAF_TABLE_NEG_OFF_BBOX_DIF_AND_FLAGS
#define PNANOVDB_LEAF_TABLE_NEG_OFF_BBOX_DIF_AND_FLAGS
Definition: PNanoVDB.h:1112
pnanovdb_leaf_get_bbox_dif_and_flags
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:1119
PNANOVDB_TREE_OFF_TILE_COUNT_UPPER
#define PNANOVDB_TREE_OFF_TILE_COUNT_UPPER
Definition: PNanoVDB.h:918
pnanovdb_leaf_get_stddev_address
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:1300
PNANOVDB_TREE_OFF_TILE_COUNT_LOWER
#define PNANOVDB_TREE_OFF_TILE_COUNT_LOWER
Definition: PNanoVDB.h:917
pnanovdb_root_get_max_address
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:1603
pnanovdb_grid_get_world_bbox
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:811
pnanovdb_root_tile_get_child
PNANOVDB_FORCE_INLINE pnanovdb_int64_t pnanovdb_root_tile_get_child(pnanovdb_buf_t buf, pnanovdb_root_tile_handle_t p)
Definition: PNanoVDB.h:1004
pnanovdb_leaf_get_min_address
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:1282
pnanovdb_root_get_ave_address
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:1609
PNANOVDB_MAP_OFF_TAPERD
#define PNANOVDB_MAP_OFF_TAPERD
Definition: PNanoVDB.h:714
pnanovdb_upper_get_max_address
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:1537
PNANOVDB_GRID_OFF_GRID_SIZE
#define PNANOVDB_GRID_OFF_GRID_SIZE
Definition: PNanoVDB.h:772
pnanovdb_grid_get_flags
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_flags(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:791
pnanovdb_grid_get_voxel_size
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:814
PNANOVDB_TREE_OFF_NODE_COUNT_UPPER
#define PNANOVDB_TREE_OFF_NODE_COUNT_UPPER
Definition: PNanoVDB.h:915
pnanovdb_root_get_value_address_and_level_and_cache
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:1834
pnanovdb_gridblindmetadata_get_flags
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_gridblindmetadata_get_flags(pnanovdb_buf_t buf, pnanovdb_gridblindmetadata_handle_t p)
Definition: PNanoVDB.h:873
PNANOVDB_ROOT_TILE_OFF_STATE
#define PNANOVDB_ROOT_TILE_OFF_STATE
Definition: PNanoVDB.h:999
PNANOVDB_GRIDBLINDMETADATA_SIZE
#define PNANOVDB_GRIDBLINDMETADATA_SIZE
Definition: PNanoVDB.h:857
pnanovdb_grid_type_leaf_type
PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_leaf_type[20]
Definition: PNanoVDB.h:688
pnanovdb_grid_get_tree
PNANOVDB_FORCE_INLINE pnanovdb_tree_handle_t pnanovdb_grid_get_tree(pnanovdb_buf_t buf, pnanovdb_grid_handle_t grid)
Definition: PNanoVDB.h:1204
pnanovdb_map_get_vecf
PNANOVDB_FORCE_INLINE float pnanovdb_map_get_vecf(pnanovdb_buf_t buf, pnanovdb_map_handle_t p, pnanovdb_uint32_t index)
Definition: PNanoVDB.h:722
pnanovdb_upper_coord_to_offset
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_upper_coord_to_offset(PNANOVDB_IN(pnanovdb_coord_t) ijk)
Definition: PNanoVDB.h:1524
pnanovdb_root_get_tile
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:1219
pnanovdb_leaf_index_get_ave_index
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_index_get_ave_index(pnanovdb_buf_t buf, pnanovdb_address_t ave_address)
Definition: PNanoVDB.h:1420
pnanovdb_grid_get_grid_type
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_grid_get_grid_type(pnanovdb_buf_t buf, pnanovdb_grid_handle_t p)
Definition: PNanoVDB.h:820
pnanovdb_leaf_index_get_dev_index
PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_leaf_index_get_dev_index(pnanovdb_buf_t buf, pnanovdb_address_t dev_address)
Definition: PNanoVDB.h:1425
pnanovdb_readaccessor_init
PNANOVDB_FORCE_INLINE void pnanovdb_readaccessor_init(PNANOVDB_INOUT(pnanovdb_readaccessor_t) acc, pnanovdb_root_handle_t root)
Definition: PNanoVDB.h:1731
pnanovdb_leaf_fp_read_float
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:1318
pnanovdb_leaf_get_ave_address
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:1294
pnanovdb_leaf_fpn_read_float
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:1349
pnanovdb_version_get_patch
PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_version_get_patch(pnanovdb_uint32_t version)
Definition: PNanoVDB.h:838
PNANOVDB_LOWER_OFF_CHILD_MASK
#define PNANOVDB_LOWER_OFF_CHILD_MASK
Definition: PNanoVDB.h:1073
PNANOVDB_GRID_OFF_FLAGS
#define PNANOVDB_GRID_OFF_FLAGS
Definition: PNanoVDB.h:769
pnanovdb_root_find_tile
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:1258
pnanovdb_root_fp4_read_float
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:1663
openvdb::v10_0::tools::composite::min
const std::enable_if<!VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:106
openvdb::v10_0::tools::composite::max
const std::enable_if<!VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:110
pnanovdb_grid_handle_t
Definition: PNanoVDB.h:761
pnanovdb_grid_handle_t::address
pnanovdb_address_t address
Definition: PNanoVDB.h:761
pnanovdb_grid_t
Definition: PNanoVDB.h:742
pnanovdb_grid_t::magic
pnanovdb_uint64_t magic
Definition: PNanoVDB.h:743
pnanovdb_grid_t::grid_class
pnanovdb_uint32_t grid_class
Definition: PNanoVDB.h:754
pnanovdb_grid_t::voxel_size
double voxel_size[3]
Definition: PNanoVDB.h:753
pnanovdb_grid_t::grid_index
pnanovdb_uint32_t grid_index
Definition: PNanoVDB.h:747
pnanovdb_grid_t::grid_size
pnanovdb_uint64_t grid_size
Definition: PNanoVDB.h:749
pnanovdb_grid_t::grid_type
pnanovdb_uint32_t grid_type
Definition: PNanoVDB.h:755
pnanovdb_grid_t::version
pnanovdb_uint32_t version
Definition: PNanoVDB.h:745
pnanovdb_grid_t::pad
pnanovdb_uint32_t pad[5]
Definition: PNanoVDB.h:758
pnanovdb_grid_t::blind_metadata_offset
pnanovdb_int64_t blind_metadata_offset
Definition: PNanoVDB.h:756
pnanovdb_grid_t::world_bbox
double world_bbox[6]
Definition: PNanoVDB.h:752
pnanovdb_grid_t::flags
pnanovdb_uint32_t flags
Definition: PNanoVDB.h:746
pnanovdb_grid_t::blind_metadata_count
pnanovdb_uint32_t blind_metadata_count
Definition: PNanoVDB.h:757
pnanovdb_grid_t::checksum
pnanovdb_uint64_t checksum
Definition: PNanoVDB.h:744
pnanovdb_grid_t::map
pnanovdb_map_t map
Definition: PNanoVDB.h:751
pnanovdb_grid_t::grid_count
pnanovdb_uint32_t grid_count
Definition: PNanoVDB.h:748
pnanovdb_grid_t::grid_name
pnanovdb_uint32_t grid_name[256/4]
Definition: PNanoVDB.h:750
pnanovdb_grid_type_constants_t
Definition: PNanoVDB.h:1128
pnanovdb_grid_type_constants_t::leaf_off_stddev
pnanovdb_uint32_t leaf_off_stddev
Definition: PNanoVDB.h:1154
pnanovdb_grid_type_constants_t::leaf_off_ave
pnanovdb_uint32_t leaf_off_ave
Definition: PNanoVDB.h:1153
pnanovdb_grid_type_constants_t::upper_off_min
pnanovdb_uint32_t upper_off_min
Definition: PNanoVDB.h:1139
pnanovdb_grid_type_constants_t::leaf_size
pnanovdb_uint32_t leaf_size
Definition: PNanoVDB.h:1156
pnanovdb_grid_type_constants_t::root_size
pnanovdb_uint32_t root_size
Definition: PNanoVDB.h:1134
pnanovdb_grid_type_constants_t::leaf_off_table
pnanovdb_uint32_t leaf_off_table
Definition: PNanoVDB.h:1155
pnanovdb_grid_type_constants_t::upper_off_max
pnanovdb_uint32_t upper_off_max
Definition: PNanoVDB.h:1140
pnanovdb_grid_type_constants_t::upper_off_ave
pnanovdb_uint32_t upper_off_ave
Definition: PNanoVDB.h:1141
pnanovdb_grid_type_constants_t::table_stride
pnanovdb_uint32_t table_stride
Definition: PNanoVDB.h:1136
pnanovdb_grid_type_constants_t::upper_off_table
pnanovdb_uint32_t upper_off_table
Definition: PNanoVDB.h:1143
pnanovdb_grid_type_constants_t::root_tile_size
pnanovdb_uint32_t root_tile_size
Definition: PNanoVDB.h:1138
pnanovdb_grid_type_constants_t::leaf_off_min
pnanovdb_uint32_t leaf_off_min
Definition: PNanoVDB.h:1151
pnanovdb_grid_type_constants_t::lower_size
pnanovdb_uint32_t lower_size
Definition: PNanoVDB.h:1150
pnanovdb_grid_type_constants_t::lower_off_min
pnanovdb_uint32_t lower_off_min
Definition: PNanoVDB.h:1145
pnanovdb_grid_type_constants_t::upper_size
pnanovdb_uint32_t upper_size
Definition: PNanoVDB.h:1144
pnanovdb_grid_type_constants_t::value_stride_bits
pnanovdb_uint32_t value_stride_bits
Definition: PNanoVDB.h:1135
pnanovdb_grid_type_constants_t::root_off_min
pnanovdb_uint32_t root_off_min
Definition: PNanoVDB.h:1130
pnanovdb_grid_type_constants_t::root_tile_off_value
pnanovdb_uint32_t root_tile_off_value
Definition: PNanoVDB.h:1137
pnanovdb_grid_type_constants_t::root_off_ave
pnanovdb_uint32_t root_off_ave
Definition: PNanoVDB.h:1132
pnanovdb_grid_type_constants_t::lower_off_stddev
pnanovdb_uint32_t lower_off_stddev
Definition: PNanoVDB.h:1148
pnanovdb_grid_type_constants_t::root_off_stddev
pnanovdb_uint32_t root_off_stddev
Definition: PNanoVDB.h:1133
pnanovdb_grid_type_constants_t::root_off_background
pnanovdb_uint32_t root_off_background
Definition: PNanoVDB.h:1129
pnanovdb_grid_type_constants_t::root_off_max
pnanovdb_uint32_t root_off_max
Definition: PNanoVDB.h:1131
pnanovdb_grid_type_constants_t::lower_off_table
pnanovdb_uint32_t lower_off_table
Definition: PNanoVDB.h:1149
pnanovdb_grid_type_constants_t::lower_off_max
pnanovdb_uint32_t lower_off_max
Definition: PNanoVDB.h:1146
pnanovdb_grid_type_constants_t::leaf_off_max
pnanovdb_uint32_t leaf_off_max
Definition: PNanoVDB.h:1152
pnanovdb_grid_type_constants_t::upper_off_stddev
pnanovdb_uint32_t upper_off_stddev
Definition: PNanoVDB.h:1142
pnanovdb_grid_type_constants_t::lower_off_ave
pnanovdb_uint32_t lower_off_ave
Definition: PNanoVDB.h:1147
pnanovdb_gridblindmetadata_handle_t
Definition: PNanoVDB.h:854
pnanovdb_gridblindmetadata_handle_t::address
pnanovdb_address_t address
Definition: PNanoVDB.h:854
pnanovdb_gridblindmetadata_t
Definition: PNanoVDB.h:844
pnanovdb_gridblindmetadata_t::element_count
pnanovdb_uint64_t element_count
Definition: PNanoVDB.h:846
pnanovdb_gridblindmetadata_t::byte_offset
pnanovdb_int64_t byte_offset
Definition: PNanoVDB.h:845
pnanovdb_gridblindmetadata_t::name
pnanovdb_uint32_t name[256/4]
Definition: PNanoVDB.h:851
pnanovdb_gridblindmetadata_t::flags
pnanovdb_uint32_t flags
Definition: PNanoVDB.h:847
pnanovdb_gridblindmetadata_t::data_type
pnanovdb_uint32_t data_type
Definition: PNanoVDB.h:850
pnanovdb_gridblindmetadata_t::data_class
pnanovdb_uint32_t data_class
Definition: PNanoVDB.h:849
pnanovdb_gridblindmetadata_t::semantic
pnanovdb_uint32_t semantic
Definition: PNanoVDB.h:848
pnanovdb_leaf_handle_t
Definition: PNanoVDB.h:1102
pnanovdb_leaf_handle_t::address
pnanovdb_address_t address
Definition: PNanoVDB.h:1102
pnanovdb_leaf_t
Definition: PNanoVDB.h:1094
pnanovdb_leaf_t::value_mask
pnanovdb_uint32_t value_mask[16]
Definition: PNanoVDB.h:1097
pnanovdb_leaf_t::bbox_dif_and_flags
pnanovdb_uint32_t bbox_dif_and_flags
Definition: PNanoVDB.h:1096
pnanovdb_leaf_t::bbox_min
pnanovdb_coord_t bbox_min
Definition: PNanoVDB.h:1095
pnanovdb_lower_handle_t
Definition: PNanoVDB.h:1063
pnanovdb_lower_handle_t::address
pnanovdb_address_t address
Definition: PNanoVDB.h:1063
pnanovdb_lower_t
Definition: PNanoVDB.h:1053
pnanovdb_lower_t::child_mask
pnanovdb_uint32_t child_mask[128]
Definition: PNanoVDB.h:1058
pnanovdb_lower_t::flags
pnanovdb_uint64_t flags
Definition: PNanoVDB.h:1056
pnanovdb_lower_t::value_mask
pnanovdb_uint32_t value_mask[128]
Definition: PNanoVDB.h:1057
pnanovdb_lower_t::bbox_max
pnanovdb_coord_t bbox_max
Definition: PNanoVDB.h:1055
pnanovdb_lower_t::bbox_min
pnanovdb_coord_t bbox_min
Definition: PNanoVDB.h:1054
pnanovdb_map_handle_t
Definition: PNanoVDB.h:702
pnanovdb_map_handle_t::address
pnanovdb_address_t address
Definition: PNanoVDB.h:702
pnanovdb_map_t
Definition: PNanoVDB.h:691
pnanovdb_map_t::matd
double matd[9]
Definition: PNanoVDB.h:696
pnanovdb_map_t::vecd
double vecd[3]
Definition: PNanoVDB.h:698
pnanovdb_map_t::taperf
float taperf
Definition: PNanoVDB.h:695
pnanovdb_map_t::invmatd
double invmatd[9]
Definition: PNanoVDB.h:697
pnanovdb_map_t::matf
float matf[9]
Definition: PNanoVDB.h:692
pnanovdb_map_t::taperd
double taperd
Definition: PNanoVDB.h:699
pnanovdb_map_t::invmatf
float invmatf[9]
Definition: PNanoVDB.h:693
pnanovdb_map_t::vecf
float vecf[3]
Definition: PNanoVDB.h:694
pnanovdb_readaccessor_t
Definition: PNanoVDB.h:1722
pnanovdb_readaccessor_t::upper
pnanovdb_upper_handle_t upper
Definition: PNanoVDB.h:1726
pnanovdb_readaccessor_t::root
pnanovdb_root_handle_t root
Definition: PNanoVDB.h:1727
pnanovdb_readaccessor_t::key
pnanovdb_coord_t key
Definition: PNanoVDB.h:1723
pnanovdb_readaccessor_t::lower
pnanovdb_lower_handle_t lower
Definition: PNanoVDB.h:1725
pnanovdb_readaccessor_t::leaf
pnanovdb_leaf_handle_t leaf
Definition: PNanoVDB.h:1724
pnanovdb_root_handle_t
Definition: PNanoVDB.h:964
pnanovdb_root_handle_t::address
pnanovdb_address_t address
Definition: PNanoVDB.h:964
pnanovdb_root_t
Definition: PNanoVDB.h:956
pnanovdb_root_t::table_size
pnanovdb_uint32_t table_size
Definition: PNanoVDB.h:959
pnanovdb_root_t::bbox_max
pnanovdb_coord_t bbox_max
Definition: PNanoVDB.h:958
pnanovdb_root_t::pad1
pnanovdb_uint32_t pad1
Definition: PNanoVDB.h:960
pnanovdb_root_t::bbox_min
pnanovdb_coord_t bbox_min
Definition: PNanoVDB.h:957
pnanovdb_root_tile_handle_t
Definition: PNanoVDB.h:992
pnanovdb_root_tile_handle_t::address
pnanovdb_address_t address
Definition: PNanoVDB.h:992
pnanovdb_root_tile_t
Definition: PNanoVDB.h:984
pnanovdb_root_tile_t::key
pnanovdb_uint64_t key
Definition: PNanoVDB.h:985
pnanovdb_root_tile_t::state
pnanovdb_uint32_t state
Definition: PNanoVDB.h:987
pnanovdb_root_tile_t::child
pnanovdb_int64_t child
Definition: PNanoVDB.h:986
pnanovdb_root_tile_t::pad1
pnanovdb_uint32_t pad1
Definition: PNanoVDB.h:988
pnanovdb_tree_handle_t
Definition: PNanoVDB.h:904
pnanovdb_tree_handle_t::address
pnanovdb_address_t address
Definition: PNanoVDB.h:904
pnanovdb_tree_t
Definition: PNanoVDB.h:890
pnanovdb_tree_t::node_count_leaf
pnanovdb_uint32_t node_count_leaf
Definition: PNanoVDB.h:895
pnanovdb_tree_t::tile_count_lower
pnanovdb_uint32_t tile_count_lower
Definition: PNanoVDB.h:899
pnanovdb_tree_t::node_offset_upper
pnanovdb_uint64_t node_offset_upper
Definition: PNanoVDB.h:893
pnanovdb_tree_t::tile_count_leaf
pnanovdb_uint32_t tile_count_leaf
Definition: PNanoVDB.h:898
pnanovdb_tree_t::node_offset_root
pnanovdb_uint64_t node_offset_root
Definition: PNanoVDB.h:894
pnanovdb_tree_t::node_offset_leaf
pnanovdb_uint64_t node_offset_leaf
Definition: PNanoVDB.h:891
pnanovdb_tree_t::voxel_count
pnanovdb_uint64_t voxel_count
Definition: PNanoVDB.h:901
pnanovdb_tree_t::tile_count_upper
pnanovdb_uint32_t tile_count_upper
Definition: PNanoVDB.h:900
pnanovdb_tree_t::node_offset_lower
pnanovdb_uint64_t node_offset_lower
Definition: PNanoVDB.h:892
pnanovdb_tree_t::node_count_upper
pnanovdb_uint32_t node_count_upper
Definition: PNanoVDB.h:897
pnanovdb_tree_t::node_count_lower
pnanovdb_uint32_t node_count_lower
Definition: PNanoVDB.h:896
pnanovdb_upper_handle_t
Definition: PNanoVDB.h:1022
pnanovdb_upper_handle_t::address
pnanovdb_address_t address
Definition: PNanoVDB.h:1022
pnanovdb_upper_t
Definition: PNanoVDB.h:1012
pnanovdb_upper_t::flags
pnanovdb_uint64_t flags
Definition: PNanoVDB.h:1015
pnanovdb_upper_t::value_mask
pnanovdb_uint32_t value_mask[1024]
Definition: PNanoVDB.h:1016
pnanovdb_upper_t::bbox_max
pnanovdb_coord_t bbox_max
Definition: PNanoVDB.h:1014
pnanovdb_upper_t::child_mask
pnanovdb_uint32_t child_mask[1024]
Definition: PNanoVDB.h:1017
pnanovdb_upper_t::bbox_min
pnanovdb_coord_t bbox_min
Definition: PNanoVDB.h:1013