Point Cloud Library (PCL)  1.8.1-dev
shapes.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010, Willow Garage, Inc.
6  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of Willow Garage, Inc. nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  */
38 
39 #pragma once
40 #include <vtkSmartPointer.h>
41 #include <vtkPoints.h>
42 #include <vtkPolygon.h>
43 #include <vtkUnstructuredGrid.h>
44 
45 ////////////////////////////////////////////////////////////////////////////////////////////
46 template <typename PointT> vtkSmartPointer<vtkDataSet>
48 {
50  if (cloud->points.empty ())
51  return (poly_grid);
52 
55 
56  poly_points->SetNumberOfPoints (cloud->points.size ());
57  polygon->GetPointIds ()->SetNumberOfIds (cloud->points.size ());
58 
59  size_t i;
60  for (i = 0; i < cloud->points.size (); ++i)
61  {
62  poly_points->SetPoint (i, cloud->points[i].x, cloud->points[i].y, cloud->points[i].z);
63  polygon->GetPointIds ()->SetId (i, i);
64  }
65 
66  allocVtkUnstructuredGrid (poly_grid);
67  poly_grid->Allocate (1, 1);
68  poly_grid->InsertNextCell (polygon->GetCellType (), polygon->GetPointIds ());
69  poly_grid->SetPoints (poly_points);
70 
71  return (poly_grid);
72 }
73 
74 ////////////////////////////////////////////////////////////////////////////////////////////
75 template <typename PointT> vtkSmartPointer<vtkDataSet>
77 {
79  if (planar_polygon.getContour ().empty ())
80  return (poly_grid);
81 
84 
85  poly_points->SetNumberOfPoints (planar_polygon.getContour ().size () + 1);
86  polygon->GetPointIds ()->SetNumberOfIds (planar_polygon.getContour ().size () + 1);
87 
88  size_t i;
89  for (i = 0; i < planar_polygon.getContour ().size (); ++i)
90  {
91  poly_points->SetPoint (i, planar_polygon.getContour ()[i].x,
92  planar_polygon.getContour ()[i].y,
93  planar_polygon.getContour ()[i].z);
94  polygon->GetPointIds ()->SetId (i, i);
95  }
96 
97  poly_points->SetPoint (i, planar_polygon.getContour ()[0].x,
98  planar_polygon.getContour ()[0].y,
99  planar_polygon.getContour ()[0].z);
100  polygon->GetPointIds ()->SetId (i, i);
101 
102  allocVtkUnstructuredGrid (poly_grid);
103  poly_grid->Allocate (1, 1);
104  poly_grid->InsertNextCell (polygon->GetCellType (), polygon->GetPointIds ());
105  poly_grid->SetPoints (poly_points);
106 
107  return (poly_grid);
108 }
109 
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
pcl::PointCloud< PointT >::VectorType & getContour()
Getter for the contour / boundary.
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
Definition: point_cloud.h:410
PlanarPolygon represents a planar (2D) polygon, potentially in a 3D space.
bool empty() const
Definition: point_cloud.h:450
vtkSmartPointer< vtkDataSet > createPolygon(const typename pcl::PointCloud< PointT >::ConstPtr &cloud)
Create a 3d poly line from a set of points.
Definition: shapes.hpp:47
size_t size() const
Definition: point_cloud.h:448
PCL_EXPORTS void allocVtkUnstructuredGrid(vtkSmartPointer< vtkUnstructuredGrid > &polydata)
Allocate a new unstructured grid smartpointer.