Point Cloud Library (PCL)  1.8.0
densecrf.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 Willow Garage, Inc. 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 #ifndef PCL_DENSE_CRF_H_
41 #define PCL_DENSE_CRF_H_
42 
43 #include <pcl/point_cloud.h>
44 #include <pcl/point_types.h>
45 
46 #include <pcl/ml/pairwise_potential.h>
47 
48 namespace pcl
49 {
50  /** \brief
51  *
52  */
53  class PCL_EXPORTS DenseCrf
54  {
55  public:
56 
57  /** \brief Constructor for DenseCrf class */
58  DenseCrf (int N, int m);
59 
60  /** \brief Deconstructor for DenseCrf class */
61  ~DenseCrf ();
62 
63  /** \brief set the input data vector.
64  * The input data vector holds the measurements
65  * coordinates as ijk of the voxel grid
66  */
67  void
68  setDataVector (const std::vector<Eigen::Vector3i, Eigen::aligned_allocator<Eigen::Vector3i> > data);
69 
70  /** \brief The associated color of the data
71  */
72  void
73  setColorVector (const std::vector<Eigen::Vector3i, Eigen::aligned_allocator<Eigen::Vector3i> > color);
74 
75  void
76  setUnaryEnergy (const std::vector<float> unary);
77 
78  /** \brief */
79  void
80  addPairwiseEnergy (const std::vector<float> &feature, const int feature_dimension, const float w);
81 
82 
83  /** \brief Add a pairwise gaussian kernel
84  *
85  */
86  void
87  addPairwiseGaussian (float sx, float sy, float sz, float w);
88 
89  /** \brief Add a bilateral gaussian kernel
90  *
91  */
92  void
93  addPairwiseBilateral (float sx, float sy, float sz,
94  float sr, float sg, float sb,
95  float w);
96 
97 
98  void
99  addPairwiseNormals (std::vector<Eigen::Vector3i, Eigen::aligned_allocator<Eigen::Vector3i> > &coord,
100  std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > &normals,
101  float sx, float sy, float sz,
102  float snx, float sny, float snz,
103  float w);
104 
105 
106  void
107  inference (int n_iterations, std::vector<float> &result, float relax = 1.0f);
108 
109  void
110  mapInference (int n_iterations, std::vector<int> &result, float relax = 1.0f);
111 
112  void
113  expAndNormalize (std::vector<float> &out, const std::vector<float> &in,
114  float scale, float relax = 1.0f);
115 
116  void
117  expAndNormalizeORI ( float* out, const float* in, float scale=1.0f, float relax=1.0f );
118  void map ( int n_iterations, std::vector<int> result, float relax=1.0f );
119  std::vector<float> runInference( int n_iterations, float relax );
120  void startInference();
121  void stepInference( float relax );
122 
123 
124  void
125  runInference (float relax);
126 
127 
128  void
129  getBarycentric (int idx, std::vector<float> &bary);
130 
131  void
132  getFeatures (int idx, std::vector<float> &features);
133 
134 
135 
136  protected:
137 
138  /** \brief Number of variables and labels */
139  int N_, M_;
140 
141  /** \brief Data vector */
142  std::vector<Eigen::Vector3i, Eigen::aligned_allocator<Eigen::Vector3i> > data_;
143 
144  /** \brief Color vector */
145  std::vector<Eigen::Vector3i, Eigen::aligned_allocator<Eigen::Vector3i> > color_;
146 
147  /** TODO: double might use to much memory */
148  /** \brief CRF unary potentials */
149  std::vector<float> unary_;
150 
151  std::vector<float> current_;
152  std::vector<float> next_;
153  std::vector<float> tmp_;
154 
155  /** \brief pairwise potentials */
156  std::vector<PairwisePotential*> pairwise_potential_;
157 
158  /** \brief input types */
159  bool xyz_, rgb_, normal_;
160 
161  public:
162  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
163  };
164 }
165 
166 
167 
168 
169 
170 #endif
std::vector< float > current_
Definition: densecrf.h:151
std::vector< PairwisePotential * > pairwise_potential_
pairwise potentials
Definition: densecrf.h:156
int N_
Number of variables and labels.
Definition: densecrf.h:139
std::vector< float > tmp_
Definition: densecrf.h:153
std::vector< Eigen::Vector3i, Eigen::aligned_allocator< Eigen::Vector3i > > color_
Color vector.
Definition: densecrf.h:145
Defines all the PCL implemented PointT point type structures.
bool xyz_
input types
Definition: densecrf.h:159
std::vector< float > unary_
TODO: double might use to much memory.
Definition: densecrf.h:149
std::vector< Eigen::Vector3i, Eigen::aligned_allocator< Eigen::Vector3i > > data_
Data vector.
Definition: densecrf.h:142
std::vector< float > next_
Definition: densecrf.h:152