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