public class RTree : IDisposable
Represents a spatial search structure based on implementations of the R-tree algorithm by Toni Gutman.
Remarks: The opennurbs rtree code is a modified version of the free and unrestricted R-tree implementation obtained from http://www.superliminal.com/sources/sources.htm .

Constructors

RTree

#ExampleSince v5.0
public RTree()
Initializes a new, empty instance of the tree.

Finalizer

~RTree

#
~RTree()
Passively reclaims unmanaged resources when the class user did not explicitly call Dispose().

Properties

Count

#Since v5.0
public int Count { get; }
Gets the number of items in this tree.

Methods

Clear

#Since v5.0
public void Clear()
Removes all elements.

CreateFromPointArray

#Since v6.0
public static RTree CreateFromPointArray(IEnumerable<Point3d> points)
Constructs a new tree with an element for each point cloud point.
points (IEnumerable<Point3d>)Points.
A new tree, or null on error.

CreateMeshFaceTree

#Since v5.0
public static RTree CreateMeshFaceTree(Mesh mesh)
Constructs a new tree with an element for each face in the mesh. The element id is set to the index of the face.
mesh (Mesh)A mesh.
A new tree, or null on error.

CreatePointCloudTree

#Since v5.0
public static RTree CreatePointCloudTree(PointCloud cloud)
Constructs a new tree with an element for each point cloud point.
cloud (PointCloud)A point cloud.
A new tree, or null on error.

Dispose

#Since v5.0
public void Dispose()
Actively reclaims unmanaged resources that this instance uses.

Dispose

#
protected virtual void Dispose(bool disposing)
For derived class implementers.

This method is called with argument true when class user calls Dispose(), while with argument false when the Garbage Collector invokes the finalizer, or Finalize() method.

You must reclaim all used unmanaged resources in both cases, and can use this chance to call Dispose on disposable fields if the argument is true.

Also, you must call the base virtual method within your overriding method.

disposing (bool)true if the call comes from the Dispose() method; false if it comes from the Garbage Collector finalizer.

Insert

#Since v5.0
public bool Insert(BoundingBox box, int elementId)
Inserts an element into the tree.
box (BoundingBox)A bounding box.
elementId (int)A number.
true if element was successfully inserted.

Insert

#Since v5.0
public bool Insert(BoundingBox box, nint elementId)
Inserts an element into the tree.
box (BoundingBox)A bounding box.
elementId (nint)A pointer.
true if element was successfully inserted.

Insert

#Since v5.0
public bool Insert(Point2d point, int elementId)
Inserts an element into the tree.
point (Point2d)A point.
elementId (int)A number.
true if element was successfully inserted.

Insert

#Since v5.0
public bool Insert(Point2d point, nint elementId)
Inserts an element into the tree.
point (Point2d)A point.
elementId (nint)A pointer.
true if element was successfully inserted.

Insert

#ExampleSince v5.0
public bool Insert(Point3d point, int elementId)
Inserts an element into the tree.
point (Point3d)A point.
elementId (int)A number.
true if element was successfully inserted.

Insert

#Since v5.0
public bool Insert(Point3d point, nint elementId)
Inserts an element into the tree.
point (Point3d)A point.
elementId (nint)A pointer.
true if element was successfully inserted.

Point3dClosestPoints

#Since v6.0
public static IEnumerable<int[]> Point3dClosestPoints(IEnumerable<Point3d> hayPoints, IEnumerable<Point3d> needlePts, double limitDistance)
Finds the point in a list of 3D points that is closest to a test point.
hayPoints (IEnumerable<Point3d>)A series of points.
needlePts (IEnumerable<Point3d>)Points to search for.
limitDistance (double)The maximum allowed distance.
An enumerable of arrays of indices; each array contains the indices for each of the needlePts.

Point3dKNeighbors

#Since v6.0
public static IEnumerable<int[]> Point3dKNeighbors(IEnumerable<Point3d> hayPoints, IEnumerable<Point3d> needlePts, int amount)
Finds a certain amount of points in a list of 3D points that are the k-closest to a test point.
hayPoints (IEnumerable<Point3d>)A series of points.
needlePts (IEnumerable<Point3d>)Points to search for.
amount (int)The required amount of closest neighbors to find.
An enumerable of arrays of indices; each array contains the indices for each of the needlePts.

PointCloudClosestPoints

#Since v6.0
public static IEnumerable<int[]> PointCloudClosestPoints(PointCloud pointcloud, IEnumerable<Point3d> needlePts, double limitDistance)
Finds the point in a list of 3D points that is closest to a test point.
pointcloud (PointCloud)A point cloud to be searched.
needlePts (IEnumerable<Point3d>)Points to search for.
limitDistance (double)The maximum allowed distance.
An enumerable of arrays of indices; each array contains the indices for each of the needlePts.

PointCloudKNeighbors

#Since v6.0
public static IEnumerable<int[]> PointCloudKNeighbors(PointCloud pointcloud, IEnumerable<Point3d> needlePts, int amount)
Finds a certain amount of points in a list of 3D points that are the k-closest to a test point.
pointcloud (PointCloud)A point cloud to be searched.
needlePts (IEnumerable<Point3d>)Points to search for.
amount (int)The required amount of closest neighbors to find.
An enumerable of arrays of indices; each array contains the indices for each of the needlePts.

Remove

#Since v5.0
public bool Remove(BoundingBox box, int elementId)
Removes an element from the tree.
box (BoundingBox)A bounding box.
elementId (int)A number.
true if element was successfully removed.

Remove

#Since v5.0
public bool Remove(BoundingBox box, nint elementId)
Removes an element from the tree.
box (BoundingBox)A bounding box.
elementId (nint)A pointer.
true if element was successfully removed.

Remove

#Since v5.0
public bool Remove(Point2d point, int elementId)
Removes an element from the tree.
point (Point2d)A point.
elementId (int)A number.
true if element was successfully removed.

Remove

#Since v5.0
public bool Remove(Point3d point, int elementId)
Removes an element from the tree.
point (Point3d)A point.
elementId (int)A number.
true if element was successfully removed.

Remove

#Since v5.0
public bool Remove(Point3d point, nint elementId)
Removes an element from the tree.
point (Point3d)A point.
elementId (nint)A pointer.
true if element was successfully removed.

Search

#Since v5.0
public bool Search(BoundingBox box, EventHandler<RTreeEventArgs> callback, object tag)
Searches for items in a bounding box.

The bounding box can be singular and contain exactly one single point.

Remarks: Do not modify the tree while a Search() is in progress. Doing so can have unintended consequences, including corruption and crashes.If you need to modify the tree, collect the results during the search and modify the tree once the search is completed.
box (BoundingBox)A bounding box.
callback (EventHandler<RTreeEventArgs>)An event handler to be raised when items are found.
tag (object)State to be passed inside the RTreeEventArgs Tag property.
true if entire tree was searched. It is possible no results were found.

Search

#Since v5.0
public bool Search(BoundingBox box, EventHandler<RTreeEventArgs> callback)
Searches for items in a bounding box.

The bounding box can be singular and contain exactly one single point.

Remarks: Do not modify the tree while a Search() is in progress. Doing so can have unintended consequences, including corruption and crashes.If you need to modify the tree, collect the results during the search and modify the tree once the search is completed.
box (BoundingBox)A bounding box.
callback (EventHandler<RTreeEventArgs>)An event handler to be raised when items are found.
true if entire tree was searched. It is possible no results were found.

Search

#ExampleSince v5.0
public bool Search(Sphere sphere, EventHandler<RTreeEventArgs> callback, object tag)
Searches for items in a sphere.
Remarks: Do not modify the tree while a Search() is in progress. Doing so can have unintended consequences, including corruption and crashes.If you need to modify the tree, collect the results during the search and modify the tree once the search is completed.
sphere (Sphere)bounds used for searching.
callback (EventHandler<RTreeEventArgs>)An event handler to be raised when items are found.
tag (object)State to be passed inside the RTreeEventArgs Tag property.
true if entire tree was searched. It is possible no results were found.

Search

#Since v5.0
public bool Search(Sphere sphere, EventHandler<RTreeEventArgs> callback)
Searches for items in a sphere.
Remarks: Do not modify the tree while a Search() is in progress. Doing so can have unintended consequences, including corruption and crashes.If you need to modify the tree, collect the results during the search and modify the tree once the search is completed.
sphere (Sphere)bounds used for searching.
callback (EventHandler<RTreeEventArgs>)An event handler to be raised when items are found.
true if entire tree was searched. It is possible no results were found.

SearchOverlaps

#Since v9.0
public bool SearchOverlaps(double tolerance, EventHandler<RTreeEventArgs> callback, object tag)
Searches for pairs of bounding boxes that overlap.
Remarks: Do not modify the tree while a Search() is in progress. Doing so can have unintended consequences, including corruption and crashes.If you need to modify the tree, collect the results during the search and modify the tree once the search is completed.
tolerance (double)bounds used for searching.
callback (EventHandler<RTreeEventArgs>)An event handler to be raised when items are found.
tag (object)State to be passed inside the RTreeEventArgs Tag property.
true if entire tree was searched. It is possible no results were found.

SearchOverlaps

#Since v5.0
public static bool SearchOverlaps(RTree treeA, RTree treeB, double tolerance, EventHandler<RTreeEventArgs> callback)
Searches two R-trees for all pairs elements whose bounding boxes overlap.
Remarks: Do not modify the tree while a Search() is in progress. Doing so can have unintended consequences, including corruption and crashes.If you need to modify the tree, collect the results during the search and modify the tree once the search is completed.
treeA (RTree)A first tree.
treeB (RTree)A second tree.
tolerance (double)If the distance between a pair of bounding boxes is less than tolerance, then callback is called.
callback (EventHandler<RTreeEventArgs>)A callback event handler.
true if entire tree was searched. It is possible no results were found.