hpp-fcl  3.0.0
HPP fork of FCL -- The Flexible Collision Library
morton.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011-2014, Willow Garage, Inc.
5  * Copyright (c) 2014-2016, Open Source Robotics Foundation
6  * Copyright (c) 2016, Toyota Research Institute
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Open Source Robotics Foundation nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  */
36 
39 #ifndef HPP_FCL_MORTON_H
40 #define HPP_FCL_MORTON_H
41 
42 #include "hpp/fcl/BV/AABB.h"
43 #include <cstdint>
44 #include <bitset>
45 
46 namespace hpp {
47 namespace fcl {
48 
50 namespace detail {
51 
52 template <typename S>
53 uint32_t quantize(S x, uint32_t n);
54 
57 uint32_t morton_code(uint32_t x, uint32_t y, uint32_t z);
58 
61 uint64_t morton_code60(uint32_t x, uint32_t y, uint32_t z);
62 
67 template <typename S, typename T>
68 struct morton_functor {};
69 
71 template <typename S>
72 struct morton_functor<S, uint32_t> {
73  morton_functor(const AABB& bbox);
74 
75  uint32_t operator()(const Vec3f& point) const;
76 
77  const Vec3f base;
78  const Vec3f inv;
79 
80  static constexpr size_t bits();
81 };
82 
83 using morton_functoru32f = morton_functor<float, uint32_t>;
84 using morton_functoru32d = morton_functor<FCL_REAL, uint32_t>;
85 
87 template <typename S>
88 struct morton_functor<S, uint64_t> {
89  morton_functor(const AABB& bbox);
90 
91  uint64_t operator()(const Vec3f& point) const;
92 
93  const Vec3f base;
94  const Vec3f inv;
95 
96  static constexpr size_t bits();
97 };
98 
101 template <typename S, size_t N>
102 struct morton_functor<S, std::bitset<N>> {
103  static_assert(N % 3 == 0, "Number of bits must be a multiple of 3");
104 
105  morton_functor(const AABB& bbox);
106 
107  std::bitset<N> operator()(const Vec3f& point) const;
108 
109  const Vec3f base;
110  const Vec3f inv;
111 
112  static constexpr size_t bits();
113 };
114 
115 } // namespace detail
117 } // namespace fcl
118 } // namespace hpp
119 
121 
122 #endif
#define HPP_FCL_DLLAPI
Definition: config.hh:88
Eigen::Matrix< FCL_REAL, 3, 1 > Vec3f
Definition: data_types.h:67
Main namespace.
Definition: broadphase_bruteforce.h:44