MeVisLab Toolbox Reference
mlPCLSupportTools.h
Go to the documentation of this file.
1 // Copyright (c) Fraunhofer MEVIS, Germany. All rights reserved.
2 // **InsertLicense** code author="Wolf Spindler"
3 //----------------------------------------------------------------------------------
5 
12 //----------------------------------------------------------------------------------
13 #pragma once
14 
15 #include "MLPCLSupportSystem.h"
16 #include <mlPCLTypes.h>
17 #include <mlModuleIncludes.h>
18 #include <mlReleaseToolsString.h>
19 
20 ML_START_NAMESPACE
21 
22 class SubImage;
23 class PagedImage;
24 
26 namespace PCLSupportTools {
27 
28 //----------------------------------------------------------------------------------
31 //----------------------------------------------------------------------------------
33 
34 //----------------------------------------------------------------------------------
37 //----------------------------------------------------------------------------------
39 
40 //----------------------------------------------------------------------------------
42 //----------------------------------------------------------------------------------
44 {
45  return Eigen::Vector3f(static_cast<float>(mlVec[0]),
46  static_cast<float>(mlVec[1]),
47  static_cast<float>(mlVec[2]));
48 }
49 
50 //----------------------------------------------------------------------------------
52 //----------------------------------------------------------------------------------
54 {
55  return Eigen::Vector4f(static_cast<float>(mlVec[0]),
56  static_cast<float>(mlVec[1]),
57  static_cast<float>(mlVec[2]),
58  static_cast<float>(mlVec[3]));
59 }
60 
61 //----------------------------------------------------------------------------------
64 //----------------------------------------------------------------------------------
65 MLPCLSUPPORT_EXPORT void castToStdVector(const Eigen::VectorXf& eigenVec, std::vector<MLfloat>& stdVec);
66 
67 //----------------------------------------------------------------------------------
71 //----------------------------------------------------------------------------------
72 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
73 MLPCLSUPPORT_EXPORT std::string getPCLPointAsString(const pcl::PointXYZ &point, int numDecimalPlaces=-1);
74 MLPCLSUPPORT_EXPORT std::string getPCLPointAsString(const pcl::PointXYZLNormal &point, int numDecimalPlaces=-1);
75 MLPCLSUPPORT_EXPORT std::string getPCLPointAsString(const pcl::PointXYZRGBNormal &point, int numDecimalPlaces=-1);
76 MLPCLSUPPORT_EXPORT std::string getPCLPointAsString(const pcl::PointXYZINormal &point, int numDecimalPlaces=-1);
78 
79 //----------------------------------------------------------------------------------
83 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
84 //----------------------------------------------------------------------------------
85 MLPCLSUPPORT_EXPORT std::string getScalarMemberNameAsString(const pcl::PointXYZ &, size_t memberIdx);
86 MLPCLSUPPORT_EXPORT std::string getScalarMemberNameAsString(const pcl::PointXYZLNormal &, size_t memberIdx);
87 MLPCLSUPPORT_EXPORT std::string getScalarMemberNameAsString(const pcl::PointXYZRGBNormal &, size_t memberIdx);
88 MLPCLSUPPORT_EXPORT std::string getScalarMemberNameAsString(const pcl::PointXYZINormal &, size_t memberIdx);
90 
91 
92 //----------------------------------------------------------------------------------
95 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
96 //----------------------------------------------------------------------------------
97 inline size_t getNumberOfScalarPointMembers(const pcl::PointXYZ &) { return 4; }
98 inline size_t getNumberOfScalarPointMembers(const MLPointCloudXYZ &) { return 4; }
99 inline size_t getNumberOfScalarPointMembers(const MLPointCloudXYZPtr &) { return 4; }
100 
101 inline size_t getNumberOfScalarPointMembers(const pcl::PointXYZLNormal &) { return 10; }
102 inline size_t getNumberOfScalarPointMembers(const MLPointCloudXYZLNormal &) { return 10; }
103 inline size_t getNumberOfScalarPointMembers(const MLPointCloudXYZLNormalPtr &) { return 10; }
104 
105 inline size_t getNumberOfScalarPointMembers(const pcl::PointXYZRGBNormal &) { return 10; }
106 inline size_t getNumberOfScalarPointMembers(const MLPointCloudXYZRGBNormal &) { return 10; }
107 inline size_t getNumberOfScalarPointMembers(const MLPointCloudXYZRGBNormalPtr&) { return 10; }
108 
109 inline size_t getNumberOfScalarPointMembers(const pcl::PointXYZINormal &) { return 10; }
110 inline size_t getNumberOfScalarPointMembers(const MLPointCloudXYZINormal &) { return 10; }
111 inline size_t getNumberOfScalarPointMembers(const MLPointCloudXYZINormalPtr &) { return 10; }
113 
114 //----------------------------------------------------------------------------------
116 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
117 //----------------------------------------------------------------------------------
118 inline bool hasNormals(const pcl::PointXYZ &) { return false; }
119 inline bool hasNormals(const MLPointCloudXYZ &) { return false; }
120 inline bool hasNormals(const MLPointCloudXYZPtr &) { return false; }
121 inline bool hasNormals(const pcl::PointXYZLNormal &) { return true; }
122 inline bool hasNormals(const MLPointCloudXYZLNormal &) { return true; }
123 inline bool hasNormals(const MLPointCloudXYZLNormalPtr &) { return true; }
124 inline bool hasNormals(const pcl::PointXYZRGBNormal &) { return true; }
125 inline bool hasNormals(const MLPointCloudXYZRGBNormal &) { return true; }
126 inline bool hasNormals(const MLPointCloudXYZRGBNormalPtr&) { return true; }
127 inline bool hasNormals(const pcl::PointXYZINormal &) { return true; }
128 inline bool hasNormals(const MLPointCloudXYZINormal &) { return true; }
129 inline bool hasNormals(const MLPointCloudXYZINormalPtr &) { return true; }
131 
132 //----------------------------------------------------------------------------------
136 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
137 //----------------------------------------------------------------------------------
138 inline size_t getMaximumNumberOfScalarPointMembers() { return 10; }
139 
140 //----------------------------------------------------------------------------------
146 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
147 //----------------------------------------------------------------------------------
148 MLPCLSUPPORT_EXPORT std::string getScalarMemberValueAsString(const pcl::PointXYZ &p,
149  size_t memberIdx,
150  int numDecimalPlaces=-1);
151 MLPCLSUPPORT_EXPORT std::string getScalarMemberValueAsString(const pcl::PointXYZLNormal &p,
152  size_t memberIdx,
153  int numDecimalPlaces=-1);
154 MLPCLSUPPORT_EXPORT std::string getScalarMemberValueAsString(const pcl::PointXYZRGBNormal &p,
155  size_t memberIdx,
156  int numDecimalPlaces=-1);
157 MLPCLSUPPORT_EXPORT std::string getScalarMemberValueAsString(const pcl::PointXYZINormal &p,
158  size_t memberIdx,
159  int numDecimalPlaces=-1);
161 
162 //----------------------------------------------------------------------------------
168 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
169 //----------------------------------------------------------------------------------
171 inline void setPointFromFields(pcl::PointXYZ &pnt, const std::vector<DoubleField*> &constantFields)
172 {
173  pnt.x = static_cast<float>(constantFields[0]->getDoubleValue());
174  pnt.y = static_cast<float>(constantFields[1]->getDoubleValue());
175  pnt.z = static_cast<float>(constantFields[2]->getDoubleValue());
176  pnt.data[3] = static_cast<float>(constantFields[3]->getDoubleValue());
177 }
178 inline void setPointFromFields(pcl::PointXYZLNormal &pnt, const std::vector<DoubleField*> &constantFields)
179 {
180  pnt.x = static_cast<float>(constantFields[0]->getDoubleValue());
181  pnt.y = static_cast<float>(constantFields[1]->getDoubleValue());
182  pnt.z = static_cast<float>(constantFields[2]->getDoubleValue());
183  pnt.data[3] = static_cast<float>(constantFields[3]->getDoubleValue());
184  pnt.normal_x = static_cast<float>(constantFields[4]->getDoubleValue());
185  pnt.normal_y = static_cast<float>(constantFields[5]->getDoubleValue());
186  pnt.normal_z = static_cast<float>(constantFields[6]->getDoubleValue());
187  pnt.data_n[3] = static_cast<float>(constantFields[7]->getDoubleValue());
188  pnt.curvature = static_cast<float>(constantFields[8]->getDoubleValue());
189  pnt.label = static_cast<std::uint32_t>(MLAbs(constantFields[9]->getDoubleValue())); // cast of neg float -> int is undefined.
190 }
191 inline void setPointFromFields(pcl::PointXYZRGBNormal &pnt, const std::vector<DoubleField*> &constantFields)
192 {
193  pnt.x = static_cast<float>(constantFields[0]->getDoubleValue());
194  pnt.y = static_cast<float>(constantFields[1]->getDoubleValue());
195  pnt.z = static_cast<float>(constantFields[2]->getDoubleValue());
196  pnt.data[3] = static_cast<float>(constantFields[3]->getDoubleValue());
197  pnt.normal_x = static_cast<float>(constantFields[4]->getDoubleValue());
198  pnt.normal_y = static_cast<float>(constantFields[5]->getDoubleValue());
199  pnt.normal_z = static_cast<float>(constantFields[6]->getDoubleValue());
200  pnt.data_n[3] = static_cast<float>(constantFields[7]->getDoubleValue());
201  pnt.curvature = static_cast<float>(constantFields[8]->getDoubleValue());
202  pnt.rgb = static_cast<float>(constantFields[9]->getDoubleValue());
203 }
204 inline void setPointFromFields(pcl::PointXYZINormal &pnt, const std::vector<DoubleField*> &constantFields)
205 {
206  pnt.x = static_cast<float>(constantFields[0]->getDoubleValue());
207  pnt.y = static_cast<float>(constantFields[1]->getDoubleValue());
208  pnt.z = static_cast<float>(constantFields[2]->getDoubleValue());
209  pnt.data[3] = static_cast<float>(constantFields[3]->getDoubleValue());
210  pnt.normal_x = static_cast<float>(constantFields[4]->getDoubleValue());
211  pnt.normal_y = static_cast<float>(constantFields[5]->getDoubleValue());
212  pnt.normal_z = static_cast<float>(constantFields[6]->getDoubleValue());
213  pnt.data_n[3] = static_cast<float>(constantFields[7]->getDoubleValue());
214  pnt.curvature = static_cast<float>(constantFields[8]->getDoubleValue());
215  pnt.intensity = static_cast<float>(constantFields[9]->getDoubleValue());
216 }
218 
219 //----------------------------------------------------------------------------------
223 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
224 //----------------------------------------------------------------------------------
226 inline void setPointFromScalar(pcl::PointXYZ &pnt, const float val)
227 {
228  pnt.x = val;
229  pnt.y = val;
230  pnt.z = val;
231  pnt.data[3] = val;
232 }
233 inline void setPointFromScalar(pcl::PointXYZLNormal &pnt, const float val)
234 {
235  pnt.x = val;
236  pnt.y = val;
237  pnt.z = val;
238  pnt.data[3] = val;
239  pnt.normal_x = val;
240  pnt.normal_y = val;
241  pnt.normal_z = val;
242  pnt.data_n[3] = val;
243  pnt.curvature = val;
244  pnt.label = static_cast<std::uint32_t>(MLAbs(val)); // Note: neg float -> uint is undefined.
245 }
246 inline void setPointFromScalar(pcl::PointXYZRGBNormal &pnt, const float val)
247 {
248  pnt.x = val;
249  pnt.y = val;
250  pnt.z = val;
251  pnt.data[3] = val;
252  pnt.normal_x = val;
253  pnt.normal_y = val;
254  pnt.normal_z = val;
255  pnt.data_n[3] = val;
256  pnt.curvature = val;
257  pnt.rgb = val;
258 }
259 inline void setPointFromScalar(pcl::PointXYZINormal &pnt, const float val)
260 {
261  pnt.x = val;
262  pnt.y = val;
263  pnt.z = val;
264  pnt.data[3] = val;
265  pnt.normal_x = val;
266  pnt.normal_y = val;
267  pnt.normal_z = val;
268  pnt.data_n[3] = val;
269  pnt.curvature = val;
270  pnt.intensity = val;
271 }
273 
274 //----------------------------------------------------------------------------------
278 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
279 //----------------------------------------------------------------------------------
281 inline void setFieldsFromPoint(const pcl::PointXYZ &pnt, std::vector<DoubleField*> &resultFields)
282 {
283  resultFields[0]->setDoubleValue(pnt.x );
284  resultFields[1]->setDoubleValue(pnt.y );
285  resultFields[2]->setDoubleValue(pnt.z );
286  resultFields[3]->setDoubleValue(pnt.data[3]);
287 }
288 inline void setFieldsFromPoint(const pcl::PointXYZLNormal &pnt, std::vector<DoubleField*> &resultFields)
289 {
290  resultFields[0]->setDoubleValue(pnt.x );
291  resultFields[1]->setDoubleValue(pnt.y );
292  resultFields[2]->setDoubleValue(pnt.z );
293  resultFields[3]->setDoubleValue(pnt.data[3] );
294  resultFields[4]->setDoubleValue(pnt.normal_x );
295  resultFields[5]->setDoubleValue(pnt.normal_y );
296  resultFields[6]->setDoubleValue(pnt.normal_z );
297  resultFields[7]->setDoubleValue(pnt.data_n[3]);
298  resultFields[8]->setDoubleValue(pnt.curvature);
299  resultFields[9]->setDoubleValue(static_cast<double>(pnt.label));
300 }
301 inline void setFieldsFromPoint(const pcl::PointXYZRGBNormal &pnt, std::vector<DoubleField*> &resultFields)
302 {
303  resultFields[0]->setDoubleValue(pnt.x );
304  resultFields[1]->setDoubleValue(pnt.y );
305  resultFields[2]->setDoubleValue(pnt.z );
306  resultFields[3]->setDoubleValue(pnt.data[3] );
307  resultFields[4]->setDoubleValue(pnt.normal_x );
308  resultFields[5]->setDoubleValue(pnt.normal_y );
309  resultFields[6]->setDoubleValue(pnt.normal_z );
310  resultFields[7]->setDoubleValue(pnt.data_n[3]);
311  resultFields[8]->setDoubleValue(pnt.curvature);
312  resultFields[9]->setDoubleValue(pnt.rgb );
313 }
314 inline void setFieldsFromPoint(const pcl::PointXYZINormal &pnt, std::vector<DoubleField*> &resultFields)
315 {
316  resultFields[0]->setDoubleValue(pnt.x );
317  resultFields[1]->setDoubleValue(pnt.y );
318  resultFields[2]->setDoubleValue(pnt.z );
319  resultFields[3]->setDoubleValue(pnt.data[3] );
320  resultFields[4]->setDoubleValue(pnt.normal_x );
321  resultFields[5]->setDoubleValue(pnt.normal_y );
322  resultFields[6]->setDoubleValue(pnt.normal_z );
323  resultFields[7]->setDoubleValue(pnt.data_n[3]);
324  resultFields[8]->setDoubleValue(pnt.curvature);
325  resultFields[9]->setDoubleValue(pnt.intensity);
326 }
328 
329 //----------------------------------------------------------------------------------
331 //----------------------------------------------------------------------------------
332 template <typename PCL_OBJECT_PTR_TYPE>
333 inline void createEmptyPCLObject(PCL_OBJECT_PTR_TYPE &retPCLObjectPtr)
334 {
335  typedef typename PCL_OBJECT_PTR_TYPE::element_type PCL_OBJECT_TYPE;
336  retPCLObjectPtr = PCL_OBJECT_PTR_TYPE(new PCL_OBJECT_TYPE);
337 }
338 
339 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
341 //----------------------------------------------------------------------------------
343 //----------------------------------------------------------------------------------
345 {
346  MLPointCloudXYZPtr retPointCloudPtr;
347  createEmptyPCLObject(retPointCloudPtr);
348  return retPointCloudPtr;
349 }
350 //----------------------------------------------------------------------------------
352 //----------------------------------------------------------------------------------
354 {
355  MLPointCloudXYZLNormalPtr retPointCloudPtr;
356  createEmptyPCLObject(retPointCloudPtr);
357  return retPointCloudPtr;
358 }
359 //----------------------------------------------------------------------------------
361 //----------------------------------------------------------------------------------
363 {
364  MLPointCloudXYZRGBNormalPtr retPointCloudPtr;
365  createEmptyPCLObject(retPointCloudPtr);
366  return retPointCloudPtr;
367 }
368 //----------------------------------------------------------------------------------
370 //----------------------------------------------------------------------------------
372 {
373  MLPointCloudXYZINormalPtr retPointCloudPtr;
374  createEmptyPCLObject(retPointCloudPtr);
375  return retPointCloudPtr;
376 }
377 //----------------------------------------------------------------------------------
379 //----------------------------------------------------------------------------------
381 {
382  MLPolygonMeshPtr retPolygonMeshPtr;
383  createEmptyPCLObject(retPolygonMeshPtr);
384  return retPolygonMeshPtr;
385 }
387 
388 //----------------------------------------------------------------------------------
390 //----------------------------------------------------------------------------------
392  Empty = 0, //<! An empty point cloud.
393  OriginPoint, //<! A point cloud with one point at (0,0,0).
394  Triangle, //<! A point cloud with the points (0,0,0), (1,0,0), (0,1,0).
395  Square, //<! A point cloud with the points (0,0,0), (1,0,0), (0,1,0), (1,1,0).
396  Cube //<! A point cloud with the points (0,0,0), (1,0,0), (0,1,0), (1,1,0),
397  //<! (0,0,1), (1,0,1), (0,1,1), (1,1,1).
398 };
399 //----------------------------------------------------------------------------------
401 //----------------------------------------------------------------------------------
402 enum {
404 };
405 
406 //----------------------------------------------------------------------------------
408 //----------------------------------------------------------------------------------
410  Fill = 0, //<! Fill with a given default value.
411  Indexed //<! Each point gets its index at data[3].
412 };
413 //----------------------------------------------------------------------------------
415 //----------------------------------------------------------------------------------
416 enum {
418 };
419 
420 //----------------------------------------------------------------------------------
423 //----------------------------------------------------------------------------------
424 template <typename POINT_CLOUD_TYPE>
425 inline void appendPoint(POINT_CLOUD_TYPE &pc,
426  const Vector3f &pos,
427  float fillValue)
428 {
429  typedef typename POINT_CLOUD_TYPE::PointType POINT_TYPE;
430  POINT_TYPE newPoint;
431  newPoint.x = pos.x;
432  newPoint.y = pos.y;
433  newPoint.z = pos.z;
434  newPoint.data[3] = fillValue;
435  pc.push_back(newPoint);
436 }
437 
438 //----------------------------------------------------------------------------------
441 //----------------------------------------------------------------------------------
442 template <typename POINT_CLOUD_TYPE>
443 inline void appendFillPattern(POINT_CLOUD_TYPE &pc,
444  PointCloudDefaultPatterns pattern,
445  PointCloudFillPatterns fillMode,
446  float fillValue=0.f)
447 {
448  // Counter for added points.
449  float index = 0;
450  bool useFillVal=false;
451  switch(fillMode){
452  case Fill: useFillVal=true; break;
453  case Indexed: useFillVal=false; break;
454  default:
455  ML_PRINT_ERROR("mlPCLMLTools.cpp: appendFillPattern", ML_BAD_PARAMETER,
456  "Bad fill mode, using fillMode 'Fill'.");
457  break;
458  }
459 
460  switch (pattern){
461  case Empty: break;
462  case OriginPoint:
463  appendPoint(pc, Vector3f(0,0,0), useFillVal ? fillValue : index); index+=1.f;
464  break;
465  case Triangle:
466  appendPoint(pc, Vector3f(0,0,0), useFillVal ? fillValue : index); index+=1.f;
467  appendPoint(pc, Vector3f(1,0,0), useFillVal ? fillValue : index); index+=1.f;
468  appendPoint(pc, Vector3f(0,1,0), useFillVal ? fillValue : index); index+=1.f;
469  break;
470  case Square:
471  appendPoint(pc, Vector3f(0,0,0), useFillVal ? fillValue : index); index+=1.f;
472  appendPoint(pc, Vector3f(1,0,0), useFillVal ? fillValue : index); index+=1.f;
473  appendPoint(pc, Vector3f(0,1,0), useFillVal ? fillValue : index); index+=1.f;
474  appendPoint(pc, Vector3f(1,1,0), useFillVal ? fillValue : index); index+=1.f;
475  break;
476  case Cube:
477  appendPoint(pc, Vector3f(0,0,0), useFillVal ? fillValue : index); index+=1.f;
478  appendPoint(pc, Vector3f(1,0,0), useFillVal ? fillValue : index); index+=1.f;
479  appendPoint(pc, Vector3f(0,1,0), useFillVal ? fillValue : index); index+=1.f;
480  appendPoint(pc, Vector3f(1,1,0), useFillVal ? fillValue : index); index+=1.f;
481  appendPoint(pc, Vector3f(0,0,1), useFillVal ? fillValue : index); index+=1.f;
482  appendPoint(pc, Vector3f(1,0,1), useFillVal ? fillValue : index); index+=1.f;
483  appendPoint(pc, Vector3f(0,1,1), useFillVal ? fillValue : index); index+=1.f;
484  appendPoint(pc, Vector3f(1,1,1), useFillVal ? fillValue : index); index+=1.f;
485  break;
486  default:
487  ML_PRINT_ERROR("mlPCLMLTools.cpp: appendFillPattern", ML_BAD_PARAMETER,
488  "Bad fill pattern, could not add points to point cloud.");
489  break;
490  }
491 }
492 
493 //----------------------------------------------------------------------------------
495 //----------------------------------------------------------------------------------
496 inline bool fourFloatsDiffer(const float data1[4],
497  const float data2[4],
498  double epsilon=FLT_EPSILON)
499 {
500  return ((MLAbs(data1[0] - data2[0]) >= epsilon) ||
501  (MLAbs(data1[1] - data2[1]) >= epsilon) ||
502  (MLAbs(data1[2] - data2[2]) >= epsilon) ||
503  (MLAbs(data1[3] - data2[3]) >= epsilon) );
504 }
505 
507 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
508 
509 //----------------------------------------------------------------------------------
514 //----------------------------------------------------------------------------------
515 template <typename POINT_TYPE1, typename POINT_TYPE2>
516 inline bool doPCLPointNonDataMembersDiffer(const POINT_TYPE1 &/*point1*/,
517  const POINT_TYPE2 &/*point2*/,
518  double /*epsilon*/=FLT_EPSILON)
519 {
520  return true;
521 }
522 
523 //----------------------------------------------------------------------------------
526 //----------------------------------------------------------------------------------
527 inline bool doPCLPointNonDataMembersDiffer(const pcl::PointXYZ &/*point1*/,
528  const pcl::PointXYZ &/*point2*/,
529  double /*epsilon*/=FLT_EPSILON)
530 {
531  return false;
532 }
533 
534 //----------------------------------------------------------------------------------
537 //----------------------------------------------------------------------------------
538 inline bool doPCLPointNonDataMembersDiffer(const pcl::PointXYZLNormal &point1,
539  const pcl::PointXYZLNormal &point2,
540  double epsilon=FLT_EPSILON)
541 {
542  return fourFloatsDiffer(point1.data_n, point2.data_n, epsilon) ||
543  (point1.label != point2.label) ||
544  (MLAbs(point1.curvature - point2.curvature) >= epsilon);
545 }
546 
547 //----------------------------------------------------------------------------------
550 //----------------------------------------------------------------------------------
551 inline bool doPCLPointNonDataMembersDiffer(const pcl::PointXYZRGBNormal &point1,
552  const pcl::PointXYZRGBNormal &point2,
553  double epsilon=FLT_EPSILON)
554 {
555  return fourFloatsDiffer(point1.data_n, point2.data_n, epsilon) ||
556  (point1.rgba != point2.rgba) ||
557  (MLAbs(point1.curvature - point2.curvature) >= epsilon);
558 }
559 
560 //----------------------------------------------------------------------------------
563 //----------------------------------------------------------------------------------
564 inline bool doPCLPointNonDataMembersDiffer(const pcl::PointXYZINormal &point1,
565  const pcl::PointXYZINormal &point2,
566  double epsilon=FLT_EPSILON)
567 {
568  return fourFloatsDiffer(point1.data_n, point2.data_n, epsilon) ||
569  (MLAbs(point1.intensity - point2.intensity) >= epsilon) ||
570  (MLAbs(point1.curvature - point2.curvature) >= epsilon);
571 }
573 
574 //----------------------------------------------------------------------------------
582 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
583 //----------------------------------------------------------------------------------
585 inline void setIntensityReplacement(pcl::PointXYZ & /*p*/, float /*value*/=1.f, MLuint8 /*opacity*/=0xff)
586 {
587  // There is no member which could be used for the intensity.
588 }
589 inline void setIntensityReplacement(pcl::PointXYZLNormal &p, float value=1.f, MLuint8 /*opacity*/=0xff)
590 {
591  p.curvature = value;
592 }
593 inline void setIntensityReplacement(pcl::PointXYZRGBNormal &p, float value=1.f, MLuint8 opacity=0xff /*opaque*/)
594 {
595  p.curvature = value;
596  p.r = p.g = p.b = static_cast<MLuint8>(value * 255.9999f);
597  p.a = opacity;
598 }
599 inline void setIntensityReplacement(pcl::PointXYZINormal &p, float value=1.f, MLuint8 /*opacity*/=0xff)
600 {
601  p.intensity = value;
602 }
604 
605 //----------------------------------------------------------------------------------
609 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
610 //----------------------------------------------------------------------------------
612 inline float getIntensityReplacement(const pcl::PointXYZ & /*p*/)
613 {
614  // There is no member which could be used for the intensity.
615  return 0.f;
616 }
617 inline float getIntensityReplacement(const pcl::PointXYZLNormal &p)
618 {
619  return p.curvature;
620 }
621 inline float getIntensityReplacement(const pcl::PointXYZRGBNormal &p)
622 {
623  return p.curvature;
624 }
625 inline float getIntensityReplacement(const pcl::PointXYZINormal &p)
626 {
627  return p.intensity;
628 }
630 
631 //----------------------------------------------------------------------------------
634 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
635 //----------------------------------------------------------------------------------
637 inline float getCurvature(const pcl::PointXYZ & /*p*/)
638 {
639  // There is no member which could be used as curvature.
640  return 0.f;
641 }
642 inline float getCurvature(const pcl::PointXYZLNormal &p)
643 {
644  return p.curvature;
645 }
646 inline float getCurvature(const pcl::PointXYZRGBNormal &p)
647 {
648  return p.curvature;
649 }
650 inline float getCurvature(const pcl::PointXYZINormal &p)
651 {
652  return p.curvature;
653 }
654 inline void setCurvature(pcl::PointXYZ & /*p*/, float /*curvature*/)
655 {
656  // This point type has no curvature which could be set.
657 }
658 inline void setCurvature(pcl::PointXYZLNormal &p, float curvature)
659 {
660  p.curvature = curvature;
661 }
662 inline void setCurvature(pcl::PointXYZRGBNormal &p, float curvature)
663 {
664  p.curvature = curvature;
665 }
666 inline void setCurvature(pcl::PointXYZINormal &p, float curvature)
667 {
668  p.curvature = curvature;
669 }
671 
672 //----------------------------------------------------------------------------------
675 // NOTE: Implement all types explicitly, because VC14-32 compiler will
676 // matches RGBA type to default template version otherwise (which reads
677 // 0u or sets nothing).
678 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
679 //----------------------------------------------------------------------------------
681 inline unsigned int getPointRGBA(const pcl::PointXYZ & /*rgbaPnt*/)
682 {
683  return 0u;
684 }
685 inline unsigned int getPointRGBA(const pcl::PointXYZINormal & /*rgbaPnt*/)
686 {
687  return 0u;
688 }
689 inline unsigned int getPointRGBA(const pcl::PointXYZRGBNormal &rgbaPnt)
690 {
691  return rgbaPnt.rgba;
692 }
693 inline unsigned int getPointRGBA(const pcl::PointXYZLNormal & /*rgbaPnt*/)
694 {
695  return 0u;
696 }
697 inline void setPointRGBA(pcl::PointXYZ &/*rgbaPnt*/,
698  MLuint32 /*srcVal*/)
699 {
700 }
701 inline void setPointRGBA(pcl::PointXYZINormal &/*rgbaPnt*/,
702  MLuint32 /*srcVal*/)
703 {
704 }
705 inline void setPointRGBA(pcl::PointXYZRGBNormal &rgbaPnt,
706  MLuint32 srcVal)
707 {
708  rgbaPnt.rgba = srcVal;
709 }
710 inline void setPointRGBA(pcl::PointXYZLNormal &/*rgbaPnt*/,
711  MLuint32 /*srcVal*/)
712 {
713 }
715 
716 //----------------------------------------------------------------------------------
720 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
721 //----------------------------------------------------------------------------------
723 inline void setPointNormal(pcl::PointXYZ &/*p*/, float /*nx*/, float /*ny*/, float /*nz*/)
724 {
725  // There is no member which could be used for the intensity.
726 }
727 inline void setPointNormal(pcl::PointXYZLNormal &p, float nx, float ny, float nz)
728 {
729  p.normal_x = nx;
730  p.normal_y = ny;
731  p.normal_z = nz;
732 }
733 inline void setPointNormal(pcl::PointXYZRGBNormal &p, float nx, float ny, float nz)
734 {
735  p.normal_x = nx;
736  p.normal_y = ny;
737  p.normal_z = nz;
738 }
739 inline void setPointNormal(pcl::PointXYZINormal &p, float nx, float ny, float nz)
740 {
741  p.normal_x = nx;
742  p.normal_y = ny;
743  p.normal_z = nz;
744 }
746 
747 //----------------------------------------------------------------------------------
751 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
752 //----------------------------------------------------------------------------------
754 inline void getPointNormal(const pcl::PointXYZ & /*p*/, float &nx, float &ny, float &nz)
755 {
756  nx = 0.f;
757  ny = 0.f;
758  nz = 0.f;
759 }
760 inline void getPointNormal(const pcl::PointXYZLNormal &p, float &nx, float &ny, float &nz)
761 {
762  nx = p.normal_x;
763  ny = p.normal_y;
764  nz = p.normal_z;
765 }
766 inline void getPointNormal(const pcl::PointXYZRGBNormal &p, float &nx, float &ny, float &nz)
767 {
768  nx = p.normal_x;
769  ny = p.normal_y;
770  nz = p.normal_z;
771 }
772 inline void getPointNormal(const pcl::PointXYZINormal &p, float &nx, float &ny, float &nz)
773 {
774  nx = p.normal_x;
775  ny = p.normal_y;
776  nz = p.normal_z;
777 }
779 
780 //----------------------------------------------------------------------------------
782 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
783 //----------------------------------------------------------------------------------
785 inline bool hasNormal (const pcl::PointXYZ &){ return false;}
786 inline bool hasNormal (const pcl::PointXYZLNormal &){ return true ;}
787 inline bool hasNormal (const pcl::PointXYZRGBNormal &){ return true ;}
788 inline bool hasNormal (const pcl::PointXYZINormal &){ return true ;}
790 
791 //----------------------------------------------------------------------------------
793 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
794 //----------------------------------------------------------------------------------
796 inline bool hasLabel (const pcl::PointXYZ &){ return false;}
797 inline bool hasLabel (const pcl::PointXYZLNormal &){ return true ;}
798 inline bool hasLabel (const pcl::PointXYZRGBNormal &){ return false;}
799 inline bool hasLabel (const pcl::PointXYZINormal &){ return false;}
801 
802 //----------------------------------------------------------------------------------
804 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
805 //----------------------------------------------------------------------------------
807 inline bool hasRGBA (const pcl::PointXYZ &){ return false;}
808 inline bool hasRGBA (const pcl::PointXYZLNormal &){ return false;}
809 inline bool hasRGBA (const pcl::PointXYZRGBNormal &){ return true ;}
810 inline bool hasRGBA (const pcl::PointXYZINormal &){ return false;}
812 
813 //----------------------------------------------------------------------------------
815 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
816 //----------------------------------------------------------------------------------
818 inline bool hasIntensity(const pcl::PointXYZ &){ return false;}
819 inline bool hasIntensity(const pcl::PointXYZLNormal &){ return false;}
820 inline bool hasIntensity(const pcl::PointXYZRGBNormal &){ return false;}
821 inline bool hasIntensity(const pcl::PointXYZINormal &){ return true ;}
823 
824 //----------------------------------------------------------------------------------
826 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
827 //----------------------------------------------------------------------------------
829 inline bool hasCurvature(const pcl::PointXYZ &){ return false;}
830 inline bool hasCurvature(const pcl::PointXYZLNormal &){ return true ;}
831 inline bool hasCurvature(const pcl::PointXYZRGBNormal &){ return true ;}
832 inline bool hasCurvature(const pcl::PointXYZINormal &){ return true ;}
834 
835 //----------------------------------------------------------------------------------
837 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
838 //----------------------------------------------------------------------------------
840 inline bool hasIntensityReplacement(const pcl::PointXYZ &){ return false;}
841 inline bool hasIntensityReplacement(const pcl::PointXYZLNormal &){ return true ;}
842 inline bool hasIntensityReplacement(const pcl::PointXYZRGBNormal &){ return true ;}
843 inline bool hasIntensityReplacement(const pcl::PointXYZINormal &){ return true ;}
845 
846 //----------------------------------------------------------------------------------
868 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
869 //----------------------------------------------------------------------------------
870 template <typename POINT_TYPE>
871 inline void getPCLPointAsFormattedString(const POINT_TYPE &point,
872  std::string &formatStr,
873  int numDecimalPlaces,
874  size_t pointIndex)
875 {
876  // For performance reasons call the replace functions and the calculations for its parameters only if the corresponding
877  // replace value is available.
878  if (std::string::npos != formatStr.find("$(x)")){
879  formatStr = ReleaseToolsString::replaceAllStr1ByStr2(formatStr, "$(x)", getScalarMemberValueAsString(point, 0, numDecimalPlaces));
880  }
881  if (std::string::npos != formatStr.find("$(data[0])")){
882  formatStr = ReleaseToolsString::replaceAllStr1ByStr2(formatStr, "$(data[0])", getScalarMemberValueAsString(point, 0, numDecimalPlaces));
883  }
884  if (std::string::npos != formatStr.find("$(y)")){
885  formatStr = ReleaseToolsString::replaceAllStr1ByStr2(formatStr, "$(y)", getScalarMemberValueAsString(point, 1, numDecimalPlaces));
886  }
887  if (std::string::npos != formatStr.find("$(data[1])")){
888  formatStr = ReleaseToolsString::replaceAllStr1ByStr2(formatStr, "$(data[1])", getScalarMemberValueAsString(point, 1, numDecimalPlaces));
889  }
890  if (std::string::npos != formatStr.find("$(z)")){
891  formatStr = ReleaseToolsString::replaceAllStr1ByStr2(formatStr, "$(z)", getScalarMemberValueAsString(point, 2, numDecimalPlaces));
892  }
893  if (std::string::npos != formatStr.find("$(data[2])")){
894  formatStr = ReleaseToolsString::replaceAllStr1ByStr2(formatStr, "$(data[2])", getScalarMemberValueAsString(point, 2, numDecimalPlaces));
895  }
896  if (std::string::npos != formatStr.find("$(data[3])")){
897  formatStr = ReleaseToolsString::replaceAllStr1ByStr2(formatStr, "$(data[3])", getScalarMemberValueAsString(point, 3, numDecimalPlaces));
898  }
899 
900  if (std::string::npos != formatStr.find("$(nx)")){
901  formatStr = ReleaseToolsString::replaceAllStr1ByStr2(formatStr, "$(nx)", getScalarMemberValueAsString(point, 4, numDecimalPlaces));
902  }
903  if (std::string::npos != formatStr.find("$(data_n[0])")){
904  formatStr = ReleaseToolsString::replaceAllStr1ByStr2(formatStr, "$(data_n[0])", getScalarMemberValueAsString(point, 4, numDecimalPlaces));
905  }
906  if (std::string::npos != formatStr.find("$(ny)")){
907  formatStr = ReleaseToolsString::replaceAllStr1ByStr2(formatStr, "$(ny)", getScalarMemberValueAsString(point, 5, numDecimalPlaces));
908  }
909  if (std::string::npos != formatStr.find("$(data_n[1])")){
910  formatStr = ReleaseToolsString::replaceAllStr1ByStr2(formatStr, "$(data_n[1])", getScalarMemberValueAsString(point, 5, numDecimalPlaces));
911  }
912  if (std::string::npos != formatStr.find("$(nz)")){
913  formatStr = ReleaseToolsString::replaceAllStr1ByStr2(formatStr, "$(nz)", getScalarMemberValueAsString(point, 6, numDecimalPlaces));
914  }
915  if (std::string::npos != formatStr.find("$(data_n[2])")){
916  formatStr = ReleaseToolsString::replaceAllStr1ByStr2(formatStr, "$(data_n[2])", getScalarMemberValueAsString(point, 6, numDecimalPlaces));
917  }
918  if (std::string::npos != formatStr.find("$(data_n[3])")){
919  formatStr = ReleaseToolsString::replaceAllStr1ByStr2(formatStr, "$(data_n[3])", getScalarMemberValueAsString(point, 7, numDecimalPlaces));
920  }
921 
922  if (std::string::npos != formatStr.find("$(ir)")){
923  const float ir = getIntensityReplacement(point);
924  formatStr = ReleaseToolsString::replaceAllStr1ByStr2(formatStr, "$(ir)", hasIntensityReplacement(point) ?
925  ReleaseToolsString::toDblStr(ir, -1, static_cast<signed char>(numDecimalPlaces), false, true):
926  std::string());
927  }
928  if (std::string::npos != formatStr.find("$(curvature)")){
929  formatStr = ReleaseToolsString::replaceAllStr1ByStr2(formatStr, "$(curvature)", getScalarMemberValueAsString(point, 8, numDecimalPlaces));
930  }
931  if (std::string::npos != formatStr.find("$(rgba)")){
932  formatStr = ReleaseToolsString::replaceAllStr1ByStr2(formatStr, "$(rgba)", hasRGBA(point) ?
933  getScalarMemberValueAsString(point, 9, numDecimalPlaces) :
934  std::string());
935  }
936  if (std::string::npos != formatStr.find("$(intensity)")){
937  formatStr = ReleaseToolsString::replaceAllStr1ByStr2(formatStr, "$(intensity)", hasIntensity(point) ?
938  getScalarMemberValueAsString(point, 9, numDecimalPlaces) :
939  std::string());
940  }
941  if (std::string::npos != formatStr.find("$(label)")){
942  formatStr = ReleaseToolsString::replaceAllStr1ByStr2(formatStr, "$(label)", hasLabel(point) ?
943  getScalarMemberValueAsString(point, 9, numDecimalPlaces) :
944  std::string());
945  }
946  if (std::string::npos != formatStr.find("$(index)")){
947  formatStr = ReleaseToolsString::replaceAllStr1ByStr2(formatStr, "$(index)", ReleaseToolsString::toSize_tStr(pointIndex));
948  }
949 }
950 
951 //----------------------------------------------------------------------------------
969 //----------------------------------------------------------------------------------
970 template <typename POINT_CLOUD_TYPE>
971 inline std::string getPCLPointListAsString(const POINT_CLOUD_TYPE &pointCloud,
972  MLint maxNumShownPoints=ML_INT64_MAX,
973  MLint indexOfFirstPoint=0,
974  bool showIndices=true,
975  const std::string &lineSeparator="\n",
976  int numDecimalPlaces = -1,
977  const std::string &pointsPrintFormatStr="")
978 {
979  std::string retString;
980  const MLuint64 numPoints = pointCloud.points.size();
981  if ( (maxNumShownPoints>0) && (numPoints > 0) && (indexOfFirstPoint < mlrange_cast<MLint64>(numPoints)) ){
982 
983  // Correct input parameters if necessary.
984  if (indexOfFirstPoint < 0){ indexOfFirstPoint = 0; }
985  if (indexOfFirstPoint >= mlrange_cast<MLint64>(numPoints)){
986  indexOfFirstPoint = mlrange_cast<MLint>(numPoints)-1;
987  }
988  if (maxNumShownPoints > mlrange_cast<MLint64>(numPoints)){
989  maxNumShownPoints = mlrange_cast<MLint>(numPoints);
990  }
991  MLuint64 startPointIdx = mlrange_cast<MLuint64>(indexOfFirstPoint);
992  MLuint64 endPointIdx = mlrange_cast<MLuint64>(indexOfFirstPoint + maxNumShownPoints);
993  if (endPointIdx > numPoints){ endPointIdx = numPoints; } // endPointIdx itself is already excluded
994 
995  std::string idxPrefix = "";
996  const std::string colonStr = ":";
997 
998  // Use size_t for indices to avoid indexing warnings on 32 bit systems.
999  const size_t firstIdx = mlrange_cast<size_t>(startPointIdx);
1000  const size_t endIdx = mlrange_cast<size_t>(endPointIdx);
1001 
1002  // Guess to avoid too many resizes.
1003  retString.reserve((endIdx-firstIdx)*20);
1004 
1005  // Empty? Then use normal print, otherwise use formatted one.
1006  const bool isFormatted = !pointsPrintFormatStr.empty();
1007 
1008  // Print points into string (reserve to avoid expensive reallocations).
1009  std::string lineStr;
1010  lineStr.reserve(512);
1011  for (size_t c=firstIdx; c < endIdx; ++c){
1012  if (showIndices){
1013  idxPrefix = ReleaseToolsString::toMLUIntStr(c) + colonStr;
1014  }
1015  if (isFormatted){
1016  lineStr = pointsPrintFormatStr;
1017  getPCLPointAsFormattedString(pointCloud.points[c], lineStr, numDecimalPlaces, c);
1018  }
1019  else{
1020  lineStr = getPCLPointAsString(pointCloud.points[c], numDecimalPlaces);
1021  }
1022  retString += idxPrefix + lineStr + lineSeparator;
1023  }
1024  }
1025  return retString;
1026 }
1027 
1028 //----------------------------------------------------------------------------------
1031 //----------------------------------------------------------------------------------
1032 template <typename POINT_CLOUD_TYPE>
1033 inline std::string getPointStructureT(const POINT_CLOUD_TYPE &pointCloud)
1034 {
1035  std::string retStr;
1036  if (pointCloud.points.size() > 0){
1037  const size_t numMembers = PCLSupportTools::getNumberOfScalarPointMembers(pointCloud);
1038  for (size_t c=0; c < numMembers; ++c){
1039  if (c > 0){
1040  retStr += ", ";
1041  }
1042  retStr += PCLSupportTools::getScalarMemberNameAsString(pointCloud.points[0], c);
1043  }
1044  }
1045  return retStr;
1046 }
1047 
1050 #define _PCLSupportTools_NewLineDefaultArgumentString "\n"
1051 
1052 //----------------------------------------------------------------------------------
1064 //----------------------------------------------------------------------------------
1065 MLPCLSUPPORT_EXPORT std::string getPCLVerticesAsString(const std::vector<pcl::Vertices> &vertices,
1066  MLint maxNumShownVertices=ML_INT64_MAX,
1067  MLint indexOfFirstVertex=0,
1068  bool showIndices=true,
1069  const std::string &lineSeparator=_PCLSupportTools_NewLineDefaultArgumentString);
1070 
1071 //----------------------------------------------------------------------------------
1082 // See python PCLInfoTest for a test testing this functionality indirectly.
1083 //----------------------------------------------------------------------------------
1084 MLPCLSUPPORT_EXPORT std::string getPCLIndicesAsString(const std::vector<int> &indices,
1085  MLint maxNumShownIndices,
1086  MLint indexOfFirstIndex,
1087  bool showIndices,
1088  const std::string &lineSeparator=_PCLSupportTools_NewLineDefaultArgumentString);
1089 
1090 //----------------------------------------------------------------------------------
1098 //----------------------------------------------------------------------------------
1099 MLPCLSUPPORT_EXPORT void PCLExtractSubIndices(const std::vector<int> &subIndices,
1100  std::vector<int> &indices);
1101 
1102 //----------------------------------------------------------------------------------
1112 //----------------------------------------------------------------------------------
1114  const std::uint8_t *dataPtr,
1115  int numDecimalPlaces = -1);
1116 
1117 //----------------------------------------------------------------------------------
1123 //----------------------------------------------------------------------------------
1125  bool aligned);
1126 
1127 //----------------------------------------------------------------------------------
1138 //----------------------------------------------------------------------------------
1139 MLPCLSUPPORT_EXPORT std::string getCloudDataString(const MLPolygonMesh &polygonMesh,
1140  MLint maxNumShownVertices=ML_INT64_MAX,
1141  MLint indexOfFirstVertex=0,
1142  bool showIndices=true,
1143  const std::string &lineSeparator=_PCLSupportTools_NewLineDefaultArgumentString,
1144  int numDecimalPlaces=-1);
1145 
1146 #if 0
1147 // Still untested. To be activated when needed.
1148 //----------------------------------------------------------------------------------
1155 //----------------------------------------------------------------------------------
1156 MLPCLSUPPORT_EXPORT double getPointFieldValueAsDouble(pcl::uint8_t fd,
1157  const pcl::uint8_t *dataPtr);
1158 
1159 //----------------------------------------------------------------------------------
1161 //----------------------------------------------------------------------------------
1162 MLPCLSUPPORT_EXPORT double getPointFieldValueAsfloat(pcl::uint8_t fd,
1163  const pcl::uint8_t *dataPtr);
1164 
1165 //----------------------------------------------------------------------------------
1167 //----------------------------------------------------------------------------------
1168 struct MLPCLSUPPORT_EXPORT XYZNormalAndValue {
1169  // Initializes all members to 0.
1170  inline XYZNormalAndValue():px(0.f),py(0.f),pz(0.f), nx(0.f),ny(0.f),nz(0.f), intensity(0.f), rgba(0), isRGBA(false){}
1171  // Initializes all members to 0.
1172  inline void clear(){ px=0.f; py=0.f; pz=0.f; nx=0.f; ny=0.f; nz=0.f; intensity=0.f; rgba=0; isRGBA=false; }
1173 
1175  float px,py,pz;
1177  float nx,ny,nz;
1179  float intensity;
1181  MLuint32 rgba;
1183  bool isRGBA;
1184 };
1185 
1186 //----------------------------------------------------------------------------------
1192 //----------------------------------------------------------------------------------
1193 MLPCLSUPPORT_EXPORT void getCloudDataGeometry(const MLPolygonMesh &polygonMesh,
1194  std::vector<XYZNormalAndValue> &geometry);
1195 #endif
1196 
1197 //----------------------------------------------------------------------------------
1199 //----------------------------------------------------------------------------------
1200 MLPCLSUPPORT_EXPORT std::string getCloudFieldsString(const std::vector<pcl::PCLPointField> &fields);
1201 
1202 //----------------------------------------------------------------------------------
1206 //----------------------------------------------------------------------------------
1207 template <typename POINT_CLOUD_TYPE>
1208 inline SubImageBoxd getBoxForPointCloud(const POINT_CLOUD_TYPE &inputPointCloud)
1209 {
1210  // Create empty return box.
1211  SubImageBoxd retBox;
1212  retBox.v1[0] = ML_FLOAT_MAX;
1213  retBox.v1[1] = ML_FLOAT_MAX;
1214  retBox.v1[2] = ML_FLOAT_MAX;
1215  retBox.v1[3] = 0.;
1216  retBox.v1[4] = 0.;
1217  retBox.v1[5] = 0.;
1218  retBox.v2[0] = -ML_FLOAT_MAX;
1219  retBox.v2[1] = -ML_FLOAT_MAX;
1220  retBox.v2[2] = -ML_FLOAT_MAX;
1221  retBox.v2[3] = 0.;
1222  retBox.v2[4] = 0.;
1223  retBox.v2[5] = 0.;
1224 
1225  const size_t numPoints = inputPointCloud.points.size();
1226  for (size_t c=0; c < numPoints; ++c){
1227  typedef typename POINT_CLOUD_TYPE::PointType PointType;
1228  const PointType &pnt = inputPointCloud.points[c];
1229  if (pnt.x < retBox.v1[0]){ retBox.v1[0] = pnt.x; }
1230  if (pnt.y < retBox.v1[1]){ retBox.v1[1] = pnt.y; }
1231  if (pnt.z < retBox.v1[2]){ retBox.v1[2] = pnt.z; }
1232 
1233  if (pnt.x > retBox.v2[0]){ retBox.v2[0] = pnt.x; }
1234  if (pnt.y > retBox.v2[1]){ retBox.v2[1] = pnt.y; }
1235  if (pnt.z > retBox.v2[2]){ retBox.v2[2] = pnt.z; }
1236  }
1237  return retBox;
1238 }
1239 
1240 //----------------------------------------------------------------------------------
1252 //----------------------------------------------------------------------------------
1253 template <typename POINT_CLOUD_TYPE>
1254 inline SubImageBox getBoxForPointCloud(const POINT_CLOUD_TYPE &pointCloud,
1255  Vector3f &pointCloudOrigin,
1256  bool includeAll)
1257 {
1258  pointCloudOrigin.assign(0,0,0);
1259  SubImageBox retBox;
1260  const SubImageBoxd doubleBox = getBoxForPointCloud(pointCloud);
1261  if (!doubleBox.isEmpty()){
1262  pointCloudOrigin.assign(static_cast<float>(doubleBox.v1[0]),
1263  static_cast<float>(doubleBox.v1[1]),
1264  static_cast<float>(doubleBox.v1[2]));
1265  if (!includeAll){
1266  retBox.v1.x = static_cast<MLint>(doubleBox.v1[0]);
1267  retBox.v1.y = static_cast<MLint>(doubleBox.v1[1]);
1268  retBox.v1.z = static_cast<MLint>(doubleBox.v1[2]);
1269  retBox.v2.x = static_cast<MLint>(doubleBox.v2[0]);
1270  retBox.v2.y = static_cast<MLint>(doubleBox.v2[1]);
1271  retBox.v2.z = static_cast<MLint>(doubleBox.v2[2]);
1272  }
1273  else{
1274  retBox.v1.x = static_cast<MLint>(std::floor(doubleBox.v1[0]));
1275  retBox.v1.y = static_cast<MLint>(std::floor(doubleBox.v1[1]));
1276  retBox.v1.z = static_cast<MLint>(std::floor(doubleBox.v1[2]));
1277  retBox.v2.x = static_cast<MLint>(std::ceil (doubleBox.v2[0]));
1278  retBox.v2.y = static_cast<MLint>(std::ceil (doubleBox.v2[1]));
1279  retBox.v2.z = static_cast<MLint>(std::ceil (doubleBox.v2[2]));
1280  }
1281  retBox.v1.c = 0;
1282  retBox.v1.t = 0;
1283  retBox.v1.u = 0;
1284  retBox.v2.c = 0;
1285  retBox.v2.t = 0;
1286  retBox.v2.u = 0;
1287  }
1288  return retBox;
1289 }
1290 
1291 //----------------------------------------------------------------------------------
1294 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
1295 //----------------------------------------------------------------------------------
1297 
1298 //----------------------------------------------------------------------------------
1300 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
1301 //----------------------------------------------------------------------------------
1303 
1304 //----------------------------------------------------------------------------------
1307 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
1308 //----------------------------------------------------------------------------------
1310 
1311 //----------------------------------------------------------------------------------
1313 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
1314 //----------------------------------------------------------------------------------
1316 
1317 //----------------------------------------------------------------------------------
1320 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
1321 //----------------------------------------------------------------------------------
1322 MLPCLSUPPORT_EXPORT size_t getByteOffset(const pcl::PointXYZ &pnt,
1323  const std::string &pointMemberName);
1324 
1325 //----------------------------------------------------------------------------------
1328 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
1329 //----------------------------------------------------------------------------------
1330 MLPCLSUPPORT_EXPORT size_t getByteOffset(const pcl::PointXYZLNormal &pnt,
1331  const std::string &pointMemberName);
1332 
1333 //----------------------------------------------------------------------------------
1336 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
1337 //----------------------------------------------------------------------------------
1338 MLPCLSUPPORT_EXPORT size_t getByteOffset(const pcl::PointXYZRGBNormal &pnt,
1339  const std::string &pointMemberName);
1340 
1341 //----------------------------------------------------------------------------------
1344 // Adapt this if a new PCL point type is integrated in the MeVisLab binding.
1345 //----------------------------------------------------------------------------------
1346 MLPCLSUPPORT_EXPORT size_t getByteOffset(const pcl::PointXYZINormal &pnt,
1347  const std::string &pointMemberName);
1348 
1349 };
1350 
1351 ML_END_NAMESPACE
1352 
Project global and OS specific declarations.
#define MLPCLSUPPORT_EXPORT
If included by external modules, exported symbols are declared as import symbols.
SubImageBoxd - SubImageBox with coordinates of float data type.
Vector6 v2
Corner v2 of the box region.
bool isEmpty() const
Returns true if any component of v1 is greater than the corresponding one of v2 (which is defined as ...
Vector6 v1
Corner v1 of the box region.
VectorType v1
Corner v1 of the subimage region (included in region).
Definition: mlSubImageBox.h:63
VectorType v2
Corner v2 of the subimage region (also included in region!).
Definition: mlSubImageBox.h:69
ComponentType c
Color component of the vector.
Definition: mlImageVector.h:65
ComponentType t
Time component of the vector.
Definition: mlImageVector.h:67
ComponentType u
Unit/Modality/User component of the vector.
Definition: mlImageVector.h:69
ComponentType z
Z component of the vector.
Definition: mlImageVector.h:63
ComponentType x
X component of the vector.
Definition: mlImageVector.h:59
ComponentType y
Y component of the vector.
Definition: mlImageVector.h:61
void assign(const DT px, const DT py, const DT pz)
Sets all components to the passed values.
Definition: mlVector3.h:172
DT x
X-component of the vector, same as _buffer[0].
Definition: mlVector3.h:39
DT z
Z-component of the vector, same as _buffer[2].
Definition: mlVector3.h:43
DT y
Y-component of the vector, same as _buffer[1].
Definition: mlVector3.h:41
DT MLAbs(const DT val)
Defines templated MLAbs version to circumvent fabs ambiguities on different platforms.
#define ML_BAD_PARAMETER
A bad/invalid parameter (or even an inappropriate image) has been passed to a module or an algorithm;...
Definition: mlTypeDefs.h:925
#define ML_PRINT_ERROR(FUNC_NAME, REASON, HANDLING)
Like ML_PRINT_ERROR_DUMP(FUNC_NAME, REASON, HANDLING, RT_OBJ) without a runtime object to be dumped.
#define _PCLSupportTools_NewLineDefaultArgumentString
A default argument used in some functions for strings and which describes a newline,...
Basic types used in the MeVislab binding of the Point Cloud Library(PCL).
Tool class for some string operations.
#define ML_FLOAT_MAX
Definition: mlTypeDefs.h:210
UINT64 MLuint64
Introduce platform independent 64 bit unsigned integer type.
Definition: mlTypeDefs.h:513
#define ML_INT64_MAX
Definition: mlTypeDefs.h:555
unsigned int MLuint32
Definition: mlTypeDefs.h:191
unsigned char MLuint8
Definition: mlTypeDefs.h:115
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition: mlTypeDefs.h:578
std::pair< boost::graph_traits< ml_graph_ptr >::vertex_iterator, boost::graph_traits< ml_graph_ptr >::vertex_iterator > vertices(ml_graph_ptr g)
Returns an iterator-range providing access to all the vertices in the graph g.
PointCloudDefaultPatterns
An enumerator defining some basic default patterns for point clouds.
void setPointNormal(pcl::PointXYZINormal &p, float nx, float ny, float nz)
MLPCLSUPPORT_EXPORT const char *const PointMemberNames[ML_PCL_NUMBER_OF_POINT_MEMBER_NAMES]
Possible members of points as strings which might appear in current implementation.
void setIntensityReplacement(pcl::PointXYZINormal &p, float value=1.f, MLuint8=0xff)
void setCurvature(pcl::PointXYZINormal &p, float curvature)
MLPCLSUPPORT_EXPORT MLuint64 getUnsigned32BitMaximumLimit()
Returns the maximum number of entries allowed in data structured with 32 bit unsigned indexing,...
bool hasLabel(const pcl::PointXYZINormal &)
bool doPCLPointNonDataMembersDiffer(const pcl::PointXYZINormal &point1, const pcl::PointXYZINormal &point2, double epsilon=FLT_EPSILON)
Returns true if differences between corresponding non data members of point1 and point2 are found whi...
MLPCLSUPPORT_EXPORT std::string getCloudFieldsString(const std::vector< pcl::PCLPointField > &fields)
Converts the pointField vector fields to a human readable string.
void setPointRGBA(pcl::PointXYZLNormal &, MLuint32)
bool fourFloatsDiffer(const float data1[4], const float data2[4], double epsilon=FLT_EPSILON)
Returns true if differences between corresponding data1 and data2 entries are >= epsilon,...
bool hasNormal(const pcl::PointXYZINormal &)
MLPCLSUPPORT_EXPORT const char *const FloatPointMemberNames[ML_PCL_NUMBER_OF_FLOAT_POINT_MEMBER_NAMES]
Number of possible float members as strings which might appear in current implementation.
Eigen::Vector4f castToEigenVector4f(const Vector4 &mlVec)
Convenience function to convert an ML Vector4f to an Eigen::Vector4f.
MLPCLSUPPORT_EXPORT void castToStdVector(const Eigen::VectorXf &eigenVec, std::vector< MLfloat > &stdVec)
Convenience function to convert an Eigen::VectorXf to a std::vector<MLfloat>, e.g.
MLPCLSUPPORT_EXPORT size_t getByteOffset(const pcl::PointXYZINormal &pnt, const std::string &pointMemberName)
Returns the offset in bytes between the given member described as string and the first member in the ...
MLPCLSUPPORT_EXPORT std::string getCloudDataString(const MLPolygonMesh &polygonMesh, MLint maxNumShownVertices=ML_INT64_MAX, MLint indexOfFirstVertex=0, bool showIndices=true, const std::string &lineSeparator=_PCLSupportTools_NewLineDefaultArgumentString, int numDecimalPlaces=-1)
Converts the cloud data of polygonMesh to a human readable string.
MLPCLSUPPORT_EXPORT void PCLExtractSubIndices(const std::vector< int > &subIndices, std::vector< int > &indices)
Extract all indices from indices if they are listed in subIndices in the order as given in subIndices...
std::string getPointStructureT(const POINT_CLOUD_TYPE &pointCloud)
Returns an empty string if pointCloud.points are empty, otherwise a concatenated, comma separated str...
void createEmptyPCLObject(PCL_OBJECT_PTR_TYPE &retPCLObjectPtr)
Creates an empty point cloud of type POINT_CLOUD_PTR_TYPE.
MLPointCloudXYZINormalPtr createEmptyXYZINormalPointCloud()
Creates an empty PointCloudXYZLNormal point cloud.
MLPCLSUPPORT_EXPORT std::string getPCLIndicesAsString(const std::vector< int > &indices, MLint maxNumShownIndices, MLint indexOfFirstIndex, bool showIndices, const std::string &lineSeparator=_PCLSupportTools_NewLineDefaultArgumentString)
Converts at most maxNumShownIndices indices from indices starting at position indexOfFirstIndex into ...
PointCloudFillPatterns
An enumerator defining some basic value fill patterns for point clouds.
MLPCLSUPPORT_EXPORT MLuint64 getSigned32BitMaximumLimit()
Returns the maximum number of entries allowed in data structured with 32 bit signed indexing,...
bool hasIntensityReplacement(const pcl::PointXYZINormal &)
Eigen::Vector3f castToEigenVector3f(const Vector3 &mlVec)
Convenience function to convert an ML Vector3f to an Eigen::Vector3f.
MLPCLSUPPORT_EXPORT std::string getPCLVerticesAsString(const std::vector< pcl::Vertices > &vertices, MLint maxNumShownVertices=ML_INT64_MAX, MLint indexOfFirstVertex=0, bool showIndices=true, const std::string &lineSeparator=_PCLSupportTools_NewLineDefaultArgumentString)
Converts at most maxNumShownVertices vertices from vertices starting at position indexOfFirstVertex i...
MLPolygonMeshPtr createEmptyPolygonMesh()
Creates an empty pcl::PolygonMesh object.
void setPointFromFields(pcl::PointXYZINormal &pnt, const std::vector< DoubleField * > &constantFields)
void appendFillPattern(POINT_CLOUD_TYPE &pc, PointCloudDefaultPatterns pattern, PointCloudFillPatterns fillMode, float fillValue=0.f)
Creates a PointCloud point cloud filled with a set of points defined by pattern and fillMode; does no...
float getIntensityReplacement(const pcl::PointXYZINormal &p)
SubImageBox getBoxForPointCloud(const POINT_CLOUD_TYPE &pointCloud, Vector3f &pointCloudOrigin, bool includeAll)
Returns an ML SubImageBox corresponding to pointCloud.
void getPointNormal(const pcl::PointXYZINormal &p, float &nx, float &ny, float &nz)
size_t getMaximumNumberOfScalarPointMembers()
From the point cloud type with the largest number of scalar members returns the number of scalar valu...
MLPCLSUPPORT_EXPORT std::string getPointFieldValueAsString(std::uint8_t fd, const std::uint8_t *dataPtr, int numDecimalPlaces=-1)
Reinterprets the data at position dataPtr as a pcl::PointField::PointFieldTypes enumerator given by f...
size_t getNumberOfScalarPointMembers(const MLPointCloudXYZINormalPtr &)
bool hasCurvature(const pcl::PointXYZINormal &)
MLPCLSUPPORT_EXPORT std::string getPointFieldDataTypeString(std::uint8_t fd, bool aligned)
Returns a human readable string for a pcl::PCLPointField::PointFieldTypes enumerator.
unsigned int getPointRGBA(const pcl::PointXYZLNormal &)
bool hasIntensity(const pcl::PointXYZINormal &)
MLPointCloudXYZLNormalPtr createEmptyXYZLNormalPointCloud()
Creates an empty PointCloudXYZLNormal point cloud.
MLPCLSUPPORT_EXPORT std::string getPCLPointAsString(const pcl::PointXYZINormal &point, int numDecimalPlaces=-1)
void appendPoint(POINT_CLOUD_TYPE &pc, const Vector3f &pos, float fillValue)
Appends a new point to pc with data[0-2] given by pos and data[3] by fillValue; does nothing if pc is...
MLPointCloudXYZPtr createEmptyXYZPointCloud()
Creates an empty PointCloudXYZ point cloud.
void setFieldsFromPoint(const pcl::PointXYZINormal &pnt, std::vector< DoubleField * > &resultFields)
bool hasRGBA(const pcl::PointXYZINormal &)
std::string getPCLPointListAsString(const POINT_CLOUD_TYPE &pointCloud, MLint maxNumShownPoints=ML_INT64_MAX, MLint indexOfFirstPoint=0, bool showIndices=true, const std::string &lineSeparator="\n", int numDecimalPlaces=-1, const std::string &pointsPrintFormatStr="")
Converts at most maxNumShownPoints from pointCloud starting at position indexOfFirstPoint into a stri...
void setPointFromScalar(pcl::PointXYZINormal &pnt, const float val)
bool hasNormals(const MLPointCloudXYZINormalPtr &)
MLPointCloudXYZRGBNormalPtr createEmptyXYZRGBNormalPointCloud()
Creates an empty PointCloudXYZRGBNormal point cloud.
float getCurvature(const pcl::PointXYZINormal &p)
MLPCLSUPPORT_EXPORT std::string getScalarMemberValueAsString(const pcl::PointXYZINormal &p, size_t memberIdx, int numDecimalPlaces=-1)
MLPCLSUPPORT_EXPORT std::string getScalarMemberNameAsString(const pcl::PointXYZINormal &, size_t memberIdx)
void getPCLPointAsFormattedString(const POINT_TYPE &point, std::string &formatStr, int numDecimalPlaces, size_t pointIndex)
Replaces placeholders in formatStr with values from the given point.
MLRELEASE_TOOLS_EXPORT std::string toSize_tStr(size_t val, signed char fieldWidth=-1, bool padWithZeros=false)
Tool function to convert a size_t to a string.
MLRELEASE_TOOLS_EXPORT std::string toMLUIntStr(MLuint val, signed char fieldWidth=-1, bool padWithZeros=false)
Tool function to convert an MLuint to a string.
MLRELEASE_TOOLS_EXPORT std::string toDblStr(MLdouble val, signed char fieldWidth=-1, signed char numDecimalPlaces=-1, bool padWithZeros=false, bool considerValAsFloat=false)
Tool function to print an MLdouble value to a std::string.
MLRELEASE_TOOLS_EXPORT std::string replaceAllStr1ByStr2(const std::string &inStr, const std::string &str1, const std::string &str2)
Same as replaceAllStr1ByStr2InStr with the difference that the changed string is returned and inStr r...
pcl::PointCloud< pcl::PointXYZRGBNormal >::Ptr MLPointCloudXYZRGBNormalPtr
The basic pointer type of a point cloud type used in the PCL MeVisLab binding.
Definition: mlPCLTypes.h:100
pcl::PointCloud< pcl::PointXYZLNormal >::Ptr MLPointCloudXYZLNormalPtr
The basic pointer type of a point cloud type used in the PCL MeVisLab binding.
Definition: mlPCLTypes.h:93
pcl::PointCloud< pcl::PointXYZ >::Ptr MLPointCloudXYZPtr
The basic pointer type of a point cloud type used in the PCL MeVisLab binding.
Definition: mlPCLTypes.h:86
pcl::PointCloud< pcl::PointXYZ > MLPointCloudXYZ
The basic point cloud type used in the PCL MeVisLab binding.
Definition: mlPCLTypes.h:83
pcl::PointCloud< pcl::PointXYZRGBNormal > MLPointCloudXYZRGBNormal
The basic point cloud type used in the PCL MeVisLab binding.
Definition: mlPCLTypes.h:97
pcl::PointCloud< pcl::PointXYZLNormal > MLPointCloudXYZLNormal
The basic point cloud type used in the PCL MeVisLab binding.
Definition: mlPCLTypes.h:90
pcl::PolygonMesh::Ptr MLPolygonMeshPtr
The basic pointer type of a pcl::PolygonMesh in the PCL MeVisLab binding.
Definition: mlPCLTypes.h:114
pcl::PolygonMesh MLPolygonMesh
The basic polygon type of a pcl::PolygonMesh used in the PCL MeVisLab binding.
Definition: mlPCLTypes.h:111
Tvec3< MLfloat > Vector3f
A vector with 3 components of type float.
Definition: mlVector3.h:294
pcl::PointCloud< pcl::PointXYZINormal >::Ptr MLPointCloudXYZINormalPtr
The basic pointer type of a point cloud type used in the PCL MeVisLab binding.
Definition: mlPCLTypes.h:107
pcl::PointCloud< pcl::PointXYZINormal > MLPointCloudXYZINormal
The basic point cloud type used in the PCL MeVisLab binding.
Definition: mlPCLTypes.h:104
Tvec4< MLfloat > Vector4f
A vector with 4 components of type float.
Definition: mlVector4.h:156