Point Cloud Library (PCL)  1.11.0
crf_segmentation.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/ml/densecrf.h>
48 #include <pcl/filters/voxel_grid.h>
49 #include <pcl/filters/voxel_grid_label.h>
50 
51 //#include <pcl/ml/densecrfORI.h>
52 
53 namespace pcl
54 {
55  /** \brief
56  *
57  */
58  template <typename PointT>
59  class PCL_EXPORTS CrfSegmentation
60  {
61  public:
62 
63  /** \brief Constructor that sets default values for member variables. */
64  CrfSegmentation ();
65 
66  /** \brief This destructor destroys the cloud...
67  *
68  */
69  ~CrfSegmentation ();
70 
71  /** \brief This method sets the input cloud.
72  * \param[in] input_cloud input point cloud
73  */
74  void
75  setInputCloud (typename pcl::PointCloud<PointT>::Ptr input_cloud);
76 
77  void
78  setAnnotatedCloud (typename pcl::PointCloud<pcl::PointXYZRGBL>::Ptr anno_cloud);
79 
80  void
81  setNormalCloud (typename pcl::PointCloud<pcl::PointNormal>::Ptr normal_cloud);
82 
83 
84  /** \brief Set the leaf size for the voxel grid.
85  * \param[in] x leaf size x-axis
86  * \param[in] y leaf size y-axis
87  * \param[in] z leaf size z-axis
88  */
89  void
90  setVoxelGridLeafSize (const float x, const float y, const float z);
91 
92  void
93  setNumberOfIterations (unsigned int n_iterations = 10) {n_iterations_ = n_iterations;};
94 
95  /** \brief This method simply launches the segmentation algorithm */
96  void
97  segmentPoints (pcl::PointCloud<pcl::PointXYZRGBL> &output);
98 
99  /** \brief Create a voxel grid to discretize the scene */
100  void
101  createVoxelGrid ();
102 
103  /** \brief Get the data from the voxel grid and convert it into a vector */
104  void
105  createDataVectorFromVoxelGrid ();
106 
107 
108  void
109  createUnaryPotentials (std::vector<float> &unary,
110  std::vector<int> &colors,
111  unsigned int n_labels);
112 
113 
114  /** \brief Set the smoothness kernel parameters.
115  * \param[in] sx standard deviation x
116  * \param[in] sy standard deviation y
117  * \param[in] sz standard deviation z
118  * \param[in] w weight
119  */
120  void
121  setSmoothnessKernelParameters (const float sx, const float sy, const float sz, const float w);
122 
123  /** \brief Set the appearanche kernel parameters.
124  * \param[in] sx standard deviation x
125  * \param[in] sy standard deviation y
126  * \param[in] sz standard deviation z
127  * \param[in] sr standard deviation red
128  * \param[in] sg standard deviation green
129  * \param[in] sb standard deviation blue
130  * \param[in] w weight
131  */
132  void
133  setAppearanceKernelParameters (float sx, float sy, float sz,
134  float sr, float sg, float sb,
135  float w);
136 
137 
138  void
139  setSurfaceKernelParameters (float sx, float sy, float sz,
140  float snx, float sny, float snz,
141  float w);
142 
143 
144  protected:
145  /** \brief Voxel grid to discretize the scene */
147 
148  /** \brief input cloud that will be segmented. */
152 
153  /** \brief voxel grid filtered cloud. */
157 
158  /** \brief indices of the filtered cloud. */
159  //typename pcl::VoxelGrid::IndicesPtr cloud_indices_;
160 
161  /** \brief Voxel grid leaf size */
162  Eigen::Vector4f voxel_grid_leaf_size_;
163 
164  /** \brief Voxel grid dimensions */
165  Eigen::Vector3i dim_;
166 
167  /** \brief voxel grid data points
168  packing order [x0y0z0, x1y0z0,x2y0z0,...,x0y1z0,x1y1z0,...,x0y0z1,x1y0z1,...]
169  */
170  std::vector<Eigen::Vector3i, Eigen::aligned_allocator<Eigen::Vector3i> > data_;
171 
172  std::vector<Eigen::Vector3i, Eigen::aligned_allocator<Eigen::Vector3i> > color_;
173 
174  std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > normal_;
175 
176  /** \brief smoothness kernel parameters
177  * [0] = standard deviation x
178  * [1] = standard deviation y
179  * [2] = standard deviation z
180  * [3] = weight
181  */
182  float smoothness_kernel_param_[4];
183 
184  /** \brief appearance kernel parameters
185  * [0] = standard deviation x
186  * [1] = standard deviation y
187  * [2] = standard deviation z
188  * [3] = standard deviation red
189  * [4] = standard deviation green
190  * [5] = standard deviation blue
191  * [6] = weight
192  */
193  float appearance_kernel_param_[7];
194 
195  float surface_kernel_param_[7];
196 
197 
198  unsigned int n_iterations_;
199 
200 
201  /** \brief Contains normals of the points that will be segmented. */
202  //typename pcl::PointCloud<pcl::Normal>::Ptr normals_;
203 
204  /** \brief Stores the cloud that will be segmented. */
205  //typename pcl::PointCloud<PointT>::Ptr cloud_for_segmentation_;
206 
207  public:
209  };
210 }
211 
212 #ifdef PCL_NO_PRECOMPILE
213 #include <pcl/segmentation/impl/crf_segmentation.hpp>
214 #endif
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
pcl::PointCloud< PointT >::Ptr input_cloud_
input cloud that will be segmented.
pcl::VoxelGrid< PointT > voxel_grid_
Voxel grid to discretize the scene.
VoxelGrid assembles a local 3D grid over a given PointCloud, and downsamples + filters the data...
Definition: voxel_grid.h:177
std::vector< Eigen::Vector3i, Eigen::aligned_allocator< Eigen::Vector3i > > color_
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
Eigen::Vector4f voxel_grid_leaf_size_
indices of the filtered cloud.
pcl::PointCloud< PointT >::Ptr filtered_cloud_
voxel grid filtered cloud.
std::vector< Eigen::Vector3i, Eigen::aligned_allocator< Eigen::Vector3i > > data_
voxel grid data points packing order [x0y0z0, x1y0z0,x2y0z0,...,x0y1z0,x1y1z0,...,x0y0z1,x1y0z1,...]
unsigned int n_iterations_
Eigen::Vector3i dim_
Voxel grid dimensions.
pcl::PointCloud< pcl::PointNormal >::Ptr normal_cloud_
std::vector< Eigen::Vector3f, Eigen::aligned_allocator< Eigen::Vector3f > > normal_
PointCloud represents the base class in PCL for storing collections of 3D points. ...
pcl::PointCloud< pcl::PointNormal >::Ptr filtered_normal_
pcl::PointCloud< pcl::PointXYZRGBL >::Ptr anno_cloud_
void setNumberOfIterations(unsigned int n_iterations=10)
pcl::PointCloud< pcl::PointXYZRGBL >::Ptr filtered_anno_