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