Point Cloud Library (PCL)  1.12.1-dev
tsdf_volume.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  */
37 
38 #pragma once
39 
40 #include <pcl/memory.h>
41 #include <pcl/pcl_macros.h>
42 #include <pcl/gpu/containers/device_array.h>
43 #include <pcl/point_types.h>
44 #include <pcl/point_cloud.h>
45 #include <Eigen/Core>
46 #include <vector>
47 
48 namespace pcl
49 {
50  namespace gpu
51  {
52  /** \brief TsdfVolume class
53  * \author Anatoly Baskeheev, Itseez Ltd, (myname.mysurname@mycompany.com)
54  */
56  {
57  public:
58  using Ptr = shared_ptr<TsdfVolume>;
59  using ConstPtr = shared_ptr<const TsdfVolume>;
60 
61  /** \brief Supported Point Types */
63  using NormalType = Normal;
64 
65  /** \brief Default buffer size for fetching cloud. It limits max number of points that can be extracted */
66  enum { DEFAULT_CLOUD_BUFFER_SIZE = 10 * 1000 * 1000 };
67 
68  /** \brief Constructor
69  * \param[in] resolution volume resolution
70  */
71  TsdfVolume(const Eigen::Vector3i& resolution);
72 
73  /** \brief Sets Tsdf volume size for each dimension
74  * \param[in] size size of tsdf volume in meters
75  */
76  void
77  setSize(const Eigen::Vector3f& size);
78 
79  /** \brief Sets Tsdf truncation distance. Must be greater than 2 * volume_voxel_size
80  * \param[in] distance TSDF truncation distance
81  */
82  void
84 
85  /** \brief Returns tsdf volume container that point to data in GPU memory */
87  data() const;
88 
89  /** \brief Returns volume size in meters */
90  const Eigen::Vector3f&
91  getSize() const;
92 
93  /** \brief Returns volume resolution */
94  const Eigen::Vector3i&
95  getResolution() const;
96 
97  /** \brief Returns volume voxel size in meters */
98  const Eigen::Vector3f
99  getVoxelSize() const;
100 
101  /** \brief Returns tsdf truncation distance in meters */
102  float
104 
105  /** \brief Resets tsdf volume data to uninitialized state */
106  void
107  reset();
108 
109  /** \brief Generates cloud using CPU (downloads volumetric representation to CPU memory)
110  * \param[out] cloud output array for cloud
111  * \param[in] connected26 If false point cloud is extracted using 6 neighbor, otherwise 26.
112  */
113  void
114  fetchCloudHost (PointCloud<PointType>& cloud, bool connected26 = false) const;
115 
116  /** \brief Generates cloud using GPU in connected6 mode only
117  * \param[out] cloud_buffer buffer to store point cloud
118  * \return DeviceArray with disabled reference counting that points to filled part of cloud_buffer.
119  */
121  fetchCloud (DeviceArray<PointType>& cloud_buffer) const;
122 
123  /** \brief Computes normals as gradient of tsdf for given points
124  * \param[in] cloud Points where normals are computed.
125  * \param[out] normals array for normals
126  */
127  void
129 
130  /** \brief Computes normals as gradient of tsdf for given points
131  * \param[in] cloud Points where normals are computed.
132  * \param[out] normals array for normals
133  */
134  void
136 
137  /** \brief Downloads tsdf volume from GPU memory.
138  * \param[out] tsdf Array with tsdf values. if volume resolution is 512x512x512, so for voxel (x,y,z) tsdf value can be retrieved as volume[512*512*z + 512*y + x];
139  */
140  void
141  downloadTsdf (std::vector<float>& tsdf) const;
142 
143  /** \brief Downloads TSDF volume and according voxel weights from GPU memory
144  * \param[out] tsdf Array with tsdf values. if volume resolution is 512x512x512, so for voxel (x,y,z) tsdf value can be retrieved as volume[512*512*z + 512*y + x];
145  * \param[out] weights Array with tsdf voxel weights. Same size and access index as for tsdf. A weight of 0 indicates the voxel was never used.
146  */
147  void
148  downloadTsdfAndWeighs(std::vector<float>& tsdf, std::vector<short>& weights) const;
149 
150  private:
151  /** \brief tsdf volume size in meters */
152  Eigen::Vector3f size_;
153 
154  /** \brief tsdf volume resolution */
155  Eigen::Vector3i resolution_;
156 
157  /** \brief tsdf volume data container */
158  DeviceArray2D<int> volume_;
159 
160  /** \brief tsdf truncation distance */
161  float tranc_dist_;
162 
163 public:
165 
166  };
167  }
168 }
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
TsdfVolume class.
Definition: tsdf_volume.h:56
void setTsdfTruncDist(float distance)
Sets Tsdf truncation distance.
shared_ptr< TsdfVolume > Ptr
Definition: tsdf_volume.h:58
DeviceArray2D< int > data() const
Returns tsdf volume container that point to data in GPU memory.
TsdfVolume(const Eigen::Vector3i &resolution)
Constructor.
shared_ptr< const TsdfVolume > ConstPtr
Definition: tsdf_volume.h:59
void setSize(const Eigen::Vector3f &size)
Sets Tsdf volume size for each dimension.
DeviceArray< PointType > fetchCloud(DeviceArray< PointType > &cloud_buffer) const
Generates cloud using GPU in connected6 mode only.
const Eigen::Vector3f getVoxelSize() const
Returns volume voxel size in meters.
const Eigen::Vector3f & getSize() const
Returns volume size in meters.
void reset()
Resets tsdf volume data to uninitialized state.
void fetchNormals(const DeviceArray< PointType > &cloud, DeviceArray< NormalType > &normals) const
Computes normals as gradient of tsdf for given points.
float getTsdfTruncDist() const
Returns tsdf truncation distance in meters.
void fetchCloudHost(PointCloud< PointType > &cloud, bool connected26=false) const
Generates cloud using CPU (downloads volumetric representation to CPU memory)
const Eigen::Vector3i & getResolution() const
Returns volume resolution.
void downloadTsdfAndWeighs(std::vector< float > &tsdf, std::vector< short > &weights) const
Downloads TSDF volume and according voxel weights from GPU memory.
void downloadTsdf(std::vector< float > &tsdf) const
Downloads tsdf volume from GPU memory.
void fetchNormals(const DeviceArray< PointType > &cloud, DeviceArray< PointType > &normals) const
Computes normals as gradient of tsdf for given points.
Defines all the PCL implemented PointT point type structures.
#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.
float distance(const PointT &p1, const PointT &p2)
Definition: geometry.h:60
Defines all the PCL and non-PCL macros used.
#define PCL_EXPORTS
Definition: pcl_macros.h:323
A point structure representing normal coordinates and the surface curvature estimate.
A point structure representing Euclidean xyz coordinates.