After one or more calls to
insert
, the internal data structure
of
AABB_tree<AT> must be reconstructed. This procedure has a complexity of
O(n log(n)), where n is the number of primitives of the tree. This
procedure is called implicitly at the first call to a query member
function. You can call
build() explicitly to ensure that the
next call to query functions will not trigger the reconstruction of the
data structure.
template <class Query>
|
bool
|
tree.do_intersect ( Query query)
|
| |
Returns true, iff the query intersects at least one of the input primitives. Type Query must be a type for which
do_intersect
predicates are defined in the AT class.
|
template <class Query>
|
size_type
|
tree.number_of_intersected_primitives ( Query query)
|
| |
Returns the number of primitives intersected by the query. Type Query must be a type for which
do_intersect
predicates are defined in the AT class.
|
template <class Query, class OutputIterator>
|
OutputIterator
|
tree.all_intersected_primitives ( Query query, OutputIterator out)
|
| |
Outputs to the iterator the list of all intersected primitives ids. This function does not compute the intersection points and is hence faster than the function all_intersections function below. Type Query must be a type for which
do_intersect
predicates are defined in the AT class.
|
template <class Query>
|
boost::optional<Primitive::Id>
|
tree.any_intersected_primitive ( Query query)
|
| |
Returns the first encountered intersected primitive id, iff the query intersects at least one of the input primitives. No particular order is guaranteed over the tree traversal, such that, e.g, the primitive returned is not necessarily the closest from the source point of a ray query. Type Query must be a type for which
do_intersect
predicates are defined in the AT class.
|
In the following paragraphs, we discuss details of the implementation of the distance queries. We explain the internal use of hints, how the user can pass his own hints to the tree, and how the user can influence the construction of the secondary data structure used for accelerating distance queries.
Internally, the distance queries algorithms are initialized with some hint, which has the same type as the return type of the query, and this value is refined along a traversal of the tree, until it is optimal, that is to say until it realizes the shortest distance to the primitives. In particular, the exact specification of these internal algorithms is that they minimize the distance to the object composed of the union of the primitives and the hint.
It follows that
- in order to return the exact distance to the set of primitives, the algorithms need the hint to be exactly on the primitives;
- if this is not the case, and if the hint happens to be closer to the query point than any of the primitives, then the hint is returned.
This second observation is reasonable, in the sense that providing a hint to the algorithm means claiming that this hint belongs to the union of the primitives. These considerations about the hints being exactly on the primitives or not are important: in the case where the set of primitives is a triangle soup, and if some of the primitives are large, one may want to provide a much better hint than a vertex of the triangle soup could be. It could be, for example, the barycenter of one of the triangles. But, except with the use of an exact constructions kernel, one cannot easily construct points other than the vertices, that lie exactly on a triangle soup. Hence, providing a good hint sometimes means not being able to provide it exactly on the primitives. In rare occasions, this hint can be returned as the closest point.
In order to accelerate distance queries significantly, the AABB tree builds an internal KD-tree containing a set of potential hints, when the method
accelerate_distance_queries is called. This KD-tree provides very good hints that allow the algorithms to run much faster than with a default hint (such as the
reference_point of the first primitive). The set of potential hints is a sampling of the union of the primitives, which is obtained, by default, by calling the method
reference_point of each of the primitives. However, such a sampling with one point per primitive may not be the most relevant one: if some primitives are very large, it helps inserting more than one sample on them. Conversely, a sparser sampling with less than one point per input primitive is relevant in some cases.
For this reason, the user can provide his own set of sample points:
template <class InputIterator, class PointAndIdBuilder>
|
bool
|
tree.accelerate_distance_queries ( |
InputIterator begin,
InputIterator beyond,
PointAndIdBuilder idb = PointAndIdBuilder()) |
|
| |
Constructs an internal KD-tree containing the specified point set, to be used as the set of potential hints for accelerating the distance queries. Iterator InputIterator must be accepted as argument by the operator provided by the idb object: this operator returns a Point_and_primitive_id corresponding to the object the iterator points to.
|
Note that, in some cases, the user is not able to provide ids of the primitives on which the points lie. In these cases, providing a default value for the ids of the hints is possible. Still, the user should be aware that if she uses the
closest_point_and_primitive method, there is a (tiny) chance that a hint is returned, along with this default value as corresponding primitive id. Hence, the validity of the returned primitive id should be checked in these cases.
As an alternative to using the KD-tree, the user can also provide the hints directly, by using the following methods:
FT
|
tree.squared_distance ( Point query, Point hint)
|
| |
Returns the minimum squared distance between the query point and all input primitives. The internal KD-tree is not used.
|
|
Point
|
tree.closest_point ( Point query, Point hint)
|
| |
Returns the point in the union of all input primitives which is closest to the query. In case there are several closest points, one arbitrarily chosen closest point is returned. The internal KD-tree is not used.
|
|
Point_and_primitive_id
|
tree.closest_point_and_primitive ( Point query, Point_and_primitive_id hint)
|
| |
Returns a Point_and_primitive_id which realizes the smallest distance between the query point and all input primitives. The internal KD-tree is not used.
|