42 #ifndef PCL_FILTERS_IMPL_MORPHOLOGICAL_FILTER_H_
43 #define PCL_FILTERS_IMPL_MORPHOLOGICAL_FILTER_H_
50 #include <pcl/common/io.h>
51 #include <pcl/filters/morphological_filter.h>
52 #include <pcl/octree/octree_search.h>
56 template <
typename Po
intT>
void
58 float resolution,
const int morphological_operator,
61 if (cloud_in->
empty ())
71 float half_res = resolution / 2.0f;
73 switch (morphological_operator)
78 for (std::size_t p_idx = 0; p_idx < cloud_in->
size (); ++p_idx)
80 Eigen::Vector3f bbox_min, bbox_max;
82 float minx = (*cloud_in)[p_idx].x - half_res;
83 float miny = (*cloud_in)[p_idx].y - half_res;
84 float minz = -std::numeric_limits<float>::max ();
85 float maxx = (*cloud_in)[p_idx].x + half_res;
86 float maxy = (*cloud_in)[p_idx].y + half_res;
87 float maxz = std::numeric_limits<float>::max ();
88 bbox_min = Eigen::Vector3f (minx, miny, minz);
89 bbox_max = Eigen::Vector3f (maxx, maxy, maxz);
90 tree.
boxSearch (bbox_min, bbox_max, pt_indices);
92 if (!pt_indices.empty ())
94 Eigen::Vector4f min_pt, max_pt;
95 pcl::getMinMax3D<PointT> (*cloud_in, pt_indices, min_pt, max_pt);
97 switch (morphological_operator)
101 cloud_out[p_idx].z = max_pt.z ();
106 cloud_out[p_idx].z = min_pt.z ();
121 for (std::size_t p_idx = 0; p_idx < cloud_temp.
size (); ++p_idx)
123 Eigen::Vector3f bbox_min, bbox_max;
125 float minx = cloud_temp[p_idx].x - half_res;
126 float miny = cloud_temp[p_idx].y - half_res;
127 float minz = -std::numeric_limits<float>::max ();
128 float maxx = cloud_temp[p_idx].x + half_res;
129 float maxy = cloud_temp[p_idx].y + half_res;
130 float maxz = std::numeric_limits<float>::max ();
131 bbox_min = Eigen::Vector3f (minx, miny, minz);
132 bbox_max = Eigen::Vector3f (maxx, maxy, maxz);
133 tree.
boxSearch (bbox_min, bbox_max, pt_indices);
135 if (!pt_indices.empty ())
137 Eigen::Vector4f min_pt, max_pt;
138 pcl::getMinMax3D<PointT> (cloud_temp, pt_indices, min_pt, max_pt);
140 switch (morphological_operator)
144 cloud_out[p_idx].z = min_pt.z ();
149 cloud_out[p_idx].z = max_pt.z ();
156 cloud_temp.
swap (cloud_out);
158 for (std::size_t p_idx = 0; p_idx < cloud_temp.
size (); ++p_idx)
160 Eigen::Vector3f bbox_min, bbox_max;
162 float minx = cloud_temp[p_idx].x - half_res;
163 float miny = cloud_temp[p_idx].y - half_res;
164 float minz = -std::numeric_limits<float>::max ();
165 float maxx = cloud_temp[p_idx].x + half_res;
166 float maxy = cloud_temp[p_idx].y + half_res;
167 float maxz = std::numeric_limits<float>::max ();
168 bbox_min = Eigen::Vector3f (minx, miny, minz);
169 bbox_max = Eigen::Vector3f (maxx, maxy, maxz);
170 tree.
boxSearch (bbox_min, bbox_max, pt_indices);
172 if (!pt_indices.empty ())
174 Eigen::Vector4f min_pt, max_pt;
175 pcl::getMinMax3D<PointT> (cloud_temp, pt_indices, min_pt, max_pt);
177 switch (morphological_operator)
182 cloud_out[p_idx].z = max_pt.z ();
187 cloud_out[p_idx].z = min_pt.z ();
197 PCL_ERROR (
"Morphological operator is not supported!\n");
207 #define PCL_INSTANTIATE_applyMorphologicalOperator(T) template PCL_EXPORTS void pcl::applyMorphologicalOperator<T> (const pcl::PointCloud<T>::ConstPtr &, float, const int, pcl::PointCloud<T> &);
PointCloud represents the base class in PCL for storing collections of 3D points.
void swap(PointCloud< PointT > &rhs)
Swap a point cloud with another cloud.
shared_ptr< const PointCloud< PointT > > ConstPtr
void setInputCloud(const PointCloudConstPtr &cloud_arg, const IndicesConstPtr &indices_arg=IndicesConstPtr())
Provide a pointer to the input data set.
void addPointsFromInputCloud()
Add points from input point cloud to octree.
Octree pointcloud search class
uindex_t boxSearch(const Eigen::Vector3f &min_pt, const Eigen::Vector3f &max_pt, Indices &k_indices) const
Search for points within rectangular search area Points exactly on the edges of the search rectangle ...
Define standard C methods and C++ classes that are common to all methods.
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.
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.
IndicesAllocator<> Indices
Type used for indices in PCL.