Point Cloud Library (PCL)  1.9.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  for (size_t i = 0; i < cloud->points.size (); ++i)
60  {
61  poly_points->SetPoint (i, cloud->points[i].x, cloud->points[i].y, cloud->points[i].z);
62  polygon->GetPointIds ()->SetId (i, i);
63  }
64 
65  allocVtkUnstructuredGrid (poly_grid);
66  poly_grid->Allocate (1, 1);
67  poly_grid->InsertNextCell (polygon->GetCellType (), polygon->GetPointIds ());
68  poly_grid->SetPoints (poly_points);
69 
70  return (poly_grid);
71 }
72 
73 ////////////////////////////////////////////////////////////////////////////////////////////
74 template <typename PointT> vtkSmartPointer<vtkDataSet>
76 {
78  if (planar_polygon.getContour ().empty ())
79  return (poly_grid);
80 
83 
84  poly_points->SetNumberOfPoints (planar_polygon.getContour ().size () + 1);
85  polygon->GetPointIds ()->SetNumberOfIds (planar_polygon.getContour ().size () + 1);
86 
87  for (size_t i = 0; i < planar_polygon.getContour ().size (); ++i)
88  {
89  poly_points->SetPoint (i, planar_polygon.getContour ()[i].x,
90  planar_polygon.getContour ()[i].y,
91  planar_polygon.getContour ()[i].z);
92  polygon->GetPointIds ()->SetId (i, i);
93  }
94 
95  size_t closingContourId = planar_polygon.getContour ().size ();
96  auto firstContour = planar_polygon.getContour ()[0];
97  poly_points->SetPoint (closingContourId, firstContour.x,
98  firstContour.y,
99  firstContour.z);
100  polygon->GetPointIds ()->SetId (closingContourId, closingContourId);
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 
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
Definition: point_cloud.h:411
pcl::PointCloud< PointT >::VectorType & getContour()
Getter for the contour / boundary.
PlanarPolygon represents a planar (2D) polygon, potentially in a 3D space.
vtkSmartPointer< vtkDataSet > createPolygon(const typename pcl::PointCloud< PointT >::ConstPtr &cloud)
Create a 3d poly line from a set of points.
Definition: shapes.hpp:47
PCL_EXPORTS void allocVtkUnstructuredGrid(vtkSmartPointer< vtkUnstructuredGrid > &polydata)
Allocate a new unstructured grid smartpointer.
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:430