FCL  0.6.0
Flexible Collision Library
types.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  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Open Source Robotics Foundation nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
38 #ifndef FCL_DATA_TYPES_H
39 #define FCL_DATA_TYPES_H
40 
41 #include <cstddef>
42 #include <cstdint>
43 #include <vector>
44 #include <map>
45 #include <memory>
46 #include <Eigen/Dense>
47 #include <Eigen/StdVector>
48 #include "fcl/common/deprecated.h"
49 
50 namespace fcl
51 {
52 
53 typedef FCL_DEPRECATED double FCL_REAL;
54 typedef FCL_DEPRECATED std::int64_t FCL_INT64;
55 typedef FCL_DEPRECATED std::uint64_t FCL_UINT64;
56 typedef FCL_DEPRECATED std::int32_t FCL_INT32;
57 typedef FCL_DEPRECATED std::uint32_t FCL_UINT32;
58 
59 using int64 = std::int64_t;
60 using uint64 = std::uint64_t;
61 using int32 = std::int32_t;
62 using uint32 = std::uint32_t;
63 
64 template <typename S>
65 using Vector2 = Eigen::Matrix<S, 2, 1>;
66 
67 template <typename S>
68 using Vector3 = Eigen::Matrix<S, 3, 1>;
69 
70 template <typename S>
71 using Vector6 = Eigen::Matrix<S, 6, 1>;
72 
73 template <typename S>
74 using Vector7 = Eigen::Matrix<S, 7, 1>;
75 
76 template <typename S, int N>
77 using VectorN = Eigen::Matrix<S, N, 1>;
78 
79 template <typename S>
80 using VectorX = Eigen::Matrix<S, Eigen::Dynamic, 1>;
81 
82 template <typename S>
83 using Matrix3 = Eigen::Matrix<S, 3, 3>;
84 
85 template <typename S>
86 using Quaternion = Eigen::Quaternion<S>;
87 
88 template <typename S>
89 using Transform3 = Eigen::Transform<S, 3, Eigen::AffineCompact>;
90 
91 template <typename S>
92 using Translation3 = Eigen::Translation<S, 3>;
93 
94 template <typename S>
95 using AngleAxis = Eigen::AngleAxis<S>;
96 
97 // float types
98 using Vector3f = Vector3<float>;
99 template <int N>
100 using VectorNf = VectorN<float, N>;
101 using VectorXf = VectorX<float>;
102 using Matrix3f = Matrix3<float>;
103 using Quaternionf = Quaternion<float>;
104 using Transform3f = Transform3<float>;
105 using Translation3f = Translation3<float>;
106 using AngleAxisf = AngleAxis<float>;
107 
108 // double types
109 using Vector3d = Vector3<double>;
110 template <int N>
111 using VectorNd = VectorN<double, N>;
112 using VectorXd = VectorX<double>;
113 using Matrix3d = Matrix3<double>;
114 using Quaterniond = Quaternion<double>;
115 using Transform3d = Transform3<double>;
116 using Translation3d = Translation3<double>;
117 using AngleAxisd = AngleAxis<double>;
118 
119 } // namespace fcl
120 
121 namespace Eigen {
122 
123 template <typename _Tp>
124 using aligned_vector = std::vector<_Tp, Eigen::aligned_allocator<_Tp>>;
125 
126 template <typename _Key, typename _Tp, typename _Compare = std::less<_Key>>
127 using aligned_map = std::map<_Key, _Tp, _Compare,
128  Eigen::aligned_allocator<std::pair<const _Key, _Tp>>>;
129 
130 #if EIGEN_VERSION_AT_LEAST(3,2,1)
131 
133 // Ref: https://bitbucket.org/eigen/eigen/commits/f5b7700
134 // TODO: Remove this and use Eigen::aligned_allocator once new version of Eigen
135 // is released with above commit.
136 template <class T>
137 class aligned_allocator_cpp11 : public std::allocator<T>
138 {
139 public:
140  typedef std::size_t size_type;
141  typedef std::ptrdiff_t difference_type;
142  typedef T* pointer;
143  typedef const T* const_pointer;
144  typedef T& reference;
145  typedef const T& const_reference;
146  typedef T value_type;
147 
148  template <class U>
149  struct rebind
150  {
151  typedef aligned_allocator_cpp11<U> other;
152  };
153 
154  aligned_allocator_cpp11()
155  : std::allocator<T>() {}
156 
157  aligned_allocator_cpp11(const aligned_allocator_cpp11& other)
158  : std::allocator<T>(other) {}
159 
160  template <class U>
161  aligned_allocator_cpp11(const aligned_allocator_cpp11<U>& other)
162  : std::allocator<T>(other) {}
163 
164  ~aligned_allocator_cpp11() {}
165 
166  pointer allocate(size_type num, const void* /*hint*/ = 0)
167  {
168  internal::check_size_for_overflow<T>(num);
169  return static_cast<pointer>( internal::aligned_malloc(num * sizeof(T)) );
170  }
171 
172  void deallocate(pointer p, size_type /*num*/)
173  {
174  internal::aligned_free(p);
175  }
176 };
177 
178 template <typename _Tp, typename... _Args>
179 inline std::shared_ptr<_Tp> make_aligned_shared(_Args&&... __args)
180 {
181  typedef typename std::remove_const<_Tp>::type _Tp_nc;
182  return std::allocate_shared<_Tp>(Eigen::aligned_allocator_cpp11<_Tp_nc>(),
183  std::forward<_Args>(__args)...);
184 }
185 
186 #else
187 
188 template <typename _Tp, typename... _Args>
189 inline std::shared_ptr<_Tp> make_aligned_shared(_Args&&... __args)
190 {
191  typedef typename std::remove_const<_Tp>::type _Tp_nc;
192  return std::allocate_shared<_Tp>(Eigen::aligned_allocator<_Tp_nc>(),
193  std::forward<_Args>(__args)...);
194 }
195 
196 #endif
197 
198 } // namespace Eigen
199 
200 #endif
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
Definition: types.h:121