44#include <pcl/common/io.h>
45#include <pcl/common/point_tests.h>
46#include <pcl/filters/local_maximum.h>
47#include <pcl/filters/project_inliers.h>
48#include <pcl/ModelCoefficients.h>
49#include <pcl/search/organized.h>
50#include <pcl/search/kdtree.h>
53template <
typename Po
intT>
void
59 PCL_WARN (
"[pcl::%s::applyFilter] No input dataset given!\n",
getClassName ().c_str ());
60 output.width = output.height = 0;
67 output.is_dense =
true;
73template <
typename Po
intT>
void
80 coefficients->values.resize (4);
81 coefficients->values[0] = coefficients->values[1] = 0;
82 coefficients->values[2] = 1.0;
83 coefficients->values[3] = 0;
90 proj.
filter (*cloud_projected);
95 if (
input_->isOrganized ())
100 if (!searcher_->setInputCloud (cloud_projected))
102 PCL_ERROR (
"[pcl::%s::applyFilter] Error when initializing search method!\n",
getClassName ().c_str ());
111 int oii = 0, rii = 0;
113 std::vector<bool> point_is_max (
indices_->size (),
false);
114 std::vector<bool> point_is_visited (
indices_->size (),
false);
128 if (point_is_visited[iii] && !point_is_max[iii])
132 (*removed_indices_)[rii++] = iii;
136 indices[oii++] = iii;
142 point_is_max[iii] =
true;
143 point_is_visited[iii] =
true;
147 std::vector<float> radius_dists;
148 PointT p = (*cloud_projected)[iii];
149 if (searcher_->radiusSearch (p, radius_, radius_indices, radius_dists) == 0)
151 PCL_WARN (
"[pcl::%s::applyFilter] Searching for neighbors within radius %f failed.\n",
getClassName ().c_str (), radius_);
156 if (radius_indices.size () == 1)
158 point_is_max[iii] =
false;
162 float query_z = (*input_)[iii].z;
163 for (
const auto& radius_index : radius_indices)
165 if ((*
input_)[radius_index].z > query_z)
168 point_is_max[iii] =
false;
175 if (point_is_max[iii])
177 for (
const auto& radius_index : radius_indices)
179 point_is_visited[radius_index] =
true;
189 (*removed_indices_)[rii++] = iii;
196 indices[oii++] = iii;
200 indices.resize (oii);
204#define PCL_INSTANTIATE_LocalMaximum(T) template class PCL_EXPORTS pcl::LocalMaximum<T>;
void filter(PointCloud &output)
Calls the filtering method and returns the filtered dataset in output.
bool extract_removed_indices_
Set to true if we want to return the indices of the removed points.
const std::string & getClassName() const
Get a string representation of the name of this class.
IndicesPtr removed_indices_
Indices of the points that are removed.
bool negative_
False = normal filter behavior (default), true = inverted behavior.
void applyFilter(PointCloud &output) override
Downsample a Point Cloud by eliminating points that are locally maximal in z.
void applyFilterIndices(Indices &indices)
Filtered results are indexed by an indices array.
typename FilterIndices< PointT >::PointCloud PointCloud
PointCloudConstPtr input_
The input point cloud dataset.
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
IndicesPtr indices_
A pointer to the vector of point indices to use.
shared_ptr< PointCloud< PointT > > Ptr
ProjectInliers uses a model and a set of inlier indices from a PointCloud to project them into a sepa...
void setModelCoefficients(const ModelCoefficientsConstPtr &model)
Provide a pointer to the model coefficients.
void setModelType(int model)
The type of model to use (user given parameter).
search::KdTree is a wrapper class which inherits the pcl::KdTree class for performing search function...
OrganizedNeighbor is a class for optimized nearest neighbor search in organized projectable point clo...
void copyPointCloud(const pcl::PointCloud< PointInT > &cloud_in, pcl::PointCloud< PointOutT > &cloud_out)
Copy all the fields from a given point cloud into a new point cloud.
bool isFinite(const PointT &pt)
Tests if the 3D components of a point are all finite param[in] pt point to be tested return true if f...
IndicesAllocator<> Indices
Type used for indices in PCL.
shared_ptr< ::pcl::ModelCoefficients > Ptr