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
boundBoundingBoxThe suggested dimensions for the bounding region. Note: if items are outside this region, the region will be automatically resized.
parentIDynamicOctreeparameterOctreeBuildParameterstackCacheStack<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
boundBoundingBoxThe bounding region for the oct tree.
objListList<T>The list of objects contained within the bounding region
parentIDynamicOctreeparameterOctreeBuildParameterstackCacheStack<KeyValuePair<int, IDynamicOctree[]>>
DynamicOctreeBase(IDynamicOctree?, OctreeBuildParameter?, Stack<KeyValuePair<int, IDynamicOctree[]>>?)
protected DynamicOctreeBase(IDynamicOctree? parent, OctreeBuildParameter? parameter, Stack<KeyValuePair<int, IDynamicOctree[]>>? stackCache)
Parameters
parentIDynamicOctreeparameterOctreeBuildParameterstackCacheStack<KeyValuePair<int, IDynamicOctree[]>>
Fields
modelHits
protected List<HitTestResult> modelHits
Field Value
stack
internal stack for tree traversal
protected readonly Stack<KeyValuePair<int, IDynamicOctree[]>> stack
Field Value
treeBuilt
protected bool treeBuilt
Field Value
Properties
ActiveNodes
public byte ActiveNodes { get; set; }
Property Value
AutoDeleteIfEmpty
Delete the octant if there is no object or child octant inside it.
public bool AutoDeleteIfEmpty { get; set; }
Property Value
Bound
public BoundingBox Bound { get; protected set; }
Property Value
ChildNodes
public IDynamicOctree?[] ChildNodes { get; }
Property Value
HasChildren
public bool HasChildren { get; }
Property Value
HitPathBoundingBoxes
public IList<BoundingBox> HitPathBoundingBoxes { get; }
Property Value
IsEmpty
public bool IsEmpty { get; }
Property Value
IsRoot
public bool IsRoot { get; }
Property Value
MIN_SIZE
The minumum size for enclosing region is a 1x1x1 cube.
public float MIN_SIZE { get; }
Property Value
Objects
public List<T>? Objects { get; protected set; }
Property Value
- List<T>
Octants
public BoundingBox[]? Octants { get; }
Property Value
Parameter
public OctreeBuildParameter Parameter { get; }
Property Value
Parent
public IDynamicOctree? Parent { get; set; }
Property Value
SelfArray
Gets the self array.
public IDynamicOctree?[] SelfArray { get; }
Property Value
- IDynamicOctree[]
The self array.
TreeBuilt
public bool TreeBuilt { get; }
Property Value
Methods
Add(T)
public bool Add(T item)
Parameters
itemT
Returns
Add(T, out IDynamicOctree?)
public virtual bool Add(T item, out IDynamicOctree? octant)
Parameters
itemToctantIDynamicOctree
Returns
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
rootIDynamicOctreestackStack<KeyValuePair<int, IDynamicOctree[]>>
CheckDimension()
public bool CheckDimension()
Returns
Clear()
public virtual void Clear()
CreateNode(ref BoundingBox, T)
protected IDynamicOctree CreateNode(ref BoundingBox bound, T Item)
Parameters
boundBoundingBoxItemT
Returns
CreateNodeWithParent(ref BoundingBox, List<T>, IDynamicOctree)
protected abstract IDynamicOctree CreateNodeWithParent(ref BoundingBox bound, List<T> objList, IDynamicOctree parent)
Parameters
boundBoundingBoxobjListList<T>parentIDynamicOctree
Returns
CreateOctants(ref BoundingBox, float)
public static BoundingBox[] CreateOctants(ref BoundingBox box, float minSize)
Parameters
boxBoundingBoxminSizefloat
Returns
CreateOctreeLineModel()
Creates the octree line model for debugging or visualize the octree
public LineGeometry3D CreateOctreeLineModel()
Returns
Expand(IDynamicOctree, ref Vector3, CreateNodeDelegate)
Return new root
public static IDynamicOctree? Expand(IDynamicOctree oldRoot, ref Vector3 direction, DynamicOctreeBase<T>.CreateNodeDelegate createNodeFunc)
Parameters
oldRootIDynamicOctreedirectionVector3createNodeFuncDynamicOctreeBase<T>.CreateNodeDelegate
Returns
Expand(ref Vector3)
Return new root
public virtual IDynamicOctree? Expand(ref Vector3 direction)
Parameters
directionVector3
Returns
FindChildByItem(T, out int)
public IDynamicOctree? FindChildByItem(T item, out int index)
Parameters
itemTindexint
Returns
FindChildByItemBound(T, ref BoundingBox, out int)
public virtual IDynamicOctree? FindChildByItemBound(T item, ref BoundingBox bound, out int index)
Parameters
itemTboundBoundingBoxindexint
Returns
FindChildByItemBound(T, out int)
public virtual IDynamicOctree? FindChildByItemBound(T item, out int index)
Parameters
itemTindexint
Returns
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
itemEboundBoundingBoxisContainsFunc<BoundingBox, BoundingBox, E, bool>rootDynamicOctreeBase<E>stackCacheStack<KeyValuePair<int, IDynamicOctree[]>>indexint
Returns
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
itemErootDynamicOctreeBase<E>stackCacheStack<KeyValuePair<int, IDynamicOctree[]>>indexint
Returns
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
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
boundBoundingBox
Returns
FindNearestPointByPointAndSearchRadius(HitTestContext?, ref Vector3, float, ref List<HitTestResult>)
public bool FindNearestPointByPointAndSearchRadius(HitTestContext? context, ref Vector3 point, float radius, ref List<HitTestResult> result)
Parameters
contextHitTestContextpointVector3radiusfloatresultList<HitTestResult>
Returns
FindNearestPointBySphere(HitTestContext?, ref BoundingSphere, ref List<HitTestResult>)
public virtual bool FindNearestPointBySphere(HitTestContext? context, ref BoundingSphere sphere, ref List<HitTestResult> points)
Parameters
contextHitTestContextsphereBoundingSpherepointsList<HitTestResult>
Returns
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
contextHitTestContextsphereBoundingSpherepointsList<HitTestResult>isIntersectbool
Returns
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
contextHitTestContextpointVector3resultsList<HitTestResult>heuristicSearchFactorfloat
Returns
FindRoot(IDynamicOctree)
public static IDynamicOctree FindRoot(IDynamicOctree node)
Parameters
nodeIDynamicOctree
Returns
FindSmallestNodeContainsBoundingBox(ref BoundingBox, T)
public IDynamicOctree? FindSmallestNodeContainsBoundingBox(ref BoundingBox bound, T item)
Parameters
boundBoundingBoxitemT
Returns
GetBoundingBoxFromItem(T)
protected abstract BoundingBox GetBoundingBoxFromItem(T item)
Parameters
itemT
Returns
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
contextHitTestContextThe context.
modelobjectThe model.
geometryGeometry3DThe geometry.
modelMatrixMatrix4x4The model matrix.
returnMultipleboolNot used
hitsList<HitTestResult>The hits.
Returns
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
contextHitTestContextmodelobjectgeometryGeometry3DmodelMatrixMatrix4x4returnMultipleboolhitsList<HitTestResult>hitThicknessfloat
Returns
HitTest(HitTestContext?, object?, Geometry3D?, Matrix4x4, ref List<HitTestResult>)
public bool HitTest(HitTestContext? context, object? model, Geometry3D? geometry, Matrix4x4 modelMatrix, ref List<HitTestResult> hits)
Parameters
contextHitTestContextmodelobjectgeometryGeometry3DmodelMatrixMatrix4x4hitsList<HitTestResult>
Returns
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
contextHitTestContextmodelobjectgeometryGeometry3DmodelMatrixMatrix4x4hitsList<HitTestResult>hitThicknessfloat
Returns
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
contextHitTestContextmodelobjectgeometryGeometry3DmodelMatrixMatrix4x4rayModelRayhitsList<HitTestResult>isIntersectboolhitThicknessfloat
Returns
IsContains(BoundingBox, BoundingBox, T)
protected virtual bool IsContains(BoundingBox source, BoundingBox target, T targetObj)
Parameters
sourceBoundingBoxtargetBoundingBoxtargetObjT
Returns
IsContains(BoundingBox, T)
protected bool IsContains(BoundingBox source, T targetObj)
Parameters
sourceBoundingBoxtargetObjT
Returns
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
nodeDynamicOctreeBase<T>indexintisContainsFunc<BoundingBox, T, bool>createNodeFuncDynamicOctreeBase<T>.CreateNodeDelegateoctantIDynamicOctree
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
indexint
Returns
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
indexintoctantIDynamicOctree
Returns
RemoveAt(int)
public virtual bool RemoveAt(int index)
Parameters
indexint
Returns
RemoveByBound(T)
public virtual bool RemoveByBound(T item)
Parameters
itemT
Returns
RemoveByBound(T, ref BoundingBox)
public virtual bool RemoveByBound(T item, ref BoundingBox bound)
Parameters
itemTboundBoundingBox
Returns
RemoveChild(IDynamicOctree)
public void RemoveChild(IDynamicOctree child)
Parameters
childIDynamicOctree
RemoveSafe(T)
public virtual bool RemoveSafe(T item)
Parameters
itemT
Returns
RemoveSelf()
public virtual void RemoveSelf()
Shrink()
Shrink the root bound to contains all items inside, return new root
public virtual IDynamicOctree? Shrink()
Returns
Shrink(IDynamicOctree)
Shrink the root bound to contains all items inside
public static IDynamicOctree? Shrink(IDynamicOctree root)
Parameters
rootIDynamicOctree
Returns
SigBit(int)
protected static int SigBit(int x)
Parameters
xint
Returns
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
rootIDynamicOctreestackStack<KeyValuePair<int, IDynamicOctree[]>>criteriaFunc<IDynamicOctree, bool>processAction<IDynamicOctree>breakCriteriaFunc<bool>useParallelbool
Events
Hit
public event EventHandler<EventArgs>? Hit