00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _PCL_REGION_GROWING_HPP_
00029 #define _PCL_REGION_GROWING_HPP_
00030
00038 #define PFLN printf("LINE=%d in FUNCTION=%s\n",__LINE__,__FUNCTION__);
00039
00040 #include <pointcloud_segmentation/region_growing.h>
00041
00042 template<class T, class T1>
00043 void region_growing<T,T1>::set_input_cloud(typename PointCloud<T>::Ptr cloud_in)
00044 {
00045 cloud=cloud_in;
00046 flags.cloud_in_set=true;
00047 }
00049
00050 template<class T, class T1>
00051 void region_growing<T,T1>::set_input_seeds(typename PointCloud<T1>::Ptr seeds_in)
00052 {
00053 seeds=seeds_in;
00054 flags.seeds_in_set=true;
00055 }
00057
00058 template<class T, class T1>
00059 void region_growing<T,T1>::process_flags()
00060 {
00061
00062 if (flags.cloud_in_set && flags.seeds_in_set)
00063 flags.ok_to_run=true;
00064
00065
00066 if (radius<=0)
00067 cout << "ERROR: MUST SET PROPERLY A POSITIVE RADIUS THRESHOLD" << endl;
00068 if (!flags.cloud_in_set)
00069 cout << "ERROR: MUST SET PROPERLY A INPUT CLOUD DATA" << endl;
00070 if (!flags.seeds_in_set)
00071 cout << "ERROR: MUST SET PROPERLY A INPUT SEED CLOUD DATA" << endl;
00072 }
00074
00075 template<class T, class T1>
00076 vector<int> region_growing<T,T1>::get_region_indices(void)
00077 {
00078 if (flags.run_finished)
00079 return region_indices;
00080 else
00081 {
00082 vector<int> empty;
00083 return empty;
00084 }
00085 }
00087
00088 template<class T, class T1>
00089 PointIndices region_growing<T,T1>::get_region_point_indices(void)
00090 {
00091 if (flags.run_finished)
00092 {
00093 region_point_indices.indices=region_indices;
00094 return region_point_indices;
00095 }
00096 else
00097 {
00098 PointIndices empty;
00099 empty.indices.push_back(0);
00100 return empty;
00101 }
00102
00103 }
00105
00106 template<class T, class T1>
00107 void region_growing<T,T1>::filter ()
00108 {
00110 process_flags();
00111
00112 if (flags.ok_to_run)
00113 {
00114
00115
00117 vector<int> queue_list;
00118
00120
00121
00122
00123 static KdTreeFLANN<T> tree;
00124 tree.setInputCloud (cloud);
00125
00126
00127
00128
00130 vector<bool> processed ((int)cloud->points.size(), false);
00131 vector<bool> processed_init ((int)cloud->points.size(), false);
00132
00134 T searchPoint;
00135
00136 for (size_t i=0; i<seeds->points.size(); ++i)
00137 {
00138 std::vector<float> pointRadiusSquaredDistance;
00139 std::vector<int> pointIdxRadiusSearch;
00140 searchPoint.x=seeds->points[i].x;
00141 searchPoint.y=seeds->points[i].y;
00142 searchPoint.z=seeds->points[i].z;
00143 int neighbor_number=tree.radiusSearch (searchPoint, radius, pointIdxRadiusSearch, pointRadiusSquaredDistance);
00144 if (neighbor_number>0)
00145 {
00146 for (size_t k=0; k<pointIdxRadiusSearch.size(); ++k)
00147 {
00148 if (!processed_init[pointIdxRadiusSearch[k]])
00149 {
00150 region_indices.push_back(pointIdxRadiusSearch[k]);
00151 processed_init[pointIdxRadiusSearch[k]]=true;
00152 }
00153 }
00154 }
00155 pointIdxRadiusSearch.clear();
00156 pointRadiusSquaredDistance.clear();
00157 }
00158
00160 queue_list=region_indices;
00162 for (size_t i=0; i<queue_list.size(); ++i)
00163 {
00164 std::vector<float> pointRadiusSquaredDistance;
00165 std::vector<int> pointIdxRadiusSearch;
00166 searchPoint=cloud->points[queue_list[i]];
00167 int neighbor_number=tree.radiusSearch (searchPoint, radius, pointIdxRadiusSearch, pointRadiusSquaredDistance);
00168 if (neighbor_number>min_neighbors)
00169 {
00171 for (size_t k=0; k<pointIdxRadiusSearch.size(); ++k)
00172 {
00174 if (!processed[pointIdxRadiusSearch[k]])
00175 {
00176 queue_list.push_back(pointIdxRadiusSearch[k]);
00177 region_indices.push_back(pointIdxRadiusSearch[k]);
00178 processed[pointIdxRadiusSearch[k]]=true;
00179 }
00180 }
00181 }
00182 pointIdxRadiusSearch.clear();
00183 pointRadiusSquaredDistance.clear();
00184 }
00186
00187 if(region_indices.size()>0)
00188 flags.run_finished=true;
00189 cloud.reset();
00190 seeds.reset();
00191 }
00192 else
00193 cout << "COULD NOT PROCCED REGION GROWING. ERRORS OCCURRED!" <<endl;
00194 }
00195
00196 #endif