@@ -151,21 +151,17 @@ namespace pcl
151
151
}
152
152
153
153
/* * \brief Convert a PCLPointCloud2 binary data blob into a pcl::PointCloud<T> object using a field_map.
154
- * \param[in] msg the PCLPointCloud2 binary blob
154
+ * \param[in] msg the PCLPointCloud2 binary blob (note that the binary point data in msg.data will not be used!)
155
155
* \param[out] cloud the resultant pcl::PointCloud<T>
156
156
* \param[in] field_map a MsgFieldMap object
157
+ * \param[in] msg_data pointer to binary blob data, used instead of msg.data
157
158
*
158
- * \note Use fromPCLPointCloud2 (PCLPointCloud2, PointCloud<T>) directly or create you
159
- * own MsgFieldMap using:
160
- *
161
- * \code
162
- * MsgFieldMap field_map;
163
- * createMapping<PointT> (msg.fields, field_map);
164
- * \endcode
159
+ * \note Use fromPCLPointCloud2 (PCLPointCloud2, PointCloud<T>) instead, except if you have a binary blob of
160
+ * point data that you do not want to copy into a pcl::PCLPointCloud2 in order to use fromPCLPointCloud2.
165
161
*/
166
162
template <typename PointT> void
167
163
fromPCLPointCloud2 (const pcl::PCLPointCloud2& msg, pcl::PointCloud<PointT>& cloud,
168
- const MsgFieldMap& field_map)
164
+ const MsgFieldMap& field_map, const std:: uint8_t * msg_data )
169
165
{
170
166
// Copy info fields
171
167
cloud.header = msg.header ;
@@ -187,11 +183,10 @@ namespace pcl
187
183
field_map[0 ].size == sizeof (PointT))
188
184
{
189
185
const auto cloud_row_step = (sizeof (PointT) * cloud.width );
190
- const std::uint8_t * msg_data = &msg.data [0 ];
191
186
// Should usually be able to copy all rows at once
192
187
if (msg.row_step == cloud_row_step)
193
188
{
194
- std::copy ( msg.data . cbegin (), msg.data . cend (), cloud_data );
189
+ memcpy (cloud_data, msg_data, msg.width * msg.height * sizeof (PointT) );
195
190
}
196
191
else
197
192
{
@@ -205,7 +200,7 @@ namespace pcl
205
200
// If not, memcpy each group of contiguous fields separately
206
201
for (uindex_t row = 0 ; row < msg.height ; ++row)
207
202
{
208
- const std::uint8_t * row_data = &msg. data [ row * msg.row_step ] ;
203
+ const std::uint8_t * row_data = msg_data + row * msg.row_step ;
209
204
for (uindex_t col = 0 ; col < msg.width ; ++col)
210
205
{
211
206
const std::uint8_t * msg_data = row_data + col * msg.point_step ;
@@ -220,6 +215,26 @@ namespace pcl
220
215
}
221
216
}
222
217
218
+ /* * \brief Convert a PCLPointCloud2 binary data blob into a pcl::PointCloud<T> object using a field_map.
219
+ * \param[in] msg the PCLPointCloud2 binary blob
220
+ * \param[out] cloud the resultant pcl::PointCloud<T>
221
+ * \param[in] field_map a MsgFieldMap object
222
+ *
223
+ * \note Use fromPCLPointCloud2 (PCLPointCloud2, PointCloud<T>) directly or create you
224
+ * own MsgFieldMap using:
225
+ *
226
+ * \code
227
+ * MsgFieldMap field_map;
228
+ * createMapping<PointT> (msg.fields, field_map);
229
+ * \endcode
230
+ */
231
+ template <typename PointT> void
232
+ fromPCLPointCloud2 (const pcl::PCLPointCloud2& msg, pcl::PointCloud<PointT>& cloud,
233
+ const MsgFieldMap& field_map)
234
+ {
235
+ fromPCLPointCloud2 (msg, cloud, field_map, msg.data .data ());
236
+ }
237
+
223
238
/* * \brief Convert a PCLPointCloud2 binary data blob into a pcl::PointCloud<T> object.
224
239
* \param[in] msg the PCLPointCloud2 binary blob
225
240
* \param[out] cloud the resultant pcl::PointCloud<T>
0 commit comments