OpenVDB: nanovdb/PNanoVDB.h Source File

OpenVDB 11.0.0

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