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