FCL  0.6.0
Flexible Collision Library
morton.h
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 FCL_MORTON_H
40 #define FCL_MORTON_H
41 
42 #include "fcl/common/types.h"
43 #include "fcl/math/bv/AABB.h"
44 
45 #include <bitset>
46 
47 namespace fcl
48 {
49 
51 namespace detail
52 {
53 
54 template <typename S>
55 uint32 quantize(S x, uint32 n);
56 
58 uint32 morton_code(uint32 x, uint32 y, uint32 z);
59 
61 uint64 morton_code60(uint32 x, uint32 y, uint32 z);
62 
67 template<typename S, typename T>
68 struct morton_functor {};
69 
71 template<typename S>
72 struct morton_functor<S, uint32>
73 {
74  morton_functor(const AABB<S>& bbox);
75 
76  uint32 operator() (const Vector3<S>& point) const;
77 
78  const Vector3<S> base;
79  const Vector3<S> inv;
80 
81  static constexpr size_t bits();
82 };
83 
84 using morton_functoru32f = morton_functor<float, uint32>;
85 using morton_functoru32d = morton_functor<double, uint32>;
86 
88 template<typename S>
89 struct morton_functor<S, uint64>
90 {
91  morton_functor(const AABB<S>& bbox);
92 
93  uint64 operator() (const Vector3<S>& point) const;
94 
95  const Vector3<S> base;
96  const Vector3<S> inv;
97 
98  static constexpr size_t bits();
99 };
100 
101 using morton_functoru64f = morton_functor<float, uint64>;
102 using morton_functoru64d = morton_functor<double, uint64>;
103 
106 template<typename S, size_t N>
107 struct morton_functor<S, std::bitset<N>>
108 {
109  static_assert(N%3==0, "Number of bits must be a multiple of 3");
110 
111  morton_functor(const AABB<S>& bbox);
112 
113  std::bitset<N> operator() (const Vector3<S>& point) const;
114 
115  const Vector3<S> base;
116  const Vector3<S> inv;
117 
118  static constexpr size_t bits();
119 };
120 
121 } // namespace detail
123 } // namespace fcl
124 
125 #include "fcl/broadphase/detail/morton-inl.h"
126 
127 #endif
Main namespace.
Definition: broadphase_bruteforce-inl.h:45