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