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/auto.h>
52 template <
typename Po
intT>
void
58 PCL_WARN (
"[pcl::%s::applyFilter] No input dataset given!\n", getClassName ().c_str ());
67 applyFilterIndices (indices);
68 pcl::copyPointCloud<PointT> (*input_, indices, output);
72 template <
typename Po
intT>
void
79 coefficients->values.resize (4);
80 coefficients->values[0] = coefficients->values[1] = 0;
81 coefficients->values[2] = 1.0;
82 coefficients->values[3] = 0;
89 proj.
filter (*cloud_projected);
96 else if (!searcher_->setInputCloud (cloud_projected))
98 PCL_ERROR (
"[pcl::%s::applyFilter] Error when initializing search method!\n", getClassName ().c_str ());
100 removed_indices_->clear ();
105 indices.resize (indices_->size ());
106 removed_indices_->resize (indices_->size ());
107 int oii = 0, rii = 0;
109 std::vector<bool> point_is_max (indices_->size (),
false);
110 std::vector<bool> point_is_visited (indices_->size (),
false);
115 for (
const auto& iii : (*indices_))
124 if (point_is_visited[iii] && !point_is_max[iii])
127 if (extract_removed_indices_) {
128 (*removed_indices_)[rii++] = iii;
132 indices[oii++] = iii;
138 point_is_max[iii] =
true;
139 point_is_visited[iii] =
true;
143 std::vector<float> radius_dists;
144 PointT p = (*cloud_projected)[iii];
145 if (searcher_->radiusSearch (p, radius_, radius_indices, radius_dists) == 0)
147 PCL_WARN (
"[pcl::%s::applyFilter] Searching for neighbors within radius %f failed.\n", getClassName ().c_str (), radius_);
152 if (radius_indices.size () == 1)
154 point_is_max[iii] =
false;
158 float query_z = (*input_)[iii].z;
159 for (
const auto& radius_index : radius_indices)
161 if ((*input_)[radius_index].z > query_z)
164 point_is_max[iii] =
false;
171 if (point_is_max[iii])
173 for (
const auto& radius_index : radius_indices)
175 point_is_visited[radius_index] =
true;
181 if ((!negative_ && point_is_max[iii]) || (negative_ && !point_is_max[iii]))
183 if (extract_removed_indices_)
185 (*removed_indices_)[rii++] = iii;
192 indices[oii++] = iii;
196 indices.resize (oii);
197 removed_indices_->resize (rii);
200 #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.
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.
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
PointCloud represents the base class in PCL for storing collections of 3D points.
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields).
std::uint32_t width
The point cloud width (if organized as an image-structure).
std::uint32_t height
The point cloud height (if organized as an image-structure).
void clear()
Removes all points in a cloud and sets the width and height to 0.
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).
@ radius_search
The search method will mainly be used for radiusSearch.
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
A point structure representing Euclidean xyz coordinates, and the RGB color.