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);
181 UWARN(
"Only NaNs returned after normals estimation! The returned point cloud is empty. Normal k (%d) and/or radius (%f) may be too small.", normalK, normalRadius);
188 UWARN(
"Voxel filter is applied, but normal parameters are not set and input scan has normals. The returned scan has no normals.");
203 float ratio = float(cloud->size()) / scan.
size();
204 scanMaxPts = int(
float(scanMaxPts) * ratio);
205 UDEBUG(
"Voxel filtering scan (voxel=%f m): %d -> %d (scanMaxPts=%d->%d)", voxelSize, scan.
size(), cloud->size(), scan.
maxPoints(), scanMaxPts);
207 if(cloud->size() && (normalK > 0 || normalRadius>0.0f))
209 pcl::PointCloud<pcl::Normal>::Ptr normals;
223 UWARN(
"Only NaNs returned after normals estimation! The returned point cloud is empty. Normal k (%d) and/or radius (%f) may be too small.", normalK, normalRadius);
232 UWARN(
"Only NaNs returned after normals estimation! The returned point cloud is empty. Normal k (%d) and/or radius (%f) may be too small.", normalK, normalRadius);
235 UDEBUG(
"Normals computed (k=%d radius=%f)", normalK, normalRadius);
241 UWARN(
"Voxel filter is applied, but normal parameters are not set and input scan has normals. The returned scan has no normals.");
263 float ratio = float(cloud->size()) / scan.
size();
264 scanMaxPts = int(
float(scanMaxPts) * ratio);
265 UDEBUG(
"Voxel filtering scan (voxel=%f m): %d -> %d (scanMaxPts=%d->%d)", voxelSize, scan.
size(), cloud->size(), scan.
maxPoints(), scanMaxPts);
267 if(cloud->size() && (normalK > 0 || normalRadius>0.0f))
269 pcl::PointCloud<pcl::Normal>::Ptr normals;
283 UWARN(
"Only NaNs returned after normals estimation! The returned point cloud is empty. Normal k (%d) and/or radius (%f) may be too small.", normalK, normalRadius);
292 UWARN(
"Only NaNs returned after normals estimation! The returned point cloud is empty. Normal k (%d) and/or radius (%f) may be too small.", normalK, normalRadius);
295 UDEBUG(
"Normals computed (k=%d radius=%f)", normalK, normalRadius);
301 UWARN(
"Voxel filter i applied, but normal parameters are not set and input scan has normals. The returned scan has no normals.");
326 int downsamplingStep,
332 bool forceGroundNormalsUp)
334 return commonFiltering(scanIn, downsamplingStep, rangeMin, rangeMax, voxelSize, normalK, normalRadius, forceGroundNormalsUp?0.8
f:0.0
f);
342 UASSERT(rangeMin >=0.0
f && rangeMax>=0.0
f);
345 if(rangeMin > 0.0
f || rangeMax > 0.0
f)
347 cv::Mat output = cv::Mat(1, scan.
size(), scan.
dataType());
348 bool is2d = scan.
is2d();
350 float rangeMinSqrd = rangeMin * rangeMin;
351 float rangeMaxSqrd = rangeMax * rangeMax;
352 for(
int i=0; i<scan.
size(); ++i)
354 const float * ptr = scan.
data().ptr<
float>(0, i);
358 r = ptr[0]*ptr[0] + ptr[1]*ptr[1];
362 r = ptr[0]*ptr[0] + ptr[1]*ptr[1] + ptr[2]*ptr[2];
365 if(rangeMin > 0.0
f && r < rangeMinSqrd)
369 if(rangeMax > 0.0
f && r > rangeMaxSqrd)
379 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());
393 if(step <= 1 || scan.
size() <=
step)
401 cv::Mat output = cv::Mat(1, finalSize, scan.
dataType());
403 for(
int i=0; i<scan.
size()-step+1; i+=
step)
415 template<
typename Po
intT>
417 const typename pcl::PointCloud<PointT>::Ptr & cloud,
421 typename pcl::PointCloud<PointT>::Ptr output(
new pcl::PointCloud<PointT>);
422 if(step <= 1 || (
int)cloud->size() <=
step)
429 if(cloud->height > 1 && cloud->height < cloud->width/4)
439 unsigned int rings = cloud->height<cloud->width?cloud->height:cloud->width;
440 unsigned int pts = cloud->height>cloud->width?cloud->height:cloud->width;
441 unsigned int finalSize = rings * pts/
step;
442 output->resize(finalSize);
443 output->width = rings;
444 output->height = pts/
step;
446 for(
unsigned int j=0; j<rings; ++j)
448 for(
unsigned int i=0; i<output->height; ++i)
450 (*output)[i*rings + j] = cloud->at(i*step*rings + j);
455 else if(cloud->height > 1)
458 UASSERT_MSG(cloud->height % step == 0 && cloud->width % step == 0,
459 uFormat(
"Decimation of depth images should be exact! (decimation=%d, size=%dx%d)",
460 step, cloud->width, cloud->height).c_str());
462 int finalSize = cloud->height/step * cloud->width/
step;
463 output->resize(finalSize);
464 output->width = cloud->width/
step;
465 output->height = cloud->height/
step;
467 for(
unsigned int j=0; j<output->height; ++j)
469 for(
unsigned int i=0; i<output->width; ++i)
471 output->at(j*output->width + i) = cloud->at(j*output->width*step + i*step);
477 int finalSize = int(cloud->size())/step;
478 output->resize(finalSize);
480 for(
unsigned int i=0; i<cloud->size()-step+1; i+=
step)
482 (*output)[oi++] = cloud->at(i);
488 pcl::PointCloud<pcl::PointXYZ>::Ptr
downsample(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
int step)
490 return downsampleImpl<pcl::PointXYZ>(cloud,
step);
492 pcl::PointCloud<pcl::PointXYZRGB>::Ptr
downsample(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
int step)
494 return downsampleImpl<pcl::PointXYZRGB>(cloud,
step);
496 pcl::PointCloud<pcl::PointXYZI>::Ptr
downsample(
const pcl::PointCloud<pcl::PointXYZI>::Ptr & cloud,
int step)
498 return downsampleImpl<pcl::PointXYZI>(cloud,
step);
500 pcl::PointCloud<pcl::PointNormal>::Ptr
downsample(
const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
int step)
502 return downsampleImpl<pcl::PointNormal>(cloud,
step);
504 pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr
downsample(
const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
int step)
506 return downsampleImpl<pcl::PointXYZRGBNormal>(cloud,
step);
508 pcl::PointCloud<pcl::PointXYZINormal>::Ptr
downsample(
const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
int step)
510 return downsampleImpl<pcl::PointXYZINormal>(cloud,
step);
513 template<
typename Po
intT>
515 const typename pcl::PointCloud<PointT>::Ptr & cloud,
516 const pcl::IndicesPtr & indices,
521 typename pcl::PointCloud<PointT>::Ptr output(
new pcl::PointCloud<PointT>);
522 if((cloud->is_dense && cloud->size()) || (!cloud->is_dense && !indices->empty()))
524 Eigen::Vector4f min_p, max_p;
527 pcl::getMinMax3D<PointT>(*cloud, min_p, max_p);
529 pcl::getMinMax3D<PointT>(*cloud, *indices, min_p, max_p);
532 float inverseVoxelSize = 1.0f/voxelSize;
539 UWARN(
"Leaf size is too small for the input dataset. Integer indices would overflow. " 540 "We will split space to be able to voxelize (lvl=%d cloud=%d min=[%f %f %f] max=[%f %f %f] voxel=%f).",
542 (
int)(indices->empty()?cloud->size():indices->size()),
543 min_p[0], min_p[1], min_p[2],
544 max_p[0], max_p[1], max_p[2],
546 pcl::IndicesPtr denseIndices;
549 denseIndices.reset(
new std::vector<int>(cloud->size()));
550 for(
size_t i=0; i<cloud->size(); ++i)
552 denseIndices->at(i) = i;
556 Eigen::Vector4f mid = (max_p-min_p)/2.0
f;
557 int zMax = max_p[2]-min_p[2] < 10?1:2;
558 for(
int x=0;
x<2; ++
x)
560 for(
int y=0; y<2; ++y)
562 for(
int z=0; z<zMax; ++z)
564 Eigen::Vector4f m = min_p+Eigen::Vector4f(mid[0]*
x,mid[1]*y,mid[2]*z,0);
565 Eigen::Vector4f mx = m+mid;
570 pcl::IndicesPtr ind =
util3d::cropBox(cloud, denseIndices.get()?denseIndices:indices, m, mx);
574 *output+=*voxelizeImpl<PointT>(cloud, ind, voxelSize, level+1);
582 pcl::VoxelGrid<PointT> filter;
583 filter.setLeafSize(voxelSize, voxelSize, voxelSize);
584 filter.setInputCloud(cloud);
587 output->resize(cloud->size());
589 if(!indices->empty())
591 filter.setIndices(indices);
593 filter.filter(*output);
596 else if(cloud->size() && !cloud->is_dense && indices->size() == 0)
598 UWARN(
"Cannot voxelize a not dense (organized) cloud with empty indices! (input=%d pts). Returning empty cloud!", (
int)cloud->size());
603 pcl::PointCloud<pcl::PointXYZ>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
const pcl::IndicesPtr & indices,
float voxelSize)
605 return voxelizeImpl<pcl::PointXYZ>(cloud, indices, voxelSize);
607 pcl::PointCloud<pcl::PointNormal>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
float voxelSize)
609 return voxelizeImpl<pcl::PointNormal>(cloud, indices, voxelSize);
611 pcl::PointCloud<pcl::PointXYZRGB>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
const pcl::IndicesPtr & indices,
float voxelSize)
613 return voxelizeImpl<pcl::PointXYZRGB>(cloud, indices, voxelSize);
615 pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
float voxelSize)
617 return voxelizeImpl<pcl::PointXYZRGBNormal>(cloud, indices, voxelSize);
619 pcl::PointCloud<pcl::PointXYZI>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointXYZI>::Ptr & cloud,
const pcl::IndicesPtr & indices,
float voxelSize)
621 return voxelizeImpl<pcl::PointXYZI>(cloud, indices, voxelSize);
623 pcl::PointCloud<pcl::PointXYZINormal>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
float voxelSize)
625 return voxelizeImpl<pcl::PointXYZINormal>(cloud, indices, voxelSize);
628 pcl::PointCloud<pcl::PointXYZ>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
float voxelSize)
630 pcl::IndicesPtr indices(
new std::vector<int>);
631 return voxelize(cloud, indices, voxelSize);
633 pcl::PointCloud<pcl::PointNormal>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
float voxelSize)
635 pcl::IndicesPtr indices(
new std::vector<int>);
636 return voxelize(cloud, indices, voxelSize);
638 pcl::PointCloud<pcl::PointXYZRGB>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
float voxelSize)
640 pcl::IndicesPtr indices(
new std::vector<int>);
641 return voxelize(cloud, indices, voxelSize);
643 pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
float voxelSize)
645 pcl::IndicesPtr indices(
new std::vector<int>);
646 return voxelize(cloud, indices, voxelSize);
648 pcl::PointCloud<pcl::PointXYZI>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointXYZI>::Ptr & cloud,
float voxelSize)
650 pcl::IndicesPtr indices(
new std::vector<int>);
651 return voxelize(cloud, indices, voxelSize);
653 pcl::PointCloud<pcl::PointXYZINormal>::Ptr
voxelize(
const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
float voxelSize)
655 pcl::IndicesPtr indices(
new std::vector<int>);
656 return voxelize(cloud, indices, voxelSize);
659 template<
typename Po
intT>
661 const typename pcl::PointCloud<PointT>::Ptr & cloud,
int samples)
664 typename pcl::PointCloud<PointT>::Ptr output(
new pcl::PointCloud<PointT>);
665 pcl::RandomSample<PointT> filter;
666 filter.setSample(samples);
667 filter.setSeed (std::rand ());
668 filter.setInputCloud(cloud);
669 filter.filter(*output);
672 pcl::PointCloud<pcl::PointXYZ>::Ptr
randomSampling(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
int samples)
674 return randomSamplingImpl<pcl::PointXYZ>(cloud, samples);
676 pcl::PointCloud<pcl::PointNormal>::Ptr
randomSampling(
const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
int samples)
678 return randomSamplingImpl<pcl::PointNormal>(cloud, samples);
680 pcl::PointCloud<pcl::PointXYZRGB>::Ptr
randomSampling(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
int samples)
682 return randomSamplingImpl<pcl::PointXYZRGB>(cloud, samples);
684 pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr
randomSampling(
const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
int samples)
686 return randomSamplingImpl<pcl::PointXYZRGBNormal>(cloud, samples);
688 pcl::PointCloud<pcl::PointXYZI>::Ptr
randomSampling(
const pcl::PointCloud<pcl::PointXYZI>::Ptr & cloud,
int samples)
690 return randomSamplingImpl<pcl::PointXYZI>(cloud, samples);
692 pcl::PointCloud<pcl::PointXYZINormal>::Ptr
randomSampling(
const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
int samples)
694 return randomSamplingImpl<pcl::PointXYZINormal>(cloud, samples);
697 template<
typename Po
intT>
699 const typename pcl::PointCloud<PointT>::Ptr & cloud,
700 const pcl::IndicesPtr & indices,
701 const std::string &
axis,
706 UASSERT_MSG(max > min,
uFormat(
"cloud=%d, max=%f min=%f axis=%s", (
int)cloud->size(),
max,
min, axis.c_str()).c_str());
707 UASSERT(axis.compare(
"x") == 0 || axis.compare(
"y") == 0 || axis.compare(
"z") == 0);
709 pcl::IndicesPtr output(
new std::vector<int>);
710 pcl::PassThrough<PointT> filter;
711 filter.setNegative(negative);
712 filter.setFilterFieldName(axis);
713 filter.setFilterLimits(min, max);
714 filter.setInputCloud(cloud);
715 filter.setIndices(indices);
716 filter.filter(*output);
720 pcl::IndicesPtr
passThrough(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
const pcl::IndicesPtr & indices,
const std::string &
axis,
float min,
float max,
bool negative)
722 return passThroughImpl<pcl::PointXYZ>(cloud, indices,
axis,
min,
max, negative);
724 pcl::IndicesPtr
passThrough(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
const pcl::IndicesPtr & indices,
const std::string &
axis,
float min,
float max,
bool negative)
726 return passThroughImpl<pcl::PointXYZRGB>(cloud, indices,
axis,
min,
max, negative);
728 pcl::IndicesPtr
passThrough(
const pcl::PointCloud<pcl::PointXYZI>::Ptr & cloud,
const pcl::IndicesPtr & indices,
const std::string &
axis,
float min,
float max,
bool negative)
730 return passThroughImpl<pcl::PointXYZI>(cloud, indices,
axis,
min,
max, negative);
732 pcl::IndicesPtr
passThrough(
const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
const std::string &
axis,
float min,
float max,
bool negative)
734 return passThroughImpl<pcl::PointNormal>(cloud, indices,
axis,
min,
max, negative);
736 pcl::IndicesPtr
passThrough(
const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
const std::string &
axis,
float min,
float max,
bool negative)
738 return passThroughImpl<pcl::PointXYZRGBNormal>(cloud, indices,
axis,
min,
max, negative);
740 pcl::IndicesPtr
passThrough(
const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
const std::string &
axis,
float min,
float max,
bool negative)
742 return passThroughImpl<pcl::PointXYZINormal>(cloud, indices,
axis,
min,
max, negative);
745 template<
typename Po
intT>
747 const typename pcl::PointCloud<PointT>::Ptr & cloud,
748 const std::string &
axis,
753 UASSERT_MSG(max > min,
uFormat(
"cloud=%d, max=%f min=%f axis=%s", (
int)cloud->size(),
max,
min, axis.c_str()).c_str());
754 UASSERT(axis.compare(
"x") == 0 || axis.compare(
"y") == 0 || axis.compare(
"z") == 0);
756 typename pcl::PointCloud<PointT>::Ptr output(
new pcl::PointCloud<PointT>);
757 pcl::PassThrough<PointT> filter;
758 filter.setNegative(negative);
759 filter.setFilterFieldName(axis);
760 filter.setFilterLimits(min, max);
761 filter.setInputCloud(cloud);
762 filter.filter(*output);
765 pcl::PointCloud<pcl::PointXYZ>::Ptr
passThrough(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
const std::string &
axis,
float min,
float max,
bool negative)
767 return passThroughImpl<pcl::PointXYZ>(cloud,
axis,
min ,
max, negative);
769 pcl::PointCloud<pcl::PointXYZRGB>::Ptr
passThrough(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
const std::string &
axis,
float min,
float max,
bool negative)
771 return passThroughImpl<pcl::PointXYZRGB>(cloud,
axis,
min ,
max, negative);
773 pcl::PointCloud<pcl::PointXYZI>::Ptr
passThrough(
const pcl::PointCloud<pcl::PointXYZI>::Ptr & cloud,
const std::string &
axis,
float min,
float max,
bool negative)
775 return passThroughImpl<pcl::PointXYZI>(cloud,
axis,
min ,
max, negative);
777 pcl::PointCloud<pcl::PointNormal>::Ptr
passThrough(
const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
const std::string &
axis,
float min,
float max,
bool negative)
779 return passThroughImpl<pcl::PointNormal>(cloud,
axis,
min ,
max, negative);
781 pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr
passThrough(
const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
const std::string &
axis,
float min,
float max,
bool negative)
783 return passThroughImpl<pcl::PointXYZRGBNormal>(cloud,
axis,
min ,
max, negative);
785 pcl::PointCloud<pcl::PointXYZINormal>::Ptr
passThrough(
const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
const std::string &
axis,
float min,
float max,
bool negative)
787 return passThroughImpl<pcl::PointXYZINormal>(cloud,
axis,
min ,
max, negative);
790 template<
typename Po
intT>
792 const typename pcl::PointCloud<PointT>::Ptr & cloud,
793 const pcl::IndicesPtr & indices,
794 const Eigen::Vector4f &
min,
795 const Eigen::Vector4f &
max,
799 UASSERT(min[0] < max[0] && min[1] < max[1] && min[2] < max[2]);
801 pcl::IndicesPtr output(
new std::vector<int>);
802 pcl::CropBox<PointT> filter;
803 filter.setNegative(negative);
808 filter.setTransform(transform.
toEigen3f());
810 filter.setInputCloud(cloud);
811 filter.setIndices(indices);
812 filter.filter(*output);
816 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)
818 UASSERT(min[0] < max[0] && min[1] < max[1] && min[2] < max[2]);
820 pcl::IndicesPtr output(
new std::vector<int>);
821 pcl::CropBox<pcl::PCLPointCloud2> filter;
822 filter.setNegative(negative);
827 filter.setTransform(transform.
toEigen3f());
829 filter.setInputCloud(cloud);
830 filter.setIndices(indices);
831 filter.filter(*output);
834 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)
836 return cropBoxImpl<pcl::PointXYZ>(cloud, indices,
min,
max, transform, negative);
838 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)
840 return cropBoxImpl<pcl::PointNormal>(cloud, indices,
min,
max, transform, negative);
842 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)
844 return cropBoxImpl<pcl::PointXYZRGB>(cloud, indices,
min,
max, transform, negative);
846 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)
848 return cropBoxImpl<pcl::PointXYZRGBNormal>(cloud, indices,
min,
max, transform, negative);
850 pcl::IndicesPtr
cropBox(
const pcl::PointCloud<pcl::PointXYZI>::Ptr & cloud,
const pcl::IndicesPtr & indices,
const Eigen::Vector4f &
min,
const Eigen::Vector4f &
max,
const Transform & transform,
bool negative)
852 return cropBoxImpl<pcl::PointXYZI>(cloud, indices,
min,
max, transform, negative);
854 pcl::IndicesPtr
cropBox(
const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
const Eigen::Vector4f &
min,
const Eigen::Vector4f &
max,
const Transform & transform,
bool negative)
856 return cropBoxImpl<pcl::PointXYZINormal>(cloud, indices,
min,
max, transform, negative);
859 template<
typename Po
intT>
861 const typename pcl::PointCloud<PointT>::Ptr & cloud,
862 const Eigen::Vector4f &
min,
863 const Eigen::Vector4f &
max,
867 UASSERT(min[0] < max[0] && min[1] < max[1] && min[2] < max[2]);
869 typename pcl::PointCloud<PointT>::Ptr output(
new pcl::PointCloud<PointT>);
870 pcl::CropBox<PointT> filter;
871 filter.setNegative(negative);
876 filter.setTransform(transform.
toEigen3f());
878 filter.setInputCloud(cloud);
879 filter.filter(*output);
882 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)
884 return cropBoxImpl<pcl::PointXYZ>(cloud,
min,
max, transform, negative);
886 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)
888 return cropBoxImpl<pcl::PointNormal>(cloud,
min,
max, transform, negative);
890 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)
892 return cropBoxImpl<pcl::PointXYZRGB>(cloud,
min,
max, transform, negative);
894 pcl::PointCloud<pcl::PointXYZI>::Ptr
cropBox(
const pcl::PointCloud<pcl::PointXYZI>::Ptr & cloud,
const Eigen::Vector4f &
min,
const Eigen::Vector4f &
max,
const Transform & transform,
bool negative)
896 return cropBoxImpl<pcl::PointXYZI>(cloud,
min,
max, transform, negative);
898 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)
900 return cropBoxImpl<pcl::PointXYZINormal>(cloud,
min,
max, transform, negative);
902 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)
904 return cropBoxImpl<pcl::PointXYZRGBNormal>(cloud,
min,
max, transform, negative);
907 template<
typename Po
intT>
909 const typename pcl::PointCloud<PointT>::Ptr & cloud,
910 const pcl::IndicesPtr & indices,
914 float nearClipPlaneDistance,
915 float farClipPlaneDistance,
918 UASSERT(horizontalFOV > 0.0
f && verticalFOV > 0.0
f);
919 UASSERT(farClipPlaneDistance > nearClipPlaneDistance);
922 pcl::IndicesPtr output(
new std::vector<int>);
923 pcl::FrustumCulling<PointT> fc;
924 fc.setNegative(negative);
925 fc.setInputCloud (cloud);
926 if(indices.get() && indices->size())
928 fc.setIndices(indices);
930 fc.setVerticalFOV (verticalFOV);
931 fc.setHorizontalFOV (horizontalFOV);
932 fc.setNearPlaneDistance (nearClipPlaneDistance);
933 fc.setFarPlaneDistance (farClipPlaneDistance);
935 fc.setCameraPose (cameraPose.
toEigen4f());
940 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)
942 return frustumFilteringImpl<pcl::PointXYZ>(cloud, indices, cameraPose, horizontalFOV, verticalFOV, nearClipPlaneDistance, farClipPlaneDistance, negative);
945 template<
typename Po
intT>
947 const typename pcl::PointCloud<PointT>::Ptr & cloud,
951 float nearClipPlaneDistance,
952 float farClipPlaneDistance,
955 UASSERT(horizontalFOV > 0.0
f && verticalFOV > 0.0
f);
956 UASSERT(farClipPlaneDistance > nearClipPlaneDistance);
959 typename pcl::PointCloud<PointT>::Ptr output(
new pcl::PointCloud<PointT>);
960 pcl::FrustumCulling<PointT> fc;
961 fc.setNegative(negative);
962 fc.setInputCloud (cloud);
963 fc.setVerticalFOV (verticalFOV);
964 fc.setHorizontalFOV (horizontalFOV);
965 fc.setNearPlaneDistance (nearClipPlaneDistance);
966 fc.setFarPlaneDistance (farClipPlaneDistance);
968 fc.setCameraPose (cameraPose.
toEigen4f());
973 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)
975 return frustumFilteringImpl<pcl::PointXYZ>(cloud, cameraPose, horizontalFOV, verticalFOV, nearClipPlaneDistance, farClipPlaneDistance, negative);
977 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)
979 return frustumFilteringImpl<pcl::PointXYZRGB>(cloud, cameraPose, horizontalFOV, verticalFOV, nearClipPlaneDistance, farClipPlaneDistance, negative);
983 template<
typename Po
intT>
985 const typename pcl::PointCloud<PointT>::Ptr & cloud)
987 typename pcl::PointCloud<PointT>::Ptr output(
new pcl::PointCloud<PointT>);
988 std::vector<int> indices;
994 return removeNaNFromPointCloudImpl<pcl::PointXYZ>(cloud);
998 return removeNaNFromPointCloudImpl<pcl::PointXYZRGB>(cloud);
1002 return removeNaNFromPointCloudImpl<pcl::PointXYZI>(cloud);
1007 pcl::PCLPointCloud2::Ptr output(
new pcl::PCLPointCloud2);
1008 output->fields = cloud->fields;
1009 output->header = cloud->header;
1011 output->point_step = cloud->point_step;
1012 output->is_dense =
true;
1013 output->data.resize(cloud->row_step*cloud->height);
1016 for(
size_t i=0; i<cloud->fields.size(); ++i)
1018 if(cloud->fields[i].name.compare(
"z") == 0)
1028 for (
size_t row = 0;
row < cloud->height; ++
row)
1031 for (
size_t col = 0; col < cloud->width; ++col)
1033 const std::uint8_t* msg_data = row_data + col * cloud->point_step;
1034 const float *
x = (
const float*)&msg_data[0];
1035 const float * y = (
const float*)&msg_data[4];
1036 const float * z = (
const float*)&msg_data[is3D?8:4];
1039 memcpy (output_data, msg_data, cloud->point_step);
1040 output_data += cloud->point_step;
1046 output->row_step = output->width*output->point_step;
1047 output->data.resize(output->row_step);
1051 template<
typename Po
intT>
1053 const typename pcl::PointCloud<PointT>::Ptr & cloud)
1055 typename pcl::PointCloud<PointT>::Ptr output(
new pcl::PointCloud<PointT>);
1056 std::vector<int> indices;
1061 const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud)
1063 return removeNaNNormalsFromPointCloudImpl<pcl::PointNormal>(cloud);
1066 const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud)
1068 return removeNaNNormalsFromPointCloudImpl<pcl::PointXYZRGBNormal>(cloud);
1071 const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud)
1073 return removeNaNNormalsFromPointCloudImpl<pcl::PointXYZINormal>(cloud);
1077 pcl::IndicesPtr
radiusFiltering(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
float radiusSearch,
int minNeighborsInRadius)
1079 pcl::IndicesPtr indices(
new std::vector<int>);
1080 return radiusFiltering(cloud, indices, radiusSearch, minNeighborsInRadius);
1082 pcl::IndicesPtr
radiusFiltering(
const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
float radiusSearch,
int minNeighborsInRadius)
1084 pcl::IndicesPtr indices(
new std::vector<int>);
1085 return radiusFiltering(cloud, indices, radiusSearch, minNeighborsInRadius);
1087 pcl::IndicesPtr
radiusFiltering(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
float radiusSearch,
int minNeighborsInRadius)
1089 pcl::IndicesPtr indices(
new std::vector<int>);
1090 return radiusFiltering(cloud, indices, radiusSearch, minNeighborsInRadius);
1092 pcl::IndicesPtr
radiusFiltering(
const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
float radiusSearch,
int minNeighborsInRadius)
1094 pcl::IndicesPtr indices(
new std::vector<int>);
1095 return radiusFiltering(cloud, indices, radiusSearch, minNeighborsInRadius);
1097 pcl::IndicesPtr
radiusFiltering(
const pcl::PointCloud<pcl::PointXYZI>::Ptr & cloud,
float radiusSearch,
int minNeighborsInRadius)
1099 pcl::IndicesPtr indices(
new std::vector<int>);
1100 return radiusFiltering(cloud, indices, radiusSearch, minNeighborsInRadius);
1102 pcl::IndicesPtr
radiusFiltering(
const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
float radiusSearch,
int minNeighborsInRadius)
1104 pcl::IndicesPtr indices(
new std::vector<int>);
1105 return radiusFiltering(cloud, indices, radiusSearch, minNeighborsInRadius);
1108 template<
typename Po
intT>
1110 const typename pcl::PointCloud<PointT>::Ptr & cloud,
1111 const pcl::IndicesPtr & indices,
1113 int minNeighborsInRadius)
1115 typename pcl::search::KdTree<PointT>::Ptr
tree (
new pcl::search::KdTree<PointT>(
false));
1119 pcl::IndicesPtr output(
new std::vector<int>(indices->size()));
1121 tree->setInputCloud(cloud, indices);
1122 for(
unsigned int i=0; i<indices->size(); ++i)
1125 std::vector<float> kDistances;
1126 int k = tree->radiusSearch(cloud->at(indices->at(i)), radiusSearch, kIndices, kDistances, minNeighborsInRadius+1);
1127 if(k > minNeighborsInRadius)
1129 output->at(oi++) = indices->at(i);
1137 pcl::IndicesPtr output(
new std::vector<int>(cloud->size()));
1139 tree->setInputCloud(cloud);
1140 for(
unsigned int i=0; i<cloud->size(); ++i)
1143 std::vector<float> kDistances;
1144 int k = tree->radiusSearch(cloud->at(i), radiusSearch,
kIndices, kDistances, minNeighborsInRadius+1);
1145 if(k > minNeighborsInRadius)
1147 output->at(oi++) = i;
1155 pcl::IndicesPtr
radiusFiltering(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
const pcl::IndicesPtr & indices,
float radiusSearch,
int minNeighborsInRadius)
1157 return radiusFilteringImpl<pcl::PointXYZ>(cloud, indices, radiusSearch, minNeighborsInRadius);
1159 pcl::IndicesPtr
radiusFiltering(
const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
float radiusSearch,
int minNeighborsInRadius)
1161 return radiusFilteringImpl<pcl::PointNormal>(cloud, indices, radiusSearch, minNeighborsInRadius);
1163 pcl::IndicesPtr
radiusFiltering(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
const pcl::IndicesPtr & indices,
float radiusSearch,
int minNeighborsInRadius)
1165 return radiusFilteringImpl<pcl::PointXYZRGB>(cloud, indices, radiusSearch, minNeighborsInRadius);
1167 pcl::IndicesPtr
radiusFiltering(
const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
float radiusSearch,
int minNeighborsInRadius)
1169 return radiusFilteringImpl<pcl::PointXYZRGBNormal>(cloud, indices, radiusSearch, minNeighborsInRadius);
1171 pcl::IndicesPtr
radiusFiltering(
const pcl::PointCloud<pcl::PointXYZI>::Ptr & cloud,
const pcl::IndicesPtr & indices,
float radiusSearch,
int minNeighborsInRadius)
1173 return radiusFilteringImpl<pcl::PointXYZI>(cloud, indices, radiusSearch, minNeighborsInRadius);
1175 pcl::IndicesPtr
radiusFiltering(
const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
float radiusSearch,
int minNeighborsInRadius)
1177 return radiusFilteringImpl<pcl::PointXYZINormal>(cloud, indices, radiusSearch, minNeighborsInRadius);
1181 const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
1182 const std::vector<int> & viewpointIndices,
1183 const std::map<int, Transform> & viewpoints,
1185 float neighborScale)
1187 pcl::IndicesPtr indices(
new std::vector<int>);
1191 const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
1192 const std::vector<int> & viewpointIndices,
1193 const std::map<int, Transform> & viewpoints,
1195 float neighborScale)
1197 pcl::IndicesPtr indices(
new std::vector<int>);
1201 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
1202 const std::vector<int> & viewpointIndices,
1203 const std::map<int, Transform> & viewpoints,
1205 float neighborScale)
1207 pcl::IndicesPtr indices(
new std::vector<int>);
1211 const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
1212 const std::vector<int> & viewpointIndices,
1213 const std::map<int, Transform> & viewpoints,
1215 float neighborScale)
1217 pcl::IndicesPtr indices(
new std::vector<int>);
1221 const pcl::PointCloud<pcl::PointXYZI>::Ptr & cloud,
1222 const std::vector<int> & viewpointIndices,
1223 const std::map<int, Transform> & viewpoints,
1225 float neighborScale)
1227 pcl::IndicesPtr indices(
new std::vector<int>);
1231 const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
1232 const std::vector<int> & viewpointIndices,
1233 const std::map<int, Transform> & viewpoints,
1235 float neighborScale)
1237 pcl::IndicesPtr indices(
new std::vector<int>);
1241 template<
typename Po
intT>
1243 const typename pcl::PointCloud<PointT>::Ptr & cloud,
1244 const pcl::IndicesPtr & indices,
1245 const std::vector<int> & viewpointIndices,
1246 const std::map<int, Transform> & viewpoints,
1248 float neighborScale)
1250 typename pcl::search::KdTree<PointT>::Ptr
tree (
new pcl::search::KdTree<PointT>(
false));
1252 UASSERT(cloud->size() == viewpointIndices.size());
1256 if(!indices->empty())
1258 std::vector<bool> kept(indices->size());
1259 tree->setInputCloud(cloud, indices);
1260 for(
size_t i=0; i<indices->size(); ++i)
1262 int index = indices->at(i);
1264 std::vector<float> kDistances;
1265 std::map<int, Transform>::const_iterator viewpointIter = viewpoints.find(viewpointIndices[index]);
1266 UASSERT(viewpointIter != viewpoints.end());
1267 cv::Point3f viewpoint(viewpointIter->second.x(), viewpointIter->second.y(), viewpointIter->second.z());
1268 cv::Point3f point = cv::Point3f(cloud->at(index).x,cloud->at(index).y, cloud->at(index).z);
1269 float radiusSearch = factor * cv::norm(viewpoint-point);
1270 int k = tree->radiusSearch(cloud->at(index), radiusSearch,
kIndices, kDistances);
1272 for(
int j=0; j<k && keep; ++j)
1274 if(kIndices[j] != index)
1276 cv::Point3f pointTmp(cloud->at(kIndices[j]).x,cloud->at(kIndices[j]).y, cloud->at(kIndices[j]).z);
1277 cv::Point3f tmp = pointTmp - point;
1278 float distPtSqr = tmp.dot(tmp);
1279 viewpointIter = viewpoints.find(viewpointIndices[kIndices[j]]);
1280 UASSERT(viewpointIter != viewpoints.end());
1281 viewpoint = cv::Point3f(viewpointIter->second.x(), viewpointIter->second.y(), viewpointIter->second.z());
1282 float radiusSearchTmp = factor * cv::norm(viewpoint-pointTmp) * neighborScale;
1283 if(distPtSqr > radiusSearchTmp*radiusSearchTmp)
1291 pcl::IndicesPtr output(
new std::vector<int>(indices->size()));
1293 for(
size_t i=0; i<indices->size(); ++i)
1297 output->at(oi++) = indices->at(i);
1305 std::vector<bool> kept(cloud->size());
1306 tree->setInputCloud(cloud);
1307 #pragma omp parallel for 1308 for(
int i=0; i<(int)cloud->size(); ++i)
1311 std::vector<float> kDistances;
1312 std::map<int, Transform>::const_iterator viewpointIter = viewpoints.find(viewpointIndices[i]);
1313 UASSERT(viewpointIter != viewpoints.end());
1314 cv::Point3f viewpoint(viewpointIter->second.x(), viewpointIter->second.y(), viewpointIter->second.z());
1315 cv::Point3f point = cv::Point3f(cloud->at(i).x,cloud->at(i).y, cloud->at(i).z);
1316 float radiusSearch = factor * cv::norm(viewpoint-point);
1317 int k = tree->radiusSearch(cloud->at(i), radiusSearch,
kIndices, kDistances);
1319 for(
int j=0; j<k && keep; ++j)
1321 if(kIndices[j] != (
int)i)
1323 cv::Point3f pointTmp(cloud->at(kIndices[j]).x,cloud->at(kIndices[j]).y, cloud->at(kIndices[j]).z);
1324 cv::Point3f tmp = pointTmp - point;
1325 float distPtSqr = tmp.dot(tmp);
1326 viewpointIter = viewpoints.find(viewpointIndices[kIndices[j]]);
1327 UASSERT(viewpointIter != viewpoints.end());
1328 viewpoint = cv::Point3f(viewpointIter->second.x(), viewpointIter->second.y(), viewpointIter->second.z());
1329 float radiusSearchTmp = factor * cv::norm(viewpoint-pointTmp) * neighborScale;
1330 if(distPtSqr > radiusSearchTmp*radiusSearchTmp)
1338 pcl::IndicesPtr output(
new std::vector<int>(cloud->size()));
1340 for(
size_t i=0; i<cloud->size(); ++i)
1344 output->at(oi++) = i;
1353 const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
1354 const pcl::IndicesPtr & indices,
1355 const std::vector<int> & viewpointIndices,
1356 const std::map<int, Transform> & viewpoints,
1358 float neighborScale)
1360 return proportionalRadiusFilteringImpl<pcl::PointXYZ>(cloud, indices, viewpointIndices, viewpoints, factor, neighborScale);
1363 const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
1364 const pcl::IndicesPtr & indices,
1365 const std::vector<int> & viewpointIndices,
1366 const std::map<int, Transform> & viewpoints,
1368 float neighborScale)
1370 return proportionalRadiusFilteringImpl<pcl::PointNormal>(cloud, indices, viewpointIndices, viewpoints, factor, neighborScale);
1373 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
1374 const pcl::IndicesPtr & indices,
1375 const std::vector<int> & viewpointIndices,
1376 const std::map<int, Transform> & viewpoints,
1378 float neighborScale)
1380 return proportionalRadiusFilteringImpl<pcl::PointXYZRGB>(cloud, indices, viewpointIndices, viewpoints, factor, neighborScale);
1383 const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
1384 const pcl::IndicesPtr & indices,
1385 const std::vector<int> & viewpointIndices,
1386 const std::map<int, Transform> & viewpoints,
1388 float neighborScale)
1390 return proportionalRadiusFilteringImpl<pcl::PointXYZRGBNormal>(cloud, indices, viewpointIndices, viewpoints, factor, neighborScale);
1393 const pcl::PointCloud<pcl::PointXYZI>::Ptr & cloud,
1394 const pcl::IndicesPtr & indices,
1395 const std::vector<int> & viewpointIndices,
1396 const std::map<int, Transform> & viewpoints,
1398 float neighborScale)
1400 return proportionalRadiusFilteringImpl<pcl::PointXYZI>(cloud, indices, viewpointIndices, viewpoints, factor, neighborScale);
1403 const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
1404 const pcl::IndicesPtr & indices,
1405 const std::vector<int> & viewpointIndices,
1406 const std::map<int, Transform> & viewpoints,
1408 float neighborScale)
1410 return proportionalRadiusFilteringImpl<pcl::PointXYZINormal>(cloud, indices, viewpointIndices, viewpoints, factor, neighborScale);
1414 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
1415 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & substractCloud,
1417 int minNeighborsInRadius)
1419 pcl::IndicesPtr indices(
new std::vector<int>);
1420 pcl::IndicesPtr indicesOut =
subtractFiltering(cloud, indices, substractCloud, indices, radiusSearch, minNeighborsInRadius);
1421 pcl::PointCloud<pcl::PointXYZRGB>::Ptr out(
new pcl::PointCloud<pcl::PointXYZRGB>);
1422 pcl::copyPointCloud(*cloud, *indicesOut, *out);
1426 template<
typename Po
intT>
1428 const typename pcl::PointCloud<PointT>::Ptr & cloud,
1429 const pcl::IndicesPtr & indices,
1430 const typename pcl::PointCloud<PointT>::Ptr & substractCloud,
1431 const pcl::IndicesPtr & substractIndices,
1433 int minNeighborsInRadius)
1435 UASSERT(minNeighborsInRadius > 0);
1436 typename pcl::search::KdTree<PointT>::Ptr
tree (
new pcl::search::KdTree<PointT>(
false));
1440 pcl::IndicesPtr output(
new std::vector<int>(indices->size()));
1442 if(substractIndices->size())
1444 tree->setInputCloud(substractCloud, substractIndices);
1448 tree->setInputCloud(substractCloud);
1450 for(
unsigned int i=0; i<indices->size(); ++i)
1453 std::vector<float> kDistances;
1454 int k = tree->radiusSearch(cloud->at(indices->at(i)), radiusSearch, kIndices, kDistances);
1455 if(k < minNeighborsInRadius)
1457 output->at(oi++) = indices->at(i);
1465 pcl::IndicesPtr output(
new std::vector<int>(cloud->size()));
1467 if(substractIndices->size())
1469 tree->setInputCloud(substractCloud, substractIndices);
1473 tree->setInputCloud(substractCloud);
1475 for(
unsigned int i=0; i<cloud->size(); ++i)
1478 std::vector<float> kDistances;
1479 int k = tree->radiusSearch(cloud->at(i), radiusSearch,
kIndices, kDistances);
1480 if(k < minNeighborsInRadius)
1482 output->at(oi++) = i;
1490 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
1491 const pcl::IndicesPtr & indices,
1492 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & substractCloud,
1493 const pcl::IndicesPtr & substractIndices,
1495 int minNeighborsInRadius)
1497 return subtractFilteringImpl<pcl::PointXYZRGB>(cloud, indices, substractCloud, substractIndices, radiusSearch, minNeighborsInRadius);
1501 const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
1502 const pcl::PointCloud<pcl::PointNormal>::Ptr & substractCloud,
1505 int minNeighborsInRadius)
1507 pcl::IndicesPtr indices(
new std::vector<int>);
1508 pcl::IndicesPtr indicesOut =
subtractFiltering(cloud, indices, substractCloud, indices, radiusSearch, maxAngle, minNeighborsInRadius);
1509 pcl::PointCloud<pcl::PointNormal>::Ptr out(
new pcl::PointCloud<pcl::PointNormal>);
1510 pcl::copyPointCloud(*cloud, *indicesOut, *out);
1514 const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
1515 const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & substractCloud,
1518 int minNeighborsInRadius)
1520 pcl::IndicesPtr indices(
new std::vector<int>);
1521 pcl::IndicesPtr indicesOut =
subtractFiltering(cloud, indices, substractCloud, indices, radiusSearch, maxAngle, minNeighborsInRadius);
1522 pcl::PointCloud<pcl::PointXYZINormal>::Ptr out(
new pcl::PointCloud<pcl::PointXYZINormal>);
1523 pcl::copyPointCloud(*cloud, *indicesOut, *out);
1527 const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
1528 const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & substractCloud,
1531 int minNeighborsInRadius)
1533 pcl::IndicesPtr indices(
new std::vector<int>);
1534 pcl::IndicesPtr indicesOut =
subtractFiltering(cloud, indices, substractCloud, indices, radiusSearch, maxAngle, minNeighborsInRadius);
1535 pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr out(
new pcl::PointCloud<pcl::PointXYZRGBNormal>);
1536 pcl::copyPointCloud(*cloud, *indicesOut, *out);
1540 template<
typename Po
intT>
1542 const typename pcl::PointCloud<PointT>::Ptr & cloud,
1543 const pcl::IndicesPtr & indices,
1544 const typename pcl::PointCloud<PointT>::Ptr & substractCloud,
1545 const pcl::IndicesPtr & substractIndices,
1548 int minNeighborsInRadius)
1550 UASSERT(minNeighborsInRadius > 0);
1551 typename pcl::search::KdTree<PointT>::Ptr
tree (
new pcl::search::KdTree<PointT>(
false));
1555 pcl::IndicesPtr output(
new std::vector<int>(indices->size()));
1557 if(substractIndices->size())
1559 tree->setInputCloud(substractCloud, substractIndices);
1563 tree->setInputCloud(substractCloud);
1565 for(
unsigned int i=0; i<indices->size(); ++i)
1568 std::vector<float> kDistances;
1569 int k = tree->radiusSearch(cloud->at(indices->at(i)), radiusSearch, kIndices, kDistances);
1570 if(k>=minNeighborsInRadius && maxAngle > 0.0
f)
1572 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);
1578 for(
int j=0; j<count && k >= minNeighborsInRadius; ++j)
1580 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);
1585 float angle = pcl::getAngle3D(normal, v);
1586 if(angle > maxAngle)
1602 if(k < minNeighborsInRadius)
1604 output->at(oi++) = indices->at(i);
1612 pcl::IndicesPtr output(
new std::vector<int>(cloud->size()));
1614 if(substractIndices->size())
1616 tree->setInputCloud(substractCloud, substractIndices);
1620 tree->setInputCloud(substractCloud);
1622 for(
unsigned int i=0; i<cloud->size(); ++i)
1625 std::vector<float> kDistances;
1626 int k = tree->radiusSearch(cloud->at(i), radiusSearch,
kIndices, kDistances);
1627 if(k>=minNeighborsInRadius && maxAngle > 0.0
f)
1629 Eigen::Vector4f normal(cloud->at(i).normal_x, cloud->at(i).normal_y, cloud->at(i).normal_z, 0.0f);
1635 for(
int j=0; j<count && k >= minNeighborsInRadius; ++j)
1637 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);
1642 float angle = pcl::getAngle3D(normal, v);
1643 if(angle > maxAngle)
1659 if(k < minNeighborsInRadius)
1661 output->at(oi++) = i;
1670 const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
1671 const pcl::IndicesPtr & indices,
1672 const pcl::PointCloud<pcl::PointNormal>::Ptr & substractCloud,
1673 const pcl::IndicesPtr & substractIndices,
1676 int minNeighborsInRadius)
1678 return subtractFilteringImpl<pcl::PointNormal>(cloud, indices, substractCloud, substractIndices, radiusSearch, maxAngle, minNeighborsInRadius);
1681 const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
1682 const pcl::IndicesPtr & indices,
1683 const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & substractCloud,
1684 const pcl::IndicesPtr & substractIndices,
1687 int minNeighborsInRadius)
1689 return subtractFilteringImpl<pcl::PointXYZINormal>(cloud, indices, substractCloud, substractIndices, radiusSearch, maxAngle, minNeighborsInRadius);
1692 const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
1693 const pcl::IndicesPtr & indices,
1694 const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & substractCloud,
1695 const pcl::IndicesPtr & substractIndices,
1698 int minNeighborsInRadius)
1700 return subtractFilteringImpl<pcl::PointXYZRGBNormal>(cloud, indices, substractCloud, substractIndices, radiusSearch, maxAngle, minNeighborsInRadius);
1704 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
1705 const pcl::IndicesPtr & indices,
1706 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & substractCloud,
1707 const pcl::IndicesPtr & substractIndices,
1708 float radiusSearchRatio,
1709 int minNeighborsInRadius,
1710 const Eigen::Vector3f & viewpoint)
1712 UWARN(
"Add angle to avoid subtraction of points with opposite normals");
1713 UASSERT(minNeighborsInRadius > 0);
1715 pcl::search::KdTree<pcl::PointXYZRGB>::Ptr
tree (
new pcl::search::KdTree<pcl::PointXYZRGB>(
false));
1719 pcl::IndicesPtr output(
new std::vector<int>(indices->size()));
1721 if(substractIndices->size())
1723 tree->setInputCloud(substractCloud, substractIndices);
1727 tree->setInputCloud(substractCloud);
1729 for(
unsigned int i=0; i<indices->size(); ++i)
1734 std::vector<float> kSqrdDistances;
1735 float radius = radiusSearchRatio*
uNorm(
1736 cloud->at(indices->at(i)).
x-viewpoint[0],
1737 cloud->at(indices->at(i)).y-viewpoint[1],
1738 cloud->at(indices->at(i)).z-viewpoint[2]);
1739 int k = tree->radiusSearch(cloud->at(indices->at(i)), radius, kIndices, kSqrdDistances);
1740 if(k < minNeighborsInRadius)
1742 output->at(oi++) = indices->at(i);
1751 pcl::IndicesPtr output(
new std::vector<int>(cloud->size()));
1753 if(substractIndices->size())
1755 tree->setInputCloud(substractCloud, substractIndices);
1759 tree->setInputCloud(substractCloud);
1761 for(
unsigned int i=0; i<cloud->size(); ++i)
1766 std::vector<float> kSqrdDistances;
1767 float radius = radiusSearchRatio*
uNorm(
1768 cloud->at(i).x-viewpoint[0],
1769 cloud->at(i).y-viewpoint[1],
1770 cloud->at(i).z-viewpoint[2]);
1771 int k = tree->radiusSearch(cloud->at(i), radius,
kIndices, kSqrdDistances);
1772 if(k < minNeighborsInRadius)
1774 output->at(oi++) = i;
1783 const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
1784 const pcl::IndicesPtr & indices,
1785 const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & substractCloud,
1786 const pcl::IndicesPtr & substractIndices,
1787 float radiusSearchRatio,
1789 int minNeighborsInRadius,
1790 const Eigen::Vector3f & viewpoint)
1792 UASSERT(minNeighborsInRadius > 0);
1794 pcl::search::KdTree<pcl::PointXYZRGBNormal>::Ptr
tree (
new pcl::search::KdTree<pcl::PointXYZRGBNormal>(
false));
1798 pcl::IndicesPtr output(
new std::vector<int>(indices->size()));
1800 if(substractIndices->size())
1802 tree->setInputCloud(substractCloud, substractIndices);
1806 tree->setInputCloud(substractCloud);
1808 for(
unsigned int i=0; i<indices->size(); ++i)
1813 std::vector<float> kSqrdDistances;
1814 float radius = radiusSearchRatio*
uNorm(
1815 cloud->at(indices->at(i)).
x-viewpoint[0],
1816 cloud->at(indices->at(i)).y-viewpoint[1],
1817 cloud->at(indices->at(i)).z-viewpoint[2]);
1818 int k = tree->radiusSearch(cloud->at(indices->at(i)), radius, kIndices, kSqrdDistances);
1819 if(k>=minNeighborsInRadius && maxAngle > 0.0
f)
1821 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);
1827 for(
int j=0; j<count && k >= minNeighborsInRadius; ++j)
1829 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);
1834 float angle = pcl::getAngle3D(normal, v);
1835 if(angle > maxAngle)
1852 if(k < minNeighborsInRadius)
1854 output->at(oi++) = indices->at(i);
1863 pcl::IndicesPtr output(
new std::vector<int>(cloud->size()));
1865 if(substractIndices->size())
1867 tree->setInputCloud(substractCloud, substractIndices);
1871 tree->setInputCloud(substractCloud);
1873 for(
unsigned int i=0; i<cloud->size(); ++i)
1878 std::vector<float> kSqrdDistances;
1879 float radius = radiusSearchRatio*
uNorm(
1880 cloud->at(i).x-viewpoint[0],
1881 cloud->at(i).y-viewpoint[1],
1882 cloud->at(i).z-viewpoint[2]);
1883 int k = tree->radiusSearch(cloud->at(i), radius,
kIndices, kSqrdDistances);
1884 if(k>=minNeighborsInRadius && maxAngle > 0.0
f)
1886 Eigen::Vector4f normal(cloud->at(i).normal_x, cloud->at(i).normal_y, cloud->at(i).normal_z, 0.0f);
1892 for(
int j=0; j<count && k >= minNeighborsInRadius; ++j)
1894 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);
1899 float angle = pcl::getAngle3D(normal, v);
1900 if(angle > maxAngle)
1916 if(k < minNeighborsInRadius)
1918 output->at(oi++) = i;
1929 const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
1931 const Eigen::Vector4f & normal,
1933 const Eigen::Vector4f & viewpoint,
1934 float groundNormalsUp)
1936 pcl::IndicesPtr indices(
new std::vector<int>);
1937 return normalFiltering(cloud, indices, angleMax, normal, normalKSearch, viewpoint, groundNormalsUp);
1940 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
1942 const Eigen::Vector4f & normal,
1944 const Eigen::Vector4f & viewpoint,
1945 float groundNormalsUp)
1947 pcl::IndicesPtr indices(
new std::vector<int>);
1948 return normalFiltering(cloud, indices, angleMax, normal, normalKSearch, viewpoint, groundNormalsUp);
1952 template<
typename Po
intT>
1954 const typename pcl::PointCloud<PointT>::Ptr & cloud,
1955 const pcl::IndicesPtr & indices,
1957 const Eigen::Vector4f & normal,
1959 const Eigen::Vector4f & viewpoint,
1960 float groundNormalsUp)
1962 pcl::IndicesPtr output(
new std::vector<int>());
1966 typename pcl::search::KdTree<PointT>::Ptr
tree(
new pcl::search::KdTree<PointT>(
false));
1968 pcl::NormalEstimationOMP<PointT, pcl::Normal> ne;
1969 ne.setInputCloud (cloud);
1972 ne.setIndices(indices);
1977 tree->setInputCloud(cloud, indices);
1981 tree->setInputCloud(cloud);
1983 ne.setSearchMethod (tree);
1985 pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (
new pcl::PointCloud<pcl::Normal>);
1987 ne.setKSearch(normalKSearch);
1988 if(viewpoint[0] != 0 || viewpoint[1] != 0 || viewpoint[2] != 0)
1990 ne.setViewPoint(viewpoint[0], viewpoint[1], viewpoint[2]);
1993 ne.compute (*cloud_normals);
1995 output->resize(cloud_normals->size());
1997 for(
unsigned int i=0; i<cloud_normals->size(); ++i)
1999 Eigen::Vector4f v(cloud_normals->at(i).normal_x, cloud_normals->at(i).normal_y, cloud_normals->at(i).normal_z, 0.0f);
2000 if(groundNormalsUp>0.0
f && v[2] < -groundNormalsUp && cloud->at(indices->size()!=0?indices->at(i):i).z < viewpoint[3])
2006 float angle = pcl::getAngle3D(normal, v);
2007 if(angle < angleMax)
2009 output->at(oi++) = indices->size()!=0?indices->at(i):i;
2018 const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
2019 const pcl::IndicesPtr & indices,
2021 const Eigen::Vector4f & normal,
2023 const Eigen::Vector4f & viewpoint,
2024 float groundNormalsUp)
2026 return normalFilteringImpl<pcl::PointXYZ>(cloud, indices, angleMax, normal, normalKSearch, viewpoint, groundNormalsUp);
2029 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
2030 const pcl::IndicesPtr & indices,
2032 const Eigen::Vector4f & normal,
2034 const Eigen::Vector4f & viewpoint,
2035 float groundNormalsUp)
2037 return normalFilteringImpl<pcl::PointXYZRGB>(cloud, indices, angleMax, normal, normalKSearch, viewpoint, groundNormalsUp);
2040 const pcl::PointCloud<pcl::PointXYZI>::Ptr & cloud,
2041 const pcl::IndicesPtr & indices,
2043 const Eigen::Vector4f & normal,
2045 const Eigen::Vector4f & viewpoint,
2046 float groundNormalsUp)
2048 return normalFilteringImpl<pcl::PointXYZI>(cloud, indices, angleMax, normal, normalKSearch, viewpoint, groundNormalsUp);
2051 template<
typename Po
intNormalT>
2053 const typename pcl::PointCloud<PointNormalT>::Ptr & cloud,
2054 const pcl::IndicesPtr & indices,
2056 const Eigen::Vector4f & normal,
2057 const Eigen::Vector4f & viewpoint,
2058 float groundNormalsUp)
2060 pcl::IndicesPtr output(
new std::vector<int>());
2067 output->resize(indices->size());
2068 for(
unsigned int i=0; i<indices->size(); ++i)
2070 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);
2071 if(groundNormalsUp>0.0
f && v[2] < -groundNormalsUp && cloud->at(indices->at(i)).z < viewpoint[3])
2076 float angle = pcl::getAngle3D(normal, v);
2077 if(angle < angleMax)
2079 output->at(oi++) = indices->size()!=0?indices->at(i):i;
2085 output->resize(cloud->size());
2086 for(
unsigned int i=0; i<cloud->size(); ++i)
2088 Eigen::Vector4f v(cloud->at(i).normal_x, cloud->at(i).normal_y, cloud->at(i).normal_z, 0.0f);
2089 if(groundNormalsUp>0.0
f && v[2] < -groundNormalsUp && cloud->at(i).z < viewpoint[3])
2094 float angle = pcl::getAngle3D(normal, v);
2095 if(angle < angleMax)
2097 output->at(oi++) = indices->size()!=0?indices->at(i):i;
2108 const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
2109 const pcl::IndicesPtr & indices,
2111 const Eigen::Vector4f & normal,
2113 const Eigen::Vector4f & viewpoint,
2114 float groundNormalsUp)
2116 return normalFilteringImpl<pcl::PointNormal>(cloud, indices, angleMax, normal, viewpoint, groundNormalsUp);
2119 const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
2120 const pcl::IndicesPtr & indices,
2122 const Eigen::Vector4f & normal,
2124 const Eigen::Vector4f & viewpoint,
2125 float groundNormalsUp)
2127 return normalFilteringImpl<pcl::PointXYZRGBNormal>(cloud, indices, angleMax, normal, viewpoint, groundNormalsUp);
2130 const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
2131 const pcl::IndicesPtr & indices,
2133 const Eigen::Vector4f & normal,
2135 const Eigen::Vector4f & viewpoint,
2136 float groundNormalsUp)
2138 return normalFilteringImpl<pcl::PointXYZINormal>(cloud, indices, angleMax, normal, viewpoint, groundNormalsUp);
2142 const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
2143 float clusterTolerance,
2146 int * biggestClusterIndex)
2148 pcl::IndicesPtr indices(
new std::vector<int>);
2149 return extractClusters(cloud, indices, clusterTolerance, minClusterSize, maxClusterSize, biggestClusterIndex);
2152 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
2153 float clusterTolerance,
2156 int * biggestClusterIndex)
2158 pcl::IndicesPtr indices(
new std::vector<int>);
2159 return extractClusters(cloud, indices, clusterTolerance, minClusterSize, maxClusterSize, biggestClusterIndex);
2162 template<
typename Po
intT>
2164 const typename pcl::PointCloud<PointT>::Ptr & cloud,
2165 const pcl::IndicesPtr & indices,
2166 float clusterTolerance,
2169 int * biggestClusterIndex)
2171 typename pcl::search::KdTree<PointT>::Ptr
tree (
new pcl::search::KdTree<PointT>(
true));
2172 pcl::EuclideanClusterExtraction<PointT> ec;
2173 ec.setClusterTolerance (clusterTolerance);
2174 ec.setMinClusterSize (minClusterSize);
2175 ec.setMaxClusterSize (maxClusterSize);
2176 ec.setInputCloud (cloud);
2180 ec.setIndices(indices);
2181 tree->setInputCloud(cloud, indices);
2185 tree->setInputCloud(cloud);
2187 ec.setSearchMethod (tree);
2189 std::vector<pcl::PointIndices> cluster_indices;
2190 ec.extract (cluster_indices);
2193 unsigned int maxSize = 0;
2194 std::vector<pcl::IndicesPtr> output(cluster_indices.size());
2195 for(
unsigned int i=0; i<cluster_indices.size(); ++i)
2197 output[i] = pcl::IndicesPtr(
new std::vector<int>(cluster_indices[i].indices));
2199 if(maxSize < cluster_indices[i].indices.size())
2201 maxSize = (
unsigned int)cluster_indices[i].indices.size();
2205 if(biggestClusterIndex)
2207 *biggestClusterIndex = maxIndex;
2214 const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
2215 const pcl::IndicesPtr & indices,
2216 float clusterTolerance,
2219 int * biggestClusterIndex)
2221 return extractClustersImpl<pcl::PointXYZ>(cloud, indices, clusterTolerance, minClusterSize, maxClusterSize, biggestClusterIndex);
2224 const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
2225 const pcl::IndicesPtr & indices,
2226 float clusterTolerance,
2229 int * biggestClusterIndex)
2231 return extractClustersImpl<pcl::PointNormal>(cloud, indices, clusterTolerance, minClusterSize, maxClusterSize, biggestClusterIndex);
2234 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
2235 const pcl::IndicesPtr & indices,
2236 float clusterTolerance,
2239 int * biggestClusterIndex)
2241 return extractClustersImpl<pcl::PointXYZRGB>(cloud, indices, clusterTolerance, minClusterSize, maxClusterSize, biggestClusterIndex);
2244 const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
2245 const pcl::IndicesPtr & indices,
2246 float clusterTolerance,
2249 int * biggestClusterIndex)
2251 return extractClustersImpl<pcl::PointXYZRGBNormal>(cloud, indices, clusterTolerance, minClusterSize, maxClusterSize, biggestClusterIndex);
2254 const pcl::PointCloud<pcl::PointXYZI>::Ptr & cloud,
2255 const pcl::IndicesPtr & indices,
2256 float clusterTolerance,
2259 int * biggestClusterIndex)
2261 return extractClustersImpl<pcl::PointXYZI>(cloud, indices, clusterTolerance, minClusterSize, maxClusterSize, biggestClusterIndex);
2264 const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
2265 const pcl::IndicesPtr & indices,
2266 float clusterTolerance,
2269 int * biggestClusterIndex)
2271 return extractClustersImpl<pcl::PointXYZINormal>(cloud, indices, clusterTolerance, minClusterSize, maxClusterSize, biggestClusterIndex);
2274 template<
typename Po
intT>
2276 const typename pcl::PointCloud<PointT>::Ptr & cloud,
2277 const pcl::IndicesPtr & indices,
2280 pcl::IndicesPtr output(
new std::vector<int>);
2281 pcl::ExtractIndices<PointT> extract;
2282 extract.setInputCloud (cloud);
2283 extract.setIndices(indices);
2284 extract.setNegative(negative);
2285 extract.filter(*output);
2289 pcl::IndicesPtr
extractIndices(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
const pcl::IndicesPtr & indices,
bool negative)
2291 return extractIndicesImpl<pcl::PointXYZ>(cloud, indices, negative);
2293 pcl::IndicesPtr
extractIndices(
const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
bool negative)
2295 return extractIndicesImpl<pcl::PointNormal>(cloud, indices, negative);
2297 pcl::IndicesPtr
extractIndices(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
const pcl::IndicesPtr & indices,
bool negative)
2299 return extractIndicesImpl<pcl::PointXYZRGB>(cloud, indices, negative);
2301 pcl::IndicesPtr
extractIndices(
const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
bool negative)
2303 return extractIndicesImpl<pcl::PointXYZRGBNormal>(cloud, indices, negative);
2305 pcl::IndicesPtr
extractIndices(
const pcl::PointCloud<pcl::PointXYZI>::Ptr & cloud,
const pcl::IndicesPtr & indices,
bool negative)
2307 return extractIndicesImpl<pcl::PointXYZI>(cloud, indices, negative);
2309 pcl::IndicesPtr
extractIndices(
const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
bool negative)
2311 return extractIndicesImpl<pcl::PointXYZINormal>(cloud, indices, negative);
2314 template<
typename Po
intT>
2316 const typename pcl::PointCloud<PointT>::Ptr & cloud,
2317 const pcl::IndicesPtr & indices,
2321 typename pcl::PointCloud<PointT>::Ptr output(
new pcl::PointCloud<PointT>);
2322 pcl::ExtractIndices<PointT> extract;
2323 extract.setInputCloud (cloud);
2324 extract.setIndices(indices);
2325 extract.setNegative(negative);
2326 extract.setKeepOrganized(keepOrganized);
2327 extract.filter(*output);
2330 pcl::PointCloud<pcl::PointXYZ>::Ptr
extractIndices(
const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
const pcl::IndicesPtr & indices,
bool negative,
bool keepOrganized)
2332 return extractIndicesImpl<pcl::PointXYZ>(cloud, indices, negative, keepOrganized);
2334 pcl::PointCloud<pcl::PointXYZRGB>::Ptr
extractIndices(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
const pcl::IndicesPtr & indices,
bool negative,
bool keepOrganized)
2336 return extractIndicesImpl<pcl::PointXYZRGB>(cloud, indices, negative, keepOrganized);
2343 pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr
extractIndices(
const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
const pcl::IndicesPtr & indices,
bool negative,
bool keepOrganized)
2345 return extractIndicesImpl<pcl::PointXYZRGBNormal>(cloud, indices, negative, keepOrganized);
2349 const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
2350 float distanceThreshold,
2352 pcl::ModelCoefficients * coefficientsOut)
2354 pcl::IndicesPtr indices(
new std::vector<int>);
2355 return extractPlane(cloud, indices, distanceThreshold, maxIterations, coefficientsOut);
2359 const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
2360 const pcl::IndicesPtr & indices,
2361 float distanceThreshold,
2363 pcl::ModelCoefficients * coefficientsOut)
2366 pcl::ModelCoefficients::Ptr coefficients (
new pcl::ModelCoefficients);
2367 pcl::PointIndices::Ptr inliers (
new pcl::PointIndices);
2369 pcl::SACSegmentation<pcl::PointXYZ> seg;
2371 seg.setOptimizeCoefficients (
true);
2372 seg.setMaxIterations (maxIterations);
2374 seg.setModelType (pcl::SACMODEL_PLANE);
2375 seg.setMethodType (pcl::SAC_RANSAC);
2376 seg.setDistanceThreshold (distanceThreshold);
2378 seg.setInputCloud (cloud);
2381 seg.setIndices(indices);
2383 seg.segment (*inliers, *coefficients);
2387 *coefficientsOut = *coefficients;
2390 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)
pcl::IndicesPtr proportionalRadiusFilteringImpl(const typename pcl::PointCloud< PointT >::Ptr &cloud, const pcl::IndicesPtr &indices, const std::vector< int > &viewpointIndices, const std::map< int, Transform > &viewpoints, float factor, float neighborScale)
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)
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 normalFilteringImpl(const typename pcl::PointCloud< PointT >::Ptr &cloud, const pcl::IndicesPtr &indices, float angleMax, const Eigen::Vector4f &normal, int normalKSearch, const Eigen::Vector4f &viewpoint, float groundNormalsUp)
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)
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)
const cv::Mat & data() const
GLM_FUNC_DECL genType::row_type row(genType const &m, length_t const &index)
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::IndicesPtr RTABMAP_EXP normalFiltering(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, float angleMax, const Eigen::Vector4f &normal, int normalKSearch, const Eigen::Vector4f &viewpoint, float groundNormalsUp=0.0f)
LaserScan RTABMAP_EXP downsample(const LaserScan &cloud, int step)
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)
LaserScan laserScanFromPointCloud(const PointCloud2T &cloud, bool filterNaNs, bool is2D, const Transform &transform)
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 proportionalRadiusFiltering(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, const std::vector< int > &viewpointIndices, const std::map< int, Transform > &viewpoints, float factor=0.01f, float neighborScale=2.0f)
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)
bool hasIntensity() const
pcl::PointCloud< pcl::PointNormal >::Ptr RTABMAP_EXP removeNaNNormalsFromPointCloud(const pcl::PointCloud< pcl::PointNormal >::Ptr &cloud)
pcl::PointCloud< PointT >::Ptr voxelizeImpl(const typename pcl::PointCloud< PointT >::Ptr &cloud, const pcl::IndicesPtr &indices, float voxelSize, int level=0)
float angleIncrement() const
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)
Transform localTransform() const
LaserScan RTABMAP_EXP laserScan2dFromPointCloud(const pcl::PointCloud< pcl::PointXYZ > &cloud, const Transform &transform=Transform(), bool filterNaNs=true)
LaserScan RTABMAP_EXP adjustNormalsToViewPoint(const LaserScan &scan, const Eigen::Vector3f &viewpoint=Eigen::Vector3f(0, 0, 0), float groundNormalsUp=0.0f)