38 #ifndef FCL_MATH_BV_UTILITY_INL_H
39 #define FCL_MATH_BV_UTILITY_INL_H
60 namespace OBB_fit_functions {
69 bv.
axis.setIdentity();
81 const S len_p1p2 = p1p2.norm();
85 bv.
extent << len_p1p2 * 0.5, 0, 0;
86 bv.
To.noalias() = 0.5 * (p1 + p2);
102 len[0] = e[0].squaredNorm();
103 len[1] = e[1].squaredNorm();
104 len[2] = e[2].squaredNorm();
107 if(len[1] > len[0]) imax = 1;
108 if(len[2] > len[imax]) imax = 2;
110 bv.
axis.col(2).noalias() = e[0].cross(e[1]);
111 bv.
axis.col(2).normalize();
112 bv.
axis.col(0) = e[imax];
113 bv.
axis.col(0).normalize();
114 bv.
axis.col(1).noalias() = bv.
axis.col(2).cross(bv.
axis.col(0));
116 getExtentAndCenter<S>(ps,
nullptr,
nullptr,
nullptr, 3, bv.
axis, bv.
To, bv.
extent);
120 template <
typename S>
131 template <
typename S>
139 getCovariance<S>(ps,
nullptr,
nullptr,
nullptr, n, M);
144 getExtentAndCenter<S>(ps,
nullptr,
nullptr,
nullptr, n, bv.
axis, bv.
To, bv.
extent);
172 namespace RSS_fit_functions {
176 template <
typename S>
181 bv.
axis.setIdentity();
188 template <
typename S>
195 const S len_p1p2 = p1p2.norm();
206 template <
typename S>
218 len[0] = e[0].squaredNorm();
219 len[1] = e[1].squaredNorm();
220 len[2] = e[2].squaredNorm();
223 if(len[1] > len[0]) imax = 1;
224 if(len[2] > len[imax]) imax = 2;
226 bv.
axis.col(2).noalias() = e[0].cross(e[1]).normalized();
227 bv.
axis.col(0).noalias() = e[imax].normalized();
228 bv.
axis.col(1).noalias() = bv.
axis.col(2).cross(bv.
axis.col(0));
230 getRadiusAndOriginAndRectangleSize<S>(ps,
nullptr,
nullptr,
nullptr, 3, bv.
axis, bv.
To, bv.
l, bv.
r);
234 template <
typename S>
245 template <
typename S>
253 getCovariance<S>(ps,
nullptr,
nullptr,
nullptr, n, M);
258 getRadiusAndOriginAndRectangleSize<S>(ps,
nullptr,
nullptr,
nullptr, n, bv.
axis, bv.
To, bv.
l, bv.
r);
291 namespace kIOS_fit_functions {
295 template <
typename S>
309 template <
typename S>
318 const S len_p1p2 = p1p2.norm();
322 S r0 = len_p1p2 * 0.5;
324 bv.
obb.
To.noalias() = (p1 + p2) * 0.5;
339 delta.noalias() = bv.
obb.
axis.col(2) * r1cosA;
345 template <
typename S>
359 len[0] = e[0].squaredNorm();
360 len[1] = e[1].squaredNorm();
361 len[2] = e[2].squaredNorm();
364 if(len[1] > len[0]) imax = 1;
365 if(len[2] > len[imax]) imax = 2;
367 bv.
obb.
axis.col(2).noalias() = e[0].cross(e[1]).normalized();
368 bv.
obb.
axis.col(0) = e[imax].normalized();
385 bv.
spheres[1].o = center - delta;
387 bv.
spheres[2].o = center + delta;
391 template <
typename S>
399 getCovariance<S>(ps,
nullptr,
nullptr,
nullptr, n, M);
408 S r0 = maximumDistance<S>(ps,
nullptr,
nullptr,
nullptr, n, center);
426 bv.
spheres[1].o = center - delta;
427 bv.
spheres[2].o = center + delta;
430 r11 = maximumDistance<S>(ps,
nullptr,
nullptr,
nullptr, n, bv.
spheres[1].o);
431 r12 = maximumDistance<S>(ps,
nullptr,
nullptr,
nullptr, n, bv.
spheres[2].o);
442 Vector3<S> delta = bv.
obb.
axis.col(1) * (sqrt(r10 * r10 - extent[0] * extent[0] - extent[2] * extent[2]) - extent[1]);
447 r21 = maximumDistance<S>(ps,
nullptr,
nullptr,
nullptr, n, bv.
spheres[3].o);
448 r22 = maximumDistance<S>(ps,
nullptr,
nullptr,
nullptr, n, bv.
spheres[4].o);
483 namespace OBBRSS_fit_functions {
487 template <
typename S>
496 template <
typename S>
505 template <
typename S>
514 template <
typename S>
543 template <
typename S,
typename BV>
548 for(
int i = 0; i < n; ++i)
554 template <
typename S>
580 template <
typename S>
603 template <
typename S>
626 template <
typename S>
650 struct Fitter<double, OBB<double>>;
654 struct Fitter<double, RSS<double>>;
658 struct Fitter<double, kIOS<double>>;
662 struct Fitter<double, OBBRSS<double>>;
669 template <
typename BV>
682 template <
typename S,
typename BV1,
typename BV2>
698 template <
typename S>
705 S
r = (bv1.
max_ - bv1.
min_).norm() * 0.5;
708 bv2.
min_ = center2 - delta;
709 bv2.
max_ = center2 + delta;
714 template <
typename S>
756 bv2.
To.noalias() = tf1 * bv1.
center();
758 bv2.
axis = tf1.linear();
763 template <
typename S>
770 bv2.
To.noalias() = tf1 * bv1.
To;
771 bv2.
axis.noalias() = tf1.linear() * bv1.
axis;
776 template <
typename S>
787 template <
typename S>
793 bv2.
extent << bv1.
l[0] * 0.5 + bv1.
r, bv1.
l[1] * 0.5 + bv1.
r, bv1.
r;
794 bv2.
To.noalias() = tf1 * bv1.
center();
795 bv2.
axis.noalias() = tf1.linear() * bv1.
axis;
800 template <
typename S,
typename BV1>
807 S
r =
Vector3<S>(bv1.width(), bv1.height(), bv1.depth()).norm() * 0.5;
810 bv2.
min_ = center2 - delta;
811 bv2.
max_ = center2 + delta;
816 template <
typename S,
typename BV1>
829 template <
typename S>
841 bv2.
axis.noalias() = tf1.linear() * bv1.
axis;
844 bv2.
l[0] = 2 * (bv1.
extent[0]);
846 bv2.
l[1] = 2 * (bv1.
extent[1]);
856 template <
typename S>
862 bv2.
To.noalias() = tf1 * bv1.
To;
863 bv2.
axis.noalias() = tf1.linear() * bv1.
axis;
872 template <
typename S>
883 template <
typename S>
891 std::size_t
id[3] = {0, 1, 2};
893 for(std::size_t i = 1; i < 3; ++i)
895 for(std::size_t j = i; j > 0; --j)
905 std::size_t tmp =
id[j];
914 bv2.
r = extent[
id[2]];
915 bv2.
l[0] = (extent[
id[0]]) * 2;
916 bv2.
l[1] = (extent[
id[1]]) * 2;
919 bool left_hand = (
id[0] == (
id[1] + 1) % 3);
921 bv2.
axis.col(0) = -R.col(
id[0]);
923 bv2.
axis.col(0) = R.col(
id[0]);
924 bv2.
axis.col(1) = R.col(
id[1]);
925 bv2.
axis.col(2) = R.col(
id[2]);
932 class FCL_EXPORT ConvertBVImpl<double, AABB<double>,
AABB<double>>;
936 class FCL_EXPORT ConvertBVImpl<double, AABB<double>,
OBB<double>>;
940 class FCL_EXPORT ConvertBVImpl<double, OBB<double>,
OBB<double>>;
944 class FCL_EXPORT ConvertBVImpl<double, OBBRSS<double>,
OBB<double>>;
948 class FCL_EXPORT ConvertBVImpl<double, RSS<double>,
OBB<double>>;
952 class FCL_EXPORT ConvertBVImpl<double, OBB<double>,
RSS<double>>;
956 class FCL_EXPORT ConvertBVImpl<double, RSS<double>,
RSS<double>>;
960 class FCL_EXPORT ConvertBVImpl<double, OBBRSS<double>,
RSS<double>>;
964 class FCL_EXPORT ConvertBVImpl<double, AABB<double>,
RSS<double>>;
971 template <
typename BV1,
typename BV2>
976 static_assert(std::is_same<typename BV1::S, typename BV2::S>::value,
977 "The scalar type of BV1 and BV2 should be the same");