38 #ifndef FCL_BV_KDOP_INL_H
39 #define FCL_BV_KDOP_INL_H
62 void minmax(
double a,
double b,
double& minv,
double& maxv);
66 void minmax(
double p,
double& minv,
double& maxv);
81 template <
typename S, std::
size_t N>
85 static_assert(N == 16 || N == 18 || N == 24,
"N should be 16, 18, or 24");
88 for(std::size_t i = 0; i < N / 2; ++i)
91 dist_[i + N / 2] = -real_max;
96 template <
typename S, std::
size_t N>
100 for(std::size_t i = 0; i < 3; ++i)
102 dist_[i] = dist_[N / 2 + i] = v[i];
107 for(std::size_t i = 0; i < (N - 6) / 2; ++i)
109 dist_[3 + i] = dist_[3 + i + N / 2] = d[i];
114 template <
typename S, std::
size_t N>
118 for(std::size_t i = 0; i < 3; ++i)
120 minmax(a[i], b[i], dist_[i], dist_[i + N / 2]);
123 S ad[(N - 6) / 2], bd[(N - 6) / 2];
126 for(std::size_t i = 0; i < (N - 6) / 2; ++i)
128 minmax(ad[i], bd[i], dist_[3 + i], dist_[3 + i + N / 2]);
133 template <
typename S, std::
size_t N>
137 for(std::size_t i = 0; i < N / 2; ++i)
139 if(dist_[i] > other.
dist_[i + N / 2])
return false;
140 if(dist_[i + N / 2] < other.
dist_[i])
return false;
147 template <
typename S, std::
size_t N>
151 for(std::size_t i = 0; i < 3; ++i)
153 if(p[i] < dist_[i] || p[i] > dist_[i + N / 2])
159 for(std::size_t i = 0; i < (N - 6) / 2; ++i)
161 if(d[i] < dist_[3 + i] || d[i] > dist_[i + 3 + N / 2])
169 template <
typename S, std::
size_t N>
173 for(std::size_t i = 0; i < 3; ++i)
175 minmax(p[i], dist_[i], dist_[N / 2 + i]);
180 for(std::size_t i = 0; i < (N - 6) / 2; ++i)
182 minmax(pd[i], dist_[3 + i], dist_[3 + N / 2 + i]);
189 template <
typename S, std::
size_t N>
193 for(std::size_t i = 0; i < N / 2; ++i)
196 dist_[i + N / 2] =
std::max(other.
dist_[i + N / 2], dist_[i + N / 2]);
202 template <
typename S, std::
size_t N>
211 template <
typename S, std::
size_t N>
215 return dist_[N / 2] - dist_[0];
219 template <
typename S, std::
size_t N>
223 return dist_[N / 2 + 1] - dist_[1];
227 template <
typename S, std::
size_t N>
231 return dist_[N / 2 + 2] - dist_[2];
235 template <
typename S, std::
size_t N>
239 return width() * height() * depth();
243 template <
typename S, std::
size_t N>
247 return width() * width() + height() * height() + depth() * depth();
251 template <
typename S, std::
size_t N>
255 return Vector3<S>(dist_[0] + dist_[N / 2], dist_[1] + dist_[N / 2 + 1], dist_[2] + dist_[N / 2 + 2]) * 0.5;
259 template <
typename S, std::
size_t N>
267 std::cerr <<
"KDOP distance not implemented!\n";
272 template <
typename S, std::
size_t N>
280 template <
typename S, std::
size_t N>
288 template <
typename S, std::
size_t N,
typename Derived>
291 const KDOP<S, N>& bv,
const Eigen::MatrixBase<Derived>& t)
294 for(std::size_t i = 0; i < 3; ++i)
297 res.
dist(N / 2 + i) += t[i];
302 for(std::size_t i = 0; i < (N - 6) / 2; ++i)
304 res.
dist(3 + i) += d[i];
305 res.
dist(3 + i + N / 2) += d[i];
312 template <
typename S>
329 template <
typename S>
333 if(p > maxv) maxv = p;
334 if(p < minv) minv = p;
338 template <
typename S, std::
size_t N>
348 template <
typename S, std::
size_t N>
356 template <
typename S>
370 template <
typename S>
385 template <
typename S>
396 d[6] = p[0] + p[1] - p[2];
397 d[7] = p[0] + p[2] - p[1];
398 d[8] = p[1] + p[2] - p[0];