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