30 #include <pcl/filters/extract_indices.h> 31 #include <pcl/filters/voxel_grid.h> 32 #include <pcl/filters/frustum_culling.h> 33 #include <pcl/filters/random_sample.h> 34 #include <pcl/filters/passthrough.h> 35 #include <pcl/filters/crop_box.h> 37 #include <pcl/features/normal_3d_omp.h> 39 #include <pcl/search/kdtree.h> 41 #include <pcl/common/common.h> 43 #include <pcl/segmentation/extract_clusters.h> 44 #include <pcl/segmentation/sac_segmentation.h> 53 #if PCL_VERSION_COMPARE(>=, 1, 8, 0) 54 #include <pcl/impl/instantiate.hpp> 55 #include <pcl/point_types.h> 56 #include <pcl/segmentation/impl/extract_clusters.hpp> 57 #include <pcl/segmentation/extract_labeled_clusters.h> 58 #include <pcl/segmentation/impl/extract_labeled_clusters.hpp> 59 #include <pcl/filters/impl/extract_indices.hpp> 61 PCL_INSTANTIATE(EuclideanClusterExtraction, (pcl::PointXYZRGBNormal));
62 PCL_INSTANTIATE(extractEuclideanClusters, (pcl::PointXYZRGBNormal));
63 PCL_INSTANTIATE(extractEuclideanClusters_indices, (pcl::PointXYZRGBNormal));
64 PCL_INSTANTIATE(ExtractIndices, (pcl::PointNormal));
82 float groundNormalsUp)
85 UDEBUG(
"scan size=%d format=%d, step=%d, rangeMin=%f, rangeMax=%f, voxel=%f, normalK=%d, normalRadius=%f, groundNormalsUp=%f",
86 scan.
size(), (int)scan.
format(), downsamplingStep, rangeMin, rangeMax, voxelSize, normalK, normalRadius, groundNormalsUp);
90 if(downsamplingStep<=1 || scan.
size() <= downsamplingStep)
95 if(downsamplingStep > 1 || rangeMin > 0.0
f || rangeMax > 0.0
f)
97 cv::Mat tmp = cv::Mat(1, scan.
size()/downsamplingStep, scan.
dataType());
98 bool is2d = scan.
is2d();
100 float rangeMinSqrd = rangeMin * rangeMin;
101 float rangeMaxSqrd = rangeMax * rangeMax;
102 for(
int i=0; i<scan.
size()-downsamplingStep+1; i+=downsamplingStep)
104 const float * ptr = scan.
data().ptr<
float>(0, i);
106 if(rangeMin>0.0
f || rangeMax>0.0
f)
111 r = ptr[0]*ptr[0] + ptr[1]*ptr[1];
115 r = ptr[0]*ptr[0] + ptr[1]*ptr[1] + ptr[2]*ptr[2];
118 if(rangeMin > 0.0
f && r < rangeMinSqrd)
122 if(rangeMax > 0.0
f && r > rangeMaxSqrd)
131 int previousSize = scan.
size();
149 scanMaxPtsTmp/downsamplingStep,
154 UDEBUG(
"Downsampling scan (step=%d): %d -> %d (scanMaxPts=%d->%d)", downsamplingStep, previousSize, scan.
size(), scanMaxPtsTmp, scan.
maxPoints());
157 if(scan.
size() && (voxelSize > 0.0f || ((normalK > 0 || normalRadius>0.0f) && !scan.
hasNormals())))
170 float ratio = float(cloud->size()) / scan.
size();
171 scanMaxPts = int(
float(scanMaxPts) * ratio);
172 UDEBUG(
"Voxel filtering scan (voxel=%f m): %d -> %d (scanMaxPts=%d->%d)", voxelSize, scan.
size(), cloud->size(), scan.
maxPoints(), scanMaxPts);
174 if(cloud->size() && (normalK > 0 || normalRadius>0.0f))
178 UDEBUG(
"Normals computed (k=%d radius=%f)", normalK, normalRadius);
184 UWARN(
"Voxel filter is applied, but normal parameters are not set and input scan has normals. The returned scan has no normals.");
199 float ratio = float(cloud->size()) / scan.
size();
200 scanMaxPts = int(
float(scanMaxPts) * ratio);
201 UDEBUG(
"Voxel filtering scan (voxel=%f m): %d -> %d (scanMaxPts=%d->%d)", voxelSize, scan.
size(), cloud->size(), scan.
maxPoints(), scanMaxPts);
203 if(cloud->size() && (normalK > 0 || normalRadius>0.0f))
205 pcl::PointCloud<pcl::Normal>::Ptr normals;
223 UDEBUG(
"Normals computed (k=%d radius=%f)", normalK, normalRadius);
229 UWARN(
"Voxel filter i applied, but normal parameters are not set and input scan has normals. The returned scan has no normals.");
251 float ratio = float(cloud->size()) / scan.
size();
252 scanMaxPts = int(
float(scanMaxPts) * ratio);
253 UDEBUG(
"Voxel filtering scan (voxel=%f m): %d -> %d (scanMaxPts=%d->%d)", voxelSize, scan.
size(), cloud->size(), scan.
maxPoints(), scanMaxPts);
255 if(cloud->size() && (normalK > 0 || normalRadius>0.0f))
257 pcl::PointCloud<pcl::Normal>::Ptr normals;
275 UDEBUG(
"Normals computed (k=%d radius=%f)", normalK, normalRadius);
281 UWARN(
"Voxel filter i applied, but normal parameters are not set and input scan has normals. The returned scan has no normals.");
306 int downsamplingStep,
312 bool forceGroundNormalsUp)
314 return commonFiltering(scanIn, downsamplingStep, rangeMin, rangeMax, voxelSize, normalK, normalRadius, forceGroundNormalsUp?0.8
f:0.0
f);
322 UASSERT(rangeMin >=0.0
f && rangeMax>=0.0
f);
325 if(rangeMin > 0.0
f || rangeMax > 0.0
f)
327 cv::Mat output = cv::Mat(1, scan.
size(), scan.
dataType());
328 bool is2d = scan.
is2d();
330 float rangeMinSqrd = rangeMin * rangeMin;
331 float rangeMaxSqrd = rangeMax * rangeMax;
332 for(
int i=0; i<scan.
size(); ++i)
334 const float * ptr = scan.
data().ptr<
float>(0, i);
338 r = ptr[0]*ptr[0] + ptr[1]*ptr[1];
342 r = ptr[0]*ptr[0] + ptr[1]*ptr[1] + ptr[2]*ptr[2];
345 if(rangeMin > 0.0
f && r < rangeMinSqrd)
349 if(rangeMax > 0.0
f && r > rangeMaxSqrd)
359 return LaserScan(cv::Mat(output,
cv::Range::all(), cv::Range(0, oi)), scan.
format(), scan.
rangeMin(), scan.
rangeMax(), scan.
angleMin(), scan.
angleMax(), scan.
angleIncrement(), scan.
localTransform());
373 if(step <= 1 || scan.
size() <=
step)
381 cv::Mat output = cv::Mat(1, finalSize, scan.
dataType());
383 for(
int i=0; i<scan.
size()-step+1; i+=
step)
395 template<
typename Po
intT>
397 const typename pcl::PointCloud<PointT>::Ptr & cloud,
401 typename pcl::PointCloud<PointT>::Ptr output(
new pcl::PointCloud<PointT>);
402 if(step <= 1 || (
int)cloud->size() <=
step)
409 if(cloud->height > 1 && cloud->height < cloud->width/4)
419 unsigned int rings = cloud->height<cloud->width?cloud->height:cloud->width;
420 unsigned int pts = cloud->height>cloud->width?cloud->height:cloud->width;
421 unsigned int finalSize = rings * pts/
step;
422 output->resize(finalSize);
423 output->width = rings;
424 output->height = pts/
step;
426 for(
unsigned int j=0; j<rings; ++j)
428 for(
unsigned int i=0; i<output->height; ++i)
430 (*output)[i*rings + j] = cloud->at(i*step*rings + j);
435 else if(cloud->height > 1)
438 UASSERT_MSG(cloud->height % step == 0 && cloud->width % step == 0,
439 uFormat(
"Decimation of depth images should be exact! (decimation=%d, size=%dx%d)",
440 step, cloud->width, cloud->height).c_str());
442 int finalSize = cloud->height/step * cloud->width/
step;
443 output->resize(finalSize);
444 output->width = cloud->width/
step;
445 output->height = cloud->height/
step;
447 for(
unsigned int j=0; j<output->height; ++j)
449 for(
unsigned int i=0; i<output->width; ++i)
451 output->at(j*output->width + i) = cloud->at(j*output->width*step + i*step);
457 int finalSize = int(cloud->size())/step;
458 output->resize(finalSize);
460 for(
unsigned int i=0; i<cloud->size()-step+1; i+=
step)
462 (*output)[oi++] = cloud->at(i);
468 pcl::PointCloud<pcl::PointXYZ>::Ptr
downsample(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
int step)
470 return downsampleImpl<pcl::PointXYZ>(cloud,
step);
472 pcl::PointCloud<pcl::PointXYZRGB>::Ptr
downsample(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
int step)
474 return downsampleImpl<pcl::PointXYZRGB>(cloud,
step);
476 pcl::PointCloud<pcl::PointXYZI>::Ptr
downsample(
const pcl::PointCloud<pcl::PointXYZI>::Ptr & cloud,
int step)
478 return downsampleImpl<pcl::PointXYZI>(cloud,
step);
480 pcl::PointCloud<pcl::PointNormal>::Ptr
downsample(
const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
int step)
482 return downsampleImpl<pcl::PointNormal>(cloud,
step);
484 pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr
downsample(
const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
int step)
486 return downsampleImpl<pcl::PointXYZRGBNormal>(cloud,
step);
488 pcl::PointCloud<pcl::PointXYZINormal>::Ptr
downsample(
const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
int step)
490 return downsampleImpl<pcl::PointXYZINormal>(cloud,
step);
493 template<
typename Po
intT>
495 const typename pcl::PointCloud<PointT>::Ptr & cloud,
496 const pcl::IndicesPtr & indices,
500 typename pcl::PointCloud<PointT>::Ptr output(
new pcl::PointCloud<PointT>);
501 if((cloud->is_dense && cloud->size()) || (!cloud->is_dense && indices->size()))
503 pcl::VoxelGrid<PointT> filter;
504 filter.setLeafSize(voxelSize, voxelSize, voxelSize);
505 filter.setInputCloud(cloud);
508 filter.setIndices(indices);
510 filter.filter(*output);
512 else if(cloud->size() && !cloud->is_dense && indices->size() == 0)
514 UWARN(
"Cannot voxelize a not dense (organized) cloud with empty indices! (input=%d pts). Returning empty cloud!", (
int)cloud->size());
519 pcl::PointCloud<pcl::PointXYZ>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
const pcl::IndicesPtr & indices,
float voxelSize)
521 return voxelizeImpl<pcl::PointXYZ>(cloud, indices, voxelSize);
523 pcl::PointCloud<pcl::PointNormal>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
float voxelSize)
525 return voxelizeImpl<pcl::PointNormal>(cloud, indices, voxelSize);
527 pcl::PointCloud<pcl::PointXYZRGB>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
const pcl::IndicesPtr & indices,
float voxelSize)
529 return voxelizeImpl<pcl::PointXYZRGB>(cloud, indices, voxelSize);
531 pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
float voxelSize)
533 return voxelizeImpl<pcl::PointXYZRGBNormal>(cloud, indices, voxelSize);
535 pcl::PointCloud<pcl::PointXYZI>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointXYZI>::Ptr & cloud,
const pcl::IndicesPtr & indices,
float voxelSize)
537 return voxelizeImpl<pcl::PointXYZI>(cloud, indices, voxelSize);
539 pcl::PointCloud<pcl::PointXYZINormal>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
float voxelSize)
541 return voxelizeImpl<pcl::PointXYZINormal>(cloud, indices, voxelSize);
544 pcl::PointCloud<pcl::PointXYZ>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
float voxelSize)
546 pcl::IndicesPtr indices(
new std::vector<int>);
547 return voxelize(cloud, indices, voxelSize);
549 pcl::PointCloud<pcl::PointNormal>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
float voxelSize)
551 pcl::IndicesPtr indices(
new std::vector<int>);
552 return voxelize(cloud, indices, voxelSize);
554 pcl::PointCloud<pcl::PointXYZRGB>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
float voxelSize)
556 pcl::IndicesPtr indices(
new std::vector<int>);
557 return voxelize(cloud, indices, voxelSize);
559 pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
float voxelSize)
561 pcl::IndicesPtr indices(
new std::vector<int>);
562 return voxelize(cloud, indices, voxelSize);
564 pcl::PointCloud<pcl::PointXYZI>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointXYZI>::Ptr & cloud,
float voxelSize)
566 pcl::IndicesPtr indices(
new std::vector<int>);
567 return voxelize(cloud, indices, voxelSize);
569 pcl::PointCloud<pcl::PointXYZINormal>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
float voxelSize)
571 pcl::IndicesPtr indices(
new std::vector<int>);
572 return voxelize(cloud, indices, voxelSize);
575 template<
typename Po
intT>
577 const typename pcl::PointCloud<PointT>::Ptr & cloud,
int samples)
580 typename pcl::PointCloud<PointT>::Ptr output(
new pcl::PointCloud<PointT>);
581 pcl::RandomSample<PointT> filter;
582 filter.setSample(samples);
583 filter.setInputCloud(cloud);
584 filter.filter(*output);
587 pcl::PointCloud<pcl::PointXYZ>::Ptr
randomSampling(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
int samples)
589 return randomSamplingImpl<pcl::PointXYZ>(cloud, samples);
591 pcl::PointCloud<pcl::PointXYZRGB>::Ptr
randomSampling(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
int samples)
593 return randomSamplingImpl<pcl::PointXYZRGB>(cloud, samples);
596 template<
typename Po
intT>
598 const typename pcl::PointCloud<PointT>::Ptr & cloud,
599 const pcl::IndicesPtr & indices,
600 const std::string &
axis,
605 UASSERT_MSG(max > min,
uFormat(
"cloud=%d, max=%f min=%f axis=%s", (
int)cloud->size(),
max,
min, axis.c_str()).c_str());
606 UASSERT(axis.compare(
"x") == 0 || axis.compare(
"y") == 0 || axis.compare(
"z") == 0);
608 pcl::IndicesPtr output(
new std::vector<int>);
609 pcl::PassThrough<PointT> filter;
610 filter.setNegative(negative);
611 filter.setFilterFieldName(axis);
612 filter.setFilterLimits(min, max);
613 filter.setInputCloud(cloud);
614 filter.setIndices(indices);
615 filter.filter(*output);
619 pcl::IndicesPtr
passThrough(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
const pcl::IndicesPtr & indices,
const std::string &
axis,
float min,
float max,
bool negative)
621 return passThroughImpl<pcl::PointXYZ>(cloud, indices,
axis,
min,
max, negative);
623 pcl::IndicesPtr
passThrough(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
const pcl::IndicesPtr & indices,
const std::string &
axis,
float min,
float max,
bool negative)
625 return passThroughImpl<pcl::PointXYZRGB>(cloud, indices,
axis,
min,
max, negative);
627 pcl::IndicesPtr
passThrough(
const pcl::PointCloud<pcl::PointXYZI>::Ptr & cloud,
const pcl::IndicesPtr & indices,
const std::string &
axis,
float min,
float max,
bool negative)
629 return passThroughImpl<pcl::PointXYZI>(cloud, indices,
axis,
min,
max, negative);
631 pcl::IndicesPtr
passThrough(
const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
const std::string &
axis,
float min,
float max,
bool negative)
633 return passThroughImpl<pcl::PointNormal>(cloud, indices,
axis,
min,
max, negative);
635 pcl::IndicesPtr
passThrough(
const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
const std::string &
axis,
float min,
float max,
bool negative)
637 return passThroughImpl<pcl::PointXYZRGBNormal>(cloud, indices,
axis,
min,
max, negative);
639 pcl::IndicesPtr
passThrough(
const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
const std::string &
axis,
float min,
float max,
bool negative)
641 return passThroughImpl<pcl::PointXYZINormal>(cloud, indices,
axis,
min,
max, negative);
644 template<
typename Po
intT>
646 const typename pcl::PointCloud<PointT>::Ptr & cloud,
647 const std::string &
axis,
652 UASSERT_MSG(max > min,
uFormat(
"cloud=%d, max=%f min=%f axis=%s", (
int)cloud->size(),
max,
min, axis.c_str()).c_str());
653 UASSERT(axis.compare(
"x") == 0 || axis.compare(
"y") == 0 || axis.compare(
"z") == 0);
655 typename pcl::PointCloud<PointT>::Ptr output(
new pcl::PointCloud<PointT>);
656 pcl::PassThrough<PointT> filter;
657 filter.setNegative(negative);
658 filter.setFilterFieldName(axis);
659 filter.setFilterLimits(min, max);
660 filter.setInputCloud(cloud);
661 filter.filter(*output);
664 pcl::PointCloud<pcl::PointXYZ>::Ptr
passThrough(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
const std::string &
axis,
float min,
float max,
bool negative)
666 return passThroughImpl<pcl::PointXYZ>(cloud,
axis,
min ,
max, negative);
668 pcl::PointCloud<pcl::PointXYZRGB>::Ptr
passThrough(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
const std::string &
axis,
float min,
float max,
bool negative)
670 return passThroughImpl<pcl::PointXYZRGB>(cloud,
axis,
min ,
max, negative);
672 pcl::PointCloud<pcl::PointXYZI>::Ptr
passThrough(
const pcl::PointCloud<pcl::PointXYZI>::Ptr & cloud,
const std::string &
axis,
float min,
float max,
bool negative)
674 return passThroughImpl<pcl::PointXYZI>(cloud,
axis,
min ,
max, negative);
676 pcl::PointCloud<pcl::PointNormal>::Ptr
passThrough(
const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
const std::string &
axis,
float min,
float max,
bool negative)
678 return passThroughImpl<pcl::PointNormal>(cloud,
axis,
min ,
max, negative);
680 pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr
passThrough(
const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
const std::string &
axis,
float min,
float max,
bool negative)
682 return passThroughImpl<pcl::PointXYZRGBNormal>(cloud,
axis,
min ,
max, negative);
684 pcl::PointCloud<pcl::PointXYZINormal>::Ptr
passThrough(
const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
const std::string &
axis,
float min,
float max,
bool negative)
686 return passThroughImpl<pcl::PointXYZINormal>(cloud,
axis,
min ,
max, negative);
689 template<
typename Po
intT>
691 const typename pcl::PointCloud<PointT>::Ptr & cloud,
692 const pcl::IndicesPtr & indices,
693 const Eigen::Vector4f &
min,
694 const Eigen::Vector4f &
max,
698 UASSERT(min[0] < max[0] && min[1] < max[1] && min[2] < max[2]);
700 pcl::IndicesPtr output(
new std::vector<int>);
701 pcl::CropBox<PointT> filter;
702 filter.setNegative(negative);
707 filter.setTransform(transform.
toEigen3f());
709 filter.setInputCloud(cloud);
710 filter.setIndices(indices);
711 filter.filter(*output);
715 pcl::IndicesPtr
cropBox(
const pcl::PCLPointCloud2::Ptr & cloud,
const pcl::IndicesPtr & indices,
const Eigen::Vector4f &
min,
const Eigen::Vector4f &
max,
const Transform & transform,
bool negative)
717 UASSERT(min[0] < max[0] && min[1] < max[1] && min[2] < max[2]);
719 pcl::IndicesPtr output(
new std::vector<int>);
720 pcl::CropBox<pcl::PCLPointCloud2> filter;
721 filter.setNegative(negative);
726 filter.setTransform(transform.
toEigen3f());
728 filter.setInputCloud(cloud);
729 filter.setIndices(indices);
730 filter.filter(*output);
733 pcl::IndicesPtr
cropBox(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
const pcl::IndicesPtr & indices,
const Eigen::Vector4f &
min,
const Eigen::Vector4f &
max,
const Transform & transform,
bool negative)
735 return cropBoxImpl<pcl::PointXYZ>(cloud, indices,
min,
max, transform, negative);
737 pcl::IndicesPtr
cropBox(
const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
const Eigen::Vector4f &
min,
const Eigen::Vector4f &
max,
const Transform & transform,
bool negative)
739 return cropBoxImpl<pcl::PointNormal>(cloud, indices,
min,
max, transform, negative);
741 pcl::IndicesPtr
cropBox(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
const pcl::IndicesPtr & indices,
const Eigen::Vector4f &
min,
const Eigen::Vector4f &
max,
const Transform & transform,
bool negative)
743 return cropBoxImpl<pcl::PointXYZRGB>(cloud, indices,
min,
max, transform, negative);
745 pcl::IndicesPtr
cropBox(
const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
const Eigen::Vector4f &
min,
const Eigen::Vector4f &
max,
const Transform & transform,
bool negative)
747 return cropBoxImpl<pcl::PointXYZRGBNormal>(cloud, indices,
min,
max, transform, negative);
750 template<
typename Po
intT>
752 const typename pcl::PointCloud<PointT>::Ptr & cloud,
753 const Eigen::Vector4f &
min,
754 const Eigen::Vector4f &
max,
758 UASSERT(min[0] < max[0] && min[1] < max[1] && min[2] < max[2]);
760 typename pcl::PointCloud<PointT>::Ptr output(
new pcl::PointCloud<PointT>);
761 pcl::CropBox<PointT> filter;
762 filter.setNegative(negative);
767 filter.setTransform(transform.
toEigen3f());
769 filter.setInputCloud(cloud);
770 filter.filter(*output);
773 pcl::PointCloud<pcl::PointXYZ>::Ptr
cropBox(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
const Eigen::Vector4f &
min,
const Eigen::Vector4f &
max,
const Transform & transform,
bool negative)
775 return cropBoxImpl<pcl::PointXYZ>(cloud,
min,
max, transform, negative);
777 pcl::PointCloud<pcl::PointNormal>::Ptr
cropBox(
const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
const Eigen::Vector4f &
min,
const Eigen::Vector4f &
max,
const Transform & transform,
bool negative)
779 return cropBoxImpl<pcl::PointNormal>(cloud,
min,
max, transform, negative);
781 pcl::PointCloud<pcl::PointXYZRGB>::Ptr
cropBox(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
const Eigen::Vector4f &
min,
const Eigen::Vector4f &
max,
const Transform & transform,
bool negative)
783 return cropBoxImpl<pcl::PointXYZRGB>(cloud,
min,
max, transform, negative);
785 pcl::PointCloud<pcl::PointXYZINormal>::Ptr
cropBox(
const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
const Eigen::Vector4f &
min,
const Eigen::Vector4f &
max,
const Transform & transform,
bool negative)
787 return cropBoxImpl<pcl::PointXYZINormal>(cloud,
min,
max, transform, negative);
789 pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr
cropBox(
const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
const Eigen::Vector4f &
min,
const Eigen::Vector4f &
max,
const Transform & transform,
bool negative)
791 return cropBoxImpl<pcl::PointXYZRGBNormal>(cloud,
min,
max, transform, negative);
794 template<
typename Po
intT>
796 const typename pcl::PointCloud<PointT>::Ptr & cloud,
797 const pcl::IndicesPtr & indices,
801 float nearClipPlaneDistance,
802 float farClipPlaneDistance,
805 UASSERT(horizontalFOV > 0.0
f && verticalFOV > 0.0
f);
806 UASSERT(farClipPlaneDistance > nearClipPlaneDistance);
809 pcl::IndicesPtr output(
new std::vector<int>);
810 pcl::FrustumCulling<PointT> fc;
811 fc.setNegative(negative);
812 fc.setInputCloud (cloud);
813 if(indices.get() && indices->size())
815 fc.setIndices(indices);
817 fc.setVerticalFOV (verticalFOV);
818 fc.setHorizontalFOV (horizontalFOV);
819 fc.setNearPlaneDistance (nearClipPlaneDistance);
820 fc.setFarPlaneDistance (farClipPlaneDistance);
822 fc.setCameraPose (cameraPose.
toEigen4f());
827 pcl::IndicesPtr
frustumFiltering(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
const pcl::IndicesPtr & indices,
const Transform & cameraPose,
float horizontalFOV,
float verticalFOV,
float nearClipPlaneDistance,
float farClipPlaneDistance,
bool negative)
829 return frustumFilteringImpl<pcl::PointXYZ>(cloud, indices, cameraPose, horizontalFOV, verticalFOV, nearClipPlaneDistance, farClipPlaneDistance, negative);
832 template<
typename Po
intT>
834 const typename pcl::PointCloud<PointT>::Ptr & cloud,
838 float nearClipPlaneDistance,
839 float farClipPlaneDistance,
842 UASSERT(horizontalFOV > 0.0
f && verticalFOV > 0.0
f);
843 UASSERT(farClipPlaneDistance > nearClipPlaneDistance);
846 typename pcl::PointCloud<PointT>::Ptr output(
new pcl::PointCloud<PointT>);
847 pcl::FrustumCulling<PointT> fc;
848 fc.setNegative(negative);
849 fc.setInputCloud (cloud);
850 fc.setVerticalFOV (verticalFOV);
851 fc.setHorizontalFOV (horizontalFOV);
852 fc.setNearPlaneDistance (nearClipPlaneDistance);
853 fc.setFarPlaneDistance (farClipPlaneDistance);
855 fc.setCameraPose (cameraPose.
toEigen4f());
860 pcl::PointCloud<pcl::PointXYZ>::Ptr
frustumFiltering(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
const Transform & cameraPose,
float horizontalFOV,
float verticalFOV,
float nearClipPlaneDistance,
float farClipPlaneDistance,
bool negative)
862 return frustumFilteringImpl<pcl::PointXYZ>(cloud, cameraPose, horizontalFOV, verticalFOV, nearClipPlaneDistance, farClipPlaneDistance, negative);
864 pcl::PointCloud<pcl::PointXYZRGB>::Ptr
frustumFiltering(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
const Transform & cameraPose,
float horizontalFOV,
float verticalFOV,
float nearClipPlaneDistance,
float farClipPlaneDistance,
bool negative)
866 return frustumFilteringImpl<pcl::PointXYZRGB>(cloud, cameraPose, horizontalFOV, verticalFOV, nearClipPlaneDistance, farClipPlaneDistance, negative);
870 template<
typename Po
intT>
872 const typename pcl::PointCloud<PointT>::Ptr & cloud)
874 typename pcl::PointCloud<PointT>::Ptr output(
new pcl::PointCloud<PointT>);
875 std::vector<int> indices;
881 return removeNaNFromPointCloudImpl<pcl::PointXYZ>(cloud);
885 return removeNaNFromPointCloudImpl<pcl::PointXYZRGB>(cloud);
889 return removeNaNFromPointCloudImpl<pcl::PointXYZI>(cloud);
892 template<
typename Po
intT>
894 const typename pcl::PointCloud<PointT>::Ptr & cloud)
896 typename pcl::PointCloud<PointT>::Ptr output(
new pcl::PointCloud<PointT>);
897 std::vector<int> indices;
902 const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud)
904 return removeNaNNormalsFromPointCloudImpl<pcl::PointNormal>(cloud);
907 const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud)
909 return removeNaNNormalsFromPointCloudImpl<pcl::PointXYZRGBNormal>(cloud);
912 const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud)
914 return removeNaNNormalsFromPointCloudImpl<pcl::PointXYZINormal>(cloud);
918 pcl::IndicesPtr
radiusFiltering(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
float radiusSearch,
int minNeighborsInRadius)
920 pcl::IndicesPtr indices(
new std::vector<int>);
921 return radiusFiltering(cloud, indices, radiusSearch, minNeighborsInRadius);
923 pcl::IndicesPtr
radiusFiltering(
const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
float radiusSearch,
int minNeighborsInRadius)
925 pcl::IndicesPtr indices(
new std::vector<int>);
926 return radiusFiltering(cloud, indices, radiusSearch, minNeighborsInRadius);
928 pcl::IndicesPtr
radiusFiltering(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
float radiusSearch,
int minNeighborsInRadius)
930 pcl::IndicesPtr indices(
new std::vector<int>);
931 return radiusFiltering(cloud, indices, radiusSearch, minNeighborsInRadius);
933 pcl::IndicesPtr
radiusFiltering(
const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
float radiusSearch,
int minNeighborsInRadius)
935 pcl::IndicesPtr indices(
new std::vector<int>);
936 return radiusFiltering(cloud, indices, radiusSearch, minNeighborsInRadius);
939 template<
typename Po
intT>
941 const typename pcl::PointCloud<PointT>::Ptr & cloud,
942 const pcl::IndicesPtr & indices,
944 int minNeighborsInRadius)
946 typename pcl::search::KdTree<PointT>::Ptr
tree (
new pcl::search::KdTree<PointT>(
false));
950 pcl::IndicesPtr output(
new std::vector<int>(indices->size()));
952 tree->setInputCloud(cloud, indices);
953 for(
unsigned int i=0; i<indices->size(); ++i)
956 std::vector<float> kDistances;
957 int k = tree->radiusSearch(cloud->at(indices->at(i)), radiusSearch, kIndices, kDistances);
958 if(k > minNeighborsInRadius)
960 output->at(oi++) = indices->at(i);
968 pcl::IndicesPtr output(
new std::vector<int>(cloud->size()));
970 tree->setInputCloud(cloud);
971 for(
unsigned int i=0; i<cloud->size(); ++i)
974 std::vector<float> kDistances;
975 int k = tree->radiusSearch(cloud->at(i), radiusSearch,
kIndices, kDistances);
976 if(k > minNeighborsInRadius)
978 output->at(oi++) = i;
986 pcl::IndicesPtr
radiusFiltering(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
const pcl::IndicesPtr & indices,
float radiusSearch,
int minNeighborsInRadius)
988 return radiusFilteringImpl<pcl::PointXYZ>(cloud, indices, radiusSearch, minNeighborsInRadius);
990 pcl::IndicesPtr
radiusFiltering(
const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
float radiusSearch,
int minNeighborsInRadius)
992 return radiusFilteringImpl<pcl::PointNormal>(cloud, indices, radiusSearch, minNeighborsInRadius);
994 pcl::IndicesPtr
radiusFiltering(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
const pcl::IndicesPtr & indices,
float radiusSearch,
int minNeighborsInRadius)
996 return radiusFilteringImpl<pcl::PointXYZRGB>(cloud, indices, radiusSearch, minNeighborsInRadius);
998 pcl::IndicesPtr
radiusFiltering(
const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
float radiusSearch,
int minNeighborsInRadius)
1000 return radiusFilteringImpl<pcl::PointXYZRGBNormal>(cloud, indices, radiusSearch, minNeighborsInRadius);
1004 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
1005 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & substractCloud,
1007 int minNeighborsInRadius)
1009 pcl::IndicesPtr indices(
new std::vector<int>);
1010 pcl::IndicesPtr indicesOut =
subtractFiltering(cloud, indices, substractCloud, indices, radiusSearch, minNeighborsInRadius);
1011 pcl::PointCloud<pcl::PointXYZRGB>::Ptr out(
new pcl::PointCloud<pcl::PointXYZRGB>);
1012 pcl::copyPointCloud(*cloud, *indicesOut, *out);
1016 template<
typename Po
intT>
1018 const typename pcl::PointCloud<PointT>::Ptr & cloud,
1019 const pcl::IndicesPtr & indices,
1020 const typename pcl::PointCloud<PointT>::Ptr & substractCloud,
1021 const pcl::IndicesPtr & substractIndices,
1023 int minNeighborsInRadius)
1025 UASSERT(minNeighborsInRadius > 0);
1026 typename pcl::search::KdTree<PointT>::Ptr
tree (
new pcl::search::KdTree<PointT>(
false));
1030 pcl::IndicesPtr output(
new std::vector<int>(indices->size()));
1032 if(substractIndices->size())
1034 tree->setInputCloud(substractCloud, substractIndices);
1038 tree->setInputCloud(substractCloud);
1040 for(
unsigned int i=0; i<indices->size(); ++i)
1043 std::vector<float> kDistances;
1044 int k = tree->radiusSearch(cloud->at(indices->at(i)), radiusSearch, kIndices, kDistances);
1045 if(k < minNeighborsInRadius)
1047 output->at(oi++) = indices->at(i);
1055 pcl::IndicesPtr output(
new std::vector<int>(cloud->size()));
1057 if(substractIndices->size())
1059 tree->setInputCloud(substractCloud, substractIndices);
1063 tree->setInputCloud(substractCloud);
1065 for(
unsigned int i=0; i<cloud->size(); ++i)
1068 std::vector<float> kDistances;
1069 int k = tree->radiusSearch(cloud->at(i), radiusSearch,
kIndices, kDistances);
1070 if(k < minNeighborsInRadius)
1072 output->at(oi++) = i;
1080 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
1081 const pcl::IndicesPtr & indices,
1082 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & substractCloud,
1083 const pcl::IndicesPtr & substractIndices,
1085 int minNeighborsInRadius)
1087 return subtractFilteringImpl<pcl::PointXYZRGB>(cloud, indices, substractCloud, substractIndices, radiusSearch, minNeighborsInRadius);
1091 const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
1092 const pcl::PointCloud<pcl::PointNormal>::Ptr & substractCloud,
1095 int minNeighborsInRadius)
1097 pcl::IndicesPtr indices(
new std::vector<int>);
1098 pcl::IndicesPtr indicesOut =
subtractFiltering(cloud, indices, substractCloud, indices, radiusSearch, maxAngle, minNeighborsInRadius);
1099 pcl::PointCloud<pcl::PointNormal>::Ptr out(
new pcl::PointCloud<pcl::PointNormal>);
1100 pcl::copyPointCloud(*cloud, *indicesOut, *out);
1104 const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
1105 const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & substractCloud,
1108 int minNeighborsInRadius)
1110 pcl::IndicesPtr indices(
new std::vector<int>);
1111 pcl::IndicesPtr indicesOut =
subtractFiltering(cloud, indices, substractCloud, indices, radiusSearch, maxAngle, minNeighborsInRadius);
1112 pcl::PointCloud<pcl::PointXYZINormal>::Ptr out(
new pcl::PointCloud<pcl::PointXYZINormal>);
1113 pcl::copyPointCloud(*cloud, *indicesOut, *out);
1117 const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
1118 const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & substractCloud,
1121 int minNeighborsInRadius)
1123 pcl::IndicesPtr indices(
new std::vector<int>);
1124 pcl::IndicesPtr indicesOut =
subtractFiltering(cloud, indices, substractCloud, indices, radiusSearch, maxAngle, minNeighborsInRadius);
1125 pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr out(
new pcl::PointCloud<pcl::PointXYZRGBNormal>);
1126 pcl::copyPointCloud(*cloud, *indicesOut, *out);
1130 template<
typename Po
intT>
1132 const typename pcl::PointCloud<PointT>::Ptr & cloud,
1133 const pcl::IndicesPtr & indices,
1134 const typename pcl::PointCloud<PointT>::Ptr & substractCloud,
1135 const pcl::IndicesPtr & substractIndices,
1138 int minNeighborsInRadius)
1140 UASSERT(minNeighborsInRadius > 0);
1141 typename pcl::search::KdTree<PointT>::Ptr
tree (
new pcl::search::KdTree<PointT>(
false));
1145 pcl::IndicesPtr output(
new std::vector<int>(indices->size()));
1147 if(substractIndices->size())
1149 tree->setInputCloud(substractCloud, substractIndices);
1153 tree->setInputCloud(substractCloud);
1155 for(
unsigned int i=0; i<indices->size(); ++i)
1158 std::vector<float> kDistances;
1159 int k = tree->radiusSearch(cloud->at(indices->at(i)), radiusSearch, kIndices, kDistances);
1160 if(k>=minNeighborsInRadius && maxAngle > 0.0
f)
1162 Eigen::Vector4f normal(cloud->at(indices->at(i)).normal_x, cloud->at(indices->at(i)).normal_y, cloud->at(indices->at(i)).normal_z, 0.0
f);
1168 for(
int j=0; j<count && k >= minNeighborsInRadius; ++j)
1170 Eigen::Vector4f v(substractCloud->at(kIndices.at(j)).normal_x, substractCloud->at(kIndices.at(j)).normal_y, substractCloud->at(kIndices.at(j)).normal_z, 0.0
f);
1175 float angle = pcl::getAngle3D(normal, v);
1176 if(angle > maxAngle)
1192 if(k < minNeighborsInRadius)
1194 output->at(oi++) = indices->at(i);
1202 pcl::IndicesPtr output(
new std::vector<int>(cloud->size()));
1204 if(substractIndices->size())
1206 tree->setInputCloud(substractCloud, substractIndices);
1210 tree->setInputCloud(substractCloud);
1212 for(
unsigned int i=0; i<cloud->size(); ++i)
1215 std::vector<float> kDistances;
1216 int k = tree->radiusSearch(cloud->at(i), radiusSearch,
kIndices, kDistances);
1217 if(k>=minNeighborsInRadius && maxAngle > 0.0
f)
1219 Eigen::Vector4f normal(cloud->at(i).normal_x, cloud->at(i).normal_y, cloud->at(i).normal_z, 0.0f);
1225 for(
int j=0; j<count && k >= minNeighborsInRadius; ++j)
1227 Eigen::Vector4f v(substractCloud->at(kIndices.at(j)).normal_x, substractCloud->at(kIndices.at(j)).normal_y, substractCloud->at(kIndices.at(j)).normal_z, 0.0
f);
1232 float angle = pcl::getAngle3D(normal, v);
1233 if(angle > maxAngle)
1249 if(k < minNeighborsInRadius)
1251 output->at(oi++) = i;
1260 const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
1261 const pcl::IndicesPtr & indices,
1262 const pcl::PointCloud<pcl::PointNormal>::Ptr & substractCloud,
1263 const pcl::IndicesPtr & substractIndices,
1266 int minNeighborsInRadius)
1268 return subtractFilteringImpl<pcl::PointNormal>(cloud, indices, substractCloud, substractIndices, radiusSearch, maxAngle, minNeighborsInRadius);
1271 const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
1272 const pcl::IndicesPtr & indices,
1273 const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & substractCloud,
1274 const pcl::IndicesPtr & substractIndices,
1277 int minNeighborsInRadius)
1279 return subtractFilteringImpl<pcl::PointXYZINormal>(cloud, indices, substractCloud, substractIndices, radiusSearch, maxAngle, minNeighborsInRadius);
1282 const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
1283 const pcl::IndicesPtr & indices,
1284 const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & substractCloud,
1285 const pcl::IndicesPtr & substractIndices,
1288 int minNeighborsInRadius)
1290 return subtractFilteringImpl<pcl::PointXYZRGBNormal>(cloud, indices, substractCloud, substractIndices, radiusSearch, maxAngle, minNeighborsInRadius);
1294 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
1295 const pcl::IndicesPtr & indices,
1296 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & substractCloud,
1297 const pcl::IndicesPtr & substractIndices,
1298 float radiusSearchRatio,
1299 int minNeighborsInRadius,
1300 const Eigen::Vector3f & viewpoint)
1302 UWARN(
"Add angle to avoid subtraction of points with opposite normals");
1303 UASSERT(minNeighborsInRadius > 0);
1305 pcl::search::KdTree<pcl::PointXYZRGB>::Ptr
tree (
new pcl::search::KdTree<pcl::PointXYZRGB>(
false));
1309 pcl::IndicesPtr output(
new std::vector<int>(indices->size()));
1311 if(substractIndices->size())
1313 tree->setInputCloud(substractCloud, substractIndices);
1317 tree->setInputCloud(substractCloud);
1319 for(
unsigned int i=0; i<indices->size(); ++i)
1324 std::vector<float> kSqrdDistances;
1325 float radius = radiusSearchRatio*
uNorm(
1326 cloud->at(indices->at(i)).x-viewpoint[0],
1327 cloud->at(indices->at(i)).y-viewpoint[1],
1328 cloud->at(indices->at(i)).z-viewpoint[2]);
1329 int k = tree->radiusSearch(cloud->at(indices->at(i)), radius, kIndices, kSqrdDistances);
1330 if(k < minNeighborsInRadius)
1332 output->at(oi++) = indices->at(i);
1341 pcl::IndicesPtr output(
new std::vector<int>(cloud->size()));
1343 if(substractIndices->size())
1345 tree->setInputCloud(substractCloud, substractIndices);
1349 tree->setInputCloud(substractCloud);
1351 for(
unsigned int i=0; i<cloud->size(); ++i)
1356 std::vector<float> kSqrdDistances;
1357 float radius = radiusSearchRatio*
uNorm(
1358 cloud->at(i).x-viewpoint[0],
1359 cloud->at(i).y-viewpoint[1],
1360 cloud->at(i).z-viewpoint[2]);
1361 int k = tree->radiusSearch(cloud->at(i), radius,
kIndices, kSqrdDistances);
1362 if(k < minNeighborsInRadius)
1364 output->at(oi++) = i;
1373 const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
1374 const pcl::IndicesPtr & indices,
1375 const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & substractCloud,
1376 const pcl::IndicesPtr & substractIndices,
1377 float radiusSearchRatio,
1379 int minNeighborsInRadius,
1380 const Eigen::Vector3f & viewpoint)
1382 UASSERT(minNeighborsInRadius > 0);
1384 pcl::search::KdTree<pcl::PointXYZRGBNormal>::Ptr
tree (
new pcl::search::KdTree<pcl::PointXYZRGBNormal>(
false));
1388 pcl::IndicesPtr output(
new std::vector<int>(indices->size()));
1390 if(substractIndices->size())
1392 tree->setInputCloud(substractCloud, substractIndices);
1396 tree->setInputCloud(substractCloud);
1398 for(
unsigned int i=0; i<indices->size(); ++i)
1403 std::vector<float> kSqrdDistances;
1404 float radius = radiusSearchRatio*
uNorm(
1405 cloud->at(indices->at(i)).x-viewpoint[0],
1406 cloud->at(indices->at(i)).y-viewpoint[1],
1407 cloud->at(indices->at(i)).z-viewpoint[2]);
1408 int k = tree->radiusSearch(cloud->at(indices->at(i)), radius, kIndices, kSqrdDistances);
1409 if(k>=minNeighborsInRadius && maxAngle > 0.0
f)
1411 Eigen::Vector4f normal(cloud->at(indices->at(i)).normal_x, cloud->at(indices->at(i)).normal_y, cloud->at(indices->at(i)).normal_z, 0.0
f);
1417 for(
int j=0; j<count && k >= minNeighborsInRadius; ++j)
1419 Eigen::Vector4f v(substractCloud->at(kIndices.at(j)).normal_x, substractCloud->at(kIndices.at(j)).normal_y, substractCloud->at(kIndices.at(j)).normal_z, 0.0
f);
1424 float angle = pcl::getAngle3D(normal, v);
1425 if(angle > maxAngle)
1442 if(k < minNeighborsInRadius)
1444 output->at(oi++) = indices->at(i);
1453 pcl::IndicesPtr output(
new std::vector<int>(cloud->size()));
1455 if(substractIndices->size())
1457 tree->setInputCloud(substractCloud, substractIndices);
1461 tree->setInputCloud(substractCloud);
1463 for(
unsigned int i=0; i<cloud->size(); ++i)
1468 std::vector<float> kSqrdDistances;
1469 float radius = radiusSearchRatio*
uNorm(
1470 cloud->at(i).x-viewpoint[0],
1471 cloud->at(i).y-viewpoint[1],
1472 cloud->at(i).z-viewpoint[2]);
1473 int k = tree->radiusSearch(cloud->at(i), radius,
kIndices, kSqrdDistances);
1474 if(k>=minNeighborsInRadius && maxAngle > 0.0
f)
1476 Eigen::Vector4f normal(cloud->at(i).normal_x, cloud->at(i).normal_y, cloud->at(i).normal_z, 0.0f);
1482 for(
int j=0; j<count && k >= minNeighborsInRadius; ++j)
1484 Eigen::Vector4f v(substractCloud->at(kIndices.at(j)).normal_x, substractCloud->at(kIndices.at(j)).normal_y, substractCloud->at(kIndices.at(j)).normal_z, 0.0
f);
1489 float angle = pcl::getAngle3D(normal, v);
1490 if(angle > maxAngle)
1506 if(k < minNeighborsInRadius)
1508 output->at(oi++) = i;
1519 const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
1521 const Eigen::Vector4f & normal,
1523 const Eigen::Vector4f & viewpoint)
1525 pcl::IndicesPtr indices(
new std::vector<int>);
1526 return normalFiltering(cloud, indices, angleMax, normal, normalKSearch, viewpoint);
1529 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
1531 const Eigen::Vector4f & normal,
1533 const Eigen::Vector4f & viewpoint)
1535 pcl::IndicesPtr indices(
new std::vector<int>);
1536 return normalFiltering(cloud, indices, angleMax, normal, normalKSearch, viewpoint);
1540 template<
typename Po
intT>
1542 const typename pcl::PointCloud<PointT>::Ptr & cloud,
1543 const pcl::IndicesPtr & indices,
1545 const Eigen::Vector4f & normal,
1547 const Eigen::Vector4f & viewpoint)
1549 pcl::IndicesPtr output(
new std::vector<int>());
1553 typename pcl::search::KdTree<PointT>::Ptr
tree(
new pcl::search::KdTree<PointT>(
false));
1555 pcl::NormalEstimationOMP<PointT, pcl::Normal> ne;
1556 ne.setInputCloud (cloud);
1559 ne.setIndices(indices);
1564 tree->setInputCloud(cloud, indices);
1568 tree->setInputCloud(cloud);
1570 ne.setSearchMethod (tree);
1572 pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (
new pcl::PointCloud<pcl::Normal>);
1574 ne.setKSearch(normalKSearch);
1575 if(viewpoint[0] != 0 || viewpoint[1] != 0 || viewpoint[2] != 0)
1577 ne.setViewPoint(viewpoint[0], viewpoint[1], viewpoint[2]);
1580 ne.compute (*cloud_normals);
1582 output->resize(cloud_normals->size());
1584 for(
unsigned int i=0; i<cloud_normals->size(); ++i)
1586 Eigen::Vector4f v(cloud_normals->at(i).normal_x, cloud_normals->at(i).normal_y, cloud_normals->at(i).normal_z, 0.0f);
1587 float angle = pcl::getAngle3D(normal, v);
1588 if(angle < angleMax)
1590 output->at(oi++) = indices->size()!=0?indices->at(i):i;
1599 const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
1600 const pcl::IndicesPtr & indices,
1602 const Eigen::Vector4f & normal,
1604 const Eigen::Vector4f & viewpoint)
1607 return normalFilteringImpl<pcl::PointXYZ>(cloud, indices, angleMax, normal, normalKSearch, viewpoint);
1610 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
1611 const pcl::IndicesPtr & indices,
1613 const Eigen::Vector4f & normal,
1615 const Eigen::Vector4f & viewpoint)
1617 return normalFilteringImpl<pcl::PointXYZRGB>(cloud, indices, angleMax, normal, normalKSearch, viewpoint);
1620 template<
typename Po
intT>
1622 const typename pcl::PointCloud<PointT>::Ptr & cloud,
1623 const pcl::IndicesPtr & indices,
1625 const Eigen::Vector4f & normal)
1627 pcl::IndicesPtr output(
new std::vector<int>());
1634 output->resize(indices->size());
1635 for(
unsigned int i=0; i<indices->size(); ++i)
1637 Eigen::Vector4f v(cloud->at(indices->at(i)).normal_x, cloud->at(indices->at(i)).normal_y, cloud->at(indices->at(i)).normal_z, 0.0
f);
1638 float angle = pcl::getAngle3D(normal, v);
1639 if(angle < angleMax)
1641 output->at(oi++) = indices->size()!=0?indices->at(i):i;
1647 output->resize(cloud->size());
1648 for(
unsigned int i=0; i<cloud->size(); ++i)
1650 Eigen::Vector4f v(cloud->at(i).normal_x, cloud->at(i).normal_y, cloud->at(i).normal_z, 0.0f);
1651 float angle = pcl::getAngle3D(normal, v);
1652 if(angle < angleMax)
1654 output->at(oi++) = indices->size()!=0?indices->at(i):i;
1665 const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
1666 const pcl::IndicesPtr & indices,
1668 const Eigen::Vector4f & normal,
1670 const Eigen::Vector4f & viewpoint)
1672 return normalFilteringImpl<pcl::PointNormal>(cloud, indices, angleMax, normal);
1675 const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
1676 const pcl::IndicesPtr & indices,
1678 const Eigen::Vector4f & normal,
1680 const Eigen::Vector4f & viewpoint)
1682 return normalFilteringImpl<pcl::PointXYZRGBNormal>(cloud, indices, angleMax, normal);
1686 const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
1687 float clusterTolerance,
1690 int * biggestClusterIndex)
1692 pcl::IndicesPtr indices(
new std::vector<int>);
1693 return extractClusters(cloud, indices, clusterTolerance, minClusterSize, maxClusterSize, biggestClusterIndex);
1696 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
1697 float clusterTolerance,
1700 int * biggestClusterIndex)
1702 pcl::IndicesPtr indices(
new std::vector<int>);
1703 return extractClusters(cloud, indices, clusterTolerance, minClusterSize, maxClusterSize, biggestClusterIndex);
1706 template<
typename Po
intT>
1708 const typename pcl::PointCloud<PointT>::Ptr & cloud,
1709 const pcl::IndicesPtr & indices,
1710 float clusterTolerance,
1713 int * biggestClusterIndex)
1715 typename pcl::search::KdTree<PointT>::Ptr
tree (
new pcl::search::KdTree<PointT>(
true));
1716 pcl::EuclideanClusterExtraction<PointT> ec;
1717 ec.setClusterTolerance (clusterTolerance);
1718 ec.setMinClusterSize (minClusterSize);
1719 ec.setMaxClusterSize (maxClusterSize);
1720 ec.setInputCloud (cloud);
1724 ec.setIndices(indices);
1725 tree->setInputCloud(cloud, indices);
1729 tree->setInputCloud(cloud);
1731 ec.setSearchMethod (tree);
1733 std::vector<pcl::PointIndices> cluster_indices;
1734 ec.extract (cluster_indices);
1737 unsigned int maxSize = 0;
1738 std::vector<pcl::IndicesPtr> output(cluster_indices.size());
1739 for(
unsigned int i=0; i<cluster_indices.size(); ++i)
1741 output[i] = pcl::IndicesPtr(
new std::vector<int>(cluster_indices[i].indices));
1743 if(maxSize < cluster_indices[i].indices.size())
1745 maxSize = (
unsigned int)cluster_indices[i].indices.size();
1749 if(biggestClusterIndex)
1751 *biggestClusterIndex = maxIndex;
1758 const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
1759 const pcl::IndicesPtr & indices,
1760 float clusterTolerance,
1763 int * biggestClusterIndex)
1765 return extractClustersImpl<pcl::PointXYZ>(cloud, indices, clusterTolerance, minClusterSize, maxClusterSize, biggestClusterIndex);
1768 const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
1769 const pcl::IndicesPtr & indices,
1770 float clusterTolerance,
1773 int * biggestClusterIndex)
1775 return extractClustersImpl<pcl::PointNormal>(cloud, indices, clusterTolerance, minClusterSize, maxClusterSize, biggestClusterIndex);
1778 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
1779 const pcl::IndicesPtr & indices,
1780 float clusterTolerance,
1783 int * biggestClusterIndex)
1785 return extractClustersImpl<pcl::PointXYZRGB>(cloud, indices, clusterTolerance, minClusterSize, maxClusterSize, biggestClusterIndex);
1788 const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
1789 const pcl::IndicesPtr & indices,
1790 float clusterTolerance,
1793 int * biggestClusterIndex)
1795 return extractClustersImpl<pcl::PointXYZRGBNormal>(cloud, indices, clusterTolerance, minClusterSize, maxClusterSize, biggestClusterIndex);
1798 template<
typename Po
intT>
1800 const typename pcl::PointCloud<PointT>::Ptr & cloud,
1801 const pcl::IndicesPtr & indices,
1804 pcl::IndicesPtr output(
new std::vector<int>);
1805 pcl::ExtractIndices<PointT> extract;
1806 extract.setInputCloud (cloud);
1807 extract.setIndices(indices);
1808 extract.setNegative(negative);
1809 extract.filter(*output);
1813 pcl::IndicesPtr
extractIndices(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
const pcl::IndicesPtr & indices,
bool negative)
1815 return extractIndicesImpl<pcl::PointXYZ>(cloud, indices, negative);
1817 pcl::IndicesPtr
extractIndices(
const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
bool negative)
1819 return extractIndicesImpl<pcl::PointNormal>(cloud, indices, negative);
1821 pcl::IndicesPtr
extractIndices(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
const pcl::IndicesPtr & indices,
bool negative)
1823 return extractIndicesImpl<pcl::PointXYZRGB>(cloud, indices, negative);
1825 pcl::IndicesPtr
extractIndices(
const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
bool negative)
1827 return extractIndicesImpl<pcl::PointXYZRGBNormal>(cloud, indices, negative);
1830 template<
typename Po
intT>
1832 const typename pcl::PointCloud<PointT>::Ptr & cloud,
1833 const pcl::IndicesPtr & indices,
1837 typename pcl::PointCloud<PointT>::Ptr output(
new pcl::PointCloud<PointT>);
1838 pcl::ExtractIndices<PointT> extract;
1839 extract.setInputCloud (cloud);
1840 extract.setIndices(indices);
1841 extract.setNegative(negative);
1842 extract.setKeepOrganized(keepOrganized);
1843 extract.filter(*output);
1846 pcl::PointCloud<pcl::PointXYZ>::Ptr
extractIndices(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
const pcl::IndicesPtr & indices,
bool negative,
bool keepOrganized)
1848 return extractIndicesImpl<pcl::PointXYZ>(cloud, indices, negative, keepOrganized);
1850 pcl::PointCloud<pcl::PointXYZRGB>::Ptr
extractIndices(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
const pcl::IndicesPtr & indices,
bool negative,
bool keepOrganized)
1852 return extractIndicesImpl<pcl::PointXYZRGB>(cloud, indices, negative, keepOrganized);
1859 pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr
extractIndices(
const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
bool negative,
bool keepOrganized)
1861 return extractIndicesImpl<pcl::PointXYZRGBNormal>(cloud, indices, negative, keepOrganized);
1865 const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
1866 float distanceThreshold,
1868 pcl::ModelCoefficients * coefficientsOut)
1870 pcl::IndicesPtr indices(
new std::vector<int>);
1871 return extractPlane(cloud, indices, distanceThreshold, maxIterations, coefficientsOut);
1875 const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
1876 const pcl::IndicesPtr & indices,
1877 float distanceThreshold,
1879 pcl::ModelCoefficients * coefficientsOut)
1882 pcl::ModelCoefficients::Ptr coefficients (
new pcl::ModelCoefficients);
1883 pcl::PointIndices::Ptr inliers (
new pcl::PointIndices);
1885 pcl::SACSegmentation<pcl::PointXYZ> seg;
1887 seg.setOptimizeCoefficients (
true);
1888 seg.setMaxIterations (maxIterations);
1890 seg.setModelType (pcl::SACMODEL_PLANE);
1891 seg.setMethodType (pcl::SAC_RANSAC);
1892 seg.setDistanceThreshold (distanceThreshold);
1894 seg.setInputCloud (cloud);
1897 seg.setIndices(indices);
1899 seg.segment (*inliers, *coefficients);
1903 *coefficientsOut = *coefficients;
1906 return pcl::IndicesPtr(
new std::vector<int>(inliers->indices));
bool RTABMAP_EXP isFinite(const cv::Point3f &pt)
pcl::PointCloud< pcl::PointXYZRGB >::Ptr RTABMAP_EXP subtractFiltering(const pcl::PointCloud< pcl::PointXYZRGB >::Ptr &cloud, const pcl::PointCloud< pcl::PointXYZRGB >::Ptr &substractCloud, float radiusSearch, int minNeighborsInRadius=1)
T uNorm(const std::vector< T > &v)
std::vector< pcl::IndicesPtr > RTABMAP_EXP extractClusters(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, float clusterTolerance, int minClusterSize, int maxClusterSize=std::numeric_limits< int >::max(), int *biggestClusterIndex=0)
GLM_FUNC_DECL genType min(genType const &x, genType const &y)
const cv::Mat & data() const
pcl::PointCloud< pcl::Normal >::Ptr RTABMAP_EXP computeNormals2D(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, int searchK=5, float searchRadius=0.0f, const Eigen::Vector3f &viewPoint=Eigen::Vector3f(0, 0, 0))
pcl::IndicesPtr RTABMAP_EXP passThrough(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, const pcl::IndicesPtr &indices, const std::string &axis, float min, float max, bool negative=false)
pcl::IndicesPtr passThroughImpl(const typename pcl::PointCloud< PointT >::Ptr &cloud, const pcl::IndicesPtr &indices, const std::string &axis, float min, float max, bool negative)
pcl::PointCloud< PointT >::Ptr removeNaNNormalsFromPointCloudImpl(const typename pcl::PointCloud< PointT >::Ptr &cloud)
pcl::IndicesPtr normalFilteringImpl(const typename pcl::PointCloud< PointT >::Ptr &cloud, const pcl::IndicesPtr &indices, float angleMax, const Eigen::Vector4f &normal, int normalKSearch, const Eigen::Vector4f &viewpoint)
GLM_FUNC_DECL detail::tvec3< T, P > axis(detail::tquat< T, P > const &x)
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP removeNaNFromPointCloud(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud)
pcl::PointCloud< PointT >::Ptr randomSamplingImpl(const typename pcl::PointCloud< PointT >::Ptr &cloud, int samples)
GLM_FUNC_DECL bool all(vecType< bool, P > const &v)
pcl::IndicesPtr RTABMAP_EXP subtractAdaptiveFiltering(const pcl::PointCloud< pcl::PointXYZRGB >::Ptr &cloud, const pcl::IndicesPtr &indices, const pcl::PointCloud< pcl::PointXYZRGB >::Ptr &substractCloud, const pcl::IndicesPtr &substractIndices, float radiusSearchRatio=0.01, int minNeighborsInRadius=1, const Eigen::Vector3f &viewpoint=Eigen::Vector3f(0, 0, 0))
Basic mathematics functions.
GLM_FUNC_DECL T angle(detail::tquat< T, P > const &x)
pcl::PointCloud< PointT >::Ptr removeNaNFromPointCloudImpl(const typename pcl::PointCloud< PointT >::Ptr &cloud)
Some conversion functions.
pcl::IndicesPtr frustumFilteringImpl(const typename pcl::PointCloud< PointT >::Ptr &cloud, const pcl::IndicesPtr &indices, const Transform &cameraPose, float horizontalFOV, float verticalFOV, float nearClipPlaneDistance, float farClipPlaneDistance, bool negative)
GLM_FUNC_DECL genType step(genType const &edge, genType const &x)
pcl::IndicesPtr RTABMAP_EXP frustumFiltering(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, const pcl::IndicesPtr &indices, const Transform &cameraPose, float horizontalFOV, float verticalFOV, float nearClipPlaneDistance, float farClipPlaneDistance, bool negative=false)
pcl::IndicesPtr RTABMAP_EXP extractIndices(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, const pcl::IndicesPtr &indices, bool negative)
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP laserScanToPointCloud(const LaserScan &laserScan, const Transform &transform=Transform())
pcl::PointCloud< PointT >::Ptr voxelizeImpl(const typename pcl::PointCloud< PointT >::Ptr &cloud, const pcl::IndicesPtr &indices, float voxelSize)
LaserScan RTABMAP_EXP downsample(const LaserScan &cloud, int step)
cv::Mat RTABMAP_EXP laserScan2dFromPointCloud(const pcl::PointCloud< pcl::PointXYZ > &cloud, const Transform &transform=Transform(), bool filterNaNs=true)
bool uIsFinite(const T &value)
pcl::IndicesPtr subtractFilteringImpl(const typename pcl::PointCloud< PointT >::Ptr &cloud, const pcl::IndicesPtr &indices, const typename pcl::PointCloud< PointT >::Ptr &substractCloud, const pcl::IndicesPtr &substractIndices, float radiusSearch, int minNeighborsInRadius)
#define UASSERT(condition)
pcl::PointCloud< PointT >::Ptr downsampleImpl(const typename pcl::PointCloud< PointT >::Ptr &cloud, int step)
pcl::PointCloud< pcl::PointXYZRGB >::Ptr RTABMAP_EXP laserScanToPointCloudRGB(const LaserScan &laserScan, const Transform &transform=Transform(), unsigned char r=100, unsigned char g=100, unsigned char b=100)
LaserScan RTABMAP_EXP commonFiltering(const LaserScan &scan, int downsamplingStep, float rangeMin=0.0f, float rangeMax=0.0f, float voxelSize=0.0f, int normalK=0, float normalRadius=0.0f, float groundNormalsUp=0.0f)
#define UASSERT_MSG(condition, msg_str)
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP randomSampling(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, int samples)
std::vector< pcl::IndicesPtr > extractClustersImpl(const typename pcl::PointCloud< PointT >::Ptr &cloud, const pcl::IndicesPtr &indices, float clusterTolerance, int minClusterSize, int maxClusterSize, int *biggestClusterIndex)
pcl::IndicesPtr cropBoxImpl(const typename pcl::PointCloud< PointT >::Ptr &cloud, const pcl::IndicesPtr &indices, const Eigen::Vector4f &min, const Eigen::Vector4f &max, const Transform &transform, bool negative)
cv::Mat RTABMAP_EXP computeNormals(const cv::Mat &laserScan, int searchK, float searchRadius)
Transform localTransform() const
float angleIncrement() const
pcl::IndicesPtr radiusFilteringImpl(const typename pcl::PointCloud< PointT >::Ptr &cloud, const pcl::IndicesPtr &indices, float radiusSearch, int minNeighborsInRadius)
pcl::IndicesPtr RTABMAP_EXP radiusFiltering(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, float radiusSearch, int minNeighborsInRadius)
GLM_FUNC_DECL genType max(genType const &x, genType const &y)
pcl::IndicesPtr extractPlane(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, float distanceThreshold, int maxIterations=100, pcl::ModelCoefficients *coefficientsOut=0)
pcl::IndicesPtr RTABMAP_EXP cropBox(const pcl::PCLPointCloud2::Ptr &cloud, const pcl::IndicesPtr &indices, const Eigen::Vector4f &min, const Eigen::Vector4f &max, const Transform &transform=Transform::getIdentity(), bool negative=false)
ULogger class and convenient macros.
LaserScan RTABMAP_EXP rangeFiltering(const LaserScan &scan, float rangeMin, float rangeMax)
pcl::PointCloud< pcl::PointNormal >::Ptr RTABMAP_EXP removeNaNNormalsFromPointCloud(const pcl::PointCloud< pcl::PointNormal >::Ptr &cloud)
static const GLushort kIndices[]
pcl::PointCloud< pcl::PointXYZI >::Ptr RTABMAP_EXP laserScanToPointCloudI(const LaserScan &laserScan, const Transform &transform=Transform(), float intensity=0.0f)
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP voxelize(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, const pcl::IndicesPtr &indices, float voxelSize)
std::string UTILITE_EXP uFormat(const char *fmt,...)
pcl::IndicesPtr extractIndicesImpl(const typename pcl::PointCloud< PointT >::Ptr &cloud, const pcl::IndicesPtr &indices, bool negative)
bool hasIntensity() const
pcl::IndicesPtr RTABMAP_EXP normalFiltering(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, float angleMax, const Eigen::Vector4f &normal, int normalKSearch, const Eigen::Vector4f &viewpoint)
LaserScan RTABMAP_EXP adjustNormalsToViewPoint(const LaserScan &scan, const Eigen::Vector3f &viewpoint=Eigen::Vector3f(0, 0, 0), float groundNormalsUp=0.0f)
LaserScan RTABMAP_EXP laserScanFromPointCloud(const pcl::PCLPointCloud2 &cloud, bool filterNaNs=true, bool is2D=false, const Transform &transform=Transform())