@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,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* stats.ts — per-node active-value statistics, computed the way NanoVDB's
|
|
3
|
+
* `tools/GridStats.h` does: min/max are the extrema of *active* voxel values in
|
|
4
|
+
* a node's subtree, `ave` is their arithmetic mean, and `stddev` is the
|
|
5
|
+
* *population* standard deviation (divide by N, not N-1). A parent node's stats
|
|
6
|
+
* are the exact aggregate of its children's plus its own active tiles, each
|
|
7
|
+
* tile counted with GridStats' weight (see {@link StatsAccumulator.addTile}).
|
|
8
|
+
*
|
|
9
|
+
* The accumulator keeps N, sum and sum-of-squares in f64 so that ave/stddev are
|
|
10
|
+
* computed at full precision before being narrowed to the f32 stored in the
|
|
11
|
+
* grid. These stats feed the material's adaptive stepping (invariant D), so they
|
|
12
|
+
* are computed for real, not stubbed.
|
|
13
|
+
*/
|
|
14
|
+
const INT_MIN = -0x80000000;
|
|
15
|
+
const INT_MAX = 0x7fffffff;
|
|
16
|
+
/** Running active-value statistics plus the tight index-space bbox of the
|
|
17
|
+
* active voxels they cover. */
|
|
18
|
+
export class StatsAccumulator {
|
|
19
|
+
count = 0;
|
|
20
|
+
sum = 0;
|
|
21
|
+
sumSq = 0;
|
|
22
|
+
min = Number.POSITIVE_INFINITY;
|
|
23
|
+
max = Number.NEGATIVE_INFINITY;
|
|
24
|
+
// Tight bbox of active voxels (inclusive). Empty when count === 0.
|
|
25
|
+
bboxMin = [INT_MAX, INT_MAX, INT_MAX];
|
|
26
|
+
bboxMax = [INT_MIN, INT_MIN, INT_MIN];
|
|
27
|
+
/** Adds one active voxel at index coord (x,y,z) with the given value. */
|
|
28
|
+
addVoxel(value, x, y, z) {
|
|
29
|
+
this.count += 1;
|
|
30
|
+
this.sum += value;
|
|
31
|
+
this.sumSq += value * value;
|
|
32
|
+
if (value < this.min)
|
|
33
|
+
this.min = value;
|
|
34
|
+
if (value > this.max)
|
|
35
|
+
this.max = value;
|
|
36
|
+
if (x < this.bboxMin[0])
|
|
37
|
+
this.bboxMin[0] = x;
|
|
38
|
+
if (y < this.bboxMin[1])
|
|
39
|
+
this.bboxMin[1] = y;
|
|
40
|
+
if (z < this.bboxMin[2])
|
|
41
|
+
this.bboxMin[2] = z;
|
|
42
|
+
if (x > this.bboxMax[0])
|
|
43
|
+
this.bboxMax[0] = x;
|
|
44
|
+
if (y > this.bboxMax[1])
|
|
45
|
+
this.bboxMax[1] = y;
|
|
46
|
+
if (z > this.bboxMax[2])
|
|
47
|
+
this.bboxMax[2] = z;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Adds an active tile: `value` counted `weight` times, with the tile's
|
|
51
|
+
* inclusive index bbox. NanoVDB GridStats passes the child node type's slot
|
|
52
|
+
* count as the weight, so once tiles are involved `count` is a stats weight,
|
|
53
|
+
* not a voxel count.
|
|
54
|
+
*/
|
|
55
|
+
addTile(value, weight, bboxMin, bboxMax) {
|
|
56
|
+
this.count += weight;
|
|
57
|
+
this.sum += value * weight;
|
|
58
|
+
this.sumSq += value * value * weight;
|
|
59
|
+
if (value < this.min)
|
|
60
|
+
this.min = value;
|
|
61
|
+
if (value > this.max)
|
|
62
|
+
this.max = value;
|
|
63
|
+
for (let a = 0; a < 3; a++) {
|
|
64
|
+
if (bboxMin[a] < this.bboxMin[a])
|
|
65
|
+
this.bboxMin[a] = bboxMin[a];
|
|
66
|
+
if (bboxMax[a] > this.bboxMax[a])
|
|
67
|
+
this.bboxMax[a] = bboxMax[a];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** Merges a child accumulator's totals into this one. */
|
|
71
|
+
merge(child) {
|
|
72
|
+
if (child.count === 0)
|
|
73
|
+
return;
|
|
74
|
+
this.count += child.count;
|
|
75
|
+
this.sum += child.sum;
|
|
76
|
+
this.sumSq += child.sumSq;
|
|
77
|
+
if (child.min < this.min)
|
|
78
|
+
this.min = child.min;
|
|
79
|
+
if (child.max > this.max)
|
|
80
|
+
this.max = child.max;
|
|
81
|
+
for (let a = 0; a < 3; a++) {
|
|
82
|
+
if (child.bboxMin[a] < this.bboxMin[a])
|
|
83
|
+
this.bboxMin[a] = child.bboxMin[a];
|
|
84
|
+
if (child.bboxMax[a] > this.bboxMax[a])
|
|
85
|
+
this.bboxMax[a] = child.bboxMax[a];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
get average() {
|
|
89
|
+
return this.count > 0 ? this.sum / this.count : 0;
|
|
90
|
+
}
|
|
91
|
+
/** Population standard deviation (GridStats convention). */
|
|
92
|
+
get stdDev() {
|
|
93
|
+
if (this.count === 0)
|
|
94
|
+
return 0;
|
|
95
|
+
const mean = this.sum / this.count;
|
|
96
|
+
const variance = this.sumSq / this.count - mean * mean;
|
|
97
|
+
return Math.sqrt(Math.max(0, variance));
|
|
98
|
+
}
|
|
99
|
+
get isEmpty() {
|
|
100
|
+
return this.count === 0;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const fround = Math.fround;
|
|
104
|
+
/** `Vec3<float>::lengthSqr()` evaluated in f32: `x*x + y*y + z*z`, left to right. */
|
|
105
|
+
export function lengthSqrF32(x, y, z) {
|
|
106
|
+
return fround(fround(fround(x * x) + fround(y * y)) + fround(z * z));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Vector statistics, NanoVDB `tools/GridStats.h` `Stats<Vec3f, 1>` (rank 1):
|
|
110
|
+
* every value is ranked by its f32 `lengthSqr()`. `min`/`max` (inherited) are
|
|
111
|
+
* the extreme squared lengths and {@link minVec}/{@link maxVec} the vectors
|
|
112
|
+
* that hold them (first one wins on ties, as `Pair::operator<` is strict);
|
|
113
|
+
* `average` and `stdDev` are the mean and population standard deviation of the
|
|
114
|
+
* squared lengths, not of the components.
|
|
115
|
+
*/
|
|
116
|
+
export class Vec3StatsAccumulator extends StatsAccumulator {
|
|
117
|
+
minVec = [0, 0, 0];
|
|
118
|
+
maxVec = [0, 0, 0];
|
|
119
|
+
/** Adds one active voxel with vector value (vx, vy, vz) at index coord (x, y, z). */
|
|
120
|
+
addVoxelVec(vx, vy, vz, x, y, z) {
|
|
121
|
+
const s = lengthSqrF32(vx, vy, vz);
|
|
122
|
+
if (s < this.min)
|
|
123
|
+
this.minVec = [vx, vy, vz];
|
|
124
|
+
if (s > this.max)
|
|
125
|
+
this.maxVec = [vx, vy, vz];
|
|
126
|
+
this.addVoxel(s, x, y, z);
|
|
127
|
+
}
|
|
128
|
+
/** Adds an active vector tile with GridStats weight `weight` (see {@link StatsAccumulator.addTile}). */
|
|
129
|
+
addTileVec(value, weight, bboxMin, bboxMax) {
|
|
130
|
+
const s = lengthSqrF32(value[0], value[1], value[2]);
|
|
131
|
+
if (s < this.min)
|
|
132
|
+
this.minVec = [value[0], value[1], value[2]];
|
|
133
|
+
if (s > this.max)
|
|
134
|
+
this.maxVec = [value[0], value[1], value[2]];
|
|
135
|
+
this.addTile(s, weight, bboxMin, bboxMax);
|
|
136
|
+
}
|
|
137
|
+
merge(child) {
|
|
138
|
+
if (child.count === 0)
|
|
139
|
+
return;
|
|
140
|
+
if (child instanceof Vec3StatsAccumulator) {
|
|
141
|
+
if (child.min < this.min)
|
|
142
|
+
this.minVec = [...child.minVec];
|
|
143
|
+
if (child.max > this.max)
|
|
144
|
+
this.maxVec = [...child.maxVec];
|
|
145
|
+
}
|
|
146
|
+
super.merge(child);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=stats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stats.js","sourceRoot":"","sources":["../../../src/tools/nanovdb/stats.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,OAAO,GAAG,CAAC,UAAU,CAAC;AAC5B,MAAM,OAAO,GAAG,UAAU,CAAC;AAE3B;gCACgC;AAChC,MAAM,OAAO,gBAAgB;IAC3B,KAAK,GAAG,CAAC,CAAC;IACF,GAAG,GAAG,CAAC,CAAC;IACR,KAAK,GAAG,CAAC,CAAC;IAClB,GAAG,GAAG,MAAM,CAAC,iBAAiB,CAAC;IAC/B,GAAG,GAAG,MAAM,CAAC,iBAAiB,CAAC;IAC/B,mEAAmE;IACnE,OAAO,GAA6B,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAChE,OAAO,GAA6B,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAEhE,yEAAyE;IACzE,QAAQ,CAAC,KAAa,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS;QACrD,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC;QAChB,IAAI,CAAC,GAAG,IAAI,KAAK,CAAC;QAClB,IAAI,CAAC,KAAK,IAAI,KAAK,GAAG,KAAK,CAAC;QAC5B,IAAI,KAAK,GAAG,IAAI,CAAC,GAAG;YAAE,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC;QACvC,IAAI,KAAK,GAAG,IAAI,CAAC,GAAG;YAAE,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC;QACvC,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;YAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAC7C,IAAI,CAAC,GAAG,IAA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,MAAM,CAAC,CAAC;YAC1D,IAAI,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG;gBAAE,IAAI,CAAC,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;QAC5D,CAAC;QACD,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;CACF","sourcesContent":["/**\n * stats.ts — per-node active-value statistics, computed the way NanoVDB's\n * `tools/GridStats.h` does: min/max are the extrema of *active* voxel values in\n * a node's subtree, `ave` is their arithmetic mean, and `stddev` is the\n * *population* standard deviation (divide by N, not N-1). A parent node's stats\n * are the exact aggregate of its children's plus its own active tiles, each\n * tile counted with GridStats' weight (see {@link StatsAccumulator.addTile}).\n *\n * The accumulator keeps N, sum and sum-of-squares in f64 so that ave/stddev are\n * computed at full precision before being narrowed to the f32 stored in the\n * grid. These stats feed the material's adaptive stepping (invariant D), so they\n * are computed for real, not stubbed.\n */\n\nconst INT_MIN = -0x80000000;\nconst INT_MAX = 0x7fffffff;\n\n/** Running active-value statistics plus the tight index-space bbox of the\n * active voxels they cover. */\nexport class StatsAccumulator {\n count = 0;\n private sum = 0;\n private sumSq = 0;\n min = Number.POSITIVE_INFINITY;\n max = Number.NEGATIVE_INFINITY;\n // Tight bbox of active voxels (inclusive). Empty when count === 0.\n bboxMin: [number, number, number] = [INT_MAX, INT_MAX, INT_MAX];\n bboxMax: [number, number, number] = [INT_MIN, INT_MIN, INT_MIN];\n\n /** Adds one active voxel at index coord (x,y,z) with the given value. */\n addVoxel(value: number, x: number, y: number, z: number): void {\n this.count += 1;\n this.sum += value;\n this.sumSq += value * value;\n if (value < this.min) this.min = value;\n if (value > this.max) this.max = value;\n if (x < this.bboxMin[0]) this.bboxMin[0] = x;\n if (y < this.bboxMin[1]) this.bboxMin[1] = y;\n if (z < this.bboxMin[2]) this.bboxMin[2] = z;\n if (x > this.bboxMax[0]) this.bboxMax[0] = x;\n if (y > this.bboxMax[1]) this.bboxMax[1] = y;\n if (z > this.bboxMax[2]) this.bboxMax[2] = z;\n }\n\n /**\n * Adds an active tile: `value` counted `weight` times, with the tile's\n * inclusive index bbox. NanoVDB GridStats passes the child node type's slot\n * count as the weight, so once tiles are involved `count` is a stats weight,\n * not a voxel count.\n */\n addTile(\n value: number,\n weight: number,\n bboxMin: readonly [number, number, number],\n bboxMax: readonly [number, number, number],\n ): void {\n this.count += weight;\n this.sum += value * weight;\n this.sumSq += value * value * weight;\n if (value < this.min) this.min = value;\n if (value > this.max) this.max = value;\n for (let a = 0; a < 3; a++) {\n if (bboxMin[a]! < this.bboxMin[a]!) this.bboxMin[a] = bboxMin[a]!;\n if (bboxMax[a]! > this.bboxMax[a]!) this.bboxMax[a] = bboxMax[a]!;\n }\n }\n\n /** Merges a child accumulator's totals into this one. */\n merge(child: StatsAccumulator): void {\n if (child.count === 0) return;\n this.count += child.count;\n this.sum += child.sum;\n this.sumSq += child.sumSq;\n if (child.min < this.min) this.min = child.min;\n if (child.max > this.max) this.max = child.max;\n for (let a = 0; a < 3; a++) {\n if (child.bboxMin[a]! < this.bboxMin[a]!) this.bboxMin[a] = child.bboxMin[a]!;\n if (child.bboxMax[a]! > this.bboxMax[a]!) this.bboxMax[a] = child.bboxMax[a]!;\n }\n }\n\n get average(): number {\n return this.count > 0 ? this.sum / this.count : 0;\n }\n\n /** Population standard deviation (GridStats convention). */\n get stdDev(): number {\n if (this.count === 0) return 0;\n const mean = this.sum / this.count;\n const variance = this.sumSq / this.count - mean * mean;\n return Math.sqrt(Math.max(0, variance));\n }\n\n get isEmpty(): boolean {\n return this.count === 0;\n }\n}\n\nconst fround = Math.fround;\n\n/** `Vec3<float>::lengthSqr()` evaluated in f32: `x*x + y*y + z*z`, left to right. */\nexport function lengthSqrF32(x: number, y: number, z: number): number {\n return fround(fround(fround(x * x) + fround(y * y)) + fround(z * z));\n}\n\n/**\n * Vector statistics, NanoVDB `tools/GridStats.h` `Stats<Vec3f, 1>` (rank 1):\n * every value is ranked by its f32 `lengthSqr()`. `min`/`max` (inherited) are\n * the extreme squared lengths and {@link minVec}/{@link maxVec} the vectors\n * that hold them (first one wins on ties, as `Pair::operator<` is strict);\n * `average` and `stdDev` are the mean and population standard deviation of the\n * squared lengths, not of the components.\n */\nexport class Vec3StatsAccumulator extends StatsAccumulator {\n minVec: [number, number, number] = [0, 0, 0];\n maxVec: [number, number, number] = [0, 0, 0];\n\n /** Adds one active voxel with vector value (vx, vy, vz) at index coord (x, y, z). */\n addVoxelVec(vx: number, vy: number, vz: number, x: number, y: number, z: number): void {\n const s = lengthSqrF32(vx, vy, vz);\n if (s < this.min) this.minVec = [vx, vy, vz];\n if (s > this.max) this.maxVec = [vx, vy, vz];\n this.addVoxel(s, x, y, z);\n }\n\n /** Adds an active vector tile with GridStats weight `weight` (see {@link StatsAccumulator.addTile}). */\n addTileVec(\n value: readonly [number, number, number],\n weight: number,\n bboxMin: readonly [number, number, number],\n bboxMax: readonly [number, number, number],\n ): void {\n const s = lengthSqrF32(value[0], value[1], value[2]);\n if (s < this.min) this.minVec = [value[0], value[1], value[2]];\n if (s > this.max) this.maxVec = [value[0], value[1], value[2]];\n this.addTile(s, weight, bboxMin, bboxMax);\n }\n\n override merge(child: StatsAccumulator): void {\n if (child.count === 0) return;\n if (child instanceof Vec3StatsAccumulator) {\n if (child.min < this.min) this.minVec = [...child.minVec];\n if (child.max > this.max) this.maxVec = [...child.maxVec];\n }\n super.merge(child);\n }\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* transform.ts — apply an affine transform to a NanoVDB grid as a metadata-only
|
|
3
|
+
* Map edit (SPEC decision D6). An axis-aligned uniform-scale + translate does not
|
|
4
|
+
* move any voxel between nodes, so the entire tree/leaf region is untouched: we
|
|
5
|
+
* copy the image and rewrite only GridData's `Map` (mat/invMat/vec, both the f32
|
|
6
|
+
* and f64 copies), the `voxelSize` triple and the world-space bbox.
|
|
7
|
+
*
|
|
8
|
+
* v1 handles uniform scale + translate only; a rotation, shear or non-uniform
|
|
9
|
+
* scale throws (those need GPU resampling — the roadmap). The voxel bytes are
|
|
10
|
+
* provably preserved (the tree region is bit-for-bit identical to the source),
|
|
11
|
+
* which the test asserts.
|
|
12
|
+
*/
|
|
13
|
+
/** Uniform scale + translate specified directly. */
|
|
14
|
+
export interface VDBTransformSpec {
|
|
15
|
+
/** New uniform voxel size (world units per voxel). */
|
|
16
|
+
voxelSize: number;
|
|
17
|
+
/** New world-space position of index origin (the Map's translation). */
|
|
18
|
+
worldOrigin: [number, number, number];
|
|
19
|
+
}
|
|
20
|
+
export type VDBGridTransformInput = Float32Array | number[] | VDBTransformSpec;
|
|
21
|
+
/**
|
|
22
|
+
* Returns a copy of `image` with its transform replaced by an affine uniform
|
|
23
|
+
* scale + translate. Accepts either a row-major 4x4 matrix (`Float32Array` /
|
|
24
|
+
* `number[16]`) or an explicit `{ voxelSize, worldOrigin }`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function vdbTransform(image: Uint32Array, input: VDBGridTransformInput): Uint32Array;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* transform.ts — apply an affine transform to a NanoVDB grid as a metadata-only
|
|
3
|
+
* Map edit (SPEC decision D6). An axis-aligned uniform-scale + translate does not
|
|
4
|
+
* move any voxel between nodes, so the entire tree/leaf region is untouched: we
|
|
5
|
+
* copy the image and rewrite only GridData's `Map` (mat/invMat/vec, both the f32
|
|
6
|
+
* and f64 copies), the `voxelSize` triple and the world-space bbox.
|
|
7
|
+
*
|
|
8
|
+
* v1 handles uniform scale + translate only; a rotation, shear or non-uniform
|
|
9
|
+
* scale throws (those need GPU resampling — the roadmap). The voxel bytes are
|
|
10
|
+
* provably preserved (the tree region is bit-for-bit identical to the source),
|
|
11
|
+
* which the test asserts.
|
|
12
|
+
*/
|
|
13
|
+
import { VDBToolsError } from "../errors.js";
|
|
14
|
+
import { GRID_OFF_MAP, GRID_OFF_VOXEL_SIZE, GRID_OFF_WORLD_BBOX, GRID_SIZE, MAP_OFF_INVMATD, MAP_OFF_INVMATF, MAP_OFF_MATD, MAP_OFF_MATF, MAP_OFF_TAPERD, MAP_OFF_TAPERF, MAP_OFF_VECD, MAP_OFF_VECF, ROOT_OFF_BBOX_MAX, ROOT_OFF_BBOX_MIN, TREE_OFF_NODE_OFFSET_ROOT, } from "./bytes.js";
|
|
15
|
+
/**
|
|
16
|
+
* Returns a copy of `image` with its transform replaced by an affine uniform
|
|
17
|
+
* scale + translate. Accepts either a row-major 4x4 matrix (`Float32Array` /
|
|
18
|
+
* `number[16]`) or an explicit `{ voxelSize, worldOrigin }`.
|
|
19
|
+
*/
|
|
20
|
+
export function vdbTransform(image, input) {
|
|
21
|
+
const { voxelSize, translation } = resolve(input);
|
|
22
|
+
if (!(voxelSize > 0)) {
|
|
23
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `transform: voxelSize must be positive, got ${voxelSize}`);
|
|
24
|
+
}
|
|
25
|
+
const out = image.slice(); // deep copy — source is never mutated
|
|
26
|
+
const view = new DataView(out.buffer, out.byteOffset, out.byteLength);
|
|
27
|
+
writeMap(view, voxelSize, translation);
|
|
28
|
+
// voxelSize triple (f64[3]).
|
|
29
|
+
view.setFloat64(GRID_OFF_VOXEL_SIZE, voxelSize, true);
|
|
30
|
+
view.setFloat64(GRID_OFF_VOXEL_SIZE + 8, voxelSize, true);
|
|
31
|
+
view.setFloat64(GRID_OFF_VOXEL_SIZE + 16, voxelSize, true);
|
|
32
|
+
// World bbox = index bbox mapped through the new transform.
|
|
33
|
+
const rootOff = GRID_SIZE + Number(view.getBigUint64(GRID_SIZE + TREE_OFF_NODE_OFFSET_ROOT, true));
|
|
34
|
+
const imin = [
|
|
35
|
+
view.getInt32(rootOff + ROOT_OFF_BBOX_MIN, true),
|
|
36
|
+
view.getInt32(rootOff + ROOT_OFF_BBOX_MIN + 4, true),
|
|
37
|
+
view.getInt32(rootOff + ROOT_OFF_BBOX_MIN + 8, true),
|
|
38
|
+
];
|
|
39
|
+
const imax = [
|
|
40
|
+
view.getInt32(rootOff + ROOT_OFF_BBOX_MAX, true),
|
|
41
|
+
view.getInt32(rootOff + ROOT_OFF_BBOX_MAX + 4, true),
|
|
42
|
+
view.getInt32(rootOff + ROOT_OFF_BBOX_MAX + 8, true),
|
|
43
|
+
];
|
|
44
|
+
for (let a = 0; a < 3; a++) {
|
|
45
|
+
view.setFloat64(GRID_OFF_WORLD_BBOX + a * 8, imin[a] * voxelSize + translation[a], true);
|
|
46
|
+
// "+ one voxel" convention: the world max corner is (indexMax + 1) * voxelSize.
|
|
47
|
+
view.setFloat64(GRID_OFF_WORLD_BBOX + 24 + a * 8, (imax[a] + 1) * voxelSize + translation[a], true);
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
function resolve(input) {
|
|
52
|
+
if (input instanceof Float32Array || Array.isArray(input)) {
|
|
53
|
+
const m = input;
|
|
54
|
+
if (m.length !== 16) {
|
|
55
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `transform: expected a 4x4 (16-element) matrix, got ${m.length}`);
|
|
56
|
+
}
|
|
57
|
+
const sx = m[0];
|
|
58
|
+
const sy = m[5];
|
|
59
|
+
const sz = m[10];
|
|
60
|
+
const offDiagonal = [m[1], m[2], m[4], m[6], m[8], m[9]];
|
|
61
|
+
const eps = 1e-6 * Math.max(1, Math.abs(sx), Math.abs(sy), Math.abs(sz));
|
|
62
|
+
const rotated = offDiagonal.some((v) => Math.abs(v) > eps);
|
|
63
|
+
const nonUniform = Math.abs(sx - sy) > eps || Math.abs(sx - sz) > eps;
|
|
64
|
+
if (rotated || nonUniform) {
|
|
65
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `transform: matrix is ${rotated ? "rotated/sheared" : "non-uniformly scaled"} ` +
|
|
66
|
+
`(scale [${sx}, ${sy}, ${sz}]). v1 supports uniform scale + translate only; ` +
|
|
67
|
+
`rotation/shear/anisotropy need GPU resampling (roadmap).`);
|
|
68
|
+
}
|
|
69
|
+
return { voxelSize: sx, translation: [m[3], m[7], m[11]] };
|
|
70
|
+
}
|
|
71
|
+
return { voxelSize: input.voxelSize, translation: [...input.worldOrigin] };
|
|
72
|
+
}
|
|
73
|
+
function writeMap(view, s, t) {
|
|
74
|
+
const inv = 1 / s;
|
|
75
|
+
const mat = [s, 0, 0, 0, s, 0, 0, 0, s];
|
|
76
|
+
const invMat = [inv, 0, 0, 0, inv, 0, 0, 0, inv];
|
|
77
|
+
const base = GRID_OFF_MAP;
|
|
78
|
+
for (let i = 0; i < 9; i++) {
|
|
79
|
+
view.setFloat32(base + MAP_OFF_MATF + i * 4, mat[i], true);
|
|
80
|
+
view.setFloat32(base + MAP_OFF_INVMATF + i * 4, invMat[i], true);
|
|
81
|
+
view.setFloat64(base + MAP_OFF_MATD + i * 8, mat[i], true);
|
|
82
|
+
view.setFloat64(base + MAP_OFF_INVMATD + i * 8, invMat[i], true);
|
|
83
|
+
}
|
|
84
|
+
for (let i = 0; i < 3; i++) {
|
|
85
|
+
view.setFloat32(base + MAP_OFF_VECF + i * 4, t[i], true);
|
|
86
|
+
view.setFloat64(base + MAP_OFF_VECD + i * 8, t[i], true);
|
|
87
|
+
}
|
|
88
|
+
view.setFloat32(base + MAP_OFF_TAPERF, 1, true);
|
|
89
|
+
view.setFloat64(base + MAP_OFF_TAPERD, 1, true);
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../src/tools/nanovdb/transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,iBAAi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QAC3B,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,YAAY,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAE,EAAE,IAAI,CAAC,CAAC;QAC1D,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,YAAY,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAE,EAAE,IAAI,CAAC,CAAC;IAC5D,CAAC;IACD,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,cAAc,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;IAChD,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,cAAc,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;AAClD,CAAC","sourcesContent":["/**\n * transform.ts — apply an affine transform to a NanoVDB grid as a metadata-only\n * Map edit (SPEC decision D6). An axis-aligned uniform-scale + translate does not\n * move any voxel between nodes, so the entire tree/leaf region is untouched: we\n * copy the image and rewrite only GridData's `Map` (mat/invMat/vec, both the f32\n * and f64 copies), the `voxelSize` triple and the world-space bbox.\n *\n * v1 handles uniform scale + translate only; a rotation, shear or non-uniform\n * scale throws (those need GPU resampling — the roadmap). The voxel bytes are\n * provably preserved (the tree region is bit-for-bit identical to the source),\n * which the test asserts.\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport {\n GRID_OFF_MAP,\n GRID_OFF_VOXEL_SIZE,\n GRID_OFF_WORLD_BBOX,\n GRID_SIZE,\n MAP_OFF_INVMATD,\n MAP_OFF_INVMATF,\n MAP_OFF_MATD,\n MAP_OFF_MATF,\n MAP_OFF_TAPERD,\n MAP_OFF_TAPERF,\n MAP_OFF_VECD,\n MAP_OFF_VECF,\n ROOT_OFF_BBOX_MAX,\n ROOT_OFF_BBOX_MIN,\n TREE_OFF_NODE_OFFSET_ROOT,\n} from \"./bytes.js\";\n\n/** Uniform scale + translate specified directly. */\nexport interface VDBTransformSpec {\n /** New uniform voxel size (world units per voxel). */\n voxelSize: number;\n /** New world-space position of index origin (the Map's translation). */\n worldOrigin: [number, number, number];\n}\n\nexport type VDBGridTransformInput = Float32Array | number[] | VDBTransformSpec;\n\n/**\n * Returns a copy of `image` with its transform replaced by an affine uniform\n * scale + translate. Accepts either a row-major 4x4 matrix (`Float32Array` /\n * `number[16]`) or an explicit `{ voxelSize, worldOrigin }`.\n */\nexport function vdbTransform(image: Uint32Array, input: VDBGridTransformInput): Uint32Array {\n const { voxelSize, translation } = resolve(input);\n if (!(voxelSize > 0)) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `transform: voxelSize must be positive, got ${voxelSize}`);\n }\n\n const out = image.slice(); // deep copy — source is never mutated\n const view = new DataView(out.buffer, out.byteOffset, out.byteLength);\n\n writeMap(view, voxelSize, translation);\n\n // voxelSize triple (f64[3]).\n view.setFloat64(GRID_OFF_VOXEL_SIZE, voxelSize, true);\n view.setFloat64(GRID_OFF_VOXEL_SIZE + 8, voxelSize, true);\n view.setFloat64(GRID_OFF_VOXEL_SIZE + 16, voxelSize, true);\n\n // World bbox = index bbox mapped through the new transform.\n const rootOff = GRID_SIZE + Number(view.getBigUint64(GRID_SIZE + TREE_OFF_NODE_OFFSET_ROOT, true));\n const imin: [number, number, number] = [\n view.getInt32(rootOff + ROOT_OFF_BBOX_MIN, true),\n view.getInt32(rootOff + ROOT_OFF_BBOX_MIN + 4, true),\n view.getInt32(rootOff + ROOT_OFF_BBOX_MIN + 8, true),\n ];\n const imax: [number, number, number] = [\n view.getInt32(rootOff + ROOT_OFF_BBOX_MAX, true),\n view.getInt32(rootOff + ROOT_OFF_BBOX_MAX + 4, true),\n view.getInt32(rootOff + ROOT_OFF_BBOX_MAX + 8, true),\n ];\n for (let a = 0; a < 3; a++) {\n view.setFloat64(GRID_OFF_WORLD_BBOX + a * 8, imin[a]! * voxelSize + translation[a]!, true);\n // \"+ one voxel\" convention: the world max corner is (indexMax + 1) * voxelSize.\n view.setFloat64(GRID_OFF_WORLD_BBOX + 24 + a * 8, (imax[a]! + 1) * voxelSize + translation[a]!, true);\n }\n\n return out;\n}\n\nfunction resolve(input: VDBGridTransformInput): { voxelSize: number; translation: [number, number, number] } {\n if (input instanceof Float32Array || Array.isArray(input)) {\n const m = input;\n if (m.length !== 16) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `transform: expected a 4x4 (16-element) matrix, got ${m.length}`);\n }\n const sx = m[0]!;\n const sy = m[5]!;\n const sz = m[10]!;\n const offDiagonal = [m[1]!, m[2]!, m[4]!, m[6]!, m[8]!, m[9]!];\n const eps = 1e-6 * Math.max(1, Math.abs(sx), Math.abs(sy), Math.abs(sz));\n const rotated = offDiagonal.some((v) => Math.abs(v) > eps);\n const nonUniform = Math.abs(sx - sy) > eps || Math.abs(sx - sz) > eps;\n if (rotated || nonUniform) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", \n `transform: matrix is ${rotated ? \"rotated/sheared\" : \"non-uniformly scaled\"} ` +\n `(scale [${sx}, ${sy}, ${sz}]). v1 supports uniform scale + translate only; ` +\n `rotation/shear/anisotropy need GPU resampling (roadmap).`,\n );\n }\n return { voxelSize: sx, translation: [m[3]!, m[7]!, m[11]!] };\n }\n return { voxelSize: input.voxelSize, translation: [...input.worldOrigin] };\n}\n\nfunction writeMap(view: DataView, s: number, t: [number, number, number]): void {\n const inv = 1 / s;\n const mat = [s, 0, 0, 0, s, 0, 0, 0, s];\n const invMat = [inv, 0, 0, 0, inv, 0, 0, 0, inv];\n const base = GRID_OFF_MAP;\n for (let i = 0; i < 9; i++) {\n view.setFloat32(base + MAP_OFF_MATF + i * 4, mat[i]!, true);\n view.setFloat32(base + MAP_OFF_INVMATF + i * 4, invMat[i]!, true);\n view.setFloat64(base + MAP_OFF_MATD + i * 8, mat[i]!, true);\n view.setFloat64(base + MAP_OFF_INVMATD + i * 8, invMat[i]!, true);\n }\n for (let i = 0; i < 3; i++) {\n view.setFloat32(base + MAP_OFF_VECF + i * 4, t[i]!, true);\n view.setFloat64(base + MAP_OFF_VECD + i * 8, t[i]!, true);\n }\n view.setFloat32(base + MAP_OFF_TAPERF, 1, true);\n view.setFloat64(base + MAP_OFF_TAPERD, 1, true);\n}\n"]}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tree.ts — dense array -> sparse NanoVDB node hierarchy (topology, masks,
|
|
3
|
+
* per-node stats and bbox). Pure data; no bytes are written here. `serialize.ts`
|
|
4
|
+
* turns the {@link BuiltTree} into a laid-out grid image.
|
|
5
|
+
*
|
|
6
|
+
* ## Topology policy (T3 decision, v1)
|
|
7
|
+
*
|
|
8
|
+
* A leaf (8^3 block) is materialised iff the block contains at least one active
|
|
9
|
+
* voxel. Every materialised leaf stores the *source value* for all 512 of its
|
|
10
|
+
* slots (active and inactive), so any voxel inside a materialised leaf round-
|
|
11
|
+
* trips exactly. A block with no active voxel collapses to an inactive
|
|
12
|
+
* background tile in its parent lower node — so empty space stays sparse.
|
|
13
|
+
*
|
|
14
|
+
* ## Collapsing uniform regions (K4.6)
|
|
15
|
+
*
|
|
16
|
+
* With `collapse` on, uniform nodes become tiles bottom-up, as OpenVDB's
|
|
17
|
+
* `tools::prune(tree, tolerance = 0)` (`TolerancePruneOp`) would do it:
|
|
18
|
+
* - a leaf whose 512 voxels all have the same active state and exactly equal
|
|
19
|
+
* values (`===`, so `-0` equals `0`, `NaN` never collapses) becomes a lower
|
|
20
|
+
* tile with that state and value (the leaf's first value);
|
|
21
|
+
* - a lower node with no child leaf whose 4096 slots all have one state and
|
|
22
|
+
* one value becomes an upper tile; an upper node likewise a root tile;
|
|
23
|
+
* - a tile that ends up inactive with the background value is the default
|
|
24
|
+
* slot, so it is not stored (an upper node that collapses to one is erased
|
|
25
|
+
* from the root, as `RootNode::eraseBackgroundTiles` does after a prune).
|
|
26
|
+
* Values read back identically. Stats follow GridStats' tile weighting (see
|
|
27
|
+
* below), so an upper or root average that mixes a collapsed region with other
|
|
28
|
+
* data weights it differently from the leaves it replaced, exactly as a native
|
|
29
|
+
* image of the pruned tree would. min/max, bbox and the active-voxel count do
|
|
30
|
+
* not change. Off by default here; the public builders choose (see
|
|
31
|
+
* `serialize.ts`).
|
|
32
|
+
*
|
|
33
|
+
* ## Active tiles passed in (K4.1)
|
|
34
|
+
*
|
|
35
|
+
* The leaf-iterator path ({@link buildTreeFromLeaves}) also accepts active
|
|
36
|
+
* tiles that already exist in the source (a parsed `.vdb`, or a NanoVDB image
|
|
37
|
+
* being re-encoded): lower-node tiles (8^3), upper-node tiles (128^3) and root
|
|
38
|
+
* tiles (4096^3). They are kept as tiles, never expanded into leaves. Stats
|
|
39
|
+
* follow NanoVDB `tools/GridStats.h`: a tile adds its value to its parent's
|
|
40
|
+
* min/max/ave/stddev with weight `ChildT::NUM_VALUES` (512, 4096 or 32768 — the
|
|
41
|
+
* child node's *slot* count, not its voxel count) and grows the parent's bbox
|
|
42
|
+
* by the tile's full extent. The active-voxel count, in contrast, counts each
|
|
43
|
+
* tile as `dim^3` voxels (CreateNanoGrid's `mVoxelCount`).
|
|
44
|
+
*
|
|
45
|
+
* ## Active predicate
|
|
46
|
+
*
|
|
47
|
+
* Default (no `activeThreshold`): a voxel is active iff `value !== background`
|
|
48
|
+
* (exact). With `activeThreshold` given: active iff
|
|
49
|
+
* `|value - background| > activeThreshold`. Note threshold 0 is equivalent to
|
|
50
|
+
* the exact rule. Under a non-zero threshold, a block whose every voxel is
|
|
51
|
+
* inactive collapses to background even if some of those voxels differ from the
|
|
52
|
+
* background value — those sub-threshold values are not preserved. This is
|
|
53
|
+
* documented and intended (topology follows activity).
|
|
54
|
+
*/
|
|
55
|
+
import { StatsAccumulator } from "./stats.js";
|
|
56
|
+
/** A tile (or background) value: a scalar, or `[x, y, z]` for Vec3f grids. */
|
|
57
|
+
export type TileValue = number | readonly [number, number, number];
|
|
58
|
+
/** Values per voxel: 1 (scalar grids) or 3 (Vec3f, xyz interleaved). */
|
|
59
|
+
export type Components = 1 | 3;
|
|
60
|
+
export interface Leaf {
|
|
61
|
+
/** 8-aligned index-space min corner. */
|
|
62
|
+
origin: [number, number, number];
|
|
63
|
+
/** All 512 voxel values in leaf-offset order (`components` scalars each). */
|
|
64
|
+
values: Float32Array;
|
|
65
|
+
/** 512-bit active mask as 16 u32 words. */
|
|
66
|
+
valueMask: Uint32Array;
|
|
67
|
+
stats: StatsAccumulator;
|
|
68
|
+
memIndex: number;
|
|
69
|
+
}
|
|
70
|
+
export interface LowerNode {
|
|
71
|
+
/** 128-aligned index-space min corner. */
|
|
72
|
+
origin: [number, number, number];
|
|
73
|
+
/** slot (0..4095) -> child leaf. */
|
|
74
|
+
children: Map<number, Leaf>;
|
|
75
|
+
/** slot (0..4095) -> value of an active 8^3 tile. Other slots are background tiles. */
|
|
76
|
+
tiles: Map<number, TileValue>;
|
|
77
|
+
/** slot (0..4095) -> value of an inactive 8^3 tile with a non-background value (K4.9). */
|
|
78
|
+
inactiveTiles: Map<number, TileValue>;
|
|
79
|
+
stats: StatsAccumulator;
|
|
80
|
+
memIndex: number;
|
|
81
|
+
}
|
|
82
|
+
export interface UpperNode {
|
|
83
|
+
/** 4096-aligned index-space min corner. */
|
|
84
|
+
origin: [number, number, number];
|
|
85
|
+
/** slot (0..32767) -> child lower node. */
|
|
86
|
+
children: Map<number, LowerNode>;
|
|
87
|
+
/** slot (0..32767) -> value of an active 128^3 tile. Other slots are background tiles. */
|
|
88
|
+
tiles: Map<number, TileValue>;
|
|
89
|
+
/** slot (0..32767) -> value of an inactive 128^3 tile with a non-background value (K4.9). */
|
|
90
|
+
inactiveTiles: Map<number, TileValue>;
|
|
91
|
+
stats: StatsAccumulator;
|
|
92
|
+
memIndex: number;
|
|
93
|
+
}
|
|
94
|
+
/** One root-table entry: a child upper node, or a 4096^3 tile (active or inactive). */
|
|
95
|
+
export type RootTile = {
|
|
96
|
+
key: bigint;
|
|
97
|
+
origin: [number, number, number];
|
|
98
|
+
child: UpperNode;
|
|
99
|
+
} | {
|
|
100
|
+
key: bigint;
|
|
101
|
+
origin: [number, number, number];
|
|
102
|
+
child: null;
|
|
103
|
+
value: TileValue;
|
|
104
|
+
active: boolean;
|
|
105
|
+
};
|
|
106
|
+
export interface BuiltTree {
|
|
107
|
+
uppers: UpperNode[];
|
|
108
|
+
lowers: LowerNode[];
|
|
109
|
+
leaves: Leaf[];
|
|
110
|
+
/** Root table, sorted by NanoVDB key (unsigned 64-bit), children and tiles interleaved. */
|
|
111
|
+
rootTiles: RootTile[];
|
|
112
|
+
/** Active tile counts per level (TreeData `mTileCount`). */
|
|
113
|
+
tileCounts: {
|
|
114
|
+
lower: number;
|
|
115
|
+
upper: number;
|
|
116
|
+
root: number;
|
|
117
|
+
};
|
|
118
|
+
/** Global active-value stats + tight index bbox (== root stats/bbox). */
|
|
119
|
+
root: StatsAccumulator;
|
|
120
|
+
/** Active voxels in leaves plus `dim^3` per active tile. */
|
|
121
|
+
activeVoxelCount: number;
|
|
122
|
+
}
|
|
123
|
+
export interface BuildTreeOptions {
|
|
124
|
+
origin: [number, number, number];
|
|
125
|
+
background: number;
|
|
126
|
+
activeThreshold: number | undefined;
|
|
127
|
+
/** Collapse uniform nodes into tiles (K4.6). Default false. */
|
|
128
|
+
collapse?: boolean;
|
|
129
|
+
}
|
|
130
|
+
/** Options of {@link buildTreeFromLeaves} beyond the leaves and tiles. */
|
|
131
|
+
export interface CollapseOptions {
|
|
132
|
+
/** Collapse uniform nodes into tiles (K4.6). Default false. */
|
|
133
|
+
collapse?: boolean;
|
|
134
|
+
/** The grid background: an inactive tile with this value is not stored. Default 0 / [0, 0, 0]. */
|
|
135
|
+
background?: TileValue;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Builds the sparse hierarchy for a dense `values` array of shape
|
|
139
|
+
* `[nx,ny,nz]` (x-major: idx = (x*ny + y)*nz + z), placed with its min corner at
|
|
140
|
+
* index-space `origin`.
|
|
141
|
+
*/
|
|
142
|
+
export declare function buildTree(values: Float32Array, dims: [number, number, number], opts: BuildTreeOptions): BuiltTree;
|
|
143
|
+
/**
|
|
144
|
+
* Builds the sparse hierarchy directly from a set of already-materialised leaves
|
|
145
|
+
* (each carrying its 8-aligned origin, all 512 values, and a 512-bit value mask).
|
|
146
|
+
* This is the memory-frugal path used by `buildFromVdb` and `quantize`: it never
|
|
147
|
+
* allocates a dense array, so a 7M-voxel grid streams leaf-by-leaf. Per-leaf
|
|
148
|
+
* stats/bbox are (re)computed from the mask + values here.
|
|
149
|
+
*/
|
|
150
|
+
export declare function buildTreeFromLeaves(source: Iterable<LeafInput>, tiles?: Iterable<TileInput>, components?: Components, options?: CollapseOptions): BuiltTree;
|
|
151
|
+
/** Minimal shape a leaf source must provide to `buildTreeFromLeaves`. */
|
|
152
|
+
export interface LeafInput {
|
|
153
|
+
origin: [number, number, number];
|
|
154
|
+
/** All 512 voxel values in leaf-offset order (active and inactive); xyz interleaved for Vec3f. */
|
|
155
|
+
values: Float32Array;
|
|
156
|
+
/** 512-bit active mask as 16 u32 words. */
|
|
157
|
+
valueMask: Uint32Array;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* An active tile to place above leaf level: `dim^3` voxels, all active, all
|
|
161
|
+
* `value`. `dim` 8 is a lower-node tile, 128 an upper-node tile, 4096 a root
|
|
162
|
+
* tile; `origin` must be a multiple of `dim`.
|
|
163
|
+
*/
|
|
164
|
+
export interface TileInput {
|
|
165
|
+
origin: [number, number, number];
|
|
166
|
+
dim: number;
|
|
167
|
+
value: TileValue;
|
|
168
|
+
/**
|
|
169
|
+
* False for an inactive tile that keeps a stored value (e.g. a level set's
|
|
170
|
+
* interior `-background`, K4.9): written with its value but no value-mask bit
|
|
171
|
+
* (root: state 0), excluded from stats, tile counts and the active-voxel count.
|
|
172
|
+
* Default true.
|
|
173
|
+
*/
|
|
174
|
+
active?: boolean;
|
|
175
|
+
}
|