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