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