Point Cloud Library (PCL)  1.11.1
reconstruction.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-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  * $Id$
37  *
38  */
39 
40 #ifndef PCL_SURFACE_RECONSTRUCTION_IMPL_H_
41 #define PCL_SURFACE_RECONSTRUCTION_IMPL_H_
42 
43 #include <pcl/search/pcl_search.h>
44 
45 
46 namespace pcl
47 {
48 
49 template <typename PointInT> void
51 {
52  // Copy the header
53  output.header = input_->header;
54 
55  if (!initCompute ())
56  {
57  output.cloud.width = output.cloud.height = 0;
58  output.cloud.data.clear ();
59  output.polygons.clear ();
60  return;
61  }
62 
63  // Check if a space search locator was given
64  if (check_tree_)
65  {
66  if (!tree_)
67  {
68  if (input_->isOrganized ())
69  tree_.reset (new pcl::search::OrganizedNeighbor<PointInT> ());
70  else
71  tree_.reset (new pcl::search::KdTree<PointInT> (false));
72  }
73 
74  // Send the surface dataset to the spatial locator
75  tree_->setInputCloud (input_, indices_);
76  }
77 
78  // Set up the output dataset
79  pcl::toPCLPointCloud2 (*input_, output.cloud); /// NOTE: passing in boost shared pointer with * as const& should be OK here
80  output.polygons.clear ();
81  output.polygons.reserve (2*indices_->size ()); /// NOTE: usually the number of triangles is around twice the number of vertices
82  // Perform the actual surface reconstruction
83  performReconstruction (output);
84 
85  deinitCompute ();
86 }
87 
88 
89 template <typename PointInT> void
91  std::vector<pcl::Vertices> &polygons)
92 {
93  // Copy the header
94  points.header = input_->header;
95 
96  if (!initCompute ())
97  {
98  points.width = points.height = 0;
99  points.clear ();
100  polygons.clear ();
101  return;
102  }
103 
104  // Check if a space search locator was given
105  if (check_tree_)
106  {
107  if (!tree_)
108  {
109  if (input_->isOrganized ())
110  tree_.reset (new pcl::search::OrganizedNeighbor<PointInT> ());
111  else
112  tree_.reset (new pcl::search::KdTree<PointInT> (false));
113  }
114 
115  // Send the surface dataset to the spatial locator
116  tree_->setInputCloud (input_, indices_);
117  }
118 
119  // Set up the output dataset
120  polygons.clear ();
121  polygons.reserve (2 * indices_->size ()); /// NOTE: usually the number of triangles is around twice the number of vertices
122  // Perform the actual surface reconstruction
123  performReconstruction (points, polygons);
124 
125  deinitCompute ();
126 }
127 
128 
129 template <typename PointInT> void
131 {
132  // Copy the header
133  output.header = input_->header;
134 
135  if (!initCompute ())
136  {
137  output.cloud.width = output.cloud.height = 1;
138  output.cloud.data.clear ();
139  output.polygons.clear ();
140  return;
141  }
142 
143  // Check if a space search locator was given
144  if (check_tree_)
145  {
146  if (!tree_)
147  {
148  if (input_->isOrganized ())
149  tree_.reset (new pcl::search::OrganizedNeighbor<PointInT> ());
150  else
151  tree_.reset (new pcl::search::KdTree<PointInT> (false));
152  }
153 
154  // Send the surface dataset to the spatial locator
155  tree_->setInputCloud (input_, indices_);
156  }
157 
158  // Set up the output dataset
159  pcl::toPCLPointCloud2 (*input_, output.cloud); /// NOTE: passing in boost shared pointer with * as const& should be OK here
160  // output.polygons.clear ();
161  // output.polygons.reserve (2*indices_->size ()); /// NOTE: usually the number of triangles is around twice the number of vertices
162  // Perform the actual surface reconstruction
163  performReconstruction (output);
164 
165  deinitCompute ();
166 }
167 
168 
169 template <typename PointInT> void
170 MeshConstruction<PointInT>::reconstruct (std::vector<pcl::Vertices> &polygons)
171 {
172  if (!initCompute ())
173  {
174  polygons.clear ();
175  return;
176  }
177 
178  // Check if a space search locator was given
179  if (check_tree_)
180  {
181  if (!tree_)
182  {
183  if (input_->isOrganized ())
184  tree_.reset (new pcl::search::OrganizedNeighbor<PointInT> ());
185  else
186  tree_.reset (new pcl::search::KdTree<PointInT> (false));
187  }
188 
189  // Send the surface dataset to the spatial locator
190  tree_->setInputCloud (input_, indices_);
191  }
192 
193  // Set up the output dataset
194  //polygons.clear ();
195  //polygons.reserve (2 * indices_->size ()); /// NOTE: usually the number of triangles is around twice the number of vertices
196  // Perform the actual surface reconstruction
197  performReconstruction (polygons);
198 
199  deinitCompute ();
200 }
201 
202 } // namespace pcl
203 
204 #endif // PCL_SURFACE_RECONSTRUCTION_IMPL_H_
205 
pcl::PolygonMesh::cloud
::pcl::PCLPointCloud2 cloud
Definition: PolygonMesh.h:22
pcl
Definition: convolution.h:46
pcl::PointCloud::height
std::uint32_t height
The point cloud height (if organized as an image-structure).
Definition: point_cloud.h:416
pcl::MeshConstruction::reconstruct
void reconstruct(pcl::PolygonMesh &output) override
Base method for surface reconstruction for all points given in <setInputCloud (), setIndices ()>
Definition: reconstruction.hpp:130
pcl::PointCloud< PointInT >
pcl::PointCloud::width
std::uint32_t width
The point cloud width (if organized as an image-structure).
Definition: point_cloud.h:414
pcl::search::KdTree
search::KdTree is a wrapper class which inherits the pcl::KdTree class for performing search function...
Definition: kdtree.h:62
pcl::PolygonMesh
Definition: PolygonMesh.h:16
pcl::PointCloud::header
pcl::PCLHeader header
The point cloud header.
Definition: point_cloud.h:408
pcl::PCLPointCloud2::data
std::vector< std::uint8_t > data
Definition: PCLPointCloud2.h:29
pcl::search::OrganizedNeighbor
OrganizedNeighbor is a class for optimized nearest neigbhor search in organized point clouds.
Definition: organized.h:64
pcl::PolygonMesh::header
::pcl::PCLHeader header
Definition: PolygonMesh.h:20
pcl::PCLPointCloud2::height
std::uint32_t height
Definition: PCLPointCloud2.h:19
pcl::PointCloud::clear
void clear()
Removes all points in a cloud and sets the width and height to 0.
Definition: point_cloud.h:691
pcl::SurfaceReconstruction::reconstruct
void reconstruct(pcl::PolygonMesh &output) override
Base method for surface reconstruction for all points given in <setInputCloud (), setIndices ()>
Definition: reconstruction.hpp:50
pcl::PolygonMesh::polygons
std::vector< ::pcl::Vertices > polygons
Definition: PolygonMesh.h:24
pcl::PCLPointCloud2::width
std::uint32_t width
Definition: PCLPointCloud2.h:20
pcl::toPCLPointCloud2
void toPCLPointCloud2(const pcl::PointCloud< PointT > &cloud, pcl::PCLPointCloud2 &msg)
Convert a pcl::PointCloud<T> object to a PCLPointCloud2 binary data blob.
Definition: conversions.h:241