Octree

An octree is a tree data structure in which each internal node has exactly eight children. Octrees are most often used to partition a three-dimensional space by recursively subdividing it into eight octants. Octrees are the three-dimensional analog of quadtrees. The word is derived from oct (Greek root meaning "eight") + tree. Octrees are often used in 3D graphics and 3D game engines.

## Contents

* 1 For spatial representation
* 2 History
* 3 Common uses
* 4 Application to color quantization
* 5 Implementation for point decomposition
* 6 Example color quantization
* 7 See also
* 8 References
* 9 External links

## For spatial representation

Each node in an octree subdivides the space it represents into eight octants. In a point region (PR) octree (analogous to a point quadtree), the node stores an explicit three-dimensional point, which is the "center" of the subdivision for that node; the point defines one of the corners for each of the eight children. In a matrix-based (MX) octree (analogous to a region quadtree), the subdivision point is implicitly the center of the space the node represents. The root node of a PR octree can represent infinite space; the root node of an MX octree must represent a finite bounded space so that the implicit centers are well-defined. Note that octrees are not the same as k-d trees: k-d trees split along a dimension and octrees split around a point. Also k-d trees are always binary, which is not the case for octrees. By using a depth-first search the nodes are to be traversed and only required surfaces are to be viewed.

## History

A spatial subdivision much like an octree was used in 1934, in the Whitney covering lemma in mathematics.[1] The use of octrees for 3D computer graphics was pioneered by Donald Meagher at Rensselaer Polytechnic Institute, described in a 1980 report "Octree Encoding: A New Technique for the Representation, Manipulation and Display of Arbitrary 3-D Objects by Computer",[2] for which he holds a 1995 patent (with a 1984 priority date) "High-speed image generation of complex solid objects using octree encoding" [3]

## Common uses

* Level of detail rendering in 3D computer graphics[4]
* Spatial indexing
* Nearest neighbor search[5]
* Efficient collision detection in three dimensions
* View frustum culling
* Fast multipole method
* Unstructured grid
* Finite element analysis
* Sparse voxel octree[6]
* State estimation[7]
* Set estimation[8]

## Application to color quantization

The octree color quantization algorithm, invented by Gervautz and Purgathofer in 1988, encodes image color data as an octree up to nine levels deep. Octrees are used because 23=8 and there are three color components in the RGB system. The node index to branch out from at the top level is determined by a formula that uses the most significant bits of the red, green, and blue color components, e.g. 4r + 2g + b. The next lower level uses the next bit significance, and so on. Less significant bits are sometimes ignored to reduce the tree size.

The algorithm is highly memory efficient because the tree's size can be limited. The bottom level of the octree consists of leaf nodes that accrue color data not represented in the tree; these nodes initially contain single bits. If much more than the desired number of palette colors are entered into the octree, its size can be continually reduced by seeking out a bottom-level node and averaging its bit data up into a leaf node, pruning part of the tree. Once sampling is complete, exploring all routes in the tree down to the leaf nodes, taking note of the bits along the way, will yield approximately the required number of colors.

## Implementation for point decomposition

The example recursive algorithm outline below (MATLAB syntax) decomposes an array of 3-dimensional points into octree style bins. The implementation begins with a single bin surrounding all given points, which then recursively subdivides into its 8 octree regions. Recursion is stopped when a given exit condition is met. Examples of such exit conditions (shown in code below) are:

* When a bin contains fewer than a given number of points
* When a bin reaches a minimum size or volume based on the length of its edges
* When recursion has reached a maximum number of subdivisions

function [binDepths, binParents, binCorners, pointBins] = OcTree(points)

binDepths = [0]     % Initialize an array of bin depths with this single base-level bin
binParents = [0]    % This base level bin is not a child of other bins
binCorners = [min(points) max(points)] % It surrounds all points in XYZ space
pointBins(:) = 1    % Initially, all points are assigned to this first bin
divide(1)           % Begin dividing this first bin

function divide(binNo)

% If this bin meets any exit conditions, do not divide it any further.
binPointCount = nnz(pointBins == binNo)
binEdgeLengths = binCorners(binNo, 1:3) - binCorners(binNo, 4:6)
binDepth = binDepths(binNo)
exitConditionsMet = binPointCount<value || min(binEdgeLengths) < value || binDepth > value
if exitConditionsMet
return; % Exit recursive function
end

% Otherwise, split this bin into 8 new sub-bins with a new division point
newDiv = (binCorners(binNo, 1:3) + binCorners(binNo, 4:6)) / 2
for i = 1:8
newBinNo = length(binDepths) + 1
binDepths(newBinNo) = binDepths(binNo) + 1
binParents(newBinNo) = binNo
binCorners(newBinNo) = [one of the 8 pairs of the newDiv with minCorner or maxCorner]
oldBinMask = pointBins == binNo
% Calculate which points in pointBins == binNo now belong in newBinNo
pointBins(newBinMask) = newBinNo
% Recursively divide this newly created bin
divide(newBinNo)
end

## Example color quantization

Taking the full list of colors of a 24-bit RGB image as point input to the Octree point decomposition implementation outlined above, the following example show the results of octree color quantization. The first image is the original (532818 distinct colors), while the second is the quantized image (184 distinct colors) using octree decomposition, with each pixel assigned the color at the center of the octree bin in which it falls. Alternatively, final colors could be chosen at the centroid of all colors in each octree bin, however this added computation has very little effect on the visual result.[9]

% Read the original RGB image
Img = imread('IMG_9980.CR2');
% Extract pixels as RGB point triplets
pts = reshape(Img, [], 3);
% Create OcTree decomposition object using a target bin capacity
OT = OcTree(pts, 'BinCapacity', ceil((size(pts, 1) / 256) * 7));
% Find which bins are "leaf nodes" on the octree object
leafs = find(~ismember(1:OT.BinCount, OT.BinParents) & ...
ismember(1:OT.BinCount, OT.PointBins));
% Find the central RGB location of each leaf bin
binCents = mean(reshape(OT.BinBoundaries(leafs,:), [], 3, 2), 3);

% Make a new "indexed" image with a color map
ImgIdx = zeros(size(Img, 1), size(Img, 2));
for i = 1:length(leafs)
pxNos = find(OT.PointBins==leafs(i));
ImgIdx(pxNos) = i;
end
ImgMap = binCents / 255; % Convert 8-bit color to MATLAB rgb values

% Display the original 532818-color image and resulting 184-color image
figure
subplot(1, 2, 1), imshow(Img)
title(sprintf('Original %d color image', size(unique(pts,'rows'), 1)))
subplot(1, 2, 2), imshow(ImgIdx, ImgMap)
title(sprintf('Octree-quantized %d color image', size(ImgMap, 1)))

## See also

* Binary space partitioning
* Bounding interval hierarchy
* Software:Cube 2: Sauerbraten, a 3D game engine in which geometry is almost entirely based on octrees
* id Tech 6 is a 3D game engine that utilizes voxels stored in octrees
* Irrlicht Engine, supports octree scene nodes
* Klee's measure problem
* Linear octree
* OGRE, has an octree scene manager implementation
* Subpaving
* Voxel
* Quadtree

## References

1. ↑ Whitney, Hassler (1934). "Analytic extensions of functions defined in closed sets". Transactions of the American Mathematical Society (American Mathematical Society) 36 (1): 63–89. doi:10.2307/1989708.
2. ↑ Meagher, Donald (October 1980). "Octree Encoding: A New Technique for the Representation, Manipulation and Display of Arbitrary 3-D Objects by Computer". Rensselaer Polytechnic Institute (Technical Report IPL-TR-80-111).
3. ↑ Meagher, Donald. "High-speed image generation of complex solid objects using octree encoding". USPO. https://patents.google.com/patent/EP0152741B1/en.
4. ↑ David P. Luebke (2003). Level of Detail for 3D Graphics. Morgan Kaufmann. ISBN 978-1-55860-838-2. https://books.google.com/books?id=M-gl4aoxQfIC.
5. ↑ Elseberg, Jan, et al. "Comparison of nearest-neighbor-search strategies and implementations for efficient shape registration." Journal of Software Engineering for Robotics 3.1 (2012): 2-12.
6. ↑ Akenine-Mo ̈ller, Tomas; Haines, Eric; Hoffman, Naty (2018-08-06) (in en). Real-Time Rendering, Fourth Edition. CRC Press. ISBN 978-1-351-81615-1. https://books.google.com/books?id=0g1mDwAAQBAJ&dq="sparse+voxel+octree"&pg=PA579.
7. ↑ "Henning Eberhardt, Vesa Klumpp, Uwe D. Hanebeck, Density Trees for Efficient Nonlinear State Estimation, Proceedings of the 13th International Conference on Information Fusion, Edinburgh, United Kingdom, July, 2010.". http://isas.uka.de/Publikationen/Fusion10_EberhardtKlumpp.pdf.
8. ↑ V. Drevelle, L. Jaulin and B. Zerr, Guaranteed Characterization of the Explored Space of a Mobile Robot by using Subpavings, NOLCOS 2013.
9. ↑ Bloomberg, Dan S. "Color quantization using octrees.", 4 September 2008. Retrieved on 12 December 2014.

## External links

* Octree Quantization in Microsoft Systems Journal
* Color Quantization using Octrees in Dr. Dobb's
* Octree Color Quantization Overview
* Sojan Lal, P.; Unnikrishnan, A.; Poulose Jacob, K. (1998). "Parallel implementation of octtree generation algorithm". Proceedings 1998 International Conference on Image Processing. ICIP98 (Cat. No.98CB36269). 3. pp. 1005–1009. doi:10.1109/ICIP.1998.727419. ISBN 0-8186-8821-1.
* Parallel Octrees for Finite Element Applications
* Video: Use of an octree in state estimation
* Quadtrees, Octrees, and Orthtrees, a chapter in CGAL, the Computational Algorithms Library

* v
* t
* e

Tree data structures

Search trees
(dynamic sets/associative arrays)|

* 2–3
* 2–3–4
* AA
* (a,b)
* AVL
* B
* B+
* B*
* Bx
* (Optimal) Binary search
* Dancing
* HTree
* Interval
* Order statistic
* (Left-leaning) Red-black
* Scapegoat
* Splay
* T
* Treap
* UB
* Weight-balanced

Heaps|

* Binary
* Binomial
* Brodal
* Fibonacci
* Leftist
* Pairing
* Skew
* van Emde Boas
* Weak

Tries|

* Ctrie
* C-trie (compressed ADT)
* Hash
* Radix
* Suffix
* Ternary search
* X-fast
* Y-fast

Spatial data partitioning trees|

* Ball
* BK
* BSP
* Cartesian
* Hilbert R
* k-d (implicit k-d)
* M
* Metric
* MVP
* Octree
* Priority R
* Quad
* R
* R+
* R*
* Segment
* VP
* X

Other trees|

* Cover
* Exponential
* Fenwick
* Finger
* Fractal tree index
* Fusion
* Hash calendar
* iDistance
* K-ary
* Left-child right-sibling
* Link/cut
* Log-structured merge
* Merkle
* PQ
* Range
* SPQR
* Top

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Octree. Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Octree&oldid=4228844"
*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template