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

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

SpatialTree

#
public SpatialTree(Evaluate<T> evaluator)
Construct a new empty octree.
evaluator (Evaluate<T>)Evaluation delegate.

Properties

Count

#
public int Count { get; }
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.

Optimized

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

Indexers

this[]

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

Methods

Add

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

AddRange

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

Bounds

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

Bounds

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

BuildTree

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

Clear

#
public void 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.

Contains

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

Difference

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

Distance

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

Draw

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

FindAbovePlane

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

FindCustom

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

FindInBox

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

FindInSphere

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

ForgetAbout

#
public void ForgetAbout(int index)
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.
index (int)

FurthestItem

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

FurthestItem

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

FurthestItems

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

FurthestItems

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

IndexOf

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

NearestItem

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

NearestItem

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

NearestItem

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

NearestItem

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

NearestItem

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

NearestItem

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

NearestItem

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

NearestItem

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

NearestItems

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

NearestItems

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

NearestItems

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

NearestItems

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

NearestItems

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

NearestItems

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

Optimize

#
public void 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.

Quadrance

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

RemoveAt

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

ToArray

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