vision
Loading...
Searching...
No Matches
YarpCloudUtils-pcl-traits.hpp
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
3#ifndef __YARP_CLOUD_UTILS_PCL_TRAITS_HPP__
4#define __YARP_CLOUD_UTILS_PCL_TRAITS_HPP__
5
6#include <type_traits>
7#include <yarp/sig/PointCloudTypes.h>
8#include <pcl/point_types.h>
9
10namespace
11{
12
13// YARP point type to PCL point type
14
15template <typename T>
16struct pcl_type_from_yarp;
17
18template <>
19struct pcl_type_from_yarp<yarp::sig::DataXY>
20{ typedef pcl::PointXY type; };
21
22template <>
23struct pcl_type_from_yarp<yarp::sig::DataXYZ>
24{ typedef pcl::PointXYZ type; };
25
26template <>
27struct pcl_type_from_yarp<yarp::sig::DataNormal>
28{ typedef pcl::Normal type; };
29
30template <>
31struct pcl_type_from_yarp<yarp::sig::DataXYZRGBA>
32{ typedef pcl::PointXYZRGB type; };
33
34template <>
35struct pcl_type_from_yarp<yarp::sig::DataXYZI>
36{ typedef pcl::PointXYZI type; };
37
38template <>
39struct pcl_type_from_yarp<yarp::sig::DataInterestPointXYZ>
40{ typedef pcl::InterestPoint type; };
41
42template <>
43struct pcl_type_from_yarp<yarp::sig::DataXYZNormal>
44{ typedef pcl::PointNormal type; };
45
46template <>
47struct pcl_type_from_yarp<yarp::sig::DataXYZNormalRGBA>
48{ typedef pcl::PointXYZRGBNormal type; };
49
50// PCL type tags
51
52struct pcl_all_xyz_types_tag {};
53
54struct pcl_xyz_rgb_types_tag {}; // XYZ or XYZ+RGB
55
56struct pcl_rgb_types_tag {}; // XYZ+RGB
57
58struct pcl_xyzi_types_tag {}; // XYZI(+Normal)
59
60struct pcl_normal_types_tag {};
61
62// special cases for pcl::MovingLeastSquares, see:
63// https://github.com/PointCloudLibrary/pcl/pull/5764
64struct pcl_mls_types_tag : public pcl_all_xyz_types_tag {};
65struct pcl_mls_normal_types_tag : public pcl_normal_types_tag {};
66
67// map PCL type according to selected tag
68
69template <typename T, typename tag>
70struct pcl_decay;
71
72// 1-to-1 mapping if T belongs to any of the supported XYZ types
73
74template <typename T>
75struct pcl_decay<T, pcl_all_xyz_types_tag>
76{ typedef T type; };
77
78// mappings for XYZ or XYZ+RGB types
79
80template <typename T>
81struct pcl_decay<T, pcl_xyz_rgb_types_tag>
82{ typedef pcl::PointXYZ type; };
83
84template <>
85struct pcl_decay<pcl::PointXYZRGB, pcl_xyz_rgb_types_tag>
86{ typedef pcl::PointXYZRGB type; };
87
88template <>
89struct pcl_decay<pcl::PointXYZRGBNormal, pcl_xyz_rgb_types_tag>
90{ typedef pcl::PointXYZRGB type; };
91
92// mappings for XYZ+RGB types
93
94template <typename T>
95struct pcl_decay<T, pcl_rgb_types_tag>
96{ typedef pcl::PointXYZRGB type; };
97
98// mappings for XYZI(+Normal) types
99
100template <typename T>
101struct pcl_decay<T, pcl_xyzi_types_tag>
102{ typedef pcl::PointXYZI type; };
103
104template <>
105struct pcl_decay<pcl::PointNormal, pcl_xyzi_types_tag>
106{ typedef pcl::PointXYZINormal type; };
107
108template <>
109struct pcl_decay<pcl::PointXYZRGBNormal, pcl_xyzi_types_tag>
110{ typedef pcl::PointXYZINormal type; };
111
112template <>
113struct pcl_decay<pcl::PointXYZINormal, pcl_xyzi_types_tag>
114{ typedef pcl::PointXYZINormal type; };
115
116// mappings for XYZ+normal types
117
118template <typename T>
119struct pcl_decay<T, pcl_normal_types_tag>
120{ typedef T type; };
121
122template <>
123struct pcl_decay<pcl::PointXYZ, pcl_normal_types_tag>
124{ typedef pcl::PointNormal type; };
125
126template <>
127struct pcl_decay<pcl::PointXYZRGB, pcl_normal_types_tag>
128{ typedef pcl::PointXYZRGBNormal type; };
129
130template <>
131struct pcl_decay<pcl::PointXYZI, pcl_normal_types_tag>
132{ typedef pcl::PointXYZINormal type; };
133
134template <>
135struct pcl_decay<pcl::InterestPoint, pcl_normal_types_tag>
136{ typedef pcl::PointNormal type; };
137
138// mappings for pcl::MovingLeastSquares (special case, less precompiled instantiations)
139
140template <typename T>
141struct pcl_decay<T, pcl_mls_types_tag>
142{ typedef T type; };
143
144template <>
145struct pcl_decay<pcl::InterestPoint, pcl_mls_types_tag>
146{ typedef pcl::PointXYZ type; };
147
148template <typename T>
149struct pcl_decay<T, pcl_mls_normal_types_tag>
150{ typedef T type; };
151
152template <>
153struct pcl_decay<pcl::PointXYZ, pcl_mls_normal_types_tag>
154{ typedef pcl::PointNormal type; };
155
156template <>
157struct pcl_decay<pcl::PointXYZRGB, pcl_mls_normal_types_tag>
158{ typedef pcl::PointXYZRGBNormal type; };
159
160template <>
161struct pcl_decay<pcl::PointXYZI, pcl_mls_normal_types_tag>
162{ typedef pcl::PointNormal type; };
163
164template <>
165struct pcl_decay<pcl::InterestPoint, pcl_mls_normal_types_tag>
166{ typedef pcl::PointNormal type; };
167
168// register allowed conversions
169
170template <typename T1, typename T2>
171struct pcl_is_convertible : std::false_type {};
172
173template <typename T>
174struct pcl_is_convertible<T, pcl::PointXYZ> : std::true_type {}; // T->XYZ always allowed
175
176template <>
177struct pcl_is_convertible<pcl::PointXYZRGBNormal, pcl::PointXYZRGB> : std::true_type {};
178
179template <>
180struct pcl_is_convertible<pcl::PointXYZRGBNormal, pcl::PointNormal> : std::true_type {};
181
182template <>
183struct pcl_is_convertible<pcl::PointXYZINormal, pcl::PointXYZI> : std::true_type {};
184
185template <>
186struct pcl_is_convertible<pcl::PointXYZINormal, pcl::PointNormal> : std::true_type {};
187
188// describe each type
189
190template <typename T>
191struct pcl_descriptor;
192
193template <>
194struct pcl_descriptor<pcl::PointXY>
195{ static constexpr const char * name = "XY"; };
196
197template <>
198struct pcl_descriptor<pcl::PointXYZ>
199{ static constexpr const char * name = "XYZ"; };
200
201template <>
202struct pcl_descriptor<pcl::Normal>
203{ static constexpr const char * name = "NORMAL"; };
204
205template <>
206struct pcl_descriptor<pcl::PointXYZRGB>
207{ static constexpr const char * name = "XYZ_RGB"; };
208
209template <>
210struct pcl_descriptor<pcl::PointXYZI>
211{ static constexpr const char * name = "XYZI"; };
212
213template <>
214struct pcl_descriptor<pcl::InterestPoint>
215{ static constexpr const char * name = "XYZ_INTEREST"; };
216
217template <>
218struct pcl_descriptor<pcl::PointNormal>
219{ static constexpr const char * name = "XYZ_NORMAL"; };
220
221template <>
222struct pcl_descriptor<pcl::PointXYZRGBNormal>
223{ static constexpr const char * name = "XYZ_RGB_NORMAL"; };
224
225template <>
226struct pcl_descriptor<pcl::PointXYZINormal>
227{ static constexpr const char * name = "XYZI_NORMAL"; };
228
229// conditional switches
230
231template <typename T>
232constexpr auto is_unsupported_type =
233 std::is_same_v<T, pcl::PointXY> ||
234 std::is_same_v<T, pcl::Normal>;
235
236} // namespace
237
238#endif // __YARP_CLOUD_UTILS_PCL_TRAITS_HPP__