Point Cloud Library (PCL)  1.11.1
unary_classifier.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of the copyright holder(s) nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  * Author : Christian Potthast
36  * Email : potthast@usc.edu
37  *
38  */
39 
40 #pragma once
41 
42 #include <pcl/memory.h>
43 #include <pcl/pcl_macros.h>
44 #include <pcl/point_cloud.h>
45 #include <pcl/point_types.h>
46 
47 #include <pcl/features/fpfh.h>
48 #include <pcl/features/normal_3d.h>
49 
50 #include <pcl/filters/filter_indices.h>
51 #include <pcl/segmentation/extract_clusters.h>
52 
53 #include <pcl/ml/kmeans.h>
54 
55 namespace pcl
56 {
57  /** \brief
58  *
59  */
60  template <typename PointT>
62  {
63  public:
64 
65  /** \brief Constructor that sets default values for member variables. */
66  UnaryClassifier ();
67 
68  /** \brief This destructor destroys the cloud...
69  *
70  */
71  ~UnaryClassifier ();
72 
73  /** \brief This method sets the input cloud.
74  * \param[in] input_cloud input point cloud
75  */
76  void
77  setInputCloud (typename pcl::PointCloud<PointT>::Ptr input_cloud);
78 
79  void
81 
82  void
83  trainWithLabel (std::vector<pcl::PointCloud<pcl::FPFHSignature33>, Eigen::aligned_allocator<pcl::PointCloud<pcl::FPFHSignature33> > > &output);
84 
85  void
87 
88  void
89  queryFeatureDistances (std::vector<pcl::PointCloud<pcl::FPFHSignature33>::Ptr> &trained_features,
91  std::vector<int> &indi,
92  std::vector<float> &dist);
93 
94  void
95  assignLabels (std::vector<int> &indi,
96  std::vector<float> &dist,
97  int n_feature_means,
98  float feature_threshold,
100 
101  void
102  setClusterSize (unsigned int k){cluster_size_ = k;};
103 
104  void
105  setNormalRadiusSearch (float param){normal_radius_search_ = param;};
106 
107  void
108  setFPFHRadiusSearch (float param){fpfh_radius_search_ = param;};
109 
110  void
111  setLabelField (bool l){label_field_ = l;};
112 
113  void
114  setTrainedFeatures (std::vector<pcl::PointCloud<pcl::FPFHSignature33>::Ptr> &features){trained_features_ = features;};
115 
116  void
117  setFeatureThreshold (float threshold){feature_threshold_ = threshold;};
118 
119  protected:
120 
121  void
122  convertCloud (typename pcl::PointCloud<PointT>::Ptr in,
124 
125  void
126  convertCloud (typename pcl::PointCloud<PointT>::Ptr in,
128 
129  void
130  findClusters (typename pcl::PointCloud<PointT>::Ptr in,
131  std::vector<int> &cluster_numbers);
132 
133  void
134  getCloudWithLabel (typename pcl::PointCloud<PointT>::Ptr in,
136  int label_num);
137 
138  void
139  computeFPFH (pcl::PointCloud<pcl::PointXYZ>::Ptr in,
141  float normal_radius_search,
142  float fpfh_radius_search);
143 
144  void
145  kmeansClustering (pcl::PointCloud<pcl::FPFHSignature33>::Ptr in,
147  int k);
148 
149 
150 
151  /** \brief Contains the input cloud */
153 
155 
156  unsigned int cluster_size_;
157 
161 
162 
163  std::vector<pcl::PointCloud<pcl::FPFHSignature33>::Ptr> trained_features_;
164 
165  /** \brief Contains normals of the points that will be segmented. */
166  //typename pcl::PointCloud<pcl::Normal>::Ptr normals_;
167 
168  /** \brief Stores the cloud that will be segmented. */
169  //typename pcl::PointCloud<PointT>::Ptr cloud_for_segmentation_;
170 
171  public:
173  };
174 }
175 
176 #ifdef PCL_NO_PRECOMPILE
177 #include <pcl/segmentation/impl/unary_classifier.hpp>
178 #endif
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:429
Defines functions, macros and traits for allocating and using memory.
void setTrainedFeatures(std::vector< pcl::PointCloud< pcl::FPFHSignature33 >::Ptr > &features)
unsigned int cluster_size_
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
std::vector< pcl::PointCloud< pcl::FPFHSignature33 >::Ptr > trained_features_
void setFeatureThreshold(float threshold)
Defines all the PCL implemented PointT point type structures.
pcl::PointCloud< PointT >::Ptr input_cloud_
Contains the input cloud.
PointCloud represents the base class in PCL for storing collections of 3D points. ...
Definition: distances.h:55
void setLabelField(bool l)
void setFPFHRadiusSearch(float param)
void setNormalRadiusSearch(float param)
#define PCL_EXPORTS
Definition: pcl_macros.h:328
void setClusterSize(unsigned int k)
Defines all the PCL and non-PCL macros used.