Point Cloud Library (PCL)  1.9.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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 #ifndef PCL_KINFU_TSDF_VOLUME_H_
39 #define PCL_KINFU_TSDF_VOLUME_H_
40 
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  */
55  class PCL_EXPORTS TsdfVolume
56  {
57  public:
58  typedef boost::shared_ptr<TsdfVolume> Ptr;
59 
60  /** \brief Supported Point Types */
62  typedef Normal NormalType;
63 
64  /** \brief Default buffer size for fetching cloud. It limits max number of points that can be extracted */
65  enum { DEFAULT_CLOUD_BUFFER_SIZE = 10 * 1000 * 1000 };
66 
67  /** \brief Constructor
68  * \param[in] resolution volume resolution
69  */
70  TsdfVolume(const Eigen::Vector3i& resolution);
71 
72  /** \brief Sets Tsdf volume size for each dimension
73  * \param[in] size size of tsdf volume in meters
74  */
75  void
76  setSize(const Eigen::Vector3f& size);
77 
78  /** \brief Sets Tsdf truncation distance. Must be greater than 2 * volume_voxel_size
79  * \param[in] distance TSDF truncation distance
80  */
81  void
82  setTsdfTruncDist (float distance);
83 
84  /** \brief Returns tsdf volume container that point to data in GPU memory */
86  data() const;
87 
88  /** \brief Returns volume size in meters */
89  const Eigen::Vector3f&
90  getSize() const;
91 
92  /** \brief Returns volume resolution */
93  const Eigen::Vector3i&
94  getResolution() const;
95 
96  /** \brief Returns volume voxel size in meters */
97  const Eigen::Vector3f
98  getVoxelSize() const;
99 
100  /** \brief Returns tsdf truncation distance in meters */
101  float
102  getTsdfTruncDist () const;
103 
104  /** \brief Resets tsdf volume data to uninitialized state */
105  void
106  reset();
107 
108  /** \brief Generates cloud using CPU (downloads volumetric representation to CPU memory)
109  * \param[out] cloud output array for cloud
110  * \param[in] connected26 If false point cloud is extracted using 6 neighbor, otherwise 26.
111  */
112  void
113  fetchCloudHost (PointCloud<PointType>& cloud, bool connected26 = false) const;
114 
115  /** \brief Generates cloud using GPU in connected6 mode only
116  * \param[out] cloud_buffer buffer to store point cloud
117  * \return DeviceArray with disabled reference counting that points to filled part of cloud_buffer.
118  */
120  fetchCloud (DeviceArray<PointType>& cloud_buffer) const;
121 
122  /** \brief Computes normals as gradient of tsdf for given points
123  * \param[in] cloud Points where normals are computed.
124  * \param[out] normals array for normals
125  */
126  void
127  fetchNormals (const DeviceArray<PointType>& cloud, DeviceArray<PointType>& normals) const;
128 
129  /** \brief Computes normals as gradient of tsdf for given points
130  * \param[in] cloud Points where normals are computed.
131  * \param[out] normals array for normals
132  */
133  void
134  fetchNormals(const DeviceArray<PointType>& cloud, DeviceArray<NormalType>& normals) const;
135 
136  /** \brief Downloads tsdf volume from GPU memory.
137  * \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];
138  */
139  void
140  downloadTsdf (std::vector<float>& tsdf) const;
141 
142  /** \brief Downloads TSDF volume and according voxel weights from GPU memory
143  * \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];
144  * \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.
145  */
146  void
147  downloadTsdfAndWeighs(std::vector<float>& tsdf, std::vector<short>& weights) const;
148 
149  private:
150  /** \brief tsdf volume size in meters */
151  Eigen::Vector3f size_;
152 
153  /** \brief tsdf volume resolution */
154  Eigen::Vector3i resolution_;
155 
156  /** \brief tsdf volume data container */
157  DeviceArray2D<int> volume_;
158 
159  /** \brief tsdf truncation distance */
160  float tranc_dist_;
161 
162 public:
163 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
164 
165  };
166  }
167 }
168 
169 #endif /* PCL_KINFU_TSDF_VOLUME_H_ */
A point structure representing normal coordinates and the surface curvature estimate.
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
boost::shared_ptr< TsdfVolume > Ptr
Definition: tsdf_volume.h:58
TsdfVolume class.
Definition: tsdf_volume.h:55
A point structure representing Euclidean xyz coordinates.
PointCloud represents the base class in PCL for storing collections of 3D points. ...
PointXYZ PointType
Supported Point Types.
Definition: tsdf_volume.h:61