10 #ifndef KDBVH_H_INCLUDED
11 #define KDBVH_H_INCLUDED
20 template<
typename Scalar,
int Dim>
21 struct vector_int_pair
26 vector_int_pair(
const VectorType &v,
int i) :
first(
v),
second(
i) {}
34 template<
typename ObjectList,
typename VolumeList,
typename BoxIter>
35 struct get_boxes_helper {
36 void operator()(
const ObjectList &objects, BoxIter boxBegin, BoxIter boxEnd, VolumeList &outBoxes)
38 outBoxes.insert(outBoxes.end(), boxBegin, boxEnd);
44 template<
typename ObjectList,
typename VolumeList>
45 struct get_boxes_helper<ObjectList, VolumeList, int> {
46 void operator()(
const ObjectList &objects,
int,
int, VolumeList &outBoxes)
48 outBoxes.reserve(objects.size());
49 for(
int i = 0;
i < (int)objects.size(); ++
i)
70 template<
typename Scalar_,
int Dim_,
typename _Object>
class KdBVH
75 typedef std::vector<Object, aligned_allocator<Object> >
ObjectList;
78 typedef std::vector<Volume, aligned_allocator<Volume> >
VolumeList;
89 template<
typename OIter,
typename BIter>
KdBVH(OIter begin, OIter
end, BIter boxBegin, BIter boxEnd) {
init(begin,
end, boxBegin, boxEnd); }
93 template<
typename Iter>
void init(Iter begin, Iter
end) {
init(begin,
end, 0, 0); }
97 template<
typename OIter,
typename BIter>
void init(OIter begin, OIter
end, BIter boxBegin, BIter boxEnd)
104 int n =
static_cast<int>(
objects.size());
113 internal::get_boxes_helper<ObjectList, VolumeList, BIter>()(
objects, boxBegin, boxEnd, objBoxes);
115 objCenters.reserve(
n);
119 for(
int i = 0;
i <
n; ++
i)
120 objCenters.push_back(
VIPair(objBoxes[
i].center(),
i));
122 build(objCenters, 0,
n, objBoxes, 0);
126 for(
int i = 0;
i <
n; ++
i)
142 outOEnd = outOBegin +
objects.size();
146 int numBoxes =
static_cast<int>(
boxes.size());
151 outVEnd = outVBegin + 2;
154 else if(
children[idx] >= numBoxes) {
157 outOEnd = outOBegin + 2;
160 outVEnd = outVBegin + 1;
162 outOEnd = outOBegin + 1;
173 typedef internal::vector_int_pair<Scalar, Dim>
VIPair;
174 typedef std::vector<VIPair, aligned_allocator<VIPair> >
VIPairList;
190 boxes.push_back(objBoxes[objCenters[from].second].merged(objBoxes[objCenters[from + 1].second]));
194 else if(to - from == 3) {
196 std::nth_element(objCenters.begin() + from, objCenters.begin() + mid,
198 build(objCenters, from, mid, objBoxes, (dim + 1) %
Dim);
199 int idx1 = (int)
boxes.size() - 1;
200 boxes.push_back(
boxes[idx1].merged(objBoxes[objCenters[mid].second]));
205 int mid = from + (to - from) / 2;
206 nth_element(objCenters.begin() + from, objCenters.begin() + mid,
208 build(objCenters, from, mid, objBoxes, (dim + 1) %
Dim);
209 int idx1 = (int)
boxes.size() - 1;
210 build(objCenters, mid, to, objBoxes, (dim + 1) %
Dim);
211 int idx2 = (int)
boxes.size() - 1;
Array< int, Dynamic, 1 > v
IndexedView_or_VectorBlock operator()(const Indices &indices)
#define EIGEN_ONLY_USED_FOR_DEBUG(x)
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar, Size)
Map< RowVectorXf > v2(M2.data(), M2.size())
M1<< 1, 2, 3, 4, 5, 6, 7, 8, 9;Map< RowVectorXf > v1(M1.data(), M1.size())
A simple bounding volume hierarchy based on AlignedBox.
std::vector< VIPair, aligned_allocator< VIPair > > VIPairList
const Object * ObjectIterator
Matrix< Scalar, Dim, 1 > VectorType
std::vector< Object, aligned_allocator< Object > > ObjectList
void init(Iter begin, Iter end)
AlignedBox< Scalar, Dim > Volume
KdBVH(OIter begin, OIter end, BIter boxBegin, BIter boxEnd)
KdBVH(Iter begin, Iter end)
const Volume & getVolume(Index index) const
internal::vector_int_pair< Scalar, Dim > VIPair
void getChildren(Index index, VolumeIterator &outVBegin, VolumeIterator &outVEnd, ObjectIterator &outOBegin, ObjectIterator &outOEnd) const
void init(OIter begin, OIter end, BIter boxBegin, BIter boxEnd)
Index getRootIndex() const
const int * VolumeIterator
void build(VIPairList &objCenters, int from, int to, const VolumeList &objBoxes, int dim)
std::vector< int > children
std::vector< Volume, aligned_allocator< Volume > > VolumeList
static const lastp1_t end
EIGEN_CONSTEXPR Index first(const T &x) EIGEN_NOEXCEPT
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend
Box2d bounding_box(const Vector2d &v)
VectorComparator(int inDim)
bool operator()(const VIPair &v1, const VIPair &v2) const