Table of Contents

Class DynamicOctreeBase<T>

Namespace
HelixToolkit.SharpDX
Assembly
HelixToolkit.SharpDX.dll

Base class template implementation for IDynamicOctree

public abstract class DynamicOctreeBase<T> : IDynamicOctree, IOctreeBasic

Type Parameters

T
Inheritance
DynamicOctreeBase<T>
Implements
Derived
Inherited Members
Extension Methods

Constructors

DynamicOctreeBase(ref BoundingBox, IDynamicOctree?, OctreeBuildParameter?, Stack<KeyValuePair<int, IDynamicOctree[]>>?)

Creates an octTree with a suggestion for the bounding region containing the items.

protected DynamicOctreeBase(ref BoundingBox bound, IDynamicOctree? parent, OctreeBuildParameter? parameter, Stack<KeyValuePair<int, IDynamicOctree[]>>? stackCache)

Parameters

bound BoundingBox

The suggested dimensions for the bounding region. Note: if items are outside this region, the region will be automatically resized.

parent IDynamicOctree
parameter OctreeBuildParameter
stackCache Stack<KeyValuePair<int, IDynamicOctree[]>>

DynamicOctreeBase(ref BoundingBox, List<T>?, IDynamicOctree?, OctreeBuildParameter?, Stack<KeyValuePair<int, IDynamicOctree[]>>?)

Creates an oct tree which encloses the given region and contains the provided objects.

protected DynamicOctreeBase(ref BoundingBox bound, List<T>? objList, IDynamicOctree? parent, OctreeBuildParameter? parameter, Stack<KeyValuePair<int, IDynamicOctree[]>>? stackCache)

Parameters

bound BoundingBox

The bounding region for the oct tree.

objList List<T>

The list of objects contained within the bounding region

parent IDynamicOctree
parameter OctreeBuildParameter
stackCache Stack<KeyValuePair<int, IDynamicOctree[]>>

DynamicOctreeBase(IDynamicOctree?, OctreeBuildParameter?, Stack<KeyValuePair<int, IDynamicOctree[]>>?)

protected DynamicOctreeBase(IDynamicOctree? parent, OctreeBuildParameter? parameter, Stack<KeyValuePair<int, IDynamicOctree[]>>? stackCache)

Parameters

parent IDynamicOctree
parameter OctreeBuildParameter
stackCache Stack<KeyValuePair<int, IDynamicOctree[]>>

Fields

modelHits

protected List<HitTestResult> modelHits

Field Value

List<HitTestResult>

stack

internal stack for tree traversal

protected readonly Stack<KeyValuePair<int, IDynamicOctree[]>> stack

Field Value

Stack<KeyValuePair<int, IDynamicOctree[]>>

treeBuilt

protected bool treeBuilt

Field Value

bool

Properties

ActiveNodes

public byte ActiveNodes { get; set; }

Property Value

byte

AutoDeleteIfEmpty

Delete the octant if there is no object or child octant inside it.

public bool AutoDeleteIfEmpty { get; set; }

Property Value

bool

Bound

public BoundingBox Bound { get; protected set; }

Property Value

BoundingBox

ChildNodes

public IDynamicOctree?[] ChildNodes { get; }

Property Value

IDynamicOctree[]

HasChildren

public bool HasChildren { get; }

Property Value

bool

HitPathBoundingBoxes

public IList<BoundingBox> HitPathBoundingBoxes { get; }

Property Value

IList<BoundingBox>

IsEmpty

public bool IsEmpty { get; }

Property Value

bool

IsRoot

public bool IsRoot { get; }

Property Value

bool

MIN_SIZE

The minumum size for enclosing region is a 1x1x1 cube.

public float MIN_SIZE { get; }

Property Value

float

Objects

public List<T>? Objects { get; protected set; }

Property Value

List<T>

Octants

public BoundingBox[]? Octants { get; }

Property Value

BoundingBox[]

Parameter

public OctreeBuildParameter Parameter { get; }

Property Value

OctreeBuildParameter

Parent

public IDynamicOctree? Parent { get; set; }

Property Value

IDynamicOctree

SelfArray

Gets the self array.

public IDynamicOctree?[] SelfArray { get; }

Property Value

IDynamicOctree[]

The self array.

TreeBuilt

public bool TreeBuilt { get; }

Property Value

bool

Methods

Add(T)

public bool Add(T item)

Parameters

item T

Returns

bool

Add(T, out IDynamicOctree?)

public virtual bool Add(T item, out IDynamicOctree? octant)

Parameters

item T
octant IDynamicOctree

Returns

bool

BuildCurretNodeOnly()

public void BuildCurretNodeOnly()

BuildSubTree()

Build sub tree nodes

protected virtual void BuildSubTree()

BuildTree()

Build the octree

public virtual void BuildTree()

BuildTree(IDynamicOctree, Stack<KeyValuePair<int, IDynamicOctree[]>>)

public void BuildTree(IDynamicOctree root, Stack<KeyValuePair<int, IDynamicOctree[]>> stack)

Parameters

root IDynamicOctree
stack Stack<KeyValuePair<int, IDynamicOctree[]>>

CheckDimension()

public bool CheckDimension()

Returns

bool

Clear()

public virtual void Clear()

CreateNode(ref BoundingBox, T)

protected IDynamicOctree CreateNode(ref BoundingBox bound, T Item)

Parameters

bound BoundingBox
Item T

Returns

IDynamicOctree

CreateNodeWithParent(ref BoundingBox, List<T>, IDynamicOctree)

protected abstract IDynamicOctree CreateNodeWithParent(ref BoundingBox bound, List<T> objList, IDynamicOctree parent)

Parameters

bound BoundingBox
objList List<T>
parent IDynamicOctree

Returns

IDynamicOctree

CreateOctants(ref BoundingBox, float)

public static BoundingBox[] CreateOctants(ref BoundingBox box, float minSize)

Parameters

box BoundingBox
minSize float

Returns

BoundingBox[]

CreateOctreeLineModel()

Creates the octree line model for debugging or visualize the octree

public LineGeometry3D CreateOctreeLineModel()

Returns

LineGeometry3D

Expand(IDynamicOctree, ref Vector3, CreateNodeDelegate)

Return new root

public static IDynamicOctree? Expand(IDynamicOctree oldRoot, ref Vector3 direction, DynamicOctreeBase<T>.CreateNodeDelegate createNodeFunc)

Parameters

oldRoot IDynamicOctree
direction Vector3
createNodeFunc DynamicOctreeBase<T>.CreateNodeDelegate

Returns

IDynamicOctree

Expand(ref Vector3)

Return new root

public virtual IDynamicOctree? Expand(ref Vector3 direction)

Parameters

direction Vector3

Returns

IDynamicOctree

FindChildByItem(T, out int)

public IDynamicOctree? FindChildByItem(T item, out int index)

Parameters

item T
index int

Returns

IDynamicOctree

FindChildByItemBound(T, ref BoundingBox, out int)

public virtual IDynamicOctree? FindChildByItemBound(T item, ref BoundingBox bound, out int index)

Parameters

item T
bound BoundingBox
index int

Returns

IDynamicOctree

FindChildByItemBound(T, out int)

public virtual IDynamicOctree? FindChildByItemBound(T item, out int index)

Parameters

item T
index int

Returns

IDynamicOctree

FindChildByItemBound<E>(E, BoundingBox, Func<BoundingBox, BoundingBox, E, bool>, DynamicOctreeBase<E>, Stack<KeyValuePair<int, IDynamicOctree[]>>, out int)

public static IDynamicOctree? FindChildByItemBound<E>(E item, BoundingBox bound, Func<BoundingBox, BoundingBox, E, bool> isContains, DynamicOctreeBase<E> root, Stack<KeyValuePair<int, IDynamicOctree[]>> stackCache, out int index)

Parameters

item E
bound BoundingBox
isContains Func<BoundingBox, BoundingBox, E, bool>
root DynamicOctreeBase<E>
stackCache Stack<KeyValuePair<int, IDynamicOctree[]>>
index int

Returns

IDynamicOctree

Type Parameters

E

FindChildByItem<E>(E, DynamicOctreeBase<E>, Stack<KeyValuePair<int, IDynamicOctree[]>>, out int)

public static IDynamicOctree? FindChildByItem<E>(E item, DynamicOctreeBase<E> root, Stack<KeyValuePair<int, IDynamicOctree[]>> stackCache, out int index)

Parameters

item E
root DynamicOctreeBase<E>
stackCache Stack<KeyValuePair<int, IDynamicOctree[]>>
index int

Returns

IDynamicOctree

Type Parameters

E

FindEnclosingBox()

This finds the dimensions of the bounding box necessary to tightly enclose all items in the object list.

protected BoundingBox FindEnclosingBox()

Returns

BoundingBox

FindEnclosingCube(ref BoundingBox)

This finds the smallest enclosing cube which is a power of 2, for all objects in the list.

public static BoundingBox FindEnclosingCube(ref BoundingBox bound)

Parameters

bound BoundingBox

Returns

BoundingBox

FindNearestPointByPointAndSearchRadius(HitTestContext?, ref Vector3, float, ref List<HitTestResult>)

public bool FindNearestPointByPointAndSearchRadius(HitTestContext? context, ref Vector3 point, float radius, ref List<HitTestResult> result)

Parameters

context HitTestContext
point Vector3
radius float
result List<HitTestResult>

Returns

bool

FindNearestPointBySphere(HitTestContext?, ref BoundingSphere, ref List<HitTestResult>)

public virtual bool FindNearestPointBySphere(HitTestContext? context, ref BoundingSphere sphere, ref List<HitTestResult> points)

Parameters

context HitTestContext
sphere BoundingSphere
points List<HitTestResult>

Returns

bool

FindNearestPointBySphereExcludeChild(HitTestContext?, ref BoundingSphere, ref List<HitTestResult>, ref bool)

Find nearest point by sphere on current node only.

public abstract bool FindNearestPointBySphereExcludeChild(HitTestContext? context, ref BoundingSphere sphere, ref List<HitTestResult> points, ref bool isIntersect)

Parameters

context HitTestContext
sphere BoundingSphere
points List<HitTestResult>
isIntersect bool

Returns

bool

FindNearestPointFromPoint(HitTestContext?, ref Vector3, ref List<HitTestResult>?, float)

public virtual bool FindNearestPointFromPoint(HitTestContext? context, ref Vector3 point, ref List<HitTestResult>? results, float heuristicSearchFactor = 1)

Parameters

context HitTestContext
point Vector3
results List<HitTestResult>
heuristicSearchFactor float

Returns

bool

FindRoot(IDynamicOctree)

public static IDynamicOctree FindRoot(IDynamicOctree node)

Parameters

node IDynamicOctree

Returns

IDynamicOctree

FindSmallestNodeContainsBoundingBox(ref BoundingBox, T)

public IDynamicOctree? FindSmallestNodeContainsBoundingBox(ref BoundingBox bound, T item)

Parameters

bound BoundingBox
item T

Returns

IDynamicOctree

GetBoundingBoxFromItem(T)

protected abstract BoundingBox GetBoundingBoxFromItem(T item)

Parameters

item T

Returns

BoundingBox

HitTest(HitTestContext?, object?, Geometry3D?, Matrix4x4, bool, ref List<HitTestResult>)

public bool HitTest(HitTestContext? context, object? model, Geometry3D? geometry, Matrix4x4 modelMatrix, bool returnMultiple, ref List<HitTestResult> hits)

Parameters

context HitTestContext

The context.

model object

The model.

geometry Geometry3D

The geometry.

modelMatrix Matrix4x4

The model matrix.

returnMultiple bool

Not used

hits List<HitTestResult>

The hits.

Returns

bool

HitTest(HitTestContext?, object?, Geometry3D?, Matrix4x4, bool, ref List<HitTestResult>, float)

public virtual bool HitTest(HitTestContext? context, object? model, Geometry3D? geometry, Matrix4x4 modelMatrix, bool returnMultiple, ref List<HitTestResult> hits, float hitThickness)

Parameters

context HitTestContext
model object
geometry Geometry3D
modelMatrix Matrix4x4
returnMultiple bool
hits List<HitTestResult>
hitThickness float

Returns

bool

HitTest(HitTestContext?, object?, Geometry3D?, Matrix4x4, ref List<HitTestResult>)

public bool HitTest(HitTestContext? context, object? model, Geometry3D? geometry, Matrix4x4 modelMatrix, ref List<HitTestResult> hits)

Parameters

context HitTestContext
model object
geometry Geometry3D
modelMatrix Matrix4x4
hits List<HitTestResult>

Returns

bool

HitTest(HitTestContext?, object?, Geometry3D?, Matrix4x4, ref List<HitTestResult>, float)

public virtual bool HitTest(HitTestContext? context, object? model, Geometry3D? geometry, Matrix4x4 modelMatrix, ref List<HitTestResult> hits, float hitThickness)

Parameters

context HitTestContext
model object
geometry Geometry3D
modelMatrix Matrix4x4
hits List<HitTestResult>
hitThickness float

Returns

bool

HitTestCurrentNodeExcludeChild(HitTestContext?, object?, Geometry3D?, Matrix4x4, ref Ray, ref List<HitTestResult>, ref bool, float)

Hit test for current node.

public abstract bool HitTestCurrentNodeExcludeChild(HitTestContext? context, object? model, Geometry3D? geometry, Matrix4x4 modelMatrix, ref Ray rayModel, ref List<HitTestResult> hits, ref bool isIntersect, float hitThickness)

Parameters

context HitTestContext
model object
geometry Geometry3D
modelMatrix Matrix4x4
rayModel Ray
hits List<HitTestResult>
isIntersect bool
hitThickness float

Returns

bool

IsContains(BoundingBox, BoundingBox, T)

protected virtual bool IsContains(BoundingBox source, BoundingBox target, T targetObj)

Parameters

source BoundingBox
target BoundingBox
targetObj T

Returns

bool

IsContains(BoundingBox, T)

protected bool IsContains(BoundingBox source, T targetObj)

Parameters

source BoundingBox
targetObj T

Returns

bool

PushExistingToChild(DynamicOctreeBase<T>, int, Func<BoundingBox, T, bool>, CreateNodeDelegate, out IDynamicOctree?)

Push existing item into child

public static bool PushExistingToChild(DynamicOctreeBase<T> node, int index, Func<BoundingBox, T, bool> isContains, DynamicOctreeBase<T>.CreateNodeDelegate createNodeFunc, out IDynamicOctree? octant)

Parameters

node DynamicOctreeBase<T>
index int
isContains Func<BoundingBox, T, bool>
createNodeFunc DynamicOctreeBase<T>.CreateNodeDelegate
octant IDynamicOctree

Returns

bool

True: Pushed into child. Otherwise false.

PushExistingToChild(int)

Push one of object belongs to current node into its child octant

public bool PushExistingToChild(int index)

Parameters

index int

Returns

bool

PushExistingToChild(int, out IDynamicOctree?)

Push one of object belongs to current node into its child octant

public virtual bool PushExistingToChild(int index, out IDynamicOctree? octant)

Parameters

index int
octant IDynamicOctree

Returns

bool

RemoveAt(int)

public virtual bool RemoveAt(int index)

Parameters

index int

Returns

bool

RemoveByBound(T)

public virtual bool RemoveByBound(T item)

Parameters

item T

Returns

bool

RemoveByBound(T, ref BoundingBox)

public virtual bool RemoveByBound(T item, ref BoundingBox bound)

Parameters

item T
bound BoundingBox

Returns

bool

RemoveChild(IDynamicOctree)

public void RemoveChild(IDynamicOctree child)

Parameters

child IDynamicOctree

RemoveSafe(T)

public virtual bool RemoveSafe(T item)

Parameters

item T

Returns

bool

RemoveSelf()

public virtual void RemoveSelf()

Shrink()

Shrink the root bound to contains all items inside, return new root

public virtual IDynamicOctree? Shrink()

Returns

IDynamicOctree

Shrink(IDynamicOctree)

Shrink the root bound to contains all items inside

public static IDynamicOctree? Shrink(IDynamicOctree root)

Parameters

root IDynamicOctree

Returns

IDynamicOctree

SigBit(int)

protected static int SigBit(int x)

Parameters

x int

Returns

int

TreeTraversal(IDynamicOctree, Stack<KeyValuePair<int, IDynamicOctree[]>>, Func<IDynamicOctree, bool>?, Action<IDynamicOctree>, Func<bool>?, bool)

Common function to traverse the tree

public static void TreeTraversal(IDynamicOctree root, Stack<KeyValuePair<int, IDynamicOctree[]>> stack, Func<IDynamicOctree, bool>? criteria, Action<IDynamicOctree> process, Func<bool>? breakCriteria = null, bool useParallel = false)

Parameters

root IDynamicOctree
stack Stack<KeyValuePair<int, IDynamicOctree[]>>
criteria Func<IDynamicOctree, bool>
process Action<IDynamicOctree>
breakCriteria Func<bool>
useParallel bool

Events

Hit

public event EventHandler<EventArgs>? Hit

Event Type

EventHandler<EventArgs>