Point Cloud Library (PCL)  1.14.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);
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,
109  };
110 
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 
137  void
138  process (const Depth& dmap, Labels& lmap);
139 
140  /** \brief same as process, but runs the trick of declaring as background any neighbor that is more than FGThresh away.**/
141  void
142  process (const Depth& dmap, Labels& lmap, int FGThresh);
143 
144  /** \brief output a probability map from the RDF.**/
145  void
146  processProb (const Depth& dmap, Labels& lmap, LabelProbability& prob, int FGThresh);
147 
148  std::vector<CUDATree> trees;
150  };
151 
152  /** \brief Implementation Class to process probability histograms on GPU **/
154  {
155  public:
156  /** \brief Default constructor **/
158  {
159  std::cout << "[pcl::device::ProbabilityProc:ProbabilityProc] : (D) : Constructor called" << std::endl;
160  //PCL_DEBUG("[pcl::device::ProbabilityProc:ProbabilityProc] : (D) : Constructor called");
161  }
162 
163  /** \brief This will merge the votes from the different trees into one final vote, including probabilistic's **/
164  void
165  CUDA_SelectLabel ( const Depth& depth, Labels& labels, LabelProbability& probabilities);
166 
167  /** \brief This will combine two probabilities according their weight **/
168  void
169  CUDA_CombineProb ( const Depth& depth, LabelProbability& probIn1, float weight1,
170  LabelProbability& probIn2, float weight2, LabelProbability& probOut);
171 
172  /** \brief This will sum a probability multiplied with it's weight **/
173  void
174  CUDA_WeightedSumProb ( const Depth& depth, LabelProbability& probIn, float weight, LabelProbability& probOut);
175 
176  /** \brief This will blur the input labelprobability with the given kernel **/
177  int
178  CUDA_GaussianBlur( const Depth& depth,
179  LabelProbability& probIn,
181  LabelProbability& probOut);
182  /** \brief This will blur the input labelprobability with the given kernel, this version avoids extended allocation **/
183  int
184  CUDA_GaussianBlur( const Depth& depth,
185  LabelProbability& probIn,
187  LabelProbability& probTemp,
188  LabelProbability& probOut);
189  };
190  }
191 }
Processor using multiple trees.
Definition: internal.h:132
void process(const Depth &dmap, Labels &lmap, int FGThresh)
same as process, but runs the trick of declaring as background any neighbor that is more than FGThres...
void processProb(const Depth &dmap, Labels &lmap, LabelProbability &prob, int FGThresh)
output a probability map from the RDF.
void process(const Depth &dmap, Labels &lmap)
MultiTreeLiveProc(int def_rows=480, int def_cols=640)
Constructor with default values, allocates multilmap device memory.
Definition: internal.h:135
std::vector< CUDATree > trees
Definition: internal.h:148
Implementation Class to process probability histograms on GPU.
Definition: internal.h:154
int CUDA_GaussianBlur(const Depth &depth, LabelProbability &probIn, DeviceArray< float > &kernel, LabelProbability &probTemp, LabelProbability &probOut)
This will blur the input labelprobability with the given kernel, this version avoids extended allocat...
int CUDA_GaussianBlur(const Depth &depth, LabelProbability &probIn, DeviceArray< float > &kernel, LabelProbability &probOut)
This will blur the input labelprobability with the given kernel.
void CUDA_WeightedSumProb(const Depth &depth, LabelProbability &probIn, float weight, LabelProbability &probOut)
This will sum a probability multiplied with it's weight.
ProbabilityProc()
Default constructor.
Definition: internal.h:157
void CUDA_CombineProb(const Depth &depth, LabelProbability &probIn1, float weight1, LabelProbability &probIn2, float weight2, LabelProbability &probOut)
This will combine two probabilities according their weight.
void CUDA_SelectLabel(const Depth &depth, Labels &labels, LabelProbability &probabilities)
This will merge the votes from the different trees into one final vote, including probabilistic's.
DeviceArray2D class
Definition: device_array.h:188
DeviceArray class
Definition: device_array.h:54
void smoothLabelImage(const Labels &src, const Depth &depth, Labels &dst, int num_parts, int patch_size, int depthThres)
void computeCloud(const Depth &depth, const Intr &intr, Cloud &cloud)
void colorLMap(const Labels &labels, const DeviceArray< uchar4 > &cmap, Image &rgb)
void mixedColorMap(const Labels &labels, const DeviceArray< uchar4 > &map, const Image &rgba, Image &output)
void computeHueWithNans(const Image &image, const Depth &depth, HueImage &hue)
void setZero(Mask &mask)
float computeHue(int rgba)
void prepareForeGroundDepth(const Depth &depth1, Mask &inverse_mask, Depth &depth2)
std::uint8_t Label
Definition: tree.h:73
Struct that holds a single RDF tree in GPU.
Definition: internal.h:117
pcl::gpu::people::trees::Label Label
Definition: internal.h:119
DeviceArray< Label > leaves_device
Definition: internal.h:125
DeviceArray< Node > nodes_device
Definition: internal.h:124
CUDATree(int treeHeight_, const std::vector< Node > &nodes, const std::vector< Label > &leaves)
static void computeEdges(const Labels &labels, const Depth &depth, int num_parts, float sq_radius, DeviceArray2D< unsigned char > &edges)
static void labelComponents(const DeviceArray2D< unsigned char > &edges, DeviceArray2D< int > &comps)
static void initEdges(int rows, int cols, DeviceArray2D< unsigned char > &edges)
static void prepareRect5x5Kernel(Kernel &kernel)
static void invoke(const Mask &src, const Kernel &kernel, Mask &dst)
Camera intrinsics structure.
Definition: internal.h:69
void setDefaultPPIfIncorrect(int cols, int rows)
Definition: internal.h:69
Intr(float fx_, float fy_, float cx_, float cy_)
Definition: internal.h:67