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.h> 56 template <
typename Po
intT>
void 58 float resolution,
const int morphological_operator,
61 if (cloud_in->
empty ())
64 pcl::copyPointCloud<PointT, PointT> (*cloud_in, cloud_out);
68 tree.setInputCloud (cloud_in);
69 tree.addPointsFromInputCloud ();
71 float half_res = resolution / 2.0f;
73 switch (morphological_operator)
78 for (
size_t p_idx = 0; p_idx < cloud_in->points.size (); ++p_idx)
80 Eigen::Vector3f bbox_min, bbox_max;
81 std::vector<int> pt_indices;
82 float minx = cloud_in->points[p_idx].x - half_res;
83 float miny = cloud_in->points[p_idx].y - half_res;
84 float minz = -std::numeric_limits<float>::max ();
85 float maxx = cloud_in->points[p_idx].x + half_res;
86 float maxy = cloud_in->points[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.size () > 0)
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.
points[p_idx].z = max_pt.z ();
106 cloud_out.
points[p_idx].z = min_pt.z ();
119 pcl::copyPointCloud<PointT, PointT> (*cloud_in, cloud_temp);
121 for (
size_t p_idx = 0; p_idx < cloud_temp.
points.size (); ++p_idx)
123 Eigen::Vector3f bbox_min, bbox_max;
124 std::vector<int> pt_indices;
125 float minx = cloud_temp.
points[p_idx].x - half_res;
126 float miny = cloud_temp.
points[p_idx].y - half_res;
127 float minz = -std::numeric_limits<float>::max ();
128 float maxx = cloud_temp.
points[p_idx].x + half_res;
129 float maxy = cloud_temp.
points[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.size () > 0)
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.
points[p_idx].z = min_pt.z ();
149 cloud_out.
points[p_idx].z = max_pt.z ();
156 cloud_temp.swap (cloud_out);
158 for (
size_t p_idx = 0; p_idx < cloud_temp.points.size (); ++p_idx)
160 Eigen::Vector3f bbox_min, bbox_max;
161 std::vector<int> pt_indices;
162 float minx = cloud_temp.points[p_idx].x - half_res;
163 float miny = cloud_temp.points[p_idx].y - half_res;
164 float minz = -std::numeric_limits<float>::max ();
165 float maxx = cloud_temp.points[p_idx].x + half_res;
166 float maxy = cloud_temp.points[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.size () > 0)
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.
points[p_idx].z = max_pt.z ();
187 cloud_out.
points[p_idx].z = min_pt.z ();
197 PCL_ERROR (
"Morphological operator is not supported!\n");
205 #define PCL_INSTANTIATE_applyMorphologicalOperator(T) template PCL_EXPORTS void pcl::applyMorphologicalOperator<T> (const pcl::PointCloud<T>::ConstPtr &, float, const int, pcl::PointCloud<T> &); 207 #endif //#ifndef PCL_FILTERS_IMPL_MORPHOLOGICAL_FILTER_H_ std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
PCL_EXPORTS 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.
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
PointCloud represents the base class in PCL for storing collections of 3D points. ...
Octree pointcloud search class