VisitPointLikeContainer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 
5 #include <boost/preprocessor/seq/for_each.hpp>
6 
7 #include <pcl/point_cloud.h>
8 #include <pcl/point_types.h>
9 
10 #pragma GCC diagnostic push
11 #pragma GCC diagnostic ignored "-Wpedantic"
12 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
13 #include <CGAL/Polyhedron_3.h>
14 #pragma GCC diagnostic pop
15 
17 
18 //point traits
19 namespace armarx::meta
20 {
21 
22 #define _detail_unpack(r, data, elem) , elem
23  template<class T>
24  static constexpr bool is_pcl_point_type_v = is_any_of_v<T /*no ,*/ BOOST_PP_SEQ_FOR_EACH(_detail_unpack,, PCL_XYZ_POINT_TYPES)>;
25 #undef _detail_unpack
26 
27  template<class T, class = void>
28  struct is_eigen_vec3_type : std::false_type {};
29 
30  template<class T>
31  struct is_eigen_vec3_type<Eigen::Matrix<T, 3, 1>, void> : std::true_type {};
32 
33  template<class T>
34  struct is_eigen_vec3_type<Eigen::Matrix<T, 1, 3>, void> : std::true_type {};
35 
36  template<class T>
37  static constexpr bool is_eigen_vec3_type_v = is_eigen_vec3_type<T>::value;
38 
39  template<class T, class = void>
40  struct point_type_traits : std::false_type {};
41 
42  template<class T>
43  struct point_type_traits<T, std::enable_if_t<is_pcl_point_type_v<T>>> : std::true_type
44  {
45  static const auto& x(const T& v)
46  {
47  return v.x;
48  }
49  static const auto& y(const T& v)
50  {
51  return v.y;
52  }
53  static const auto& z(const T& v)
54  {
55  return v.z;
56  }
57  };
58 
59  template<class T>
60  struct point_type_traits<T, std::enable_if_t<is_eigen_vec3_type_v<T>>> : std::true_type
61  {
62  static const auto& x(const T& v)
63  {
64  return v.x();
65  }
66  static const auto& y(const T& v)
67  {
68  return v.y();
69  }
70  static const auto& z(const T& v)
71  {
72  return v.z();
73  }
74  };
75 
76  template<>
77  struct point_type_traits<CGAL::Epick::Point_3, void> : std::true_type
78  {
79  using T = CGAL::Epick::Point_3;
80  static const auto& x(const T& v)
81  {
82  return v.x();
83  }
84  static const auto& y(const T& v)
85  {
86  return v.y();
87  }
88  static const auto& z(const T& v)
89  {
90  return v.z();
91  }
92  };
93 
94  template<class T>
95  static constexpr bool is_point_type_v = point_type_traits<T>::value;
96 
97  static_assert(is_point_type_v<pcl::PointXYZ>);
98  static_assert(is_point_type_v<Eigen::Vector3f>);
99  static_assert(is_point_type_v<Eigen::Vector3i>);
100  static_assert(is_point_type_v<Eigen::RowVector3cd>);
101  static_assert(is_point_type_v<CGAL::Epick::Point_3>);
102 }
103 
104 //container traits
105 #include <vector>
106 #include <deque>
107 #include <list>
108 #include <forward_list>
109 #include <set>
110 #include <unordered_set>
111 namespace armarx::meta
112 {
113 #define _detail_containerlist std::vector, std::deque, std::list, std::forward_list, std::set, std::unordered_set
114  static_assert(!TypeTemplateTraits::IsInstanceOfAnyV<int, _detail_containerlist>);
115  static_assert(TypeTemplateTraits::IsInstanceOfAnyV<std::vector<int>, _detail_containerlist>);
116 
117  template<class T, class = void>
118  struct container_traits : std::false_type {};
119 
120  template<class T>
121  struct container_traits<T, std::enable_if_t<TypeTemplateTraits::IsInstanceOfAnyV<T, _detail_containerlist>>> : std::true_type
122  {
123  using element_t = typename T::value_type;
124  static auto begin(const T& t)
125  {
126  return t.begin();
127  }
128  static auto begin(T& t)
129  {
130  return t.begin();
131  }
132 
133  static auto end(const T& t)
134  {
135  return t.end();
136  }
137  static auto end(T& t)
138  {
139  return t.end();
140  }
141 
142  static const auto deref(auto& it)
143  {
144  return *it;
145  }
146 
147  static auto size(const T& t)
148  {
149  return t.size();
150  }
151  };
152 
153 #undef _detail_containerlist
154 
155  template<class PType>
156  struct container_traits<pcl::PointCloud<PType>, void> : std::true_type
157  {
158  using T = pcl::PointCloud<PType>;
159  using element_t = PType;
160  static auto begin(const T& t)
161  {
162  return t.points.begin();
163  }
164  static auto begin(T& t)
165  {
166  return t.points.begin();
167  }
168 
169  static auto end(const T& t)
170  {
171  return t.points.end();
172  }
173  static auto end(T& t)
174  {
175  return t.points.end();
176  }
177 
178  static const auto deref(auto& it)
179  {
180  return *it;
181  }
182 
183  static auto size(const T& t)
184  {
185  return t.points.size();
186  }
187  };
188 
189  template<class T>
190  static constexpr bool is_container_type_v = container_traits<T>::value;
191 }
192 
193 
195 {
196  static_assert(meta::is_container_type_v<std::vector<Eigen::Vector3f>>);
197  static_assert(meta::is_container_type_v<std::vector<Eigen::Vector3d>>);
198  static_assert(meta::is_container_type_v<std::vector<Eigen::RowVector3cd>>);
199  static_assert(meta::is_container_type_v<pcl::PointCloud<pcl::PointXYZ>>);
200 
201  template<class T, class = void>
202  struct VisitPointLike : std::false_type
203  {
204  //template<class F, class F2>
205  //static void visit(const T& c, F& sizeinfo, F2& perElem);
206  //{
207  // sizeinfo(c.size());
208  // perElem(p.x(), p.y(), p.z());
209  //}
210  };
211 
212  template<class T>
213  struct VisitPointLike < T, std::enable_if_t < meta::is_container_type_v<T>&& meta::is_point_type_v<typename meta::container_traits<T>::element_t >>> : std::true_type
214  {
215  template<class F, class F2>
216  static void visit(const T& c, F& sizeinfo, F2& perElem)
217  {
218  using ctr = meta::container_traits<T>;
220  sizeinfo(ctr::size(c));
221  auto f = ctr::begin(c);
222  auto l = ctr::end(c);
223  for (; f != l; ++f)
224  {
225  auto&& p = ctr::deref(f);
226  perElem(tr::x(p), tr::y(p), tr::z(p));
227  }
228  }
229  };
230 
231  template<class T>
232  struct VisitPointLike<T, std::enable_if_t<VisitPointLike<meta::pointer_type_pointee_t<T>>::value>> : std::true_type
233  {
234  template<class F, class F2>
235  static void visit(const T& c, F& sizeinfo, F2& perElem)
236  {
239  }
240  };
241 
242  template<class K>
243  struct VisitPointLike <CGAL::Polyhedron_3<K>, void> : std::true_type
244  {
245  template<class F, class F2>
246  static void visit(const CGAL::Polyhedron_3<K>& c, F& sizeinfo, F2& perElem)
247  {
248  sizeinfo(c.size_of_vertices());
249  for (auto v = c.vertices_begin(); v != c.vertices_end(); ++v)
250  {
251  perElem(v->point().x(), v->point().y(), v->point().z());
252  }
253  }
254  };
255 
256 
257  template<class T>
258  struct VisitPointLike<const T> : VisitPointLike<T> {};
259 
260  template<class T>
262 
263  static_assert(VisitPointLike<std::vector<Eigen::Matrix<float, 3, 1>, std::allocator<Eigen::Matrix<float, 3, 1> > >>::value);
264  static_assert(VisitPointLike<std::vector<Eigen::Vector3f>>::value);
265  static_assert(VisitPointLike<std::vector<Eigen::Vector3d>>::value);
266  static_assert(VisitPointLike<std::vector<Eigen::RowVector3cd>>::value);
267  static_assert(VisitPointLike<pcl::PointCloud<pcl::PointXYZ>>::value);
268  static_assert(VisitPointLike<const std::vector<Eigen::Vector3f>&>::value);
269 }
270 
271 namespace armarx
272 {
273  inline void VisitPointLikeContainer(const auto& cloud, auto&& perElem, auto&& sizeInfo)
274  {
275  using handler = ::armarx::detail::VisitPointLike::VisitPointLike<decltype(cloud)>;
276  static_assert(handler::value, "This type is not supported!");
277  handler::visit(cloud, perElem, sizeInfo);
278  }
279 }
armarx::VisitPointLikeContainer
void VisitPointLikeContainer(const auto &cloud, auto &&perElem, auto &&sizeInfo)
Definition: VisitPointLikeContainer.h:273
armarx::meta::point_type_traits< T, std::enable_if_t< is_pcl_point_type_v< T > > >::y
static const auto & y(const T &v)
Definition: VisitPointLikeContainer.h:49
armarx::meta::point_type_traits< T, std::enable_if_t< is_eigen_vec3_type_v< T > > >::x
static const auto & x(const T &v)
Definition: VisitPointLikeContainer.h:62
pcl
Definition: pcl_point_operators.cpp:4
Eigen
Definition: Elements.h:36
armarx::meta::container_traits< pcl::PointCloud< PType >, void >::end
static auto end(const T &t)
Definition: VisitPointLikeContainer.h:169
armarx::meta::container_traits< T, std::enable_if_t< TypeTemplateTraits::IsInstanceOfAnyV< T, _detail_containerlist > > >::size
static auto size(const T &t)
Definition: VisitPointLikeContainer.h:147
armarx::meta::TypeTemplateTraits::IsInstanceOfAnyV
static constexpr bool IsInstanceOfAnyV
Definition: TemplateMetaProgramming.h:81
armarx::detail::VisitPointLike
Definition: VisitPointLikeContainer.h:194
armarx::meta::point_type_traits< T, std::enable_if_t< is_pcl_point_type_v< T > > >::z
static const auto & z(const T &v)
Definition: VisitPointLikeContainer.h:53
ARMARX_CHECK_NOT_NULL
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
Definition: ExpressionException.h:206
armarx::meta::container_traits< pcl::PointCloud< PType >, void >::T
pcl::PointCloud< PType > T
Definition: VisitPointLikeContainer.h:158
armarx::detail::VisitPointLike::VisitPointLike< CGAL::Polyhedron_3< K >, void >::visit
static void visit(const CGAL::Polyhedron_3< K > &c, F &sizeinfo, F2 &perElem)
Definition: VisitPointLikeContainer.h:246
CGAL
Definition: Mesh.h:14
armarx::meta::container_traits< T, std::enable_if_t< TypeTemplateTraits::IsInstanceOfAnyV< T, _detail_containerlist > > >::begin
static auto begin(T &t)
Definition: VisitPointLikeContainer.h:128
armarx::meta::container_traits< pcl::PointCloud< PType >, void >::end
static auto end(T &t)
Definition: VisitPointLikeContainer.h:173
armarx::meta::point_type_traits< T, std::enable_if_t< is_pcl_point_type_v< T > > >::x
static const auto & x(const T &v)
Definition: VisitPointLikeContainer.h:45
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::meta::point_type_traits< CGAL::Epick::Point_3, void >::y
static const auto & y(const T &v)
Definition: VisitPointLikeContainer.h:84
armarx::detail::VisitPointLike::VisitPointLike
Definition: VisitPointLikeContainer.h:202
armarx::meta
Definition: PluginCfgStruct.h:31
armarx::meta::container_traits< T, std::enable_if_t< TypeTemplateTraits::IsInstanceOfAnyV< T, _detail_containerlist > > >::end
static auto end(const T &t)
Definition: VisitPointLikeContainer.h:133
armarx::meta::container_traits< pcl::PointCloud< PType >, void >::element_t
PType element_t
Definition: VisitPointLikeContainer.h:159
armarx::meta::point_type_traits
Definition: VisitPointLikeContainer.h:40
armarx::meta::container_traits< T, std::enable_if_t< TypeTemplateTraits::IsInstanceOfAnyV< T, _detail_containerlist > > >::begin
static auto begin(const T &t)
Definition: VisitPointLikeContainer.h:124
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::detail::VisitPointLike::VisitPointLike< T, std::enable_if_t< meta::is_container_type_v< T > &&meta::is_point_type_v< typename meta::container_traits< T >::element_t > > >::visit
static void visit(const T &c, F &sizeinfo, F2 &perElem)
Definition: VisitPointLikeContainer.h:216
armarx::meta::point_type_traits< T, std::enable_if_t< is_eigen_vec3_type_v< T > > >::y
static const auto & y(const T &v)
Definition: VisitPointLikeContainer.h:66
armarx::meta::container_traits< pcl::PointCloud< PType >, void >::begin
static auto begin(T &t)
Definition: VisitPointLikeContainer.h:164
armarx::meta::point_type_traits< CGAL::Epick::Point_3, void >::T
CGAL::Epick::Point_3 T
Definition: VisitPointLikeContainer.h:79
_detail_unpack
#define _detail_unpack(r, data, elem)
Definition: VisitPointLikeContainer.h:22
armarx::meta::container_traits
Definition: VisitPointLikeContainer.h:118
armarx::meta::point_type_traits< T, std::enable_if_t< is_eigen_vec3_type_v< T > > >::z
static const auto & z(const T &v)
Definition: VisitPointLikeContainer.h:70
armarx::meta::container_traits< T, std::enable_if_t< TypeTemplateTraits::IsInstanceOfAnyV< T, _detail_containerlist > > >::element_t
typename T::value_type element_t
Definition: VisitPointLikeContainer.h:123
armarx::meta::container_traits< T, std::enable_if_t< TypeTemplateTraits::IsInstanceOfAnyV< T, _detail_containerlist > > >::deref
static const auto deref(auto &it)
Definition: VisitPointLikeContainer.h:142
armarx::meta::container_traits< pcl::PointCloud< PType >, void >::size
static auto size(const T &t)
Definition: VisitPointLikeContainer.h:183
PointCloud
Definition: PointCloud.h:69
armarx::meta::point_type_traits< CGAL::Epick::Point_3, void >::z
static const auto & z(const T &v)
Definition: VisitPointLikeContainer.h:88
CGAL::Polyhedron_3
Definition: Mesh.h:21
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::meta::point_type_traits< CGAL::Epick::Point_3, void >::x
static const auto & x(const T &v)
Definition: VisitPointLikeContainer.h:80
armarx::detail::VisitPointLike::VisitPointLike< T, std::enable_if_t< VisitPointLike< meta::pointer_type_pointee_t< T > >::value > >::visit
static void visit(const T &c, F &sizeinfo, F2 &perElem)
Definition: VisitPointLikeContainer.h:235
std
Definition: Application.h:66
F
Definition: ExportDialogControllerTest.cpp:16
armarx::meta::container_traits< pcl::PointCloud< PType >, void >::deref
static const auto deref(auto &it)
Definition: VisitPointLikeContainer.h:178
armarx::meta::container_traits< T, std::enable_if_t< TypeTemplateTraits::IsInstanceOfAnyV< T, _detail_containerlist > > >::end
static auto end(T &t)
Definition: VisitPointLikeContainer.h:137
armarx::aron::data::visit
requires isVisitor< VisitorImplementation, typename VisitorImplementation::Input > void visit(VisitorImplementation &v, typename VisitorImplementation::Input &o)
Definition: Visitor.h:124
Eigen::Matrix
Definition: EigenForwardDeclarations.h:27
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx::meta::is_eigen_vec3_type
Definition: VisitPointLikeContainer.h:28
TemplateMetaProgrammingBoost.h
armarx::meta::container_traits< pcl::PointCloud< PType >, void >::begin
static auto begin(const T &t)
Definition: VisitPointLikeContainer.h:160
_detail_containerlist
#define _detail_containerlist
Definition: VisitPointLikeContainer.h:113
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28