Show / Hide Table of Contents

    Class PointOctree<T>

    A Dynamic Octree for storing any objects that can be described as a single point. This is a thin wrapper around the PointOctree class from NetOctree (https://github.com/mcserep/NetOctree).

    Inheritance
    System.Object
    PointOctree<T>
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: Elements.Search
    Assembly: Hypar.Elements.dll
    Syntax
    public class PointOctree<T>
    Type Parameters
    Name Description
    T

    The content of the octree can be anything, since the bounds data is supplied separately.

    Remarks

    Octree: An octree is a tree data structure which divides 3D space into smaller partitions (nodes) and places objects into the appropriate nodes. This allows fast access to objects in an area of interest without having to check every object.

    Dynamic: The octree grows or shrinks as required when objects as added or removed. It also splits and merges nodes as appropriate. There is no maximum depth.

    Constructors

    PointOctree(Double, Vector3, Double)

    Constructor for the point octree.

    Declaration
    public PointOctree(double initialWorldSize, Vector3 initialWorldPos, double minNodeSize)
    Parameters
    Type Name Description
    System.Double initialWorldSize

    Size of the sides of the initial node. The octree will never shrink smaller than this.

    Vector3 initialWorldPos

    Position of the center of the initial node.

    System.Double minNodeSize

    Nodes will stop splitting if the new nodes would be smaller than this.

    Properties

    Count

    The total amount of objects currently in the tree

    Declaration
    public int Count { get; }
    Property Value
    Type Description
    System.Int32

    MaxBounds

    Gets the bounding box that represents the whole octree

    Declaration
    public BBox3 MaxBounds { get; }
    Property Value
    Type Description
    BBox3

    The bounding box of the root node.

    Methods

    Add(T, Vector3)

    Add an object.

    Declaration
    public void Add(T obj, Vector3 objPos)
    Parameters
    Type Name Description
    T obj

    Object to add.

    Vector3 objPos

    Position of the object.

    GetAll()

    Returns all objects in the tree. If none, returns an empty array (not null).

    Declaration
    public ICollection<T> GetAll()
    Returns
    Type Description
    System.Collections.Generic.ICollection<T>

    All objects.

    GetNearby(Ray, Double)

    Returns objects that are within maxDistance of the specified ray. If none, returns an empty array (not null).

    Declaration
    public T[] GetNearby(Ray ray, double maxDistance)
    Parameters
    Type Name Description
    Ray ray

    The ray.

    System.Double maxDistance

    Maximum distance from the ray to consider.

    Returns
    Type Description
    T[]

    Objects within range.

    GetNearby(Vector3, Double)

    Returns objects that are within maxDistance of the specified position. If none, returns an empty array (not null).

    Declaration
    public T[] GetNearby(Vector3 position, double maxDistance)
    Parameters
    Type Name Description
    Vector3 position

    The position. Passing as ref to improve performance since it won't have to be copied.

    System.Double maxDistance

    Maximum distance from the position to consider.

    Returns
    Type Description
    T[]

    Objects within range.

    Remove(T)

    Remove an object. Makes the assumption that the object only exists once in the tree.

    Declaration
    public bool Remove(T obj)
    Parameters
    Type Name Description
    T obj

    Object to remove.

    Returns
    Type Description
    System.Boolean

    True if the object was removed successfully.

    Remove(T, Vector3)

    Removes the specified object at the given position. Makes the assumption that the object only exists once in the tree.

    Declaration
    public bool Remove(T obj, Vector3 objPos)
    Parameters
    Type Name Description
    T obj

    Object to remove.

    Vector3 objPos

    Position of the object.

    Returns
    Type Description
    System.Boolean

    True if the object was removed successfully.