Point Cloud Library (PCL)  1.15.1-dev
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/conversions.h> // for pcl::toPCLPointCloud2
44 #include <pcl/search/auto.h>
45 
46 
47 namespace pcl
48 {
49 
50 template <typename PointInT> void
52 {
53  // Copy the header
54  output.header = input_->header;
55 
56  if (!initCompute ())
57  {
58  output.cloud.width = output.cloud.height = 0;
59  output.cloud.data.clear ();
60  output.polygons.clear ();
61  return;
62  }
63 
64  // Check if a space search locator was given
65  if (check_tree_)
66  {
67  if (!tree_)
68  {
69  tree_.reset (pcl::search::autoSelectMethod<PointInT>(input_, indices_, false));
70  }
71  else
72  {
73  // Send the surface dataset to the spatial locator
74  tree_->setInputCloud (input_, indices_);
75  }
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  tree_.reset (pcl::search::autoSelectMethod<PointInT>(input_, indices_, false));
110  }
111  else
112  {
113  // Send the surface dataset to the spatial locator
114  tree_->setInputCloud (input_, indices_);
115  }
116  }
117 
118  // Set up the output dataset
119  polygons.clear ();
120  polygons.reserve (2 * indices_->size ()); /// NOTE: usually the number of triangles is around twice the number of vertices
121  // Perform the actual surface reconstruction
122  performReconstruction (points, polygons);
123 
124  deinitCompute ();
125 }
126 
127 
128 template <typename PointInT> void
130 {
131  // Copy the header
132  output.header = input_->header;
133 
134  if (!initCompute ())
135  {
136  output.cloud.width = output.cloud.height = 1;
137  output.cloud.data.clear ();
138  output.polygons.clear ();
139  return;
140  }
141 
142  // Check if a space search locator was given
143  if (check_tree_)
144  {
145  if (!tree_)
146  {
147  tree_.reset (pcl::search::autoSelectMethod<PointInT>(input_, indices_, false));
148  }
149  else
150  {
151  // Send the surface dataset to the spatial locator
152  tree_->setInputCloud (input_, indices_);
153  }
154  }
155 
156  // Set up the output dataset
157  pcl::toPCLPointCloud2 (*input_, output.cloud); /// NOTE: passing in boost shared pointer with * as const& should be OK here
158  // output.polygons.clear ();
159  // output.polygons.reserve (2*indices_->size ()); /// NOTE: usually the number of triangles is around twice the number of vertices
160  // Perform the actual surface reconstruction
161  performReconstruction (output);
162 
163  deinitCompute ();
164 }
165 
166 
167 template <typename PointInT> void
168 MeshConstruction<PointInT>::reconstruct (std::vector<pcl::Vertices> &polygons)
169 {
170  if (!initCompute ())
171  {
172  polygons.clear ();
173  return;
174  }
175 
176  // Check if a space search locator was given
177  if (check_tree_)
178  {
179  if (!tree_)
180  {
181  tree_.reset(pcl::search::autoSelectMethod<PointInT>(input_, indices_, false));
182  }
183  else
184  {
185  // Send the surface dataset to the spatial locator
186  tree_->setInputCloud (input_, indices_);
187  }
188  }
189 
190  // Set up the output dataset
191  //polygons.clear ();
192  //polygons.reserve (2 * indices_->size ()); /// NOTE: usually the number of triangles is around twice the number of vertices
193  // Perform the actual surface reconstruction
194  performReconstruction (polygons);
195 
196  deinitCompute ();
197 }
198 
199 } // namespace pcl
200 
201 #endif // PCL_SURFACE_RECONSTRUCTION_IMPL_H_
202 
void reconstruct(pcl::PolygonMesh &output) override
Base method for surface reconstruction for all points given in <setInputCloud (), setIndices ()>
std::uint32_t width
The point cloud width (if organized as an image-structure).
Definition: point_cloud.h:399
pcl::PCLHeader header
The point cloud header.
Definition: point_cloud.h:393
std::uint32_t height
The point cloud height (if organized as an image-structure).
Definition: point_cloud.h:401
void clear()
Removes all points in a cloud and sets the width and height to 0.
Definition: point_cloud.h:886
void reconstruct(pcl::PolygonMesh &output) override
Base method for surface reconstruction for all points given in <setInputCloud (), setIndices ()>
void toPCLPointCloud2(const pcl::PointCloud< PointT > &cloud, pcl::PCLPointCloud2 &msg, bool padding)
Convert a pcl::PointCloud<T> object to a PCLPointCloud2 binary data blob.
Definition: conversions.h:372
std::vector< std::uint8_t > data
::pcl::PCLHeader header
Definition: PolygonMesh.h:18
std::vector< ::pcl::Vertices > polygons
Definition: PolygonMesh.h:22
::pcl::PCLPointCloud2 cloud
Definition: PolygonMesh.h:20