42 #ifndef PCL_FILTERS_IMPL_MORPHOLOGICAL_FILTER_H_
43 #define PCL_FILTERS_IMPL_MORPHOLOGICAL_FILTER_H_
50 #include <pcl/common/common.h>
51 #include <pcl/common/io.h>
52 #include <pcl/filters/morphological_filter.h>
53 #include <pcl/octree/octree_search.h>
57 template <
typename Po
intT>
void
59 float resolution,
const int morphological_operator,
62 if (cloud_in->
empty ())
72 float half_res = resolution / 2.0f;
74 switch (morphological_operator)
79 for (std::size_t p_idx = 0; p_idx < cloud_in->
points.size (); ++p_idx)
81 Eigen::Vector3f bbox_min, bbox_max;
82 std::vector<int> pt_indices;
83 float minx = cloud_in->
points[p_idx].x - half_res;
84 float miny = cloud_in->
points[p_idx].y - half_res;
85 float minz = -std::numeric_limits<float>::max ();
86 float maxx = cloud_in->
points[p_idx].x + half_res;
87 float maxy = cloud_in->
points[p_idx].y + half_res;
88 float maxz = std::numeric_limits<float>::max ();
89 bbox_min = Eigen::Vector3f (minx, miny, minz);
90 bbox_max = Eigen::Vector3f (maxx, maxy, maxz);
91 tree.
boxSearch (bbox_min, bbox_max, pt_indices);
93 if (!pt_indices.empty ())
95 Eigen::Vector4f min_pt, max_pt;
96 pcl::getMinMax3D<PointT> (*cloud_in, pt_indices, min_pt, max_pt);
98 switch (morphological_operator)
102 cloud_out.
points[p_idx].z = max_pt.z ();
107 cloud_out.
points[p_idx].z = min_pt.z ();
122 for (std::size_t p_idx = 0; p_idx < cloud_temp.
points.size (); ++p_idx)
124 Eigen::Vector3f bbox_min, bbox_max;
125 std::vector<int> pt_indices;
126 float minx = cloud_temp.
points[p_idx].x - half_res;
127 float miny = cloud_temp.
points[p_idx].y - half_res;
128 float minz = -std::numeric_limits<float>::max ();
129 float maxx = cloud_temp.
points[p_idx].x + half_res;
130 float maxy = cloud_temp.
points[p_idx].y + half_res;
131 float maxz = std::numeric_limits<float>::max ();
132 bbox_min = Eigen::Vector3f (minx, miny, minz);
133 bbox_max = Eigen::Vector3f (maxx, maxy, maxz);
134 tree.
boxSearch (bbox_min, bbox_max, pt_indices);
136 if (!pt_indices.empty ())
138 Eigen::Vector4f min_pt, max_pt;
139 pcl::getMinMax3D<PointT> (cloud_temp, pt_indices, min_pt, max_pt);
141 switch (morphological_operator)
145 cloud_out.
points[p_idx].z = min_pt.z ();
150 cloud_out.
points[p_idx].z = max_pt.z ();
157 cloud_temp.
swap (cloud_out);
159 for (std::size_t p_idx = 0; p_idx < cloud_temp.
points.size (); ++p_idx)
161 Eigen::Vector3f bbox_min, bbox_max;
162 std::vector<int> pt_indices;
163 float minx = cloud_temp.
points[p_idx].x - half_res;
164 float miny = cloud_temp.
points[p_idx].y - half_res;
165 float minz = -std::numeric_limits<float>::max ();
166 float maxx = cloud_temp.
points[p_idx].x + half_res;
167 float maxy = cloud_temp.
points[p_idx].y + half_res;
168 float maxz = std::numeric_limits<float>::max ();
169 bbox_min = Eigen::Vector3f (minx, miny, minz);
170 bbox_max = Eigen::Vector3f (maxx, maxy, maxz);
171 tree.
boxSearch (bbox_min, bbox_max, pt_indices);
173 if (!pt_indices.empty ())
175 Eigen::Vector4f min_pt, max_pt;
176 pcl::getMinMax3D<PointT> (cloud_temp, pt_indices, min_pt, max_pt);
178 switch (morphological_operator)
183 cloud_out.
points[p_idx].z = max_pt.z ();
188 cloud_out.
points[p_idx].z = min_pt.z ();
198 PCL_ERROR (
"Morphological operator is not supported!\n");
208 #define PCL_INSTANTIATE_applyMorphologicalOperator(T) template PCL_EXPORTS void pcl::applyMorphologicalOperator<T> (const pcl::PointCloud<T>::ConstPtr &, float, const int, pcl::PointCloud<T> &);
210 #endif //#ifndef PCL_FILTERS_IMPL_MORPHOLOGICAL_FILTER_H_
void addPointsFromInputCloud()
Add points from input point cloud to octree.
void applyMorphologicalOperator(const typename pcl::PointCloud< PointT >::ConstPtr &cloud_in, float resolution, const int morphological_operator, pcl::PointCloud< PointT > &cloud_out)
Apply morphological operator to the z dimension of the input point cloud.
void setInputCloud(const PointCloudConstPtr &cloud_arg, const IndicesConstPtr &indices_arg=IndicesConstPtr())
Provide a pointer to the input data set.
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
int boxSearch(const Eigen::Vector3f &min_pt, const Eigen::Vector3f &max_pt, std::vector< int > &k_indices) const
Search for points within rectangular search area Points exactly on the edges of the search rectangle ...
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.
PointCloud represents the base class in PCL for storing collections of 3D points. ...
shared_ptr< const PointCloud< PointT > > ConstPtr
Octree pointcloud search class
void swap(PointCloud< PointT > &rhs)
Swap a point cloud with another cloud.