Point Cloud Library (PCL)  1.9.1-dev
internal.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2011, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * @authors: Cedric Cagniart, Koen Buys, Anatoly Baksheev
37  */
38 
39 #pragma once
40 
41 #include <pcl/gpu/containers/device_array.h>
42 #include <pcl/gpu/utils/safe_call.hpp>
43 #include <pcl/gpu/people/label_common.h>
44 #include <pcl/gpu/people/tree.h>
45 
47 
48 namespace pcl
49 {
50  namespace device
51  {
54 
59 
61 
62  /** \brief The intrinsic camera calibration **/
63  struct Intr
64  {
65  float fx, fy, cx, cy;
66  Intr () {}
67  Intr (float fx_, float fy_, float cx_, float cy_) : fx(fx_), fy(fy_), cx(cx_), cy(cy_) {}
68 
69  void setDefaultPPIfIncorrect(int cols, int rows)
70  {
71  cx = cx > 0 ? cx : cols/2 - 0.5f;
72  cy = cy > 0 ? cy : rows/2 - 0.5f;
73  }
74  };
75 
76  void smoothLabelImage(const Labels& src, const Depth& depth, Labels& dst, int num_parts, int patch_size, int depthThres);
77  void colorLMap(const Labels& labels, const DeviceArray<uchar4>& cmap, Image& rgb);
78  void mixedColorMap(const Labels& labels, const DeviceArray<uchar4>& map, const Image& rgba, Image& output);
79 
80  ////////////// connected components ///////////////////
81 
83  {
84  static void initEdges(int rows, int cols, DeviceArray2D<unsigned char>& edges);
85  //static void computeEdges(const Labels& labels, const Cloud& cloud, int num_parts, float sq_radius, DeviceArray2D<unsigned char>& edges);
86  static void computeEdges(const Labels& labels, const Depth& depth, int num_parts, float sq_radius, DeviceArray2D<unsigned char>& edges);
87  static void labelComponents(const DeviceArray2D<unsigned char>& edges, DeviceArray2D<int>& comps);
88  };
89 
90  void computeCloud(const Depth& depth, const Intr& intr, Cloud& cloud);
91 
92  void setZero(Mask& mask);
93  void prepareForeGroundDepth(const Depth& depth1, Mask& inverse_mask, Depth& depth2);
94 
95  float computeHue(int rgba);
96  void computeHueWithNans(const Image& image, const Depth& depth, HueImage& hue);
97 
98  //void shs(const DeviceArray2D<float4> &cloud, float tolerance, const std::vector<int>& indices_in, float delta_hue, Mask& indices_out);
99 
100  struct Dilatation
101  {
103  enum
104  {
105  KSIZE_X = 5,
106  KSIZE_Y = 5,
107  ANCH_X = KSIZE_X/2,
108  ANCH_Y = KSIZE_Y/2,
109  };
110 
111  static void prepareRect5x5Kernel(Kernel& kernel);
112  static void invoke(const Mask& src, const Kernel& kernel, Mask& dst);
113  };
114 
115  /** \brief Struct that holds a single RDF tree in GPU **/
116  struct CUDATree
117  {
120 
122  int numNodes;
123 
126 
127  CUDATree (int treeHeight_, const std::vector<Node>& nodes, const std::vector<Label>& leaves);
128  };
129 
130  /** \brief Processor using multiple trees */
132  {
133  public:
134  /** \brief Constructor with default values, allocates multilmap device memory **/
135  MultiTreeLiveProc(int def_rows = 480, int def_cols = 640) : multilmap (def_rows, def_cols) {}
136  /** \brief Empty destructor **/
138 
139  void
140  process (const Depth& dmap, Labels& lmap);
141 
142  /** \brief same as process, but runs the trick of declaring as background any neighbor that is more than FGThresh away.**/
143  void
144  process (const Depth& dmap, Labels& lmap, int FGThresh);
145 
146  /** \brief output a probability map from the RDF.**/
147  void
148  processProb (const Depth& dmap, Labels& lmap, LabelProbability& prob, int FGThresh);
149 
150  std::vector<CUDATree> trees;
152  };
153 
154  /** \brief Implementation Class to process probability histograms on GPU **/
156  {
157  public:
158  /** \brief Default constructor **/
160  {
161  std::cout << "[pcl::device::ProbabilityProc:ProbabilityProc] : (D) : Constructor called" << std::endl;
162  //PCL_DEBUG("[pcl::device::ProbabilityProc:ProbabilityProc] : (D) : Constructor called");
163  }
164 
165  /** \brief Default destructor **/
167 
168  /** \brief This will merge the votes from the different trees into one final vote, including probabilistic's **/
169  void
170  CUDA_SelectLabel ( const Depth& depth, Labels& labels, LabelProbability& probabilities);
171 
172  /** \brief This will combine two probabilities according their weight **/
173  void
174  CUDA_CombineProb ( const Depth& depth, LabelProbability& probIn1, float weight1,
175  LabelProbability& probIn2, float weight2, LabelProbability& probOut);
176 
177  /** \brief This will sum a probability multiplied with it's weight **/
178  void
179  CUDA_WeightedSumProb ( const Depth& depth, LabelProbability& probIn, float weight, LabelProbability& probOut);
180 
181  /** \brief This will blur the input labelprobability with the given kernel **/
182  int
183  CUDA_GaussianBlur( const Depth& depth,
184  LabelProbability& probIn,
186  LabelProbability& probOut);
187  /** \brief This will blur the input labelprobability with the given kernel, this version avoids extended allocation **/
188  int
189  CUDA_GaussianBlur( const Depth& depth,
190  LabelProbability& probIn,
191  DeviceArray<float>& kernel,
192  LabelProbability& probTemp,
193  LabelProbability& probOut);
194  };
195  }
196 }
void setZero(Mask &mask)
void prepareForeGroundDepth(const Depth &depth1, Mask &inverse_mask, Depth &depth2)
Intr(float fx_, float fy_, float cx_, float cy_)
Definition: internal.h:67
DeviceArray< Node > nodes_device
Definition: internal.h:124
float computeHue(int rgba)
Implementation Class to process probability histograms on GPU.
Definition: internal.h:155
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
void computeHueWithNans(const Image &image, const Depth &depth, HueImage &hue)
DeviceArray2D class
Definition: device_array.h:153
std::vector< CUDATree > trees
Definition: internal.h:150
Processor using multiple trees.
Definition: internal.h:131
Struct that holds a single RDF tree in GPU.
Definition: internal.h:116
void smoothLabelImage(const Labels &src, const Depth &depth, Labels &dst, int num_parts, int patch_size, int depthThres)
~ProbabilityProc()
Default destructor.
Definition: internal.h:166
DeviceArray class
Definition: device_array.h:56
std::uint8_t Label
Definition: tree.h:73
Camera intrinsics structure.
Definition: internal.h:68
pcl::gpu::people::trees::Label Label
Definition: internal.h:119
void colorLMap(const Labels &labels, const DeviceArray< uchar4 > &cmap, Image &rgb)
void computeCloud(const Depth &depth, const Intr &intr, Cloud &cloud)
void setDefaultPPIfIncorrect(int cols, int rows)
Definition: internal.h:69
~MultiTreeLiveProc()
Empty destructor.
Definition: internal.h:137
DeviceArray< Label > leaves_device
Definition: internal.h:125
ProbabilityProc()
Default constructor.
Definition: internal.h:159
MultiTreeLiveProc(int def_rows=480, int def_cols=640)
Constructor with default values, allocates multilmap device memory.
Definition: internal.h:135
void mixedColorMap(const Labels &labels, const DeviceArray< uchar4 > &map, const Image &rgba, Image &output)