SpatialTree<T>

References
public class SpatialTree<T>
Provides a spatial lookup tree for 3d point-like data. This class uses an adaptive octree-subdivision algorithm. If you're dealing with n-dimensional where n != 3, then you can use the SampleSet class in the Grasshopper2.Geometry.Clustering namespace.
TType of data to encapsulate.

Constructors

SpatialTree

#
Construct a new empty octree.
public SpatialTree(
evaluator,
Evaluation delegate.
threshold
Number of items per node prior to subdivision. 100 is a good value in most cases.
)

SpatialTree

#
Construct a new empty octree.
public SpatialTree(
evaluator
Evaluation delegate.
)

Properties

Count

#
Gets the number of items stored in this tree. Though note some of these may have been removed from the spatial lookup caches and can thus no longer be found.
public int Count { get; }

Optimized

#
Gets whether this tree has been optimized.
public bool Optimized { get; }

Indexers

this[]

#
Gets a specific item in the tree.
public T this[
index
Index of item.
] { get; }

Methods

Add

#
Add a single item to the tree.
public void Add(
T
item
Item to insert.
)

AddRange

#
Add a collection of items to the tree.
public void AddRange(
items
Items to add.
)

Bounds

#
Gets the bounding box for the entire tree.
public OrthogonalBox Bounds()
Bounding box

Bounds

#
Gets the bounding box for a collection of indexed items.
public OrthogonalBox Bounds(
indices
Indices to include.
)
Bounding box.

BuildTree

#
Ensure the tree has been constructed.
public void BuildTree()
Remarks: This method locks, so check to see whether _root is null as a lightweight test.

Clear

#
Remove all items from the tree. Although why you would want to do this instead of just creating just a new spatial tree is unclear.
public void Clear()

Contains

#
Gets whether an item is defined within the tree.
public bool Contains(
T
item
)

Difference

#
Compute the difference along the x, y and z axes between two items.
public void Difference(
T
a,
First item.
T
b,
Second item.
out double
dx,
Signed difference along X.
out double
dy,
Signed difference along Y.
out double
dz
Signed difference along Z.
)

Distance

#
Compute the distance between two instances.
public double Distance(
T
a,
First instance.
T
b
Second instance.
)
Distance between a and b.

Draw

#
Draw all leaf nodes as box corners.
public void Draw(
pipeline,
viewport
)

FindAbovePlane

#
Find all items above a plane.
public int[] FindAbovePlane(
slice
Plane slice.
)
An array of item indices.

FindCustom

#
Perform a custom search.
public int[] FindCustom(
regionDelegate,
Delegate used for accepting/rejecting node regions.
locusDelegate
Delegate used for accepting/rejecting individual items.
)
Array of all indices that were found using the search delegates.

FindInBox

#
Find all items within a box.
public int[] FindInBox(
box
Box region.
)
An array of item indices.

FindInSphere

#
Find all items within a sphere.
public int[] FindInSphere(
sphere
Sphere region.
)
An array of item indices.

ForgetAbout

#
Remove an item from the spatial lookup caches. This will prevent the item from being found using a Near or Far search, but it will not remove the item from this collection or affect the indices of other items.
public void ForgetAbout(
index
)

FurthestItem

#
Find the nearest item to a search point.
public int FurthestItem(
locus,
Start of search.
minSearchRadius,
Minimum search distance.
maxSearchRadius
Maximum search distance.
)
Integer of nearest item or -1 if no such item could be found.

FurthestItem

#
Find the nearest item to a search point.
public int FurthestItem(
locus
Start of search.
)
Integer of nearest item or -1 if no such item could be found.

FurthestItems

#
Find the nearest items to a search point.
public int[] FurthestItems(
locus,
Start of search.
count,
Number of results to return.
minSearchRadius,
Minimum search distance.
maxSearchRadius
Maximum search distance.
)
Integer of nearest item or -1 if no such item could be found.

FurthestItems

#
Find the nearest items to a search point.
public int[] FurthestItems(
locus,
Start of search.
count
Number of results to return.
)
Integer of nearest item or -1 if no such item could be found.

IndexOf

#
Gets the index of a specific item.
public int IndexOf(
T
item
)

NearestItem

#
Find the nearest item to a search line.
public int NearestItem(
line,
Line of search.
minSearchRadius,
Minimum search distance.
maxSearchRadius
Maximum search distance.
)
Integer of nearest item or -1 if no such item could be found.

NearestItem

#
Find the nearest item to a search line.
public int NearestItem(
line
Line of search.
)
Integer of nearest item or -1 if no such item could be found.

NearestItem

#
Find the nearest item to a search point.
public int NearestItem(
locus,
Start of search.
minSearchRadius,
Minimum search distance.
maxSearchRadius
Maximum search distance.
)
Integer of nearest item or -1 if no such item could be found.

NearestItem

#
Find the nearest item to a search point.
public int NearestItem(
locus
Start of search.
)
Integer of nearest item or -1 if no such item could be found.

NearestItem

#
Find the nearest item using a custom distance metric.
public int NearestItem(
regionDelegate,
Delegate used for region distance metrics.
locusDelegate,
Delegate used for locus distance metrics.
minSearchRadius,
Minimum search distance.
maxSearchRadius
Maximum search distance.
)
Integer of nearest item or -1 if no such item could be found.

NearestItem

#
Find the nearest item using a custom distance metric.
public int NearestItem(
regionDelegate,
Delegate used for region distance metrics.
locusDelegate
Delegate used for locus distance metrics.
)
Integer of nearest item or -1 if no such item could be found.

NearestItem

#
Find the nearest item to a search locus.
public int NearestItem(
T
locus,
Start of search.
minSearchRadius,
Minimum search distance.
maxSearchRadius
Maximum search distance.
)
Integer of nearest item or -1 if no such item could be found.

NearestItem

#
Find the nearest item to a search locus.
public int NearestItem(
T
locus
Start of search.
)
Integer of nearest item or -1 if no such item could be found.

NearestItems

#
Find the nearest item to a search line.
public int[] NearestItems(
line,
Line of search.
count,
Number of items to include.
minSearchRadius,
Minimum search distance.
maxSearchRadius
Maximum search distance.
)
Integer of nearest item or -1 if no such item could be found.

NearestItems

#
Find the nearest item to a search line.
public int[] NearestItems(
line,
Line of search.
count
Number of items to include.
)
Integer of nearest item or -1 if no such item could be found.

NearestItems

#
Find the nearest items to a search point.
public int[] NearestItems(
locus,
Start of search.
count,
Number of results to return.
minSearchRadius,
Minimum search distance.
maxSearchRadius
Maximum search distance.
)
Integer of nearest item or -1 if no such item could be found.

NearestItems

#
Find the nearest items to a search point.
public int[] NearestItems(
locus,
Start of search.
count
Number of results to return.
)
Integer of nearest item or -1 if no such item could be found.

NearestItems

#
Find the nearest items using a custom distance metric.
public int[] NearestItems(
regionDelegate,
Delegate used for region distance metrics.
locusDelegate,
Delegate used for locus distance metrics.
count,
Number of items to include.
minSearchRadius,
Minimum search distance.
maxSearchRadius
Maximum search distance.
)
Integer of nearest item or -1 if no such item could be found.

NearestItems

#
Find the nearest items using a custom distance metric.
public int[] NearestItems(
regionDelegate,
Delegate used for region distance metrics.
locusDelegate,
Delegate used for locus distance metrics.
count
Number of items to include.
)
Integer of nearest item or -1 if no such item could be found.

Optimize

#
Optimize this tree. Optimized trees will have faster searches, but they become immutable. Any changes made to an optimized tree will result in the tree being rebuilt.
public void Optimize()

Quadrance

#
Compute the quadrance between two instances.
public double Quadrance(
T
a,
First instance.
T
b
Second instance.
)
Quadrance between a and b.

RemoveAt

#
Remove a specific item from this spatial tree.
public void RemoveAt(
index
Index of item to remove.
)

ToArray

#
Create an array of all the items in this tree.
public T[] ToArray()