@@ -215,6 +215,148 @@ pcl::LineRGBD<PointXYZT, PointRGBT>::loadTemplates (const std::string &file_name
215
215
return (true );
216
216
}
217
217
218
+ // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
219
+ template <typename PointXYZT, typename PointRGBT> bool
220
+ pcl::LineRGBD<PointXYZT, PointRGBT>::loadTemplateSQMMT (
221
+ const std::vector<std::string> &file_name,
222
+ const std::size_t object_id)
223
+ {
224
+ std::string sqmmt_ext (" .sqmmt" );
225
+ std::size_t file_loaded = 0 ;
226
+
227
+ for (const auto file : file_name)
228
+ {
229
+ std::transform (file.begin (), file.end (), file.begin (), ::tolower);
230
+ std::string::size_type it;
231
+
232
+ if ((it = file.find (sqmmt_ext)) == std::string::npos)
233
+ {
234
+ PCL_WARN (" %s: Invalid file type. Skipping.\n " , file.c_str ());
235
+ continue ;
236
+ }
237
+
238
+ std::ifstream stream;
239
+ int nr_templates;
240
+
241
+ stream.open (file, std::stringstream::in | std::stringstream::out | std::stringstream::binary);
242
+ read (stream, nr_templates);
243
+ for (std::size_t i=0 ; i<nr_templates; ++i)
244
+ {
245
+ SparseQuantizedMultiModTemplate sqmmt;
246
+ sqmmt.deserialize (stream);
247
+
248
+ linemod_.addTemplate (sqmmt);
249
+ object_ids_.push_back (object_id);
250
+ }
251
+
252
+ ++file_loaded;
253
+ }
254
+
255
+ if (file_loaded < file_name.size ())
256
+ return (false );
257
+
258
+ return (true );
259
+ }
260
+
261
+ // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
262
+ template <typename PointXYZT, typename PointRGBT> bool
263
+ pcl::LineRGBD<PointXYZT, PointRGBT>::loadTemplatePCD (
264
+ const std::vector<std::string> &file_name,
265
+ const std::size_t object_id)
266
+ {
267
+ std::string pcd_ext (" .pcd" );
268
+ PCDReader pcd_reader;
269
+ std::size_t file_loaded = 0 ;
270
+
271
+ for (const auto file : file_name)
272
+ {
273
+ std::transform (file.begin (), file.end (), file.begin (), ::tolower);
274
+ std::string::size_type it;
275
+
276
+ if ((it = file.find (pcd_ext)) == std::string::npos)
277
+ {
278
+ PCL_WARN (" %s: Invalid file type. Skipping.\n " , file.c_str ());
279
+ continue ;
280
+ }
281
+
282
+ template_point_clouds_.resize (template_point_clouds_.size () + 1 );
283
+ pcd_reader.read (file_name, template_point_clouds_[template_point_clouds_.size () - 1 ]);
284
+
285
+ ++file_loaded;
286
+ }
287
+
288
+ bounding_boxes_.resize (template_point_clouds_.size ());
289
+ for (std::size_t i = 0 ; i < template_point_clouds_.size (); ++i)
290
+ {
291
+ PointCloud<PointXYZRGBA> & template_point_cloud = template_point_clouds_[i];
292
+ BoundingBoxXYZ & bb = bounding_boxes_[i];
293
+ bb.x = bb.y = bb.z = std::numeric_limits<float >::max ();
294
+ bb.width = bb.height = bb.depth = 0 .0f ;
295
+
296
+ float center_x = 0 .0f ;
297
+ float center_y = 0 .0f ;
298
+ float center_z = 0 .0f ;
299
+ float min_x = std::numeric_limits<float >::max ();
300
+ float min_y = std::numeric_limits<float >::max ();
301
+ float min_z = std::numeric_limits<float >::max ();
302
+ float max_x = -std::numeric_limits<float >::max ();
303
+ float max_y = -std::numeric_limits<float >::max ();
304
+ float max_z = -std::numeric_limits<float >::max ();
305
+ std::size_t counter = 0 ;
306
+ for (std::size_t j = 0 ; j < template_point_cloud.size (); ++j)
307
+ {
308
+ const PointXYZRGBA & p = template_point_cloud.points [j];
309
+
310
+ if (!std::isfinite (p.x ) || !std::isfinite (p.y ) || !std::isfinite (p.z ))
311
+ continue ;
312
+
313
+ min_x = std::min (min_x, p.x );
314
+ min_y = std::min (min_y, p.y );
315
+ min_z = std::min (min_z, p.z );
316
+ max_x = std::max (max_x, p.x );
317
+ max_y = std::max (max_y, p.y );
318
+ max_z = std::max (max_z, p.z );
319
+
320
+ center_x += p.x ;
321
+ center_y += p.y ;
322
+ center_z += p.z ;
323
+
324
+ ++counter;
325
+ }
326
+
327
+ center_x /= static_cast <float > (counter);
328
+ center_y /= static_cast <float > (counter);
329
+ center_z /= static_cast <float > (counter);
330
+
331
+ bb.width = max_x - min_x;
332
+ bb.height = max_y - min_y;
333
+ bb.depth = max_z - min_z;
334
+
335
+ bb.x = (min_x + bb.width / 2 .0f ) - center_x - bb.width / 2 .0f ;
336
+ bb.y = (min_y + bb.height / 2 .0f ) - center_y - bb.height / 2 .0f ;
337
+ bb.z = (min_z + bb.depth / 2 .0f ) - center_z - bb.depth / 2 .0f ;
338
+
339
+ for (std::size_t j = 0 ; j < template_point_cloud.size (); ++j)
340
+ {
341
+ PointXYZRGBA p = template_point_cloud.points [j];
342
+
343
+ if (!std::isfinite (p.x ) || !std::isfinite (p.y ) || !std::isfinite (p.z ))
344
+ continue ;
345
+
346
+ p.x -= center_x;
347
+ p.y -= center_y;
348
+ p.z -= center_z;
349
+
350
+ template_point_cloud.points [j] = p;
351
+ }
352
+ }
353
+
354
+ if (file_loaded < file_name.size ())
355
+ return (false );
356
+
357
+ return (true );
358
+ }
359
+
218
360
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
219
361
template <typename PointXYZT, typename PointRGBT> int
220
362
pcl::LineRGBD<PointXYZT, PointRGBT>::createAndAddTemplate (
0 commit comments