Octree is a tree data structure in which each internal node can have at most 8 children. Like Binary tree which divides the space two segments, Octree divides the space into at most eight-part which is called as octanes. It is used to store the 3-D point which takes a large amount of space. if all the internal node of the Octree contains exactly 8 children is called full Octree. It is also useful for high-resolution graphics like 3D computer graphics.
The Octree can be formed form 3D volume by doing the following steps:
- Divide the current 3D volume into eight boxes
- If any box has more than one point then divide it further into boxes
- Do not divide the box which has one or zero points in it
- Do this process repeatedly util all the box contains one or zero point in it
The above steps are shown in figure.
If S is the number of points in each dimension then the number of nodes that are formed in Octree is given by this formula .
Insertion in Octree:
- To insert a node in Octree, first of all, we check if a node exists or not if a node exists then return otherwise we go recursively
- First, we start with the root node and mark it as current
- Then we find the child node in which we can store the point
- If the node is empty the replace with the node we want to insert and make it a leaf node
- If the node is the leaf node then make it an internal node and if it is an internal node then go to the child node. do this process recursively till an empty node is not found
- The time complexity of this function is where N is the number of nodes
Search in Octree:
- This function is used to search the point exist is the tree or not
- Start with the root node and search recursively if the node with given point found then return true if an empty node or boundary point or empty point is encountered then return false
- If an internal node is found go that node. The time complexity of this function is also O(Log N) where N is the number of nodes
Below is the implementation of the above approach
Point already exist in the tree Point is out of bound found not found found
- It is used in 3D computer graphics games
- It is also used to find nearest neighboring objects in 3D space
- It is also used for color quantization
- Pattern Searching using a Trie of all Suffixes
- Skip List | Set 3 (Searching and Deletion)
- Pattern Searching using Suffix Tree
- AVL Tree | Set 1 (Insertion)
- Suffix Tree Application 2 - Searching All Patterns
- Skip List | Set 2 (Insertion)
- Insertion in a Trie recursively
- ScapeGoat Tree | Set 1 (Introduction and Insertion)
- Insertion in Unrolled Linked List
- Fibonacci Heap - Insertion and Union
- Optimal sequence for AVL tree insertion (without any rotations)
- Insertion at Specific Position in a Circular Doubly Linked List
- Proto Van Emde Boas Tree | Set 3 | Insertion and isMember Query
- Van Emde Boas Tree | Set 2 | Insertion, Find, Minimum and Maximum Queries
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.