module Data.Octree.BoundingBox.BoundingBox
( BBoxConfig (..)
, traverseOctreeBB
, defBBoxConfig
) where
import Data.Maybe (mapMaybe)
import Data.BoundingBox.B3 (BBox3)
import Data.Octree.Internal (Octree (..), allOctants)
import Data.Octree.BoundingBox.Internal
data BBoxConfig x y a = BBoxConfig {
select :: BBox3 -> x -> Maybe x,
procLeaf :: BBox3 -> x -> [LeafValue a] -> y,
combine :: x -> [y] -> y
}
defBBoxConfig :: BBoxConfig DefInput DefOutput DefNodeValue
defBBoxConfig = BBoxConfig {
select = filterNodes ,
procLeaf = points,
combine = result
}
traverseOctreeBB :: BBoxConfig x y a -> BBox3 -> Octree a -> x -> y
traverseOctreeBB bbc bbx (Leaf leaf_vals) input = procLeaf' bbx input leaf_vals
where
procLeaf' = procLeaf bbc
traverseOctreeBB
bbc bbx (Node split' nwu' nwd' neu' ned' swu' swd' seu' sed') x =
combine' x res
where
combine' = combine bbc
res = mapMaybe traverseOctreeBB' octList
select' = select bbc
traverseOctreeBB' (subbox, subtree) =
case select' subbox x of
Just x' -> Just (traverseOctreeBB bbc subbox subtree x)
Nothing -> Nothing
octList = zip boxList children
boxList = map (newBBox3 bbx split') allOctants
children = [swd',sed',nwd',ned',swu',seu',nwu',neu']