Point Cloud Library (PCL)  1.9.1
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 #ifndef PCL_GPU_PEOPLE_INTERNAL_H_
40 #define PCL_GPU_PEOPLE_INTERNAL_H_
41 
42 #include <pcl/gpu/containers/device_array.h>
43 #include <pcl/gpu/utils/safe_call.hpp>
44 #include <pcl/gpu/people/label_common.h>
45 #include <pcl/gpu/people/tree.h>
46 
48 
49 namespace pcl
50 {
51  namespace device
52  {
55 
60 
62 
63  /** \brief The intrinsic camera calibration **/
64  struct Intr
65  {
66  float fx, fy, cx, cy;
67  Intr () {}
68  Intr (float fx_, float fy_, float cx_, float cy_) : fx(fx_), fy(fy_), cx(cx_), cy(cy_) {}
69 
70  void setDefaultPPIfIncorrect(int cols, int rows)
71  {
72  cx = cx > 0 ? cx : cols/2 - 0.5f;
73  cy = cy > 0 ? cy : rows/2 - 0.5f;
74  }
75  };
76 
77  void smoothLabelImage(const Labels& src, const Depth& depth, Labels& dst, int num_parts, int patch_size, int depthThres);
78  void colorLMap(const Labels& labels, const DeviceArray<uchar4>& cmap, Image& rgb);
79  void mixedColorMap(const Labels& labels, const DeviceArray<uchar4>& map, const Image& rgba, Image& output);
80 
81  ////////////// connected components ///////////////////
82 
84  {
85  static void initEdges(int rows, int cols, DeviceArray2D<unsigned char>& edges);
86  //static void computeEdges(const Labels& labels, const Cloud& cloud, int num_parts, float sq_radius, DeviceArray2D<unsigned char>& edges);
87  static void computeEdges(const Labels& labels, const Depth& depth, int num_parts, float sq_radius, DeviceArray2D<unsigned char>& edges);
88  static void labelComponents(const DeviceArray2D<unsigned char>& edges, DeviceArray2D<int>& comps);
89  };
90 
91  void computeCloud(const Depth& depth, const Intr& intr, Cloud& cloud);
92 
93  void setZero(Mask& mask);
94  void prepareForeGroundDepth(const Depth& depth1, Mask& inverse_mask, Depth& depth2);
95 
96  float computeHue(int rgba);
97  void computeHueWithNans(const Image& image, const Depth& depth, HueImage& hue);
98 
99  //void shs(const DeviceArray2D<float4> &cloud, float tolerance, const std::vector<int>& indices_in, float delta_hue, Mask& indices_out);
100 
101  struct Dilatation
102  {
104  enum
105  {
106  KSIZE_X = 5,
107  KSIZE_Y = 5,
108  ANCH_X = KSIZE_X/2,
109  ANCH_Y = KSIZE_Y/2,
110  };
111 
112  static void prepareRect5x5Kernel(Kernel& kernel);
113  static void invoke(const Mask& src, const Kernel& kernel, Mask& dst);
114  };
115 
116  /** \brief Struct that holds a single RDF tree in GPU **/
117  struct CUDATree
118  {
121 
123  int numNodes;
124 
127 
128  CUDATree (int treeHeight_, const std::vector<Node>& nodes, const std::vector<Label>& leaves);
129  };
130 
131  /** \brief Processor using multiple trees */
133  {
134  public:
135  /** \brief Constructor with default values, allocates multilmap device memory **/
136  MultiTreeLiveProc(int def_rows = 480, int def_cols = 640) : multilmap (def_rows, def_cols) {}
137  /** \brief Empty destructor **/
139 
140  void
141  process (const Depth& dmap, Labels& lmap);
142 
143  /** \brief same as process, but runs the trick of declaring as background any neighbor that is more than FGThresh away.**/
144  void
145  process (const Depth& dmap, Labels& lmap, int FGThresh);
146 
147  /** \brief output a probability map from the RDF.**/
148  void
149  processProb (const Depth& dmap, Labels& lmap, LabelProbability& prob, int FGThresh);
150 
151  std::vector<CUDATree> trees;
152  MultiLabels multilmap;
153  };
154 
155  /** \brief Implementation Class to process probability histograms on GPU **/
157  {
158  public:
159  /** \brief Default constructor **/
161  {
162  std::cout << "[pcl::device::ProbabilityProc:ProbabilityProc] : (D) : Constructor called" << std::endl;
163  //PCL_DEBUG("[pcl::device::ProbabilityProc:ProbabilityProc] : (D) : Constructor called");
164  }
165 
166  /** \brief Default destructor **/
168 
169  /** \brief This will merge the votes from the different trees into one final vote, including probabilistic's **/
170  void
171  CUDA_SelectLabel ( const Depth& depth, Labels& labels, LabelProbability& probabilities);
172 
173  /** \brief This will combine two probabilities according their weight **/
174  void
175  CUDA_CombineProb ( const Depth& depth, LabelProbability& probIn1, float weight1,
176  LabelProbability& probIn2, float weight2, LabelProbability& probOut);
177 
178  /** \brief This will sum a probability multiplied with it's weight **/
179  void
180  CUDA_WeightedSumProb ( const Depth& depth, LabelProbability& probIn, float weight, LabelProbability& probOut);
181 
182  /** \brief This will blur the input labelprobability with the given kernel **/
183  int
184  CUDA_GaussianBlur( const Depth& depth,
185  LabelProbability& probIn,
187  LabelProbability& probOut);
188  /** \brief This will blur the input labelprobability with the given kernel, this version avoids extended allocation **/
189  int
190  CUDA_GaussianBlur( const Depth& depth,
191  LabelProbability& probIn,
192  DeviceArray<float>& kernel,
193  LabelProbability& probTemp,
194  LabelProbability& probOut);
195  };
196  }
197 }
198 
199 #endif /* PCL_GPU_PEOPLE_INTERNAL_H_ */
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:68
DeviceArray< Node > nodes_device
Definition: internal.h:125
float computeHue(int rgba)
Implementation Class to process probability histograms on GPU.
Definition: internal.h:156
DeviceArray2D< float > HueImage
Definition: internal.h:58
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:154
std::vector< CUDATree > trees
Definition: internal.h:151
pcl::gpu::people::trees::Label Label
Definition: internal.h:120
DeviceArray2D< unsigned short > Depth
Definition: internal.h:56
Processor using multiple trees.
Definition: internal.h:132
Struct that holds a single RDF tree in GPU.
Definition: internal.h:117
DeviceArray< unsigned char > Kernel
Definition: internal.h:103
void smoothLabelImage(const Labels &src, const Depth &depth, Labels &dst, int num_parts, int patch_size, int depthThres)
~ProbabilityProc()
Default destructor.
Definition: internal.h:167
DeviceArray2D< char4 > MultiLabels
Definition: internal.h:61
DeviceArray class
Definition: device_array.h:57
Camera intrinsics structure.
Definition: internal.h:67
DeviceArray2D< uchar4 > Image
Definition: internal.h:54
DeviceArray2D< float4 > Cloud
Definition: internal.h:53
void colorLMap(const Labels &labels, const DeviceArray< uchar4 > &cmap, Image &rgb)
pcl::gpu::people::trees::Node Node
Definition: internal.h:119
void computeCloud(const Depth &depth, const Intr &intr, Cloud &cloud)
DeviceArray2D< unsigned char > Mask
Definition: internal.h:59
void setDefaultPPIfIncorrect(int cols, int rows)
Definition: internal.h:70
~MultiTreeLiveProc()
Empty destructor.
Definition: internal.h:138
DeviceArray< Label > leaves_device
Definition: internal.h:126
DeviceArray2D< unsigned char > Labels
Definition: internal.h:57
ProbabilityProc()
Default constructor.
Definition: internal.h:160
MultiTreeLiveProc(int def_rows=480, int def_cols=640)
Constructor with default values, allocates multilmap device memory.
Definition: internal.h:136
void mixedColorMap(const Labels &labels, const DeviceArray< uchar4 > &map, const Image &rgba, Image &output)