@pmndrs/vdb 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +137 -0
- package/LICENSE +21 -0
- package/README.md +448 -2
- package/THIRD_PARTY_NOTICES.md +147 -0
- package/dist/core/compute/atlas.d.ts +94 -0
- package/dist/core/compute/atlas.js +98 -0
- package/dist/core/compute/atlas.js.map +1 -0
- package/dist/core/compute/index.d.ts +13 -0
- package/dist/core/compute/index.js +9 -0
- package/dist/core/compute/index.js.map +1 -0
- package/dist/core/compute/pyramid.d.ts +105 -0
- package/dist/core/compute/pyramid.js +455 -0
- package/dist/core/compute/pyramid.js.map +1 -0
- package/dist/core/compute/shared.d.ts +115 -0
- package/dist/core/compute/shared.js +211 -0
- package/dist/core/compute/shared.js.map +1 -0
- package/dist/core/compute/stats.d.ts +71 -0
- package/dist/core/compute/stats.js +188 -0
- package/dist/core/compute/stats.js.map +1 -0
- package/dist/core/compute/value-transform.d.ts +23 -0
- package/dist/core/compute/value-transform.js +58 -0
- package/dist/core/compute/value-transform.js.map +1 -0
- package/dist/core/errors.d.ts +11 -0
- package/dist/core/errors.js +9 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/index.d.ts +30 -0
- package/dist/core/index.js +27 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/internal.d.ts +15 -0
- package/dist/core/internal.js +15 -0
- package/dist/core/internal.js.map +1 -0
- package/dist/core/pool/affine.d.ts +34 -0
- package/dist/core/pool/affine.js +100 -0
- package/dist/core/pool/affine.js.map +1 -0
- package/dist/core/pool/allocator.d.ts +32 -0
- package/dist/core/pool/allocator.js +81 -0
- package/dist/core/pool/allocator.js.map +1 -0
- package/dist/core/pool/image-header.d.ts +82 -0
- package/dist/core/pool/image-header.js +175 -0
- package/dist/core/pool/image-header.js.map +1 -0
- package/dist/core/pool/layout.d.ts +164 -0
- package/dist/core/pool/layout.js +267 -0
- package/dist/core/pool/layout.js.map +1 -0
- package/dist/core/pool/limits.d.ts +40 -0
- package/dist/core/pool/limits.js +79 -0
- package/dist/core/pool/limits.js.map +1 -0
- package/dist/core/pool/pool.d.ts +279 -0
- package/dist/core/pool/pool.js +953 -0
- package/dist/core/pool/pool.js.map +1 -0
- package/dist/core/source/dense.d.ts +19 -0
- package/dist/core/source/dense.js +287 -0
- package/dist/core/source/dense.js.map +1 -0
- package/dist/core/source/types.d.ts +63 -0
- package/dist/core/source/types.js +9 -0
- package/dist/core/source/types.js.map +1 -0
- package/dist/core/types.d.ts +28 -0
- package/dist/core/types.js +28 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/wgsl/api.d.ts +41 -0
- package/dist/core/wgsl/api.js +463 -0
- package/dist/core/wgsl/api.js.map +1 -0
- package/dist/core/wgsl/generate.d.ts +82 -0
- package/dist/core/wgsl/generate.js +505 -0
- package/dist/core/wgsl/generate.js.map +1 -0
- package/dist/core/wgsl/level-set.d.ts +54 -0
- package/dist/core/wgsl/level-set.js +194 -0
- package/dist/core/wgsl/level-set.js.map +1 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +14 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.js +330 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -0
- package/dist/core/wgsl/reserved.d.ts +9 -0
- package/dist/core/wgsl/reserved.js +26 -0
- package/dist/core/wgsl/reserved.js.map +1 -0
- package/dist/core/wgsl/types.d.ts +104 -0
- package/dist/core/wgsl/types.js +2 -0
- package/dist/core/wgsl/types.js.map +1 -0
- package/dist/three/coarse-first.d.ts +162 -0
- package/dist/three/coarse-first.js +187 -0
- package/dist/three/coarse-first.js.map +1 -0
- package/dist/three/compute.d.ts +63 -0
- package/dist/three/compute.js +56 -0
- package/dist/three/compute.js.map +1 -0
- package/dist/three/device.d.ts +59 -0
- package/dist/three/device.js +59 -0
- package/dist/three/device.js.map +1 -0
- package/dist/three/frame/blackbody.d.ts +42 -0
- package/dist/three/frame/blackbody.js +74 -0
- package/dist/three/frame/blackbody.js.map +1 -0
- package/dist/three/frame/chunks.d.ts +157 -0
- package/dist/three/frame/chunks.js +559 -0
- package/dist/three/frame/chunks.js.map +1 -0
- package/dist/three/frame/density-material.d.ts +53 -0
- package/dist/three/frame/density-material.js +353 -0
- package/dist/three/frame/density-material.js.map +1 -0
- package/dist/three/frame/emission-light.d.ts +167 -0
- package/dist/three/frame/emission-light.js +655 -0
- package/dist/three/frame/emission-light.js.map +1 -0
- package/dist/three/frame/environment-grid-material.d.ts +21 -0
- package/dist/three/frame/environment-grid-material.js +184 -0
- package/dist/three/frame/environment-grid-material.js.map +1 -0
- package/dist/three/frame/environment-material.d.ts +22 -0
- package/dist/three/frame/environment-material.js +87 -0
- package/dist/three/frame/environment-material.js.map +1 -0
- package/dist/three/frame/grid-mip-material.d.ts +12 -0
- package/dist/three/frame/grid-mip-material.js +61 -0
- package/dist/three/frame/grid-mip-material.js.map +1 -0
- package/dist/three/frame/index.d.ts +39 -0
- package/dist/three/frame/index.js +35 -0
- package/dist/three/frame/index.js.map +1 -0
- package/dist/three/frame/inject-material.d.ts +56 -0
- package/dist/three/frame/inject-material.js +424 -0
- package/dist/three/frame/inject-material.js.map +1 -0
- package/dist/three/frame/integrate-material.d.ts +26 -0
- package/dist/three/frame/integrate-material.js +198 -0
- package/dist/three/frame/integrate-material.js.map +1 -0
- package/dist/three/frame/layout.d.ts +34 -0
- package/dist/three/frame/layout.js +48 -0
- package/dist/three/frame/layout.js.map +1 -0
- package/dist/three/frame/lighting-material.d.ts +41 -0
- package/dist/three/frame/lighting-material.js +257 -0
- package/dist/three/frame/lighting-material.js.map +1 -0
- package/dist/three/frame/lights.d.ts +11 -0
- package/dist/three/frame/lights.js +16 -0
- package/dist/three/frame/lights.js.map +1 -0
- package/dist/three/frame/medium.d.ts +21 -0
- package/dist/three/frame/medium.js +29 -0
- package/dist/three/frame/medium.js.map +1 -0
- package/dist/three/frame/neural.d.ts +14 -0
- package/dist/three/frame/neural.js +105 -0
- package/dist/three/frame/neural.js.map +1 -0
- package/dist/three/frame/phase.d.ts +44 -0
- package/dist/three/frame/phase.js +80 -0
- package/dist/three/frame/phase.js.map +1 -0
- package/dist/three/frame/renderer.d.ts +493 -0
- package/dist/three/frame/renderer.js +1498 -0
- package/dist/three/frame/renderer.js.map +1 -0
- package/dist/three/frame/shadow-density-material.d.ts +30 -0
- package/dist/three/frame/shadow-density-material.js +123 -0
- package/dist/three/frame/shadow-density-material.js.map +1 -0
- package/dist/three/frame/spectrum.d.ts +18 -0
- package/dist/three/frame/spectrum.js +36 -0
- package/dist/three/frame/spectrum.js.map +1 -0
- package/dist/three/frame/temporal-material.d.ts +29 -0
- package/dist/three/frame/temporal-material.js +152 -0
- package/dist/three/frame/temporal-material.js.map +1 -0
- package/dist/three/frame/three-internals.d.ts +65 -0
- package/dist/three/frame/three-internals.js +150 -0
- package/dist/three/frame/three-internals.js.map +1 -0
- package/dist/three/frame/transmittance-material.d.ts +31 -0
- package/dist/three/frame/transmittance-material.js +315 -0
- package/dist/three/frame/transmittance-material.js.map +1 -0
- package/dist/three/frame/view.d.ts +103 -0
- package/dist/three/frame/view.js +296 -0
- package/dist/three/frame/view.js.map +1 -0
- package/dist/three/frame/volume-shadow-material.d.ts +36 -0
- package/dist/three/frame/volume-shadow-material.js +128 -0
- package/dist/three/frame/volume-shadow-material.js.map +1 -0
- package/dist/three/frame/volume-shadows.d.ts +153 -0
- package/dist/three/frame/volume-shadows.js +756 -0
- package/dist/three/frame/volume-shadows.js.map +1 -0
- package/dist/three/frame/volume.d.ts +172 -0
- package/dist/three/frame/volume.js +256 -0
- package/dist/three/frame/volume.js.map +1 -0
- package/dist/three/grid-node.d.ts +196 -0
- package/dist/three/grid-node.js +510 -0
- package/dist/three/grid-node.js.map +1 -0
- package/dist/three/index.d.ts +43 -0
- package/dist/three/index.js +49 -0
- package/dist/three/index.js.map +1 -0
- package/dist/three/internal.d.ts +14 -0
- package/dist/three/internal.js +14 -0
- package/dist/three/internal.js.map +1 -0
- package/dist/three/level-set-material.d.ts +112 -0
- package/dist/three/level-set-material.js +204 -0
- package/dist/three/level-set-material.js.map +1 -0
- package/dist/three/material.d.ts +194 -0
- package/dist/three/material.js +359 -0
- package/dist/three/material.js.map +1 -0
- package/dist/three/points.d.ts +84 -0
- package/dist/three/points.js +130 -0
- package/dist/three/points.js.map +1 -0
- package/dist/three/sequence.d.ts +317 -0
- package/dist/three/sequence.js +526 -0
- package/dist/three/sequence.js.map +1 -0
- package/dist/three/sparse-source.d.ts +233 -0
- package/dist/three/sparse-source.js +876 -0
- package/dist/three/sparse-source.js.map +1 -0
- package/dist/three/volume-source.d.ts +167 -0
- package/dist/three/volume-source.js +353 -0
- package/dist/three/volume-source.js.map +1 -0
- package/dist/tools/cpu/compute.d.ts +97 -0
- package/dist/tools/cpu/compute.js +218 -0
- package/dist/tools/cpu/compute.js.map +1 -0
- package/dist/tools/cpu/level-set.d.ts +72 -0
- package/dist/tools/cpu/level-set.js +261 -0
- package/dist/tools/cpu/level-set.js.map +1 -0
- package/dist/tools/cpu/march.d.ts +206 -0
- package/dist/tools/cpu/march.js +575 -0
- package/dist/tools/cpu/march.js.map +1 -0
- package/dist/tools/cpu/probe-coords.d.ts +70 -0
- package/dist/tools/cpu/probe-coords.js +116 -0
- package/dist/tools/cpu/probe-coords.js.map +1 -0
- package/dist/tools/cpu/read-value.d.ts +31 -0
- package/dist/tools/cpu/read-value.js +336 -0
- package/dist/tools/cpu/read-value.js.map +1 -0
- package/dist/tools/cpu/sample-trilinear.d.ts +30 -0
- package/dist/tools/cpu/sample-trilinear.js +156 -0
- package/dist/tools/cpu/sample-trilinear.js.map +1 -0
- package/dist/tools/cpu/stride-tables.d.ts +56 -0
- package/dist/tools/cpu/stride-tables.generated.d.ts +1058 -0
- package/dist/tools/cpu/stride-tables.generated.js +1266 -0
- package/dist/tools/cpu/stride-tables.generated.js.map +1 -0
- package/dist/tools/cpu/stride-tables.js +78 -0
- package/dist/tools/cpu/stride-tables.js.map +1 -0
- package/dist/tools/errors.d.ts +57 -0
- package/dist/tools/errors.js +58 -0
- package/dist/tools/errors.js.map +1 -0
- package/dist/tools/frame/blackbody.d.ts +42 -0
- package/dist/tools/frame/blackbody.js +116 -0
- package/dist/tools/frame/blackbody.js.map +1 -0
- package/dist/tools/frame/emission.d.ts +128 -0
- package/dist/tools/frame/emission.js +282 -0
- package/dist/tools/frame/emission.js.map +1 -0
- package/dist/tools/frame/environment.d.ts +105 -0
- package/dist/tools/frame/environment.js +268 -0
- package/dist/tools/frame/environment.js.map +1 -0
- package/dist/tools/frame/grid.d.ts +302 -0
- package/dist/tools/frame/grid.js +703 -0
- package/dist/tools/frame/grid.js.map +1 -0
- package/dist/tools/frame/index.d.ts +136 -0
- package/dist/tools/frame/index.js +348 -0
- package/dist/tools/frame/index.js.map +1 -0
- package/dist/tools/frame/medium.d.ts +61 -0
- package/dist/tools/frame/medium.js +99 -0
- package/dist/tools/frame/medium.js.map +1 -0
- package/dist/tools/frame/mie-table.d.ts +6 -0
- package/dist/tools/frame/mie-table.js +16 -0
- package/dist/tools/frame/mie-table.js.map +1 -0
- package/dist/tools/frame/mie.d.ts +54 -0
- package/dist/tools/frame/mie.js +176 -0
- package/dist/tools/frame/mie.js.map +1 -0
- package/dist/tools/frame/neural-weights.d.ts +9 -0
- package/dist/tools/frame/neural-weights.js +245 -0
- package/dist/tools/frame/neural-weights.js.map +1 -0
- package/dist/tools/frame/neural.d.ts +80 -0
- package/dist/tools/frame/neural.js +150 -0
- package/dist/tools/frame/neural.js.map +1 -0
- package/dist/tools/frame/pyramid-layout.d.ts +38 -0
- package/dist/tools/frame/pyramid-layout.js +53 -0
- package/dist/tools/frame/pyramid-layout.js.map +1 -0
- package/dist/tools/frame/shadows.d.ts +80 -0
- package/dist/tools/frame/shadows.js +182 -0
- package/dist/tools/frame/shadows.js.map +1 -0
- package/dist/tools/frame/sparse.d.ts +65 -0
- package/dist/tools/frame/sparse.js +191 -0
- package/dist/tools/frame/sparse.js.map +1 -0
- package/dist/tools/frame/spectral.d.ts +203 -0
- package/dist/tools/frame/spectral.js +550 -0
- package/dist/tools/frame/spectral.js.map +1 -0
- package/dist/tools/index.d.ts +106 -0
- package/dist/tools/index.js +88 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/internal.d.ts +46 -0
- package/dist/tools/internal.js +31 -0
- package/dist/tools/internal.js.map +1 -0
- package/dist/tools/nanovdb/build-from-vdb.d.ts +50 -0
- package/dist/tools/nanovdb/build-from-vdb.js +92 -0
- package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
- package/dist/tools/nanovdb/bytes.d.ts +220 -0
- package/dist/tools/nanovdb/bytes.js +345 -0
- package/dist/tools/nanovdb/bytes.js.map +1 -0
- package/dist/tools/nanovdb/coarse-first.d.ts +62 -0
- package/dist/tools/nanovdb/coarse-first.js +86 -0
- package/dist/tools/nanovdb/coarse-first.js.map +1 -0
- package/dist/tools/nanovdb/index.d.ts +32 -0
- package/dist/tools/nanovdb/index.js +24 -0
- package/dist/tools/nanovdb/index.js.map +1 -0
- package/dist/tools/nanovdb/inspect.d.ts +24 -0
- package/dist/tools/nanovdb/inspect.js +63 -0
- package/dist/tools/nanovdb/inspect.js.map +1 -0
- package/dist/tools/nanovdb/leaf-codec.d.ts +85 -0
- package/dist/tools/nanovdb/leaf-codec.js +320 -0
- package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
- package/dist/tools/nanovdb/quantize.d.ts +43 -0
- package/dist/tools/nanovdb/quantize.js +277 -0
- package/dist/tools/nanovdb/quantize.js.map +1 -0
- package/dist/tools/nanovdb/resample.d.ts +160 -0
- package/dist/tools/nanovdb/resample.js +679 -0
- package/dist/tools/nanovdb/resample.js.map +1 -0
- package/dist/tools/nanovdb/serialize.d.ts +145 -0
- package/dist/tools/nanovdb/serialize.js +395 -0
- package/dist/tools/nanovdb/serialize.js.map +1 -0
- package/dist/tools/nanovdb/stats.d.ts +58 -0
- package/dist/tools/nanovdb/stats.js +149 -0
- package/dist/tools/nanovdb/stats.js.map +1 -0
- package/dist/tools/nanovdb/transform.d.ts +26 -0
- package/dist/tools/nanovdb/transform.js +91 -0
- package/dist/tools/nanovdb/transform.js.map +1 -0
- package/dist/tools/nanovdb/tree.d.ts +175 -0
- package/dist/tools/nanovdb/tree.js +518 -0
- package/dist/tools/nanovdb/tree.js.map +1 -0
- package/dist/tools/nanovdb/write-nvdb.d.ts +39 -0
- package/dist/tools/nanovdb/write-nvdb.js +210 -0
- package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
- package/dist/tools/nvdb-file.d.ts +195 -0
- package/dist/tools/nvdb-file.js +606 -0
- package/dist/tools/nvdb-file.js.map +1 -0
- package/dist/tools/nvdb-stream.d.ts +138 -0
- package/dist/tools/nvdb-stream.js +365 -0
- package/dist/tools/nvdb-stream.js.map +1 -0
- package/dist/tools/vdb/bit-utils.d.ts +20 -0
- package/dist/tools/vdb/bit-utils.js +42 -0
- package/dist/tools/vdb/bit-utils.js.map +1 -0
- package/dist/tools/vdb/blosc.d.ts +56 -0
- package/dist/tools/vdb/blosc.js +231 -0
- package/dist/tools/vdb/blosc.js.map +1 -0
- package/dist/tools/vdb/byte-reader.d.ts +40 -0
- package/dist/tools/vdb/byte-reader.js +139 -0
- package/dist/tools/vdb/byte-reader.js.map +1 -0
- package/dist/tools/vdb/compression.d.ts +73 -0
- package/dist/tools/vdb/compression.js +249 -0
- package/dist/tools/vdb/compression.js.map +1 -0
- package/dist/tools/vdb/errors.d.ts +10 -0
- package/dist/tools/vdb/errors.js +11 -0
- package/dist/tools/vdb/errors.js.map +1 -0
- package/dist/tools/vdb/grid.d.ts +37 -0
- package/dist/tools/vdb/grid.js +147 -0
- package/dist/tools/vdb/grid.js.map +1 -0
- package/dist/tools/vdb/half-float.d.ts +9 -0
- package/dist/tools/vdb/half-float.js +24 -0
- package/dist/tools/vdb/half-float.js.map +1 -0
- package/dist/tools/vdb/index.d.ts +3 -0
- package/dist/tools/vdb/index.js +3 -0
- package/dist/tools/vdb/index.js.map +1 -0
- package/dist/tools/vdb/inflate.d.ts +24 -0
- package/dist/tools/vdb/inflate.js +334 -0
- package/dist/tools/vdb/inflate.js.map +1 -0
- package/dist/tools/vdb/metadata.d.ts +17 -0
- package/dist/tools/vdb/metadata.js +72 -0
- package/dist/tools/vdb/metadata.js.map +1 -0
- package/dist/tools/vdb/parse.d.ts +25 -0
- package/dist/tools/vdb/parse.js +171 -0
- package/dist/tools/vdb/parse.js.map +1 -0
- package/dist/tools/vdb/point-render-data.d.ts +31 -0
- package/dist/tools/vdb/point-render-data.js +57 -0
- package/dist/tools/vdb/point-render-data.js.map +1 -0
- package/dist/tools/vdb/points.d.ts +160 -0
- package/dist/tools/vdb/points.js +794 -0
- package/dist/tools/vdb/points.js.map +1 -0
- package/dist/tools/vdb/transform.d.ts +23 -0
- package/dist/tools/vdb/transform.js +54 -0
- package/dist/tools/vdb/transform.js.map +1 -0
- package/dist/tools/vdb/tree.d.ts +111 -0
- package/dist/tools/vdb/tree.js +228 -0
- package/dist/tools/vdb/tree.js.map +1 -0
- package/dist/tools/vdb/types.d.ts +138 -0
- package/dist/tools/vdb/types.js +3 -0
- package/dist/tools/vdb/types.js.map +1 -0
- package/dist/tools/wvdb/bake.d.ts +116 -0
- package/dist/tools/wvdb/bake.js +311 -0
- package/dist/tools/wvdb/bake.js.map +1 -0
- package/dist/tools/wvdb/dense.d.ts +112 -0
- package/dist/tools/wvdb/dense.js +309 -0
- package/dist/tools/wvdb/dense.js.map +1 -0
- package/dist/tools/wvdb/format.d.ts +161 -0
- package/dist/tools/wvdb/format.js +303 -0
- package/dist/tools/wvdb/format.js.map +1 -0
- package/dist/tools/wvdb/index.d.ts +13 -0
- package/dist/tools/wvdb/index.js +14 -0
- package/dist/tools/wvdb/index.js.map +1 -0
- package/dist/tools/wvdb/level-set.d.ts +48 -0
- package/dist/tools/wvdb/level-set.js +153 -0
- package/dist/tools/wvdb/level-set.js.map +1 -0
- package/dist/tools/wvdb/nanovdb.d.ts +54 -0
- package/dist/tools/wvdb/nanovdb.js +60 -0
- package/dist/tools/wvdb/nanovdb.js.map +1 -0
- package/dist/tools/wvdb/read.d.ts +260 -0
- package/dist/tools/wvdb/read.js +743 -0
- package/dist/tools/wvdb/read.js.map +1 -0
- package/dist/tools/wvdb/sha256.d.ts +7 -0
- package/dist/tools/wvdb/sha256.js +76 -0
- package/dist/tools/wvdb/sha256.js.map +1 -0
- package/dist/tools/wvdb/write.d.ts +127 -0
- package/dist/tools/wvdb/write.js +396 -0
- package/dist/tools/wvdb/write.js.map +1 -0
- package/package.json +82 -4
- package/vendor/LICENSE +201 -0
- package/vendor/NOTICE +19 -0
- package/vendor/VENDOR.md +85 -0
- package/vendor/pnanovdb.wgsl +1539 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* quantize.ts — re-encode a FLOAT NanoVDB grid image as Fp4, Fp8, Fp16 or FpN.
|
|
3
|
+
*
|
|
4
|
+
* Quantization is a leaf-value-representation change only: topology, masks,
|
|
5
|
+
* internal-node tables/stats, GridData and the transform are unchanged. So
|
|
6
|
+
* `quantize` reads the source FLOAT image's leaves (each: 8-aligned origin,
|
|
7
|
+
* all 512 values, value mask), its active tiles (root, upper, lower; kept as
|
|
8
|
+
* tiles since K4.1 — tile values stay plain f32 in Fp8/FpN grids) and its
|
|
9
|
+
* GridData transform/background, then re-runs the leaf-iterator build path
|
|
10
|
+
* ({@link vdbBuildFromLeavesDetailed}) with the chosen quantizing {@link VDBLeafCodec}. The result satisfies the repo's proven decoders
|
|
11
|
+
* (`read-value.ts` `leafFp*ReadFloat`, `pnanovdb.wgsl`).
|
|
12
|
+
*
|
|
13
|
+
* - `fp4` / `fp8` / `fp16` — fixed 4/8/16-bit codes; per-leaf quantum = (max-min)/(2^bits-1).
|
|
14
|
+
* The CreateNanoGrid rules Fp8 uses (min/quantum over all 512 values, round-to-nearest, no
|
|
15
|
+
* dither); `tolerance` is ignored. No native Fp4/Fp16 fixtures exist, so these are verified
|
|
16
|
+
* by decoder round-trip and GPU parity, not byte-compared to `nanovdb_convert`.
|
|
17
|
+
* - `fpn` — per-leaf variable bit-width, smallest of 1/2/4/8/16 bits whose
|
|
18
|
+
* dequantized values stay within `tolerance` (default: native's FogVolume 0.01).
|
|
19
|
+
*
|
|
20
|
+
* v1 quantizes FLOAT sources only (throws otherwise) — that is the conversion
|
|
21
|
+
* the toolset exposes (`float -> fp8/fpn`), and it is what the native
|
|
22
|
+
* `nanovdb_convert --fp8/--fpn` pipeline does too.
|
|
23
|
+
*/
|
|
24
|
+
import { VDBToolsError } from "../errors.js";
|
|
25
|
+
import { FLOAT_LAYOUT, GRID_OFF_GRID_CLASS, GRID_OFF_GRID_NAME, GRID_OFF_GRID_TYPE, GRID_OFF_MAP, GRID_OFF_VOXEL_SIZE, GRID_SIZE, GRID_TYPE_FLOAT, LEAF_OFF_VALUE_MASK, LEAF_TABLE_COUNT, LOWER_OFF_CHILD_MASK, LOWER_TABLE_COUNT, MAP_OFF_VECD, NODE_OFF_VALUE_MASK, ROOT_OFF_TABLE_SIZE, ROOT_TILE_OFF_CHILD, ROOT_TILE_OFF_KEY, ROOT_TILE_OFF_STATE, TREE_OFF_NODE_OFFSET_ROOT, UPPER_OFF_CHILD_MASK, UPPER_TABLE_COUNT, } from "./bytes.js";
|
|
26
|
+
import { VDB_FLOAT_LEAF_CODEC, VDB_FP4_LEAF_CODEC, VDB_FP8_LEAF_CODEC, VDB_FP16_LEAF_CODEC, vdbMakeFpNLeafCodec } from "./leaf-codec.js";
|
|
27
|
+
import { vdbBuildFromLeavesDetailed } from "./serialize.js";
|
|
28
|
+
/** Quantizes a FLOAT grid image (or built grid) to Fp8/FpN. Returns a new image. */
|
|
29
|
+
export function vdbQuantize(input, mode, tolerance, options = {}) {
|
|
30
|
+
return vdbQuantizeDetailed(input, mode, tolerance, options).image;
|
|
31
|
+
}
|
|
32
|
+
/** As {@link vdbQuantize}, but returns the computed metadata alongside the image. */
|
|
33
|
+
export function vdbQuantizeDetailed(input, mode, tolerance, options = {}) {
|
|
34
|
+
const image = input instanceof Uint32Array ? input : input.image;
|
|
35
|
+
const src = readFloatGrid(image);
|
|
36
|
+
const codec = mode === "fp4" ? VDB_FP4_LEAF_CODEC
|
|
37
|
+
: mode === "fp8" ? VDB_FP8_LEAF_CODEC
|
|
38
|
+
: mode === "fp16" ? VDB_FP16_LEAF_CODEC
|
|
39
|
+
: vdbMakeFpNLeafCodec(tolerance);
|
|
40
|
+
return vdbBuildFromLeavesDetailed(src.leaves, codec, {
|
|
41
|
+
voxelSize: src.voxelSize,
|
|
42
|
+
worldOrigin: src.translation,
|
|
43
|
+
background: src.background,
|
|
44
|
+
gridName: src.gridName,
|
|
45
|
+
gridClass: src.gridClassId === 1 ? "LevelSet" : src.gridClassId === 2 ? "FogVolume" : "Unknown",
|
|
46
|
+
tiles: src.tiles,
|
|
47
|
+
collapse: options.collapse === true,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Re-encodes a FLOAT grid image (still FLOAT) with uniform leaves and nodes
|
|
52
|
+
* collapsed into tiles (OpenVDB `prune`, tolerance 0; K4.6). Values read back
|
|
53
|
+
* identically; see `tree.ts` for the rules.
|
|
54
|
+
*/
|
|
55
|
+
export function vdbCollapseGrid(input) {
|
|
56
|
+
const image = input instanceof Uint32Array ? input : input.image;
|
|
57
|
+
const src = readFloatGrid(image, "vdbCollapseGrid");
|
|
58
|
+
return vdbBuildFromLeavesDetailed(src.leaves, VDB_FLOAT_LEAF_CODEC, {
|
|
59
|
+
voxelSize: src.voxelSize,
|
|
60
|
+
worldOrigin: src.translation,
|
|
61
|
+
background: src.background,
|
|
62
|
+
gridName: src.gridName,
|
|
63
|
+
gridClass: src.gridClassId === 1 ? "LevelSet" : src.gridClassId === 2 ? "FogVolume" : "Unknown",
|
|
64
|
+
tiles: src.tiles,
|
|
65
|
+
collapse: true,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function floorDiv(v, block) {
|
|
69
|
+
return Math.floor(v / block) * block;
|
|
70
|
+
}
|
|
71
|
+
function readI64(view, off) {
|
|
72
|
+
return Number(view.getBigInt64(off, true));
|
|
73
|
+
}
|
|
74
|
+
function maskBit(view, maskBase, n) {
|
|
75
|
+
return ((view.getUint32(maskBase + 4 * (n >>> 5), true) >>> (n & 31)) & 1) !== 0;
|
|
76
|
+
}
|
|
77
|
+
/** Reads a FLOAT grid image's transform/background and yields its leaves. */
|
|
78
|
+
function readFloatGrid(image, caller = "quantize") {
|
|
79
|
+
const view = new DataView(image.buffer, image.byteOffset, image.byteLength);
|
|
80
|
+
const gridType = view.getUint32(GRID_OFF_GRID_TYPE, true);
|
|
81
|
+
if (gridType !== GRID_TYPE_FLOAT) {
|
|
82
|
+
throw new VDBToolsError("VDB_UNSUPPORTED_GRID_TYPE", `${caller}: source grid type ${gridType} is not FLOAT (${GRID_TYPE_FLOAT}); ` +
|
|
83
|
+
`v1 re-encodes float grids only (float -> float/fp8/fpn).`);
|
|
84
|
+
}
|
|
85
|
+
// All three: a resampled grid can be anisotropic (K4.4), and the Map must survive quantization.
|
|
86
|
+
const voxelSize = [
|
|
87
|
+
view.getFloat64(GRID_OFF_VOXEL_SIZE, true),
|
|
88
|
+
view.getFloat64(GRID_OFF_VOXEL_SIZE + 8, true),
|
|
89
|
+
view.getFloat64(GRID_OFF_VOXEL_SIZE + 16, true),
|
|
90
|
+
];
|
|
91
|
+
const vecBase = GRID_OFF_MAP + MAP_OFF_VECD;
|
|
92
|
+
const translation = [
|
|
93
|
+
view.getFloat64(vecBase, true),
|
|
94
|
+
view.getFloat64(vecBase + 8, true),
|
|
95
|
+
view.getFloat64(vecBase + 16, true),
|
|
96
|
+
];
|
|
97
|
+
const gridClassId = view.getUint32(GRID_OFF_GRID_CLASS, true);
|
|
98
|
+
const gridName = readCString(image, GRID_OFF_GRID_NAME);
|
|
99
|
+
const treeOff = GRID_SIZE;
|
|
100
|
+
const rootOff = treeOff + Number(view.getBigUint64(treeOff + TREE_OFF_NODE_OFFSET_ROOT, true));
|
|
101
|
+
const background = effectiveBackground(view, rootOff);
|
|
102
|
+
const tiles = [];
|
|
103
|
+
collectFloatTiles(view, rootOff, tiles);
|
|
104
|
+
const leaves = traverseFloatLeaves(view, rootOff);
|
|
105
|
+
return { voxelSize, translation, background, gridName, gridClassId, leaves, tiles };
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The value inactive regions near the active data read back as. Native grids
|
|
109
|
+
* routinely store a far-field `mBackground` (e.g. a level-set narrow-band 3)
|
|
110
|
+
* that differs from the value written into the *near-field* inactive internal
|
|
111
|
+
* tiles surrounding the active voxels (typically 0). The re-layout emits no
|
|
112
|
+
* inactive tiles, so it fills empty slots with a single background; using the
|
|
113
|
+
* near-field inactive-tile value (the first inactive lower- then upper-tile
|
|
114
|
+
* found) reproduces the source's readback around the data, falling back to the
|
|
115
|
+
* root `mBackground` when the grid has no inactive internal tile at all.
|
|
116
|
+
*/
|
|
117
|
+
function effectiveBackground(view, rootOff) {
|
|
118
|
+
const rootBg = view.getFloat32(rootOff + FLOAT_LAYOUT.rootOffBackground, true);
|
|
119
|
+
const L = FLOAT_LAYOUT;
|
|
120
|
+
const nTiles = view.getUint32(rootOff + ROOT_OFF_TABLE_SIZE, true);
|
|
121
|
+
let upperInactive;
|
|
122
|
+
for (let t = 0; t < nTiles; t++) {
|
|
123
|
+
const tileOff = rootOff + L.rootSize + t * L.rootTileSize;
|
|
124
|
+
const child = readI64(view, tileOff + ROOT_TILE_OFF_CHILD);
|
|
125
|
+
if (child === 0)
|
|
126
|
+
continue;
|
|
127
|
+
const upperOff = rootOff + child;
|
|
128
|
+
for (let n = 0; n < UPPER_TABLE_COUNT; n++) {
|
|
129
|
+
const slotOff = upperOff + L.upperOffTable + n * L.tableStride;
|
|
130
|
+
if (maskBit(view, upperOff + UPPER_OFF_CHILD_MASK, n)) {
|
|
131
|
+
// Descend one lower node: an inactive lower tile is the near-field value.
|
|
132
|
+
const lowerOff = upperOff + readI64(view, slotOff);
|
|
133
|
+
for (let m = 0; m < LOWER_TABLE_COUNT; m++) {
|
|
134
|
+
const lslot = lowerOff + L.lowerOffTable + m * L.tableStride;
|
|
135
|
+
if (!maskBit(view, lowerOff + LOWER_OFF_CHILD_MASK, m) &&
|
|
136
|
+
!maskBit(view, lowerOff + NODE_OFF_VALUE_MASK, m)) {
|
|
137
|
+
return view.getFloat32(lslot, true);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else if (upperInactive === undefined && !maskBit(view, upperOff + NODE_OFF_VALUE_MASK, n)) {
|
|
142
|
+
upperInactive = view.getFloat32(slotOff, true);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return upperInactive ?? rootBg;
|
|
147
|
+
}
|
|
148
|
+
/** Child-node offset (relative to `rootOff`) of each root-table entry that has a child. */
|
|
149
|
+
function* rootChildren(view, rootOff) {
|
|
150
|
+
const L = FLOAT_LAYOUT;
|
|
151
|
+
const nTiles = view.getUint32(rootOff + ROOT_OFF_TABLE_SIZE, true);
|
|
152
|
+
for (let t = 0; t < nTiles; t++) {
|
|
153
|
+
const tileOff = rootOff + L.rootSize + t * L.rootTileSize;
|
|
154
|
+
const child = readI64(view, tileOff + ROOT_TILE_OFF_CHILD);
|
|
155
|
+
if (child !== 0)
|
|
156
|
+
yield child;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/** Index-space min corner of an internal node, from its bbox min. */
|
|
160
|
+
function nodeOrigin(view, nodeOff, dim) {
|
|
161
|
+
return [
|
|
162
|
+
floorDiv(view.getInt32(nodeOff, true), dim),
|
|
163
|
+
floorDiv(view.getInt32(nodeOff + 4, true), dim),
|
|
164
|
+
floorDiv(view.getInt32(nodeOff + 8, true), dim),
|
|
165
|
+
];
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Collects every active tile of a FLOAT image: root tiles (state on, no
|
|
169
|
+
* child), and upper/lower table slots whose value-mask bit is on and child bit
|
|
170
|
+
* off. They are re-emitted as tiles, so the quantized grid keeps the source
|
|
171
|
+
* topology (no expansion into constant leaves).
|
|
172
|
+
*/
|
|
173
|
+
function collectFloatTiles(view, rootOff, out) {
|
|
174
|
+
const L = FLOAT_LAYOUT;
|
|
175
|
+
const nTiles = view.getUint32(rootOff + ROOT_OFF_TABLE_SIZE, true);
|
|
176
|
+
for (let t = 0; t < nTiles; t++) {
|
|
177
|
+
const tileOff = rootOff + L.rootSize + t * L.rootTileSize;
|
|
178
|
+
if (readI64(view, tileOff + ROOT_TILE_OFF_CHILD) !== 0)
|
|
179
|
+
continue;
|
|
180
|
+
if (view.getUint32(tileOff + ROOT_TILE_OFF_STATE, true) === 0)
|
|
181
|
+
continue;
|
|
182
|
+
const key = view.getBigUint64(tileOff + ROOT_TILE_OFF_KEY, true);
|
|
183
|
+
out.push({ origin: keyToOrigin(key), dim: 4096, value: view.getFloat32(tileOff + L.rootTileOffValue, true) });
|
|
184
|
+
}
|
|
185
|
+
for (const child of rootChildren(view, rootOff)) {
|
|
186
|
+
const upperOff = rootOff + child;
|
|
187
|
+
const upperOrigin = nodeOrigin(view, upperOff, 4096);
|
|
188
|
+
for (let n = 0; n < UPPER_TABLE_COUNT; n++) {
|
|
189
|
+
const slotOff = upperOff + L.upperOffTable + n * L.tableStride;
|
|
190
|
+
if (maskBit(view, upperOff + UPPER_OFF_CHILD_MASK, n)) {
|
|
191
|
+
const lowerOff = upperOff + readI64(view, slotOff);
|
|
192
|
+
const lowerOrigin = nodeOrigin(view, lowerOff, 128);
|
|
193
|
+
for (let m = 0; m < LOWER_TABLE_COUNT; m++) {
|
|
194
|
+
if (maskBit(view, lowerOff + LOWER_OFF_CHILD_MASK, m))
|
|
195
|
+
continue;
|
|
196
|
+
if (!maskBit(view, lowerOff + NODE_OFF_VALUE_MASK, m))
|
|
197
|
+
continue;
|
|
198
|
+
out.push({
|
|
199
|
+
origin: [
|
|
200
|
+
lowerOrigin[0] + (((m >> 8) & 15) << 3),
|
|
201
|
+
lowerOrigin[1] + (((m >> 4) & 15) << 3),
|
|
202
|
+
lowerOrigin[2] + ((m & 15) << 3),
|
|
203
|
+
],
|
|
204
|
+
dim: 8,
|
|
205
|
+
value: view.getFloat32(lowerOff + L.lowerOffTable + m * L.tableStride, true),
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
else if (maskBit(view, upperOff + NODE_OFF_VALUE_MASK, n)) {
|
|
210
|
+
out.push({
|
|
211
|
+
origin: [
|
|
212
|
+
upperOrigin[0] + (((n >> 10) & 31) << 7),
|
|
213
|
+
upperOrigin[1] + (((n >> 5) & 31) << 7),
|
|
214
|
+
upperOrigin[2] + ((n & 31) << 7),
|
|
215
|
+
],
|
|
216
|
+
dim: 128,
|
|
217
|
+
value: view.getFloat32(slotOff, true),
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Inverse of `coordToKey`: each 21-bit field holds `u32(c) >>> 12`, so
|
|
225
|
+
* shifting it back up by 12 in 32-bit arithmetic restores the signed,
|
|
226
|
+
* 4096-aligned coordinate.
|
|
227
|
+
*/
|
|
228
|
+
function keyToOrigin(key) {
|
|
229
|
+
const axis = (shift) => Number((key >> shift) & 0xfffffn) << 12;
|
|
230
|
+
return [axis(42n), axis(21n), axis(0n)];
|
|
231
|
+
}
|
|
232
|
+
/** Walks root -> upper -> lower -> leaf, yielding one {@link LeafInput} per real leaf. */
|
|
233
|
+
function* traverseFloatLeaves(view, rootOff) {
|
|
234
|
+
for (const child of rootChildren(view, rootOff)) {
|
|
235
|
+
const upperOff = rootOff + child;
|
|
236
|
+
for (let n = 0; n < UPPER_TABLE_COUNT; n++) {
|
|
237
|
+
if (!maskBit(view, upperOff + UPPER_OFF_CHILD_MASK, n))
|
|
238
|
+
continue;
|
|
239
|
+
const slotOff = upperOff + FLOAT_LAYOUT.upperOffTable + n * FLOAT_LAYOUT.tableStride;
|
|
240
|
+
yield* traverseLower(view, upperOff + readI64(view, slotOff));
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
function* traverseLower(view, lowerOff) {
|
|
245
|
+
const L = FLOAT_LAYOUT;
|
|
246
|
+
const lowerOrigin = nodeOrigin(view, lowerOff, 128);
|
|
247
|
+
for (let n = 0; n < LOWER_TABLE_COUNT; n++) {
|
|
248
|
+
if (!maskBit(view, lowerOff + LOWER_OFF_CHILD_MASK, n))
|
|
249
|
+
continue;
|
|
250
|
+
const slotOff = lowerOff + L.lowerOffTable + n * L.tableStride;
|
|
251
|
+
const origin = [
|
|
252
|
+
lowerOrigin[0] + (((n >> 8) & 15) << 3),
|
|
253
|
+
lowerOrigin[1] + (((n >> 4) & 15) << 3),
|
|
254
|
+
lowerOrigin[2] + ((n & 15) << 3),
|
|
255
|
+
];
|
|
256
|
+
yield readLeaf(view, lowerOff + readI64(view, slotOff), origin);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/** Reads one real FLOAT leaf (512 values + value mask) at `leafOff`. */
|
|
260
|
+
function readLeaf(view, leafOff, origin) {
|
|
261
|
+
const tableOff = FLOAT_LAYOUT.leafOffTable;
|
|
262
|
+
const valueMask = new Uint32Array(16);
|
|
263
|
+
for (let w = 0; w < 16; w++)
|
|
264
|
+
valueMask[w] = view.getUint32(leafOff + LEAF_OFF_VALUE_MASK + w * 4, true);
|
|
265
|
+
const values = new Float32Array(LEAF_TABLE_COUNT);
|
|
266
|
+
for (let n = 0; n < LEAF_TABLE_COUNT; n++)
|
|
267
|
+
values[n] = view.getFloat32(leafOff + tableOff + n * 4, true);
|
|
268
|
+
return { origin, values, valueMask };
|
|
269
|
+
}
|
|
270
|
+
function readCString(image, byteOffset) {
|
|
271
|
+
const bytes = new Uint8Array(image.buffer, image.byteOffset + byteOffset);
|
|
272
|
+
let end = 0;
|
|
273
|
+
while (end < 256 && bytes[end] !== 0)
|
|
274
|
+
end++;
|
|
275
|
+
return new TextDecoder().decode(bytes.subarray(0, end));
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=quantize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quantize.js","sourceRoot":"","sources":["../../../src/tools/nanovdb/quantize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,yBAAyB,EACzB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,mBAAmB,EAAqB,MAAM,iBAAiB,CAAC;AAC5J,OAAO,EAAE,0BAA0B,EAAqB,MAAM,gBAAgB,CAAC;AAc/E,oFAAoF;AACpF,MAAM,UAAU,WAAW,CACzB,KAAiC,EACjC,IAAqB,EACrB,SAAkB,EAClB,UAA8B,EAAE;IAEhC,OAAO,mBAAmB,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC;AACpE,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,mBAAmB,CACjC,KAAiC,EACjC,IAAqB,EACrB,SAAkB,EAClB,UAA8B,EAAE;IAEhC,MAAM,KAAK,GAAG,KAAK,YAAY,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;IACjE,MA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E,CAAC;IAC5C,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["/**\n * quantize.ts — re-encode a FLOAT NanoVDB grid image as Fp4, Fp8, Fp16 or FpN.\n *\n * Quantization is a leaf-value-representation change only: topology, masks,\n * internal-node tables/stats, GridData and the transform are unchanged. So\n * `quantize` reads the source FLOAT image's leaves (each: 8-aligned origin,\n * all 512 values, value mask), its active tiles (root, upper, lower; kept as\n * tiles since K4.1 — tile values stay plain f32 in Fp8/FpN grids) and its\n * GridData transform/background, then re-runs the leaf-iterator build path\n * ({@link vdbBuildFromLeavesDetailed}) with the chosen quantizing {@link VDBLeafCodec}. The result satisfies the repo's proven decoders\n * (`read-value.ts` `leafFp*ReadFloat`, `pnanovdb.wgsl`).\n *\n * - `fp4` / `fp8` / `fp16` — fixed 4/8/16-bit codes; per-leaf quantum = (max-min)/(2^bits-1).\n * The CreateNanoGrid rules Fp8 uses (min/quantum over all 512 values, round-to-nearest, no\n * dither); `tolerance` is ignored. No native Fp4/Fp16 fixtures exist, so these are verified\n * by decoder round-trip and GPU parity, not byte-compared to `nanovdb_convert`.\n * - `fpn` — per-leaf variable bit-width, smallest of 1/2/4/8/16 bits whose\n * dequantized values stay within `tolerance` (default: native's FogVolume 0.01).\n *\n * v1 quantizes FLOAT sources only (throws otherwise) — that is the conversion\n * the toolset exposes (`float -> fp8/fpn`), and it is what the native\n * `nanovdb_convert --fp8/--fpn` pipeline does too.\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport {\n FLOAT_LAYOUT,\n GRID_OFF_GRID_CLASS,\n GRID_OFF_GRID_NAME,\n GRID_OFF_GRID_TYPE,\n GRID_OFF_MAP,\n GRID_OFF_VOXEL_SIZE,\n GRID_SIZE,\n GRID_TYPE_FLOAT,\n LEAF_OFF_VALUE_MASK,\n LEAF_TABLE_COUNT,\n LOWER_OFF_CHILD_MASK,\n LOWER_TABLE_COUNT,\n MAP_OFF_VECD,\n NODE_OFF_VALUE_MASK,\n ROOT_OFF_TABLE_SIZE,\n ROOT_TILE_OFF_CHILD,\n ROOT_TILE_OFF_KEY,\n ROOT_TILE_OFF_STATE,\n TREE_OFF_NODE_OFFSET_ROOT,\n UPPER_OFF_CHILD_MASK,\n UPPER_TABLE_COUNT,\n} from \"./bytes.js\";\nimport { VDB_FLOAT_LEAF_CODEC, VDB_FP4_LEAF_CODEC, VDB_FP8_LEAF_CODEC, VDB_FP16_LEAF_CODEC, vdbMakeFpNLeafCodec, type VDBLeafCodec } from \"./leaf-codec.js\";\nimport { vdbBuildFromLeavesDetailed, type VDBBuiltGrid } from \"./serialize.js\";\nimport type { LeafInput, TileInput } from \"./tree.js\";\n\nexport type VDBQuantizeMode = \"fp4\" | \"fp8\" | \"fp16\" | \"fpn\";\n\nexport interface VDBQuantizeOptions {\n /**\n * Also collapse uniform leaves and nodes of the source into tiles (OpenVDB\n * `prune`, tolerance 0; K4.6). Default false: quantizing keeps the source\n * topology, so a native FLOAT image quantizes to native's Fp8/FpN layout.\n */\n collapse?: boolean;\n}\n\n/** Quantizes a FLOAT grid image (or built grid) to Fp8/FpN. Returns a new image. */\nexport function vdbQuantize(\n input: Uint32Array | VDBBuiltGrid,\n mode: VDBQuantizeMode,\n tolerance?: number,\n options: VDBQuantizeOptions = {},\n): Uint32Array {\n return vdbQuantizeDetailed(input, mode, tolerance, options).image;\n}\n\n/** As {@link vdbQuantize}, but returns the computed metadata alongside the image. */\nexport function vdbQuantizeDetailed(\n input: Uint32Array | VDBBuiltGrid,\n mode: VDBQuantizeMode,\n tolerance?: number,\n options: VDBQuantizeOptions = {},\n): VDBBuiltGrid {\n const image = input instanceof Uint32Array ? input : input.image;\n const src = readFloatGrid(image);\n const codec: VDBLeafCodec =\n mode === \"fp4\" ? VDB_FP4_LEAF_CODEC\n : mode === \"fp8\" ? VDB_FP8_LEAF_CODEC\n : mode === \"fp16\" ? VDB_FP16_LEAF_CODEC\n : vdbMakeFpNLeafCodec(tolerance);\n return vdbBuildFromLeavesDetailed(src.leaves, codec, {\n voxelSize: src.voxelSize,\n worldOrigin: src.translation,\n background: src.background,\n gridName: src.gridName,\n gridClass:\n src.gridClassId === 1 ? \"LevelSet\" : src.gridClassId === 2 ? \"FogVolume\" : \"Unknown\",\n tiles: src.tiles,\n collapse: options.collapse === true,\n });\n}\n\n/**\n * Re-encodes a FLOAT grid image (still FLOAT) with uniform leaves and nodes\n * collapsed into tiles (OpenVDB `prune`, tolerance 0; K4.6). Values read back\n * identically; see `tree.ts` for the rules.\n */\nexport function vdbCollapseGrid(input: Uint32Array | VDBBuiltGrid): VDBBuiltGrid {\n const image = input instanceof Uint32Array ? input : input.image;\n const src = readFloatGrid(image, \"vdbCollapseGrid\");\n return vdbBuildFromLeavesDetailed(src.leaves, VDB_FLOAT_LEAF_CODEC, {\n voxelSize: src.voxelSize,\n worldOrigin: src.translation,\n background: src.background,\n gridName: src.gridName,\n gridClass: src.gridClassId === 1 ? \"LevelSet\" : src.gridClassId === 2 ? \"FogVolume\" : \"Unknown\",\n tiles: src.tiles,\n collapse: true,\n });\n}\n\ninterface FloatGridView {\n voxelSize: [number, number, number];\n translation: [number, number, number];\n background: number;\n gridName: string;\n gridClassId: number;\n leaves: Iterable<LeafInput>;\n tiles: TileInput[];\n}\n\nfunction floorDiv(v: number, block: number): number {\n return Math.floor(v / block) * block;\n}\n\nfunction readI64(view: DataView, off: number): number {\n return Number(view.getBigInt64(off, true));\n}\n\nfunction maskBit(view: DataView, maskBase: number, n: number): boolean {\n return ((view.getUint32(maskBase + 4 * (n >>> 5), true) >>> (n & 31)) & 1) !== 0;\n}\n\n/** Reads a FLOAT grid image's transform/background and yields its leaves. */\nfunction readFloatGrid(image: Uint32Array, caller = \"quantize\"): FloatGridView {\n const view = new DataView(image.buffer, image.byteOffset, image.byteLength);\n const gridType = view.getUint32(GRID_OFF_GRID_TYPE, true);\n if (gridType !== GRID_TYPE_FLOAT) {\n throw new VDBToolsError(\"VDB_UNSUPPORTED_GRID_TYPE\", \n `${caller}: source grid type ${gridType} is not FLOAT (${GRID_TYPE_FLOAT}); ` +\n `v1 re-encodes float grids only (float -> float/fp8/fpn).`,\n );\n }\n // All three: a resampled grid can be anisotropic (K4.4), and the Map must survive quantization.\n const voxelSize: [number, number, number] = [\n view.getFloat64(GRID_OFF_VOXEL_SIZE, true),\n view.getFloat64(GRID_OFF_VOXEL_SIZE + 8, true),\n view.getFloat64(GRID_OFF_VOXEL_SIZE + 16, true),\n ];\n const vecBase = GRID_OFF_MAP + MAP_OFF_VECD;\n const translation: [number, number, number] = [\n view.getFloat64(vecBase, true),\n view.getFloat64(vecBase + 8, true),\n view.getFloat64(vecBase + 16, true),\n ];\n const gridClassId = view.getUint32(GRID_OFF_GRID_CLASS, true);\n const gridName = readCString(image, GRID_OFF_GRID_NAME);\n\n const treeOff = GRID_SIZE;\n const rootOff = treeOff + Number(view.getBigUint64(treeOff + TREE_OFF_NODE_OFFSET_ROOT, true));\n const background = effectiveBackground(view, rootOff);\n\n const tiles: TileInput[] = [];\n collectFloatTiles(view, rootOff, tiles);\n const leaves = traverseFloatLeaves(view, rootOff);\n return { voxelSize, translation, background, gridName, gridClassId, leaves, tiles };\n}\n\n/**\n * The value inactive regions near the active data read back as. Native grids\n * routinely store a far-field `mBackground` (e.g. a level-set narrow-band 3)\n * that differs from the value written into the *near-field* inactive internal\n * tiles surrounding the active voxels (typically 0). The re-layout emits no\n * inactive tiles, so it fills empty slots with a single background; using the\n * near-field inactive-tile value (the first inactive lower- then upper-tile\n * found) reproduces the source's readback around the data, falling back to the\n * root `mBackground` when the grid has no inactive internal tile at all.\n */\nfunction effectiveBackground(view: DataView, rootOff: number): number {\n const rootBg = view.getFloat32(rootOff + FLOAT_LAYOUT.rootOffBackground, true);\n const L = FLOAT_LAYOUT;\n const nTiles = view.getUint32(rootOff + ROOT_OFF_TABLE_SIZE, true);\n let upperInactive: number | undefined;\n for (let t = 0; t < nTiles; t++) {\n const tileOff = rootOff + L.rootSize + t * L.rootTileSize;\n const child = readI64(view, tileOff + ROOT_TILE_OFF_CHILD);\n if (child === 0) continue;\n const upperOff = rootOff + child;\n for (let n = 0; n < UPPER_TABLE_COUNT; n++) {\n const slotOff = upperOff + L.upperOffTable + n * L.tableStride;\n if (maskBit(view, upperOff + UPPER_OFF_CHILD_MASK, n)) {\n // Descend one lower node: an inactive lower tile is the near-field value.\n const lowerOff = upperOff + readI64(view, slotOff);\n for (let m = 0; m < LOWER_TABLE_COUNT; m++) {\n const lslot = lowerOff + L.lowerOffTable + m * L.tableStride;\n if (\n !maskBit(view, lowerOff + LOWER_OFF_CHILD_MASK, m) &&\n !maskBit(view, lowerOff + NODE_OFF_VALUE_MASK, m)\n ) {\n return view.getFloat32(lslot, true);\n }\n }\n } else if (upperInactive === undefined && !maskBit(view, upperOff + NODE_OFF_VALUE_MASK, n)) {\n upperInactive = view.getFloat32(slotOff, true);\n }\n }\n }\n return upperInactive ?? rootBg;\n}\n\n/** Child-node offset (relative to `rootOff`) of each root-table entry that has a child. */\nfunction* rootChildren(view: DataView, rootOff: number): Iterable<number> {\n const L = FLOAT_LAYOUT;\n const nTiles = view.getUint32(rootOff + ROOT_OFF_TABLE_SIZE, true);\n for (let t = 0; t < nTiles; t++) {\n const tileOff = rootOff + L.rootSize + t * L.rootTileSize;\n const child = readI64(view, tileOff + ROOT_TILE_OFF_CHILD);\n if (child !== 0) yield child;\n }\n}\n\n/** Index-space min corner of an internal node, from its bbox min. */\nfunction nodeOrigin(view: DataView, nodeOff: number, dim: number): [number, number, number] {\n return [\n floorDiv(view.getInt32(nodeOff, true), dim),\n floorDiv(view.getInt32(nodeOff + 4, true), dim),\n floorDiv(view.getInt32(nodeOff + 8, true), dim),\n ];\n}\n\n/**\n * Collects every active tile of a FLOAT image: root tiles (state on, no\n * child), and upper/lower table slots whose value-mask bit is on and child bit\n * off. They are re-emitted as tiles, so the quantized grid keeps the source\n * topology (no expansion into constant leaves).\n */\nfunction collectFloatTiles(view: DataView, rootOff: number, out: TileInput[]): void {\n const L = FLOAT_LAYOUT;\n const nTiles = view.getUint32(rootOff + ROOT_OFF_TABLE_SIZE, true);\n for (let t = 0; t < nTiles; t++) {\n const tileOff = rootOff + L.rootSize + t * L.rootTileSize;\n if (readI64(view, tileOff + ROOT_TILE_OFF_CHILD) !== 0) continue;\n if (view.getUint32(tileOff + ROOT_TILE_OFF_STATE, true) === 0) continue;\n const key = view.getBigUint64(tileOff + ROOT_TILE_OFF_KEY, true);\n out.push({ origin: keyToOrigin(key), dim: 4096, value: view.getFloat32(tileOff + L.rootTileOffValue, true) });\n }\n for (const child of rootChildren(view, rootOff)) {\n const upperOff = rootOff + child;\n const upperOrigin = nodeOrigin(view, upperOff, 4096);\n for (let n = 0; n < UPPER_TABLE_COUNT; n++) {\n const slotOff = upperOff + L.upperOffTable + n * L.tableStride;\n if (maskBit(view, upperOff + UPPER_OFF_CHILD_MASK, n)) {\n const lowerOff = upperOff + readI64(view, slotOff);\n const lowerOrigin = nodeOrigin(view, lowerOff, 128);\n for (let m = 0; m < LOWER_TABLE_COUNT; m++) {\n if (maskBit(view, lowerOff + LOWER_OFF_CHILD_MASK, m)) continue;\n if (!maskBit(view, lowerOff + NODE_OFF_VALUE_MASK, m)) continue;\n out.push({\n origin: [\n lowerOrigin[0] + (((m >> 8) & 15) << 3),\n lowerOrigin[1] + (((m >> 4) & 15) << 3),\n lowerOrigin[2] + ((m & 15) << 3),\n ],\n dim: 8,\n value: view.getFloat32(lowerOff + L.lowerOffTable + m * L.tableStride, true),\n });\n }\n } else if (maskBit(view, upperOff + NODE_OFF_VALUE_MASK, n)) {\n out.push({\n origin: [\n upperOrigin[0] + (((n >> 10) & 31) << 7),\n upperOrigin[1] + (((n >> 5) & 31) << 7),\n upperOrigin[2] + ((n & 31) << 7),\n ],\n dim: 128,\n value: view.getFloat32(slotOff, true),\n });\n }\n }\n }\n}\n\n/**\n * Inverse of `coordToKey`: each 21-bit field holds `u32(c) >>> 12`, so\n * shifting it back up by 12 in 32-bit arithmetic restores the signed,\n * 4096-aligned coordinate.\n */\nfunction keyToOrigin(key: bigint): [number, number, number] {\n const axis = (shift: bigint): number => Number((key >> shift) & 0xfffffn) << 12;\n return [axis(42n), axis(21n), axis(0n)];\n}\n\n/** Walks root -> upper -> lower -> leaf, yielding one {@link LeafInput} per real leaf. */\nfunction* traverseFloatLeaves(view: DataView, rootOff: number): Iterable<LeafInput> {\n for (const child of rootChildren(view, rootOff)) {\n const upperOff = rootOff + child;\n for (let n = 0; n < UPPER_TABLE_COUNT; n++) {\n if (!maskBit(view, upperOff + UPPER_OFF_CHILD_MASK, n)) continue;\n const slotOff = upperOff + FLOAT_LAYOUT.upperOffTable + n * FLOAT_LAYOUT.tableStride;\n yield* traverseLower(view, upperOff + readI64(view, slotOff));\n }\n }\n}\n\nfunction* traverseLower(view: DataView, lowerOff: number): Iterable<LeafInput> {\n const L = FLOAT_LAYOUT;\n const lowerOrigin = nodeOrigin(view, lowerOff, 128);\n for (let n = 0; n < LOWER_TABLE_COUNT; n++) {\n if (!maskBit(view, lowerOff + LOWER_OFF_CHILD_MASK, n)) continue;\n const slotOff = lowerOff + L.lowerOffTable + n * L.tableStride;\n const origin: [number, number, number] = [\n lowerOrigin[0] + (((n >> 8) & 15) << 3),\n lowerOrigin[1] + (((n >> 4) & 15) << 3),\n lowerOrigin[2] + ((n & 15) << 3),\n ];\n yield readLeaf(view, lowerOff + readI64(view, slotOff), origin);\n }\n}\n\n/** Reads one real FLOAT leaf (512 values + value mask) at `leafOff`. */\nfunction readLeaf(view: DataView, leafOff: number, origin: [number, number, number]): LeafInput {\n const tableOff = FLOAT_LAYOUT.leafOffTable;\n const valueMask = new Uint32Array(16);\n for (let w = 0; w < 16; w++) valueMask[w] = view.getUint32(leafOff + LEAF_OFF_VALUE_MASK + w * 4, true);\n const values = new Float32Array(LEAF_TABLE_COUNT);\n for (let n = 0; n < LEAF_TABLE_COUNT; n++) values[n] = view.getFloat32(leafOff + tableOff + n * 4, true);\n return { origin, values, valueMask };\n}\n\nfunction readCString(image: Uint32Array, byteOffset: number): string {\n const bytes = new Uint8Array(image.buffer, image.byteOffset + byteOffset);\n let end = 0;\n while (end < 256 && bytes[end] !== 0) end++;\n return new TextDecoder().decode(bytes.subarray(0, end));\n}\n"]}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* resample.ts — resample a sparse grid to a new resolution (K4.4) and build a
|
|
3
|
+
* NanoVDB FLOAT image from it, optionally quantized to Fp8/FpN.
|
|
4
|
+
*
|
|
5
|
+
* ## Conventions
|
|
6
|
+
*
|
|
7
|
+
* Voxels are centred at integer index coordinates, the convention of the CPU
|
|
8
|
+
* oracle's `readValue`/`vdbSampleTrilinear` (and the WGSL sampler), and of
|
|
9
|
+
* mjurczyk's `.wvdb` bake (`Math.round` in index space). Voxel `i` therefore
|
|
10
|
+
* covers the index interval `[i - 0.5, i + 0.5]`.
|
|
11
|
+
*
|
|
12
|
+
* - **Box.** A world-space box `[min, max]`. Default: the cell box of the
|
|
13
|
+
* source's active voxels, `[imin - 0.5, imax + 0.5]` in source index space,
|
|
14
|
+
* mapped to world. Pass `bbox` for a shared box (a sequence) or to reproduce
|
|
15
|
+
* a `.wvdb` bake (his box is the voxel-centre box, `wvdbSourceFromVdbGrid(g).bbox`).
|
|
16
|
+
* - **Target lattice.** `dims` voxels per axis with voxel size `vs` per axis;
|
|
17
|
+
* target voxel `j` is centred at `min + ((j + 0.5) / dims) * (dims * vs)`, the
|
|
18
|
+
* arithmetic of his `forEachTexel`. The output Map is `world = vs * ijk + t`
|
|
19
|
+
* with `t = min + vs / 2`, so the target index box is `[0, dims - 1]`.
|
|
20
|
+
* - **Resolution.** Exactly one of `resolution` (voxels on the longest box side,
|
|
21
|
+
* uniform voxels), `voxelSize` (number: uniform; `[x, y, z]`: anisotropic) or
|
|
22
|
+
* `dimensions` (voxels per axis; voxel size = box / dims, anisotropic unless
|
|
23
|
+
* the box is proportional). With none, the source voxel size (an identity
|
|
24
|
+
* resample). With `resolution` or `voxelSize`, `dims = ceil(side / vs)` and the
|
|
25
|
+
* box grows at its max side to a whole number of voxels; with `dimensions`
|
|
26
|
+
* the box is kept exactly.
|
|
27
|
+
*
|
|
28
|
+
* ## Filters
|
|
29
|
+
*
|
|
30
|
+
* The map between target and source index space is separable (both maps are
|
|
31
|
+
* axis-aligned), so every filter is a per-axis weight table applied as three
|
|
32
|
+
* 1D passes over a gathered block of source voxels.
|
|
33
|
+
*
|
|
34
|
+
* - `'point'`: the nearest source voxel (`Math.round`), no prefilter. Same
|
|
35
|
+
* positions and arithmetic as the `.wvdb` bake; aliases when downsampling.
|
|
36
|
+
* - `'box'` (default): the area-weighted average of the source voxels the
|
|
37
|
+
* target voxel's cell overlaps (inactive voxels count with their stored
|
|
38
|
+
* value, normally the background). It is the right default for
|
|
39
|
+
* downsampling: it is the integral of the source field over the target
|
|
40
|
+
* voxel, so mass (density times volume) is conserved, the coarse grid is the
|
|
41
|
+
* source seen at the coarse scale, and thin features fade instead of
|
|
42
|
+
* flickering in or out with the sampling phase. A downsample by 2 on an
|
|
43
|
+
* aligned box is the exact 2x2x2 mean.
|
|
44
|
+
* - `'trilinear'`: the trilinear interpolation of the source at the target
|
|
45
|
+
* voxel centre (`vdbSampleTrilinear`). Smooth for upsampling and small ratios;
|
|
46
|
+
* aliases like `'point'` at large downsampling ratios.
|
|
47
|
+
*
|
|
48
|
+
* ## Sparsity
|
|
49
|
+
*
|
|
50
|
+
* Only target leaves whose filter footprint overlaps a source leaf or active
|
|
51
|
+
* tile are visited (empty space costs nothing), and a target voxel is active
|
|
52
|
+
* only when its footprint touches an active source voxel and, given `cutoff`,
|
|
53
|
+
* `|value - background| > cutoff`. Leaves left with no active voxel are dropped.
|
|
54
|
+
* Inactive voxels inside an emitted leaf keep their filtered value (the field a
|
|
55
|
+
* texture sampler would see).
|
|
56
|
+
*/
|
|
57
|
+
import type { VdbFile, VdbGrid } from "../vdb/types.js";
|
|
58
|
+
import { type VDBQuantizeMode } from "./quantize.js";
|
|
59
|
+
import { type VDBBuiltGrid } from "./serialize.js";
|
|
60
|
+
type Vec3 = [number, number, number];
|
|
61
|
+
export type VDBResampleFilter = "point" | "box" | "trilinear";
|
|
62
|
+
/** A NanoVDB FLOAT/Fp8/FpN grid image, a parsed `.vdb` float grid, or a parsed `.vdb` file. */
|
|
63
|
+
export type VDBResampleSource = Uint32Array | VdbGrid | VdbFile;
|
|
64
|
+
export interface VDBResampleOptions {
|
|
65
|
+
/** Voxels on the longest side of the box; uniform voxels. */
|
|
66
|
+
resolution?: number;
|
|
67
|
+
/** Target voxel size in world units: uniform, or `[x, y, z]` (anisotropic). */
|
|
68
|
+
voxelSize?: number | Vec3;
|
|
69
|
+
/** Target voxels per axis; voxel size = box size / dims per axis. */
|
|
70
|
+
dimensions?: Vec3;
|
|
71
|
+
/** Default `'box'`. */
|
|
72
|
+
filter?: VDBResampleFilter;
|
|
73
|
+
/** World box `[min, max]`. Default: the source's active cell box. */
|
|
74
|
+
bbox?: [Vec3, Vec3];
|
|
75
|
+
/**
|
|
76
|
+
* Keep a target voxel active only if `|value - background| > cutoff` (as
|
|
77
|
+
* well as touching an active source voxel). Default: no value test.
|
|
78
|
+
*/
|
|
79
|
+
cutoff?: number;
|
|
80
|
+
/** Quantize the result (via `quantize`). Default: FLOAT. */
|
|
81
|
+
quantize?: VDBQuantizeMode;
|
|
82
|
+
/** FpN tolerance (`quantize`'s, default 0.01). */
|
|
83
|
+
tolerance?: number;
|
|
84
|
+
/** Which grid of a `VdbFile` to resample. Default: the first float grid. */
|
|
85
|
+
sourceGridName?: string;
|
|
86
|
+
/** Output grid name. Default: the source grid's name. */
|
|
87
|
+
gridName?: string;
|
|
88
|
+
/** Output background. Default: the source's root background. */
|
|
89
|
+
background?: number;
|
|
90
|
+
/**
|
|
91
|
+
* Collapse uniform target leaves and nodes into tiles (OpenVDB `prune`,
|
|
92
|
+
* tolerance 0; K4.6), before any quantization. Default true: a resample is a
|
|
93
|
+
* new build with no native topology to keep, and a uniform interior (a
|
|
94
|
+
* source tile, or a saturated core) costs one tile instead of leaves.
|
|
95
|
+
*/
|
|
96
|
+
collapse?: boolean;
|
|
97
|
+
}
|
|
98
|
+
export interface VDBResampledGrid extends VDBBuiltGrid {
|
|
99
|
+
/** Target voxels per axis (the index box is `[0, dims - 1]`). */
|
|
100
|
+
dimensions: Vec3;
|
|
101
|
+
/** The world box that was resampled (grown to whole voxels for `resolution`/`voxelSize`). */
|
|
102
|
+
bbox: [Vec3, Vec3];
|
|
103
|
+
filter: VDBResampleFilter;
|
|
104
|
+
/** Source voxel size per axis. */
|
|
105
|
+
sourceVoxelSize: Vec3;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Resamples a sparse grid to a new resolution over a world box and builds a
|
|
109
|
+
* NanoVDB FLOAT image (optionally quantized to Fp8/FpN). See the module doc for
|
|
110
|
+
* the conventions, filters and sparsity rule.
|
|
111
|
+
*/
|
|
112
|
+
export declare function vdbResampleGrid(source: VDBResampleSource, options?: VDBResampleOptions): VDBResampledGrid;
|
|
113
|
+
export interface VDBResampleDenseOptions {
|
|
114
|
+
/** World box `[min, max]`: target voxel `j` is centred at `min + ((j + 0.5) / dims) * (max - min)`. */
|
|
115
|
+
bbox: [Vec3, Vec3];
|
|
116
|
+
/** Target voxels per axis. */
|
|
117
|
+
dimensions: Vec3;
|
|
118
|
+
/** Default `'box'`. */
|
|
119
|
+
filter?: VDBResampleFilter;
|
|
120
|
+
/** Which grid of a `VdbFile`. Default: the first float grid. */
|
|
121
|
+
sourceGridName?: string;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* {@link vdbResampleGrid}'s filters onto a dense lattice (the `.wvdb` bake's,
|
|
125
|
+
* K4.13): `values` x fastest (`x + y*X + z*X*Y`), `active` 1 where the target
|
|
126
|
+
* voxel's footprint touches an active source voxel. Voxels in no emitted leaf
|
|
127
|
+
* (the footprint touches no active source voxel) hold the source background.
|
|
128
|
+
* Unlike `vdbResampleGrid`, the box may have zero size on an axis (one voxel
|
|
129
|
+
* thick); that axis samples the nearest source voxel.
|
|
130
|
+
*/
|
|
131
|
+
export declare function vdbResampleDense(source: VDBResampleSource, options: VDBResampleDenseOptions): {
|
|
132
|
+
values: Float32Array;
|
|
133
|
+
active: Uint8Array;
|
|
134
|
+
background: number;
|
|
135
|
+
};
|
|
136
|
+
export interface VDBResampleErrorOptions {
|
|
137
|
+
/** Use every `stride`-th active source voxel (leaf order). Default 7, as in the comparison report. */
|
|
138
|
+
stride?: number;
|
|
139
|
+
/** Which grid of a `VdbFile`. Default: the first float grid. */
|
|
140
|
+
sourceGridName?: string;
|
|
141
|
+
}
|
|
142
|
+
export interface VDBResampleErrorResult {
|
|
143
|
+
/** Mean |target − source| over the sampled active source voxels. */
|
|
144
|
+
meanAbsError: number;
|
|
145
|
+
/** Mean source value over the same voxels. */
|
|
146
|
+
meanValue: number;
|
|
147
|
+
/** `100 * meanAbsError / meanValue`. */
|
|
148
|
+
percent: number;
|
|
149
|
+
/** Voxels compared. */
|
|
150
|
+
count: number;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* The error metric of the mjurczyk comparison (docs/dev/research/INDEX): mean absolute
|
|
154
|
+
* difference over every `stride`-th active source voxel, as a percentage of the
|
|
155
|
+
* mean source value there. The target (any NanoVDB FLOAT/Fp8/FpN image with an
|
|
156
|
+
* axis-aligned Map) is read back with `vdbSampleTrilinear` at each source voxel
|
|
157
|
+
* centre. Active tiles are not sampled (leaves only).
|
|
158
|
+
*/
|
|
159
|
+
export declare function vdbResampleError(source: VDBResampleSource, target: Uint32Array, options?: VDBResampleErrorOptions): VDBResampleErrorResult;
|
|
160
|
+
export {};
|