voctopus.util - nphyx/voctopus GitHub Wiki

voctopus/util

Description

This module contains an assortment of export functions used internally in Voctopus, as well as some export functions for analyzing octree properties for experimental purposes (they help find "sweet spots" for initial octree memory allocations)

#Functions


getUint24

getUint24() ⇨

Provide a 24 bit int implementation for DataViews. Note this causes two reads/writes per call, meaning it's going to be around half as fast as the native implementations.


setUint24

setUint24() ⇨

Setter for Uint24.


sump8

sump8(n) ⇨ Float64

Sum of powers of 8 up to n. Used in various calculations.

Parameters

name type description
n int highest power of 8, up to 24 (after which precision errors become a problem)

Returns: Float64


octantIdentity

octantIdentity(vector, dc, dm) ⇨ int

Find the cardinal identity (0-7) of an octant. Octets contain 8 octants, so in x,y,z order they live at identities 0-7.

Parameters

name type description
vector vector representing the absolute coordinate of a voxel at max depth
dc int current depth (zero-indexed)
dm int maximum depth

Returns: intidentity


fullOctreeSize

fullOctreeSize(octantSize, depth) ⇨ int

Figures out the maximum size of a voctopus octree, assuming it's 100% dense (e.g. filled with random noise).

Parameters

name type description
octantSize int size of a single octant in the tree
depth int octree depth

Returns: int


maxAddressableOctreeDepth

maxAddressableOctreeDepth(octantSize) ⇨ int

Discover the maximum addressable depth for an octree schema at 100% density. Note that this is not very useful on its own because ArrayBuffers have a hard limit of 2gb, and this can produce buffers sized in EXABYTES if used naively!

Parameters

name type description
octantSize int (in bytes)

Returns: intdepth


maxOctreeDensityFactor

maxOctreeDensityFactor(octantSize, depth, limit) ⇨

Find the maximum density factor of an octree given an octantSize, depth, and memory limit. Voctopus figures out how much memory to allocate based on its octant size, depth and density factor.

Parameters

name type description
octantSize int size of a single octant in bytes
depth int octree depth
limit int memory limit in bytes

npot

npot(n) ⇨ int

Find the nearest power of two greater than a number.

Parameters

name type description
n int number to test against

Returns: int


loop3D

loop3D(size, cbs) ⇨ undefined

Used to loop through every voxel in an octree and run callbacks. Used for Voctopus testing. Three nested loops of X, Y, and Z axis, supporting a callback for each iteration of each loop as supplied in the cbs parameter.

Parameters

name type description
size int size of a volume
cbs Object callback object {x:f(vector),y:f(vector),z:f(vector)}

Returns: undefined


coordinateSpace

coordinateSpace(depth) ⇨

Find the coordinate space (size of a single octree axis) for a given depth.

Parameters

name type description
depth int octree depth

rayAABB

rayAABB(bs, be, ro, rd) ⇨

Check the ray - box intersection of a voxel (which is an axis-aligned bounding box)

Parameters

name type description
bs vector box start (top, left, back)
be vector box end (bottom, right, front)
ro vector ray origin
rd vector inverse of ray direction (inverse should be precalculated)

Returns: bool true if there was a hit, otherwise false