38 #ifndef FCL_BV_KDOP_INL_H 39 #define FCL_BV_KDOP_INL_H 41 #include "fcl/math/bv/kDOP.h" 48 class KDOP<double, 16>;
52 class KDOP<double, 18>;
56 class KDOP<double, 24>;
60 void minmax(
double a,
double b,
double& minv,
double& maxv);
64 void minmax(
double p,
double& minv,
double& maxv);
68 void getDistances<double, 5>(
const Vector3<double>& p,
double* d);
72 void getDistances<double, 6>(
const Vector3<double>& p,
double* d);
76 void getDistances<double, 9>(
const Vector3<double>& p,
double* d);
79 template <
typename S, std::
size_t N>
82 static_assert(N == 16 || N == 18 || N == 24,
"N should be 16, 18, or 24");
84 S real_max = std::numeric_limits<S>::max();
85 for(std::size_t i = 0; i < N / 2; ++i)
88 dist_[i + N / 2] = -real_max;
93 template <
typename S, std::
size_t N>
96 for(std::size_t i = 0; i < 3; ++i)
98 dist_[i] = dist_[N / 2 + i] = v[i];
103 for(std::size_t i = 0; i < (N - 6) / 2; ++i)
105 dist_[3 + i] = dist_[3 + i + N / 2] = d[i];
110 template <
typename S, std::
size_t N>
113 for(std::size_t i = 0; i < 3; ++i)
115 minmax(a[i], b[i], dist_[i], dist_[i + N / 2]);
118 S ad[(N - 6) / 2], bd[(N - 6) / 2];
121 for(std::size_t i = 0; i < (N - 6) / 2; ++i)
123 minmax(ad[i], bd[i], dist_[3 + i], dist_[3 + i + N / 2]);
128 template <
typename S, std::
size_t N>
131 for(std::size_t i = 0; i < N / 2; ++i)
133 if(dist_[i] > other.dist_[i + N / 2])
return false;
134 if(dist_[i + N / 2] < other.dist_[i])
return false;
141 template <
typename S, std::
size_t N>
144 for(std::size_t i = 0; i < 3; ++i)
146 if(p[i] < dist_[i] || p[i] > dist_[i + N / 2])
152 for(std::size_t i = 0; i < (N - 6) / 2; ++i)
154 if(d[i] < dist_[3 + i] || d[i] > dist_[i + 3 + N / 2])
162 template <
typename S, std::
size_t N>
165 for(std::size_t i = 0; i < 3; ++i)
167 minmax(p[i], dist_[i], dist_[N / 2 + i]);
172 for(std::size_t i = 0; i < (N - 6) / 2; ++i)
174 minmax(pd[i], dist_[3 + i], dist_[3 + N / 2 + i]);
181 template <
typename S, std::
size_t N>
184 for(std::size_t i = 0; i < N / 2; ++i)
186 dist_[i] = std::min(other.dist_[i], dist_[i]);
187 dist_[i + N / 2] = std::max(other.dist_[i + N / 2], dist_[i + N / 2]);
193 template <
typename S, std::
size_t N>
201 template <
typename S, std::
size_t N>
204 return dist_[N / 2] - dist_[0];
208 template <
typename S, std::
size_t N>
211 return dist_[N / 2 + 1] - dist_[1];
215 template <
typename S, std::
size_t N>
218 return dist_[N / 2 + 2] - dist_[2];
222 template <
typename S, std::
size_t N>
225 return width() * height() * depth();
229 template <
typename S, std::
size_t N>
232 return width() * width() + height() * height() + depth() * depth();
236 template <
typename S, std::
size_t N>
239 return Vector3<S>(dist_[0] + dist_[N / 2], dist_[1] + dist_[N / 2 + 1], dist_[2] + dist_[N / 2 + 2]) * 0.5;
243 template <
typename S, std::
size_t N>
246 std::cerr <<
"KDOP distance not implemented!" << std::endl;
251 template <
typename S, std::
size_t N>
258 template <
typename S, std::
size_t N>
265 template <
typename S, std::
size_t N,
typename Derived>
267 const KDOP<S, N>& bv,
const Eigen::MatrixBase<Derived>& t)
270 for(std::size_t i = 0; i < 3; ++i)
273 res.dist(N / 2 + i) += t[i];
278 for(std::size_t i = 0; i < (N - 6) / 2; ++i)
280 res.dist(3 + i) += d[i];
281 res.dist(3 + i + N / 2) += d[i];
288 template <
typename S>
289 void minmax(S a, S b, S& minv, S& maxv)
304 template <
typename S>
305 void minmax(S p, S& minv, S& maxv)
307 if(p > maxv) maxv = p;
308 if(p < minv) minv = p;
312 template <
typename S, std::
size_t N>
315 static void run(
const Vector3<S>& , S* )
322 template <
typename S, std::
size_t N>
329 template <
typename S>
332 static void run(
const Vector3<S>& p, S* d)
343 template <
typename S>
346 static void run(
const Vector3<S>& p, S* d)
358 template <
typename S>
361 static void run(
const Vector3<S>& p, S* d)
369 d[6] = p[0] + p[1] - p[2];
370 d[7] = p[0] + p[2] - p[1];
371 d[8] = p[1] + p[2] - p[0];
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
S depth() const
The (AABB) depth.
Definition: kDOP-inl.h:216
void getDistances(const Vector3< S > &p, S *d)
Compute the distances to planes with normals from KDOP vectors except those of AABB face planes...
Definition: kDOP-inl.h:323
AABB< S > translate(const AABB< S > &aabb, const Eigen::MatrixBase< Derived > &t)
translate the center of AABB by t
Definition: AABB-inl.h:345
S width() const
The (AABB) width.
Definition: kDOP-inl.h:202
KDOP< S, N > operator+(const KDOP< S, N > &other) const
Create a KDOP by mergin two KDOPs.
Definition: kDOP-inl.h:194
S distance(const KDOP< S, N > &other, Vector3< S > *P=nullptr, Vector3< S > *Q=nullptr) const
The distance between two KDOP<S, N>. Not implemented.
Definition: kDOP-inl.h:244
Definition: kDOP-inl.h:344
S size() const
Size of the kDOP (used in BV_Splitter to order two kDOPs)
Definition: kDOP-inl.h:230
KDOP< S, N > & operator+=(const Vector3< S > &p)
Merge the point and the KDOP.
Definition: kDOP-inl.h:163
bool overlap(const KDOP< S, N > &other) const
Check whether two KDOPs are overlapped.
Definition: kDOP-inl.h:129
KDOP class describes the KDOP collision structures. K is set as the template parameter, which should be 16, 18, or 24 The KDOP structure is defined by some pairs of parallel planes defined by some axes. For K = 16, the planes are 6 AABB planes and 10 diagonal planes that cut off some space of the edges: (-1,0,0) and (1,0,0) -> indices 0 and 8 (0,-1,0) and (0,1,0) -> indices 1 and 9 (0,0,-1) and (0,0,1) -> indices 2 and 10 (-1,-1,0) and (1,1,0) -> indices 3 and 11 (-1,0,-1) and (1,0,1) -> indices 4 and 12 (0,-1,-1) and (0,1,1) -> indices 5 and 13 (-1,1,0) and (1,-1,0) -> indices 6 and 14 (-1,0,1) and (1,0,-1) -> indices 7 and 15 For K = 18, the planes are 6 AABB planes and 12 diagonal planes that cut off some space of the edges: (-1,0,0) and (1,0,0) -> indices 0 and 9 (0,-1,0) and (0,1,0) -> indices 1 and 10 (0,0,-1) and (0,0,1) -> indices 2 and 11 (-1,-1,0) and (1,1,0) -> indices 3 and 12 (-1,0,-1) and (1,0,1) -> indices 4 and 13 (0,-1,-1) and (0,1,1) -> indices 5 and 14 (-1,1,0) and (1,-1,0) -> indices 6 and 15 (-1,0,1) and (1,0,-1) -> indices 7 and 16 (0,-1,1) and (0,1,-1) -> indices 8 and 17 For K = 18, the planes are 6 AABB planes and 18 diagonal planes that cut off some space of the edges: (-1,0,0) and (1,0,0) -> indices 0 and 12 (0,-1,0) and (0,1,0) -> indices 1 and 13 (0,0,-1) and (0,0,1) -> indices 2 and 14 (-1,-1,0) and (1,1,0) -> indices 3 and 15 (-1,0,-1) and (1,0,1) -> indices 4 and 16 (0,-1,-1) and (0,1,1) -> indices 5 and 17 (-1,1,0) and (1,-1,0) -> indices 6 and 18 (-1,0,1) and (1,0,-1) -> indices 7 and 19 (0,-1,1) and (0,1,-1) -> indices 8 and 20 (-1, -1, 1) and (1, 1, -1) –> indices 9 and 21 (-1, 1, -1) and (1, -1, 1) –> indices 10 and 22 (1, -1, -1) and (-1, 1, 1) –> indices 11 and 23.
Definition: kDOP.h:84
Vector3< S > center() const
The (AABB) center.
Definition: kDOP-inl.h:237
KDOP()
Creating kDOP containing nothing.
Definition: kDOP-inl.h:80
S volume() const
The (AABB) volume.
Definition: kDOP-inl.h:223
S height() const
The (AABB) height.
Definition: kDOP-inl.h:209
Definition: kDOP-inl.h:359
Definition: kDOP-inl.h:313
Definition: kDOP-inl.h:330