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