region_growing.hpp
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
27 
28 #ifndef _PCL_REGION_GROWING_HPP_
29 #define _PCL_REGION_GROWING_HPP_
30 
38 #define PFLN printf("LINE=%d in FUNCTION=%s\n",__LINE__,__FUNCTION__);
39 
41 
42 template<class T, class T1>
43 void region_growing<T,T1>::set_input_cloud(typename PointCloud<T>::Ptr cloud_in)
44 {
45  cloud=cloud_in; // sets the private pointer
46  flags.cloud_in_set=true;
47 }
49 
50 template<class T, class T1>
51 void region_growing<T,T1>::set_input_seeds(typename PointCloud<T1>::Ptr seeds_in)
52 {
53  seeds=seeds_in; // sets the private pointer
54  flags.seeds_in_set=true;
55 }
57 
58 template<class T, class T1>
60 {
61 
62  if (flags.cloud_in_set && flags.seeds_in_set)
63  flags.ok_to_run=true;
64 
65  // cout to the screen errors on flags
66  if (radius<=0)
67  cout << "ERROR: MUST SET PROPERLY A POSITIVE RADIUS THRESHOLD" << endl;
68  if (!flags.cloud_in_set)
69  cout << "ERROR: MUST SET PROPERLY A INPUT CLOUD DATA" << endl;
70  if (!flags.seeds_in_set)
71  cout << "ERROR: MUST SET PROPERLY A INPUT SEED CLOUD DATA" << endl;
72 }
74 
75 template<class T, class T1>
77 {
78  if (flags.run_finished)
79  return region_indices;
80  else
81  {
82  vector<int> empty;
83  return empty;
84  }
85 }
87 
88 template<class T, class T1>
90 {
91  if (flags.run_finished)
92  {
93  region_point_indices.indices=region_indices;
94  return region_point_indices;
95  }
96  else
97  {
98  PointIndices empty;
99  empty.indices.push_back(0);
100  return empty;
101  }
102 
103 }
105 
106 template<class T, class T1>
108 {
110  process_flags();
111 
112  if (flags.ok_to_run)
113  {
114 // static bool initialize=true;
115 
117  vector<int> queue_list;
118 
120 // octree::OctreePointCloud<T> tree (100);
121 // if (initialize)
122 // {
123  static KdTreeFLANN<T> tree;
124  tree.setInputCloud (cloud);
125 // tree.addPointsFromInputCloud ();
126 // initialize=false;
127 // }
128 
130  vector<bool> processed ((int)cloud->points.size(), false);
131  vector<bool> processed_init ((int)cloud->points.size(), false);
132 
134  T searchPoint;
135 
136  for (size_t i=0; i<seeds->points.size(); ++i)
137  {
138  std::vector<float> pointRadiusSquaredDistance;
139  std::vector<int> pointIdxRadiusSearch;
140  searchPoint.x=seeds->points[i].x;
141  searchPoint.y=seeds->points[i].y;
142  searchPoint.z=seeds->points[i].z;
143  int neighbor_number=tree.radiusSearch (searchPoint, radius, pointIdxRadiusSearch, pointRadiusSquaredDistance);
144  if (neighbor_number>0)
145  {
146  for (size_t k=0; k<pointIdxRadiusSearch.size(); ++k)
147  {
148  if (!processed_init[pointIdxRadiusSearch[k]])
149  {
150  region_indices.push_back(pointIdxRadiusSearch[k]);
151  processed_init[pointIdxRadiusSearch[k]]=true;
152  }
153  }
154  }
155  pointIdxRadiusSearch.clear();
156  pointRadiusSquaredDistance.clear();
157  }
158 
160  queue_list=region_indices;
162  for (size_t i=0; i<queue_list.size(); ++i)
163  {
164  std::vector<float> pointRadiusSquaredDistance;
165  std::vector<int> pointIdxRadiusSearch;
166  searchPoint=cloud->points[queue_list[i]];
167  int neighbor_number=tree.radiusSearch (searchPoint, radius, pointIdxRadiusSearch, pointRadiusSquaredDistance);
168  if (neighbor_number>min_neighbors)
169  {
171  for (size_t k=0; k<pointIdxRadiusSearch.size(); ++k)
172  {
174  if (!processed[pointIdxRadiusSearch[k]])
175  {
176  queue_list.push_back(pointIdxRadiusSearch[k]); // Add on queue list
177  region_indices.push_back(pointIdxRadiusSearch[k]); // Add on region indices
178  processed[pointIdxRadiusSearch[k]]=true; // Mark the point as processed
179  }
180  }
181  }
182  pointIdxRadiusSearch.clear();
183  pointRadiusSquaredDistance.clear();
184  }
186 
187  if(region_indices.size()>0)
188  flags.run_finished=true;
189  cloud.reset();
190  seeds.reset();
191  }
192  else
193  cout << "COULD NOT PROCCED REGION GROWING. ERRORS OCCURRED!" <<endl;
194 }
195 
196 #endif
void set_input_seeds(typename PointCloud< T1 >::Ptr seeds_in)
Sets the input point cloud seeds.
void process_flags()
Process flags to check if it is ok to run.
PointIndices get_region_point_indices(void)
Provide acces to the result indices.
void set_input_cloud(typename PointCloud< T >::Ptr cloud_in)
Sets the input point cloud data.
vector< int > get_region_indices(void)
Provide acces to the result indices.
void filter()
simply runs the algorithm
Class for pcl region growing algorithm.


pointcloud_segmentation
Author(s): Tiago Talhada
autogenerated on Mon Mar 2 2015 01:32:39