Class OctTree<T>
- Namespace
- CADability
- Assembly
- CADability.dll
Generic class to provide fast access to IOctTreeInsertable implementing objects.
public class OctTree<T> where T : IOctTreeInsertable
Type Parameters
TThe generic type, must implement IOctTreeInsertable
- Inheritance
-
OctTree<T>
- Derived
- Inherited Members
Constructors
OctTree()
public OctTree()
OctTree(BoundingCube, double, SplitTestFunction)
Constructs an octtree providing an initial size and a precision
public OctTree(BoundingCube ext, double precision, OctTree<T>.SplitTestFunction splitTest = null)
Parameters
extBoundingCubeInitial size of the tree. Objects beeng added later may exceed this cube
precisiondoublePrecision, used internally
splitTestOctTree<T>.SplitTestFunctionCriterion whether to split a node when an object is added to it, null: use the default criterion of SplitNode(Node<T>, T)
Fields
precision
The precision of this octtree
public double precision
Field Value
Properties
Extend
returns the extend of the root node.
public BoundingCube Extend { get; }
Property Value
IsEmpty
Returns true if the tree is empty
public bool IsEmpty { get; }
Property Value
Methods
AddMany(IEnumerable<T>)
public void AddMany(IEnumerable<T> objectsToAdd)
Parameters
objectsToAddIEnumerable<T>
AddObject(T)
Add the provided object to the tree. This may split some nodes and cause calls to the method of other objects already in the tree.
public void AddObject(T objectToAdd)
Parameters
objectToAddTObject beeing added
AddObjectAsync(T)
public void AddObjectAsync(T objectToAdd)
Parameters
objectToAddT
FindExactNode(BoundingCube)
Find the node which corresponds exactely to the provided boundingcube
public OctTree<T>.Node<T> FindExactNode(BoundingCube bc)
Parameters
bcBoundingCube
Returns
FindNode(GeoPoint)
Find the node containing the provided point.
public OctTree<T>.Node<T> FindNode(GeoPoint center)
Parameters
centerGeoPointthe point
Returns
GetAllObjects()
public T[] GetAllObjects()
Returns
- T[]
GetNeighbourNodes(Node<T>, FilterNode)
Returns all neighbour nodes to the provided node. The result is sortet in a 2-dimensional array where the first index defines the side according to OctTree<T>.Side.
protected OctTree<T>.Node<T>[][] GetNeighbourNodes(OctTree<T>.Node<T> node, OctTree<T>.FilterNode filter)
Parameters
nodeOctTree<T>.Node<T>The node which neighbours are requested
filterOctTree<T>.FilterNodeA optinal filter or null if unfiltered
Returns
- Node<T>[][]
The neighbour nodes
GetNeighbours(Node<T>, Filter)
Returns all neighbours to the provided node. The result is sortet in a 2-dimensional array where the first index defines the side according to OctTree<T>.Side.
protected T[][] GetNeighbours(OctTree<T>.Node<T> node, OctTree<T>.Filter filter)
Parameters
nodeOctTree<T>.Node<T>The node which neighbours are requested
filterOctTree<T>.FilterA optinal filter or null if unfiltered
Returns
- T[][]
The neighbours
GetNodesCloseTo(IOctTreeInsertable)
Returns all nodes close to the provided object.
protected OctTree<T>.Node<T>[] GetNodesCloseTo(IOctTreeInsertable closeToThis)
Parameters
closeToThisIOctTreeInsertableObject for selection
Returns
- Node<T>[]
All nodes interfering with the provided object
GetNodesFromBox(BoundingCube, FilterNode)
Returns all nodes of this tree that interfere with the provided box and pass the filter test.
public OctTree<T>.Node<T>[] GetNodesFromBox(BoundingCube box, OctTree<T>.FilterNode filter)
Parameters
boxBoundingCubeRestricting box
filterOctTree<T>.FilterNodeAdditional filter (may be null)
Returns
- Node<T>[]
All nodes which match the criterion
GetObjectsCloseTo(IOctTreeInsertable)
Returns all objects that are close to the provided object.
public T[] GetObjectsCloseTo(IOctTreeInsertable closeToThis)
Parameters
closeToThisIOctTreeInsertableObject which neighbours are searched
Returns
- T[]
All objects close to
closeToThis
GetObjectsFromBox(BoundingCube)
Returns all objects that interfere or are close to the provided box.
public T[] GetObjectsFromBox(BoundingCube box)
Parameters
boxBoundingCubeBox for the selection
Returns
- T[]
Array of all objects which match the criterion
GetObjectsFromBox(BoundingCube, Filter)
Returns all objects that interfere or are close to the provided box and accepted by the filter.
public T[] GetObjectsFromBox(BoundingCube box, OctTree<T>.Filter filter)
Parameters
boxBoundingCubeBox specifying the selection
filterOctTree<T>.FilterFilter restriction the result
Returns
- T[]
Array of all objects which match the criterion
GetObjectsFromLine(GeoPoint, GeoVector, double)
Returns an array of objects which contains all objects that are close to the provided line. It may also contain some objects
that have a greater distance than maxdist to the line.
public T[] GetObjectsFromLine(GeoPoint start, GeoVector dir, double maxdist)
Parameters
startGeoPointStarting point of the line
dirGeoVectorDirection of the line
maxdistdoubleMaximum distance to the line
Returns
- T[]
Array of all objects which match the criterion
GetObjectsFromPlane(Plane)
Returns all objects that are close to the provided plane
public T[] GetObjectsFromPlane(Plane plane)
Parameters
planePlanePlane for selection
Returns
- T[]
All objects close to the plane
GetObjectsFromPoint(GeoPoint)
Returns all objects that are close to the provided point.
public T[] GetObjectsFromPoint(GeoPoint p)
Parameters
pGeoPointPoint for selection
Returns
- T[]
Array of all objects which match the criterion
GetObjectsFromRect(Projection, BoundingRect, bool)
Returns an array of all objects that interfere with the provided rectangle in repect to the provided Projection.
It may also contain some objects which don't interfere but are close to the rectangle, if onlyInside is false.
public T[] GetObjectsFromRect(Projection projection, BoundingRect rect, bool onlyInside)
Parameters
projectionProjectionThe projection
rectBoundingRectThe rectangle, usually from a selection
onlyInsideboolIf true, only objects completely inside the rectangle are returned
Returns
- T[]
Array of all objects which match the criterion
GetObjectsFromRect(PickArea, bool)
Returns an array of all objects that interfere with the provided Projection.PickArea area. If onlyInside is true
only objects inside the frustum or box of the area are returned, otherwise there may also be objects
that are aoutside this area.
public T[] GetObjectsFromRect(Projection.PickArea area, bool onlyInside)
Parameters
areaProjection.PickAreathe frustum or box defining the selection
onlyInsideboolTrue to only return objects completely inside the area
Returns
- T[]
Array of all objects which match the criterion
Initialize(BoundingCube, double)
public void Initialize(BoundingCube ext, double precision)
Parameters
extBoundingCubeprecisiondouble
InitializePrecise(BoundingCube, double)
public void InitializePrecise(BoundingCube ext, double precision)
Parameters
extBoundingCubeprecisiondouble
RemoveObject(T)
Remove object from the tree
public void RemoveObject(T objectToRemove)
Parameters
objectToRemoveTobject to bee removed
SplitNode(Node<T>, T)
Criterion whether to split a node when it contains too many leaves. The default implemenation yield a dynamically balanced tree which allows more leaves in deeper nodes.
protected virtual bool SplitNode(OctTree<T>.Node<T> node, T objectToAdd)
Parameters
Returns
- bool
true, if node should be splitted, false otherwise