Warning, /include/eigen3/unsupported/Eigen/BVH is written in an unsupported language. File is not indexed.
0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2009 Ilya Baran <ibaran@mit.edu>
0005 //
0006 // This Source Code Form is subject to the terms of the Mozilla
0007 // Public License v. 2.0. If a copy of the MPL was not distributed
0008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0009
0010 #ifndef EIGEN_BVH_MODULE_H
0011 #define EIGEN_BVH_MODULE_H
0012
0013 #include "../../Eigen/Core"
0014 #include "../../Eigen/Geometry"
0015 #include "../../Eigen/StdVector"
0016 #include <algorithm>
0017 #include <queue>
0018
0019 namespace Eigen {
0020
0021 /**
0022 * \defgroup BVH_Module BVH module
0023 * \brief This module provides generic bounding volume hierarchy algorithms
0024 * and reference tree implementations.
0025 *
0026 *
0027 * \code
0028 * #include <unsupported/Eigen/BVH>
0029 * \endcode
0030 *
0031 * A bounding volume hierarchy (BVH) can accelerate many geometric queries. This module provides a generic implementation
0032 * of the two basic algorithms over a BVH: intersection of a query object against all objects in the hierarchy and minimization
0033 * of a function over the objects in the hierarchy. It also provides intersection and minimization over a cartesian product of
0034 * two BVH's. A BVH accelerates intersection by using the fact that if a query object does not intersect a volume, then it cannot
0035 * intersect any object contained in that volume. Similarly, a BVH accelerates minimization because the minimum of a function
0036 * over a volume is no greater than the minimum of a function over any object contained in it.
0037 *
0038 * Some sample queries that can be written in terms of intersection are:
0039 * - Determine all points where a ray intersects a triangle mesh
0040 * - Given a set of points, determine which are contained in a query sphere
0041 * - Given a set of spheres, determine which contain the query point
0042 * - Given a set of disks, determine if any is completely contained in a query rectangle (represent each 2D disk as a point \f$(x,y,r)\f$
0043 * in 3D and represent the rectangle as a pyramid based on the original rectangle and shrinking in the \f$r\f$ direction)
0044 * - Given a set of points, count how many pairs are \f$d\pm\epsilon\f$ apart (done by looking at the cartesian product of the set
0045 * of points with itself)
0046 *
0047 * Some sample queries that can be written in terms of function minimization over a set of objects are:
0048 * - Find the intersection between a ray and a triangle mesh closest to the ray origin (function is infinite off the ray)
0049 * - Given a polyline and a query point, determine the closest point on the polyline to the query
0050 * - Find the diameter of a point cloud (done by looking at the cartesian product and using negative distance as the function)
0051 * - Determine how far two meshes are from colliding (this is also a cartesian product query)
0052 *
0053 * This implementation decouples the basic algorithms both from the type of hierarchy (and the types of the bounding volumes) and
0054 * from the particulars of the query. To enable abstraction from the BVH, the BVH is required to implement a generic mechanism
0055 * for traversal. To abstract from the query, the query is responsible for keeping track of results.
0056 *
0057 * To be used in the algorithms, a hierarchy must implement the following traversal mechanism (see KdBVH for a sample implementation): \code
0058 typedef Volume //the type of bounding volume
0059 typedef Object //the type of object in the hierarchy
0060 typedef Index //a reference to a node in the hierarchy--typically an int or a pointer
0061 typedef VolumeIterator //an iterator type over node children--returns Index
0062 typedef ObjectIterator //an iterator over object (leaf) children--returns const Object &
0063 Index getRootIndex() const //returns the index of the hierarchy root
0064 const Volume &getVolume(Index index) const //returns the bounding volume of the node at given index
0065 void getChildren(Index index, VolumeIterator &outVBegin, VolumeIterator &outVEnd,
0066 ObjectIterator &outOBegin, ObjectIterator &outOEnd) const
0067 //getChildren takes a node index and makes [outVBegin, outVEnd) range over its node children
0068 //and [outOBegin, outOEnd) range over its object children
0069 \endcode
0070 *
0071 * To use the hierarchy, call BVIntersect or BVMinimize, passing it a BVH (or two, for cartesian product) and a minimizer or intersector.
0072 * For an intersection query on a single BVH, the intersector encapsulates the query and must provide two functions:
0073 * \code
0074 bool intersectVolume(const Volume &volume) //returns true if the query intersects the volume
0075 bool intersectObject(const Object &object) //returns true if the intersection search should terminate immediately
0076 \endcode
0077 * The guarantee that BVIntersect provides is that intersectObject will be called on every object whose bounding volume
0078 * intersects the query (but possibly on other objects too) unless the search is terminated prematurely. It is the
0079 * responsibility of the intersectObject function to keep track of the results in whatever manner is appropriate.
0080 * The cartesian product intersection and the BVMinimize queries are similar--see their individual documentation.
0081 *
0082 * The following is a simple but complete example for how to use the BVH to accelerate the search for a closest red-blue point pair:
0083 * \include BVH_Example.cpp
0084 * Output: \verbinclude BVH_Example.out
0085 */
0086 }
0087
0088 //@{
0089
0090 #include "src/BVH/BVAlgorithms.h"
0091 #include "src/BVH/KdBVH.h"
0092
0093 //@}
0094
0095 #endif // EIGEN_BVH_MODULE_H