10 #ifndef EIGEN_BVALGORITHMS_H
11 #define EIGEN_BVALGORITHMS_H
19 #ifndef EIGEN_PARSED_BY_DOXYGEN
20 template<
typename BVH,
typename Intersector>
21 bool intersect_helper(
const BVH &tree, Intersector &intersector,
typename BVH::Index root)
23 typedef typename BVH::Index
Index;
24 typedef typename BVH::VolumeIterator VolIter;
25 typedef typename BVH::ObjectIterator ObjIter;
27 VolIter vBegin = VolIter(), vEnd = VolIter();
28 ObjIter oBegin = ObjIter(), oEnd = ObjIter();
30 std::vector<Index> todo(1, root);
32 while(!todo.empty()) {
33 tree.getChildren(todo.back(), vBegin, vEnd, oBegin, oEnd);
36 for(; vBegin != vEnd; ++vBegin)
37 if(intersector.intersectVolume(tree.getVolume(*vBegin)))
38 todo.push_back(*vBegin);
40 for(; oBegin != oEnd; ++oBegin)
41 if(intersector.intersectObject(*oBegin))
48 template<
typename Volume1,
typename Object1,
typename Object2,
typename Intersector>
49 struct intersector_helper1
51 intersector_helper1(
const Object2 &inStored, Intersector &in) : stored(inStored), intersector(in) {}
52 bool intersectVolume(
const Volume1 &vol) {
return intersector.intersectVolumeObject(vol, stored); }
53 bool intersectObject(
const Object1 &obj) {
return intersector.intersectObjectObject(obj, stored); }
55 Intersector &intersector;
57 intersector_helper1& operator=(
const intersector_helper1&);
60 template<
typename Volume2,
typename Object2,
typename Object1,
typename Intersector>
61 struct intersector_helper2
63 intersector_helper2(
const Object1 &inStored, Intersector &in) : stored(inStored), intersector(in) {}
64 bool intersectVolume(
const Volume2 &vol) {
return intersector.intersectObjectVolume(stored, vol); }
65 bool intersectObject(
const Object2 &obj) {
return intersector.intersectObjectObject(stored, obj); }
67 Intersector &intersector;
69 intersector_helper2& operator=(
const intersector_helper2&);
80 template<
typename BVH,
typename Intersector>
83 internal::intersect_helper(tree, intersector, tree.getRootIndex());
94 template<
typename BVH1,
typename BVH2,
typename Intersector>
95 void BVIntersect(
const BVH1 &tree1,
const BVH2 &tree2, Intersector &intersector)
97 typedef typename BVH1::Index Index1;
98 typedef typename BVH2::Index Index2;
99 typedef internal::intersector_helper1<typename BVH1::Volume, typename BVH1::Object, typename BVH2::Object, Intersector> Helper1;
100 typedef internal::intersector_helper2<typename BVH2::Volume, typename BVH2::Object, typename BVH1::Object, Intersector> Helper2;
101 typedef typename BVH1::VolumeIterator VolIter1;
102 typedef typename BVH1::ObjectIterator ObjIter1;
103 typedef typename BVH2::VolumeIterator VolIter2;
104 typedef typename BVH2::ObjectIterator ObjIter2;
106 VolIter1 vBegin1 = VolIter1(), vEnd1 = VolIter1();
107 ObjIter1 oBegin1 = ObjIter1(), oEnd1 = ObjIter1();
108 VolIter2 vBegin2 = VolIter2(), vEnd2 = VolIter2(), vCur2 = VolIter2();
109 ObjIter2 oBegin2 = ObjIter2(), oEnd2 = ObjIter2(), oCur2 = ObjIter2();
111 std::vector<std::pair<Index1, Index2> > todo(1, std::make_pair(tree1.getRootIndex(), tree2.getRootIndex()));
113 while(!todo.empty()) {
114 tree1.getChildren(todo.back().first, vBegin1, vEnd1, oBegin1, oEnd1);
115 tree2.getChildren(todo.back().second, vBegin2, vEnd2, oBegin2, oEnd2);
118 for(; vBegin1 != vEnd1; ++vBegin1) {
119 const typename BVH1::Volume &vol1 = tree1.getVolume(*vBegin1);
120 for(vCur2 = vBegin2; vCur2 != vEnd2; ++vCur2) {
121 if(intersector.intersectVolumeVolume(vol1, tree2.getVolume(*vCur2)))
122 todo.push_back(std::make_pair(*vBegin1, *vCur2));
125 for(oCur2 = oBegin2; oCur2 != oEnd2; ++oCur2) {
126 Helper1 helper(*oCur2, intersector);
127 if(internal::intersect_helper(tree1, helper, *vBegin1))
132 for(; oBegin1 != oEnd1; ++oBegin1) {
133 for(vCur2 = vBegin2; vCur2 != vEnd2; ++vCur2) {
134 Helper2 helper(*oBegin1, intersector);
135 if(internal::intersect_helper(tree2, helper, *vCur2))
139 for(oCur2 = oBegin2; oCur2 != oEnd2; ++oCur2) {
140 if(intersector.intersectObjectObject(*oBegin1, *oCur2))
149 #ifndef EIGEN_PARSED_BY_DOXYGEN
150 template<
typename BVH,
typename Minimizer>
151 typename Minimizer::Scalar minimize_helper(
const BVH &tree, Minimizer &minimizer,
typename BVH::Index root,
typename Minimizer::Scalar minimum)
153 typedef typename Minimizer::Scalar Scalar;
154 typedef typename BVH::Index
Index;
155 typedef std::pair<Scalar, Index> QueueElement;
156 typedef typename BVH::VolumeIterator VolIter;
157 typedef typename BVH::ObjectIterator ObjIter;
159 VolIter vBegin = VolIter(), vEnd = VolIter();
160 ObjIter oBegin = ObjIter(), oEnd = ObjIter();
161 std::priority_queue<QueueElement, std::vector<QueueElement>, std::greater<QueueElement> > todo;
163 todo.push(std::make_pair(Scalar(), root));
165 while(!todo.empty()) {
166 tree.getChildren(todo.top().second, vBegin, vEnd, oBegin, oEnd);
169 for(; oBegin != oEnd; ++oBegin)
170 minimum = (
std::min)(minimum, minimizer.minimumOnObject(*oBegin));
172 for(; vBegin != vEnd; ++vBegin) {
173 Scalar val = minimizer.minimumOnVolume(tree.getVolume(*vBegin));
175 todo.push(std::make_pair(val, *vBegin));
184 template<
typename Volume1,
typename Object1,
typename Object2,
typename Minimizer>
185 struct minimizer_helper1
187 typedef typename Minimizer::Scalar Scalar;
188 minimizer_helper1(
const Object2 &inStored, Minimizer &m) : stored(inStored), minimizer(
m) {}
189 Scalar minimumOnVolume(
const Volume1 &vol) {
return minimizer.minimumOnVolumeObject(vol, stored); }
190 Scalar minimumOnObject(
const Object1 &obj) {
return minimizer.minimumOnObjectObject(obj, stored); }
192 Minimizer &minimizer;
194 minimizer_helper1& operator=(
const minimizer_helper1&);
197 template<
typename Volume2,
typename Object2,
typename Object1,
typename Minimizer>
198 struct minimizer_helper2
200 typedef typename Minimizer::Scalar Scalar;
201 minimizer_helper2(
const Object1 &inStored, Minimizer &m) : stored(inStored), minimizer(
m) {}
202 Scalar minimumOnVolume(
const Volume2 &vol) {
return minimizer.minimumOnObjectVolume(stored, vol); }
203 Scalar minimumOnObject(
const Object2 &obj) {
return minimizer.minimumOnObjectObject(stored, obj); }
205 Minimizer &minimizer;
207 minimizer_helper2& operator=(
const minimizer_helper2&);
220 template<
typename BVH,
typename Minimizer>
221 typename Minimizer::Scalar
BVMinimize(
const BVH &tree, Minimizer &minimizer)
236 template<
typename BVH1,
typename BVH2,
typename Minimizer>
237 typename Minimizer::Scalar
BVMinimize(
const BVH1 &tree1,
const BVH2 &tree2, Minimizer &minimizer)
239 typedef typename Minimizer::Scalar Scalar;
240 typedef typename BVH1::Index Index1;
241 typedef typename BVH2::Index Index2;
242 typedef internal::minimizer_helper1<typename BVH1::Volume, typename BVH1::Object, typename BVH2::Object, Minimizer> Helper1;
243 typedef internal::minimizer_helper2<typename BVH2::Volume, typename BVH2::Object, typename BVH1::Object, Minimizer> Helper2;
244 typedef std::pair<Scalar, std::pair<Index1, Index2> > QueueElement;
245 typedef typename BVH1::VolumeIterator VolIter1;
246 typedef typename BVH1::ObjectIterator ObjIter1;
247 typedef typename BVH2::VolumeIterator VolIter2;
248 typedef typename BVH2::ObjectIterator ObjIter2;
250 VolIter1 vBegin1 = VolIter1(), vEnd1 = VolIter1();
251 ObjIter1 oBegin1 = ObjIter1(), oEnd1 = ObjIter1();
252 VolIter2 vBegin2 = VolIter2(), vEnd2 = VolIter2(), vCur2 = VolIter2();
253 ObjIter2 oBegin2 = ObjIter2(), oEnd2 = ObjIter2(), oCur2 = ObjIter2();
254 std::priority_queue<QueueElement, std::vector<QueueElement>, std::greater<QueueElement> > todo;
257 todo.push(std::make_pair(Scalar(), std::make_pair(tree1.getRootIndex(), tree2.getRootIndex())));
259 while(!todo.empty()) {
260 tree1.getChildren(todo.top().second.first, vBegin1, vEnd1, oBegin1, oEnd1);
261 tree2.getChildren(todo.top().second.second, vBegin2, vEnd2, oBegin2, oEnd2);
264 for(; oBegin1 != oEnd1; ++oBegin1) {
265 for(oCur2 = oBegin2; oCur2 != oEnd2; ++oCur2) {
266 minimum = (
std::min)(minimum, minimizer.minimumOnObjectObject(*oBegin1, *oCur2));
269 for(vCur2 = vBegin2; vCur2 != vEnd2; ++vCur2) {
270 Helper2 helper(*oBegin1, minimizer);
271 minimum = (
std::min)(minimum, internal::minimize_helper(tree2, helper, *vCur2, minimum));
275 for(; vBegin1 != vEnd1; ++vBegin1) {
276 const typename BVH1::Volume &vol1 = tree1.getVolume(*vBegin1);
278 for(oCur2 = oBegin2; oCur2 != oEnd2; ++oCur2) {
279 Helper1 helper(*oCur2, minimizer);
280 minimum = (
std::min)(minimum, internal::minimize_helper(tree1, helper, *vBegin1, minimum));
283 for(vCur2 = vBegin2; vCur2 != vEnd2; ++vCur2) {
284 Scalar val = minimizer.minimumOnVolumeVolume(vol1, tree2.getVolume(*vCur2));
286 todo.push(std::make_pair(val, std::make_pair(*vBegin1, *vCur2)));
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend
void BVIntersect(const BVH &tree, Intersector &intersector)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
CleanedUpDerType< DerType >::type() min(const AutoDiffScalar< DerType > &x, const T &y)
CleanedUpDerType< DerType >::type() max(const AutoDiffScalar< DerType > &x, const T &y)
Minimizer::Scalar BVMinimize(const BVH &tree, Minimizer &minimizer)