39 #ifndef FCL_MORTON_INL_H
40 #define FCL_MORTON_INL_H
54 struct morton_functor<double, uint32>;
58 struct morton_functor<double, uint64>;
69 morton_functor<S, uint32>::morton_functor(
const AABB<S>& bbox)
71 inv(1.0 / (bbox.max_[0] - bbox.min_[0]),
72 1.0 / (bbox.max_[1] - bbox.min_[1]),
73 1.0 / (bbox.max_[2] - bbox.min_[2]))
80 uint32 morton_functor<S, uint32>::operator()(
const Vector3<S>&
point)
const
82 uint32 x = detail::quantize((
point[0] - base[0]) * inv[0], 1024u);
83 uint32 y = detail::quantize((
point[1] - base[1]) * inv[1], 1024u);
84 uint32 z = detail::quantize((
point[2] - base[2]) * inv[2], 1024u);
86 return detail::morton_code(x, y, z);
91 morton_functor<S, uint64>::morton_functor(
const AABB<S>& bbox)
93 inv(1.0 / (bbox.max_[0] - bbox.min_[0]),
94 1.0 / (bbox.max_[1] - bbox.min_[1]),
95 1.0 / (bbox.max_[2] - bbox.min_[2]))
102 uint64 morton_functor<S, uint64>::operator()(
const Vector3<S>&
point)
const
104 uint32 x = detail::quantize((
point[0] - base[0]) * inv[0], 1u << 20);
105 uint32 y = detail::quantize((
point[1] - base[1]) * inv[1], 1u << 20);
106 uint32 z = detail::quantize((
point[2] - base[2]) * inv[2], 1u << 20);
108 return detail::morton_code60(x, y, z);
113 constexpr
size_t morton_functor<S, uint64>::bits()
120 constexpr
size_t morton_functor<S, uint32>::bits()
126 template<
typename S,
size_t N>
127 morton_functor<S, std::bitset<N>>::morton_functor(
const AABB<S>& bbox)
129 inv(1.0 / (bbox.max_[0] - bbox.min_[0]),
130 1.0 / (bbox.max_[1] - bbox.min_[1]),
131 1.0 / (bbox.max_[2] - bbox.min_[2]))
137 template<
typename S,
size_t N>
138 std::bitset<N> morton_functor<S, std::bitset<N>>::operator()(
139 const Vector3<S>&
point)
const
141 S x = (
point[0] - base[0]) * inv[0];
142 S y = (
point[1] - base[1]) * inv[1];
143 S z = (
point[2] - base[2]) * inv[2];
144 int start_bit = bits() - 1;
151 for(
size_t i = 0; i < bits()/3; ++i)
153 bset[start_bit--] = ((z < 1) ? 0 : 1);
154 bset[start_bit--] = ((y < 1) ? 0 : 1);
155 bset[start_bit--] = ((x < 1) ? 0 : 1);
156 x = ((x >= 1) ? 2*(x-1) : 2*x);
157 y = ((y >= 1) ? 2*(y-1) : 2*y);
158 z = ((z >= 1) ? 2*(z-1) : 2*z);
165 template<
typename S,
size_t N>
166 constexpr
size_t morton_functor<S, std::bitset<N>>::bits()