Point Cloud Library (PCL)  1.11.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,
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,
192  LabelProbability& probTemp,
193  LabelProbability& probOut);
194  };
195  }
196 }
pcl
Definition: convolution.h:46
pcl::device::prepareForeGroundDepth
void prepareForeGroundDepth(const Depth &depth1, Mask &inverse_mask, Depth &depth2)
pcl::device::ConnectedComponents
Definition: internal.h:82
pcl::device::Depth
DeviceArray2D< unsigned short > Depth
Definition: internal.h:55
pcl::device::ConnectedComponents::computeEdges
static void computeEdges(const Labels &labels, const Depth &depth, int num_parts, float sq_radius, DeviceArray2D< unsigned char > &edges)
pcl::device::ProbabilityProc::ProbabilityProc
ProbabilityProc()
Default constructor.
Definition: internal.h:159
pcl::device::CUDATree::leaves_device
DeviceArray< Label > leaves_device
Definition: internal.h:125
pcl::device::computeHueWithNans
void computeHueWithNans(const Image &image, const Depth &depth, HueImage &hue)
pcl::device::Intr::Intr
Intr(float fx_, float fy_, float cx_, float cy_)
Definition: internal.h:67
pcl::device::computeHue
float computeHue(int rgba)
pcl::device::MultiTreeLiveProc::process
void process(const Depth &dmap, Labels &lmap)
pcl::gpu::DeviceArray2D
DeviceArray2D class
Definition: device_array.h:153
pcl::device::Intr
Camera intrinsics structure.
Definition: internal.h:68
pcl::device::MultiTreeLiveProc::multilmap
MultiLabels multilmap
Definition: internal.h:151
pcl::device::Intr::cx
float cx
Definition: internal.h:70
pcl::device::Dilatation
Definition: internal.h:100
pcl::device::smoothLabelImage
void smoothLabelImage(const Labels &src, const Depth &depth, Labels &dst, int num_parts, int patch_size, int depthThres)
pcl::device::Dilatation::Kernel
DeviceArray< unsigned char > Kernel
Definition: internal.h:102
pcl::device::CUDATree::Label
pcl::gpu::people::trees::Label Label
Definition: internal.h:119
pcl::device::MultiTreeLiveProc::trees
std::vector< CUDATree > trees
Definition: internal.h:150
pcl::device::ConnectedComponents::initEdges
static void initEdges(int rows, int cols, DeviceArray2D< unsigned char > &edges)
pcl::device::Dilatation::invoke
static void invoke(const Mask &src, const Kernel &kernel, Mask &dst)
pcl::device::MultiTreeLiveProc::~MultiTreeLiveProc
~MultiTreeLiveProc()
Empty destructor.
Definition: internal.h:137
pcl::device::ProbabilityProc::CUDA_GaussianBlur
int CUDA_GaussianBlur(const Depth &depth, LabelProbability &probIn, DeviceArray< float > &kernel, LabelProbability &probOut)
This will blur the input labelprobability with the given kernel.
pcl::device::CUDATree
Struct that holds a single RDF tree in GPU.
Definition: internal.h:116
pcl::device::ProbabilityProc::CUDA_SelectLabel
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.
pcl::device::CUDATree::numNodes
int numNodes
Definition: internal.h:122
pcl::gpu::people::trees::Label
std::uint8_t Label
Definition: tree.h:73
pcl::device::CUDATree::nodes_device
DeviceArray< Node > nodes_device
Definition: internal.h:124
pcl::device::Intr::cy
float cy
Definition: internal.h:70
pcl::gpu::people::trees::Node
Definition: tree.h:91
pcl::device::CUDATree::treeHeight
int treeHeight
Definition: internal.h:121
pcl::device::Dilatation::ANCH_X
@ ANCH_X
Definition: internal.h:107
pcl::device::Dilatation::KSIZE_Y
@ KSIZE_Y
Definition: internal.h:106
pcl::gpu::DeviceArray
DeviceArray class
Definition: device_array.h:56
pcl::device::colorLMap
void colorLMap(const Labels &labels, const DeviceArray< uchar4 > &cmap, Image &rgb)
pcl::device::MultiTreeLiveProc::MultiTreeLiveProc
MultiTreeLiveProc(int def_rows=480, int def_cols=640)
Constructor with default values, allocates multilmap device memory.
Definition: internal.h:135
pcl::device::ProbabilityProc::CUDA_CombineProb
void CUDA_CombineProb(const Depth &depth, LabelProbability &probIn1, float weight1, LabelProbability &probIn2, float weight2, LabelProbability &probOut)
This will combine two probabilities according their weight.
pcl::device::computeCloud
void computeCloud(const Depth &depth, const Intr &intr, Cloud &cloud)
pcl::device::ProbabilityProc
Implementation Class to process probability histograms on GPU.
Definition: internal.h:155
pcl::device::Dilatation::prepareRect5x5Kernel
static void prepareRect5x5Kernel(Kernel &kernel)
pcl::device::Intr::fy
float fy
Definition: internal.h:70
pcl::device::ProbabilityProc::CUDA_WeightedSumProb
void CUDA_WeightedSumProb(const Depth &depth, LabelProbability &probIn, float weight, LabelProbability &probOut)
This will sum a probability multiplied with it's weight.
pcl::device::ProbabilityProc::~ProbabilityProc
~ProbabilityProc()
Default destructor.
Definition: internal.h:166
pcl::device::Dilatation::KSIZE_X
@ KSIZE_X
Definition: internal.h:105
pcl::device::Image
DeviceArray2D< uchar4 > Image
Definition: internal.h:53
pcl::device::CUDATree::CUDATree
CUDATree(int treeHeight_, const std::vector< Node > &nodes, const std::vector< Label > &leaves)
pcl::device::Dilatation::ANCH_Y
@ ANCH_Y
Definition: internal.h:108
pcl::device::MultiTreeLiveProc::processProb
void processProb(const Depth &dmap, Labels &lmap, LabelProbability &prob, int FGThresh)
output a probability map from the RDF.
pcl::gpu::people::NUM_PARTS
@ NUM_PARTS
Definition: label_common.h:60
pcl::device::Intr::fx
float fx
Definition: internal.h:70
pcl::device::Intr::setDefaultPPIfIncorrect
void setDefaultPPIfIncorrect(int cols, int rows)
Definition: internal.h:69
pcl::kernel
Definition: kernel.h:46
pcl::device::MultiTreeLiveProc
Processor using multiple trees.
Definition: internal.h:131
pcl::device::ConnectedComponents::labelComponents
static void labelComponents(const DeviceArray2D< unsigned char > &edges, DeviceArray2D< int > &comps)
pcl::device::Labels
DeviceArray2D< unsigned char > Labels
Definition: internal.h:56
pcl::device::Intr::Intr
Intr()
Definition: internal.h:66
pcl::device::mixedColorMap
void mixedColorMap(const Labels &labels, const DeviceArray< uchar4 > &map, const Image &rgba, Image &output)
pcl::device::setZero
void setZero(Mask &mask)