Logo Euclid.BVH

Bvh<'T> Type

A generic static Bounding Volume Hierarchy (BVH) over any items,
 built from Euclid axis aligned bounding boxes (BBox).
 The tree is built once from an array of items plus a function that returns the bounding box
 of each item, and is then immutable.
 It is well suited to unevenly distributed input because the tree adapts to the actual
 bounding boxes of the items instead of subdividing space uniformly (as an octree or grid would).
 All queries come in two flavors: box based, where the distance between two items is measured
 as the distance between their bounding boxes, and exact, where a distance function for the
 actual items is supplied. The bounding box distance is always a valid lower bound of the
 exact distance, so it is used for branch and bound pruning in both cases.

Instance members

Instance member Description

this.Box

Full Usage: this.Box

Returns: BBox

The axis aligned bounding box around all items in this Bvh.

Returns: BBox

this.Boxes

Full Usage: this.Boxes

Returns: BBox[]

The bounding box of each input item, in the same order as Items. Do not mutate this array.

Returns: BBox[]

this.ClosePairs

Full Usage: this.ClosePairs

Parameters:
    maxDistance : float - The maximum distance between two item boxes for the pair to be reported.

Returns: ResizeArray<BvhPair> A ResizeArray of BvhPair, each with IdxA less than IdxB. The order of the pairs is not defined.

Finds all pairs of items whose bounding boxes are closer to each other than the given maximum distance. The distance between two boxes is 0.0 if they overlap or touch, so a maxDistance of 0.0 finds all pairs of overlapping or touching boxes.

maxDistance : float

The maximum distance between two item boxes for the pair to be reported.

Returns: ResizeArray<BvhPair>

A ResizeArray of BvhPair, each with IdxA less than IdxB. The order of the pairs is not defined.

this.ClosePairs

Full Usage: this.ClosePairs

Parameters:
    maxDistance : float - The maximum distance between two items for the pair to be reported.
    sqDistance : 'T -> 'T -> float - Returns the exact squared distance between two items.

Returns: ResizeArray<BvhPair> A ResizeArray of BvhPair, each with IdxA less than IdxB. The order of the pairs is not defined.

Finds all pairs of items that are closer to each other than the given maximum distance, measured with the given exact squared distance function. Uses a dual tree traversal: pairs of subtrees whose bounding boxes are farther apart than the maximum distance are skipped entirely.

maxDistance : float

The maximum distance between two items for the pair to be reported.

sqDistance : 'T -> 'T -> float

Returns the exact squared distance between two items.

Returns: ResizeArray<BvhPair>

A ResizeArray of BvhPair, each with IdxA less than IdxB. The order of the pairs is not defined.

this.ClosestBox

Full Usage: this.ClosestBox

Parameters:
    pt : Pnt - The 3D point to search the closest item box for.
    ?skipIdx : int - An index into the input items array to exclude from the search. Optional, -1 (skip nothing) by default.

Returns: int * float The index of the item with the closest bounding box and the distance from the point to that box.

Finds the item in the tree whose bounding box is closest to the given query point. The distance between a point and a box is 0.0 if the point is inside or on the box.

pt : Pnt

The 3D point to search the closest item box for.

?skipIdx : int

An index into the input items array to exclude from the search. Optional, -1 (skip nothing) by default.

Returns: int * float

The index of the item with the closest bounding box and the distance from the point to that box.

this.ClosestBox

Full Usage: this.ClosestBox

Parameters:
    queryBox : BBox - The axis aligned bounding box to search the closest item box for.
    ?skipIdx : int - An index into the input items array to exclude from the search. Optional, -1 (skip nothing) by default.

Returns: int * float The index of the item with the closest bounding box and the distance between the boxes.

Finds the item in the tree whose bounding box is closest to the given query box. The distance between two boxes is 0.0 if they overlap or touch.

queryBox : BBox

The axis aligned bounding box to search the closest item box for.

?skipIdx : int

An index into the input items array to exclude from the search. Optional, -1 (skip nothing) by default.

Returns: int * float

The index of the item with the closest bounding box and the distance between the boxes.

this.ClosestItem

Full Usage: this.ClosestItem

Parameters:
    pt : Pnt - The 3D point to search the closest item for.
    sqDistanceTo : 'T -> float - Returns the exact squared distance from the query point to an item.
    ?skipIdx : int - An index into the input items array to exclude from the search. Optional, -1 (skip nothing) by default.

Returns: int * float The index of the closest item in the input array and the distance to it.

Finds the item in the tree closest to the given query point. The distance to an item is measured to the exact geometry via the given squared distance function, while the item bounding boxes provide lower bounds for branch and bound pruning: subtrees whose bounding box is farther away from the point than the best distance found so far are skipped.

pt : Pnt

The 3D point to search the closest item for.

sqDistanceTo : 'T -> float

Returns the exact squared distance from the query point to an item.

?skipIdx : int

An index into the input items array to exclude from the search. Optional, -1 (skip nothing) by default.

Returns: int * float

The index of the closest item in the input array and the distance to it.

this.ClosestItem

Full Usage: this.ClosestItem

Parameters:
    queryBox : BBox - The axis aligned bounding box of the query geometry. It must fully contain the query geometry that sqDistanceTo measures from, otherwise subtrees may be pruned incorrectly.
    sqDistanceTo : 'T -> float - Returns the exact squared distance from the query geometry to an item.
    ?skipIdx : int - An index into the input items array to exclude from the search. Use this to find the nearest neighbor of an item that is part of the tree itself. Optional, -1 (skip nothing) by default.

Returns: int * float The index of the closest item in the input array and the distance to it.

Finds the item in the tree closest to the given query bounding box. The distance to an item is measured to the exact geometry via the given squared distance function, while the query box and the item boxes provide lower bounds for branch and bound pruning: subtrees whose bounding box is farther away from the query box than the best distance found so far are skipped.

queryBox : BBox

The axis aligned bounding box of the query geometry. It must fully contain the query geometry that sqDistanceTo measures from, otherwise subtrees may be pruned incorrectly.

sqDistanceTo : 'T -> float

Returns the exact squared distance from the query geometry to an item.

?skipIdx : int

An index into the input items array to exclude from the search. Use this to find the nearest neighbor of an item that is part of the tree itself. Optional, -1 (skip nothing) by default.

Returns: int * float

The index of the closest item in the input array and the distance to it.

this.ClosestPair

Full Usage: this.ClosestPair

Returns: BvhPair A BvhPair with the indices of the two items and the distance between their boxes.

Finds the pair of items whose bounding boxes are closest to each other. The distance between two boxes is 0.0 if they overlap or touch.

Returns: BvhPair

A BvhPair with the indices of the two items and the distance between their boxes.

this.ClosestPair

Full Usage: this.ClosestPair

Parameters:
    sqDistance : 'T -> 'T -> float - Returns the exact squared distance between two items.

Returns: BvhPair A BvhPair with the indices of the two closest items and their distance.

Finds the pair of closest items among all items in the tree, measured with the given exact squared distance function. For every item the nearest neighbor is searched with branch and bound pruning on the bounding boxes.

sqDistance : 'T -> 'T -> float

Returns the exact squared distance between two items.

Returns: BvhPair

A BvhPair with the indices of the two closest items and their distance.

this.Count

Full Usage: this.Count

Returns: int

The count of items in this Bvh.

Returns: int

this.Items

Full Usage: this.Items

Returns: IList<'T>

The input items this Bvh was built from. Do not mutate this array.

Returns: IList<'T>

this.ItemsInBox

Full Usage: this.ItemsInBox

Parameters:
    box : BBox - The axis aligned bounding box to search in.
    ?tolerance : float - The tolerance distance around the box. Optional, 0.0 by default.

Returns: ResizeArray<int> A ResizeArray of the indices of the found items in the input array.

Finds the indices of all items whose bounding box is closer to the given axis aligned bounding box than the given tolerance.

box : BBox

The axis aligned bounding box to search in.

?tolerance : float

The tolerance distance around the box. Optional, 0.0 by default.

Returns: ResizeArray<int>

A ResizeArray of the indices of the found items in the input array.

this.ItemsNearPoint

Full Usage: this.ItemsNearPoint

Parameters:
    pt : Pnt - The 3D point to search around.
    ?tolerance : float - The tolerance distance around the point. Optional, 0.0 by default.

Returns: ResizeArray<int> A ResizeArray of the indices of the found items in the input array.

Finds the indices of all items whose bounding box is closer to the given 3D point than the given tolerance. The distance between a point and a box is 0.0 if the point is inside or on the box.

pt : Pnt

The 3D point to search around.

?tolerance : float

The tolerance distance around the point. Optional, 0.0 by default.

Returns: ResizeArray<int>

A ResizeArray of the indices of the found items in the input array.

this.NearestNeighbors

Full Usage: this.NearestNeighbors

Returns: BvhPair[] An array of BvhPair. The entry at index i holds i as IdxA, the index of the item with the nearest bounding box as IdxB and the distance between the boxes.

For every item in the tree finds the item whose bounding box is nearest to its own. The distance between two boxes is 0.0 if they overlap or touch.

Returns: BvhPair[]

An array of BvhPair. The entry at index i holds i as IdxA, the index of the item with the nearest bounding box as IdxB and the distance between the boxes.

this.NearestNeighbors

Full Usage: this.NearestNeighbors

Parameters:
    sqDistance : 'T -> 'T -> float - Returns the exact squared distance between two items.

Returns: BvhPair[] An array of BvhPair. The entry at index i holds i as IdxA, the index of the nearest neighbor of item i as IdxB and the distance between them.

For every item in the tree finds its nearest neighbor item, measured with the given exact squared distance function.

sqDistance : 'T -> 'T -> float

Returns the exact squared distance between two items.

Returns: BvhPair[]

An array of BvhPair. The entry at index i holds i as IdxA, the index of the nearest neighbor of item i as IdxB and the distance between them.

Static members

Static member Description

Bvh.DefaultLeafSize

Full Usage: Bvh.DefaultLeafSize

Returns: int

The default maximum amount of items per leaf node.

Returns: int

Bvh.create (items, getBox, ?leafSize)

Full Usage: Bvh.create (items, getBox, ?leafSize)

Parameters:
    items : 'T seq - The items to build the tree from. They are enumerated and copied to an array at build time.
    getBox : 'T -> BBox - A function returning the axis aligned bounding box of an item. It is called once per item at build time.
    ?leafSize : int - The maximum amount of items per leaf node. Optional, 4 by default.

Returns: Bvh<'T> A new immutable Bvh.

Builds a Bvh from the given sequence of items.

items : 'T seq

The items to build the tree from. They are enumerated and copied to an array at build time.

getBox : 'T -> BBox

A function returning the axis aligned bounding box of an item. It is called once per item at build time.

?leafSize : int

The maximum amount of items per leaf node. Optional, 4 by default.

Returns: Bvh<'T>

A new immutable Bvh.

Bvh.create (items, getBox, ?leafSize)

Full Usage: Bvh.create (items, getBox, ?leafSize)

Parameters:
    items : ResizeArray<'T> - The items to build the tree from. They are copied to an array at build time.
    getBox : 'T -> BBox - A function returning the axis aligned bounding box of an item. It is called once per item at build time.
    ?leafSize : int - The maximum amount of items per leaf node. Optional, 4 by default.

Returns: Bvh<'T> A new immutable Bvh.

Builds a Bvh from the given resizable array of items.

items : ResizeArray<'T>

The items to build the tree from. They are copied to an array at build time.

getBox : 'T -> BBox

A function returning the axis aligned bounding box of an item. It is called once per item at build time.

?leafSize : int

The maximum amount of items per leaf node. Optional, 4 by default.

Returns: Bvh<'T>

A new immutable Bvh.

Bvh.create (items, getBox, ?leafSize)

Full Usage: Bvh.create (items, getBox, ?leafSize)

Parameters:
    items : 'T[] - The items to build the tree from. The array is referenced, not copied. Do not mutate it afterwards.
    getBox : 'T -> BBox - A function returning the axis aligned bounding box of an item. It is called once per item at build time.
    ?leafSize : int - The maximum amount of items per leaf node. Optional, 4 by default.

Returns: Bvh<'T> A new immutable Bvh.

Builds a Bvh from the given items. The tree is built top-down by splitting at the median of the item-box centers along the longest axis of the current bounding box.

items : 'T[]

The items to build the tree from. The array is referenced, not copied. Do not mutate it afterwards.

getBox : 'T -> BBox

A function returning the axis aligned bounding box of an item. It is called once per item at build time.

?leafSize : int

The maximum amount of items per leaf node. Optional, 4 by default.

Returns: Bvh<'T>

A new immutable Bvh.

Type something to start searching.