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