39 #ifndef COAL_MORTON_INL_H 
   40 #define COAL_MORTON_INL_H 
   50   return std::max(std::min((uint32_t)(x * (S)n), 
uint32_t(n - 1)), 
uint32_t(0));
 
   55 morton_functor<S, uint32_t>::morton_functor(
const AABB& bbox)
 
   57       inv(1.0 / (bbox.max_[0] - bbox.min_[0]),
 
   58           1.0 / (bbox.max_[1] - bbox.min_[1]),
 
   59           1.0 / (bbox.max_[2] - bbox.min_[2])) {
 
   65 uint32_t morton_functor<S, uint32_t>::operator()(
const Vec3s& point)
 const {
 
   66   uint32_t x = detail::quantize((point[0] - base[0]) * inv[0], 1024u);
 
   67   uint32_t y = detail::quantize((point[1] - base[1]) * inv[1], 1024u);
 
   68   uint32_t z = detail::quantize((point[2] - base[2]) * inv[2], 1024u);
 
   70   return detail::morton_code(x, y, z);
 
   75 morton_functor<S, uint64_t>::morton_functor(
const AABB& bbox)
 
   77       inv(1.0 / (bbox.max_[0] - bbox.min_[0]),
 
   78           1.0 / (bbox.max_[1] - bbox.min_[1]),
 
   79           1.0 / (bbox.max_[2] - bbox.min_[2])) {
 
   85 uint64_t morton_functor<S, uint64_t>::operator()(
const Vec3s& point)
 const {
 
   86   uint32_t x = detail::quantize((point[0] - base[0]) * inv[0], 1u << 20);
 
   87   uint32_t y = detail::quantize((point[1] - base[1]) * inv[1], 1u << 20);
 
   88   uint32_t z = detail::quantize((point[2] - base[2]) * inv[2], 1u << 20);
 
   90   return detail::morton_code60(x, y, z);
 
   95 constexpr 
size_t morton_functor<S, uint64_t>::bits() {
 
  100 template <
typename S>
 
  101 constexpr 
size_t morton_functor<S, uint32_t>::bits() {
 
  106 template <
typename S, 
size_t N>
 
  107 morton_functor<S, std::bitset<N>>::morton_functor(
const AABB& bbox)
 
  109       inv(1.0 / (bbox.max_[0] - bbox.min_[0]),
 
  110           1.0 / (bbox.max_[1] - bbox.min_[1]),
 
  111           1.0 / (bbox.max_[2] - bbox.min_[2])) {
 
  116 template <
typename S, 
size_t N>
 
  117 std::bitset<N> morton_functor<S, std::bitset<N>>::operator()(
 
  118     const Vec3s& point) 
const {
 
  119   S 
x = (point[0] - 
base[0]) * inv[0];
 
  120   S 
y = (point[1] - 
base[1]) * inv[1];
 
  121   S z = (point[2] - 
base[2]) * inv[2];
 
  122   int start_bit = bits() - 1;
 
  129   for (
size_t i = 0; i < bits() / 3; ++i) {
 
  130     bset[start_bit--] = ((z < 1) ? 0 : 1);
 
  131     bset[start_bit--] = ((
y < 1) ? 0 : 1);
 
  132     bset[start_bit--] = ((
x < 1) ? 0 : 1);
 
  133     x = ((
x >= 1) ? 2 * (x - 1) : 2 * 
x);
 
  134     y = ((
y >= 1) ? 2 * (y - 1) : 2 * 
y);
 
  135     z = ((z >= 1) ? 2 * (z - 1) : 2 * z);
 
  142 template <
typename S, 
size_t N>
 
  143 constexpr 
size_t morton_functor<S, std::bitset<N>>::bits() {