Point Cloud Library (PCL)  1.9.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
standalone_marching_cubes.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_STANDALONE_MARCHING_CUBES_H_
39  #define PCL_STANDALONE_MARCHING_CUBES_H_
40 
41 //General includes and I/O
42 
43 #include <iostream>
44 #include <pcl/io/pcd_io.h>
45 #include <pcl/io/ply_io.h>
46 #include <pcl/io/vtk_io.h>
47 #include <pcl/point_types.h>
48 #include <stdio.h>
49 #include <stdarg.h>
50 #include <pcl/pcl_macros.h>
51 
52 //Marching cubes includes
53 #include <pcl/gpu/kinfu_large_scale/marching_cubes.h>
54 #include <pcl/PolygonMesh.h>
55 
56 #include <pcl/gpu/containers/device_array.h>
57 
58 //TSDF volume includes
59 #include <pcl/gpu/kinfu_large_scale/tsdf_volume.h>
60 
61 //Eigen Geometry and Transforms
62 #include <pcl/common/transforms.h>
63 #include <Eigen/Geometry>
64 //#include <boost/graph/buffer_concepts.hpp>
65 
66 namespace pcl
67 {
68  namespace gpu
69  {
70  namespace kinfuLS
71  {
72  /** \brief The Standalone Marching Cubes Class provides encapsulated functionality for the Marching Cubes implementation originally by Anatoly Baksheev.
73  * \author Raphael Favier
74  * \author Francisco Heredia
75  */
76 
77  template <typename PointT>
79  {
80  public:
83  typedef boost::shared_ptr<pcl::PolygonMesh> MeshPtr;
84 
85  /** \brief Constructor
86  */
87  StandaloneMarchingCubes (int voxels_x = 512, int voxels_y = 512, int voxels_z = 512, float volume_size = 3.0f);
88 
89  /** \brief Destructor
90  */
92 
93  /** \brief Run marching cubes in a TSDF cloud and returns a PolygonMesh. Input X,Y,Z coordinates must be in indices of the TSDF volume grid, output is in meters.
94  * \param[in] cloud TSDF cloud with indices between [0 ... VOXELS_X][0 ... VOXELS_Y][0 ... VOXELS_Z]. Intensity value corresponds to the TSDF value in that coordinate.
95  * \return pointer to a PolygonMesh in meters generated by marching cubes.
96  */
97  MeshPtr
98  getMeshFromTSDFCloud (const PointCloud &cloud);
99 
100  /** \brief Runs marching cubes on every pointcloud in the vector. Returns a vector containing the PolygonMeshes.
101  * \param[in] tsdf_clouds Vector of TSDF Clouds
102  * \param[in] tsdf_offsets Vector of the offsets for every pointcloud in TsdfClouds. This offset (in indices) indicates the position of the cloud with respect to the absolute origin of the world model
103  */
104  void
105  getMeshesFromTSDFVector (const std::vector<PointCloudPtr> &tsdf_clouds, const std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > &tsdf_offsets);
106 
107  /** \brief Returns the associated Tsdf Volume buffer in GPU
108  * \return pointer to the Tsdf Volume buffer in GPU
109  */
111  tsdfVolumeGPU ();
112 
113  /** \brief Returns the associated Tsdf Volume buffer in CPU
114  * \return the Tsdf Volume buffer in CPU returned returned by reference
115  */
116  std::vector<int>&
117  tsdfVolumeCPU ();
118 
119  protected:
120 
121  /** \brief Loads a TSDF Cloud to the TSDF Volume in GPU
122  * \param[in] cloud TSDF cloud that will be loaded. X,Y,Z of the cloud will only be loaded if their range is between [0 ... VOXELS_X][0 ... VOXELS_Y][0 ... VOXELS_Z]
123  */
124  void
125  loadTsdfCloudToGPU (const PointCloud &cloud);
126 
127  /** \brief Read the data in the point cloud. Performs a conversion to a suitable format for the TSDF Volume. Loads the converted data to the output vector.
128  * \param[in] cloud point cloud to be converted
129  * \param[out] output the vector of converted values, ready to be loaded to the GPU.
130  */
131  void
132  convertTsdfVectors (const PointCloud &cloud, std::vector<int> &output);
133 
134  /** \brief Converts the triangles buffer device to a PolygonMesh.
135  * \param[in] triangles the triangles buffer containing the points of the mesh
136  * \return pointer to the PolygonMesh egnerated by marchign cubes
137  */
138  MeshPtr
140 
141  /** \brief Runs marching cubes on the data that is contained in the TSDF Volume in GPU.
142  * \return param[return] pointer to a PolygonMesh in meters generated by marching cubes.
143  */
144  MeshPtr
145  runMarchingCubes ();
146 
147  private:
148 
149  /** The TSDF volume in GPU*/
150  TsdfVolume::Ptr tsdf_volume_gpu_;
151 
152  /** The TSDF volume in CPU */
153  std::vector<int> tsdf_volume_cpu_;
154 
155  /** Number of voxels in the grid for each axis */
156  int voxels_x_;
157  int voxels_y_;
158  int voxels_z_;
159 
160  /** Tsdf volume size in meters. Should match the ones in internal.h */
161  float volume_size_;
162 
163  /** Mesh counter used to name the output meshes */
164  int mesh_counter_;
165 
166  };
167  }
168  }
169 }
170 
171 #define PCL_INSTANTIATE_StandaloneMarchingCubes(PointT) template class PCL_EXPORTS pcl::gpu::kinfuLS::StandaloneMarchingCubes<PointT>;
172 
173 #endif // PCL_STANDALONE_MARCHING_CUBES_H_
174 
void convertTsdfVectors(const PointCloud &cloud, std::vector< int > &output)
Read the data in the point cloud.
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
std::vector< int > & tsdfVolumeCPU()
Returns the associated Tsdf Volume buffer in CPU.
void getMeshesFromTSDFVector(const std::vector< PointCloudPtr > &tsdf_clouds, const std::vector< Eigen::Vector3f, Eigen::aligned_allocator< Eigen::Vector3f > > &tsdf_offsets)
Runs marching cubes on every pointcloud in the vector.
boost::shared_ptr< pcl::PolygonMesh > MeshPtr
The Standalone Marching Cubes Class provides encapsulated functionality for the Marching Cubes implem...
boost::shared_ptr< TsdfVolume > Ptr
Definition: tsdf_volume.h:65
PointCloud represents the base class in PCL for storing collections of 3D points. ...
MeshPtr getMeshFromTSDFCloud(const PointCloud &cloud)
Run marching cubes in a TSDF cloud and returns a PolygonMesh.
MeshPtr convertTrianglesToMesh(const pcl::gpu::DeviceArray< pcl::PointXYZ > &triangles)
Converts the triangles buffer device to a PolygonMesh.
TsdfVolume::Ptr tsdfVolumeGPU()
Returns the associated Tsdf Volume buffer in GPU.
MeshPtr runMarchingCubes()
Runs marching cubes on the data that is contained in the TSDF Volume in GPU.
void loadTsdfCloudToGPU(const PointCloud &cloud)
Loads a TSDF Cloud to the TSDF Volume in GPU.
StandaloneMarchingCubes(int voxels_x=512, int voxels_y=512, int voxels_z=512, float volume_size=3.0f)
Constructor.