Point Cloud Library (PCL)  1.9.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
point_cloud_geometry_handlers.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2012-, Open Perception, 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 the copyright holder(s) 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: point_cloud_handlers.hpp 7678 2012-10-22 20:54:04Z rusu $
37  *
38  */
39 #ifndef PCL_POINT_CLOUD_GEOMETRY_HANDLERS_IMPL_HPP_
40 #define PCL_POINT_CLOUD_GEOMETRY_HANDLERS_IMPL_HPP_
41 
42 #include <pcl/pcl_macros.h>
43 
44 ///////////////////////////////////////////////////////////////////////////////////////////
45 template <typename PointT>
48 {
49  field_x_idx_ = pcl::getFieldIndex (*cloud, "x", fields_);
50  if (field_x_idx_ == -1)
51  return;
52  field_y_idx_ = pcl::getFieldIndex (*cloud, "y", fields_);
53  if (field_y_idx_ == -1)
54  return;
55  field_z_idx_ = pcl::getFieldIndex (*cloud, "z", fields_);
56  if (field_z_idx_ == -1)
57  return;
58  capable_ = true;
59 }
60 
61 ///////////////////////////////////////////////////////////////////////////////////////////
62 template <typename PointT> void
64 {
65  if (!capable_)
66  return;
67 
68  if (!points)
70  points->SetDataTypeToFloat ();
71 
73  data->SetNumberOfComponents (3);
74  vtkIdType nr_points = cloud_->points.size ();
75 
76  // Add all points
77  vtkIdType j = 0; // true point index
78  float* pts = static_cast<float*> (malloc (nr_points * 3 * sizeof (float)));
79 
80  // If the dataset has no invalid values, just copy all of them
81  if (cloud_->is_dense)
82  {
83  for (vtkIdType i = 0; i < nr_points; ++i)
84  {
85  pts[i * 3 + 0] = cloud_->points[i].x;
86  pts[i * 3 + 1] = cloud_->points[i].y;
87  pts[i * 3 + 2] = cloud_->points[i].z;
88  }
89  data->SetArray (&pts[0], nr_points * 3, 0);
90  points->SetData (data);
91  }
92  // Need to check for NaNs, Infs, ec
93  else
94  {
95  for (vtkIdType i = 0; i < nr_points; ++i)
96  {
97  // Check if the point is invalid
98  if (!pcl_isfinite (cloud_->points[i].x) || !pcl_isfinite (cloud_->points[i].y) || !pcl_isfinite (cloud_->points[i].z))
99  continue;
100 
101  pts[j * 3 + 0] = cloud_->points[i].x;
102  pts[j * 3 + 1] = cloud_->points[i].y;
103  pts[j * 3 + 2] = cloud_->points[i].z;
104  // Set j and increment
105  j++;
106  }
107  data->SetArray (&pts[0], j * 3, 0);
108  points->SetData (data);
109  }
110 }
111 
112 ///////////////////////////////////////////////////////////////////////////////////////////
113 template <typename PointT>
116 {
117  field_x_idx_ = pcl::getFieldIndex (*cloud, "normal_x", fields_);
118  if (field_x_idx_ == -1)
119  return;
120  field_y_idx_ = pcl::getFieldIndex (*cloud, "normal_y", fields_);
121  if (field_y_idx_ == -1)
122  return;
123  field_z_idx_ = pcl::getFieldIndex (*cloud, "normal_z", fields_);
124  if (field_z_idx_ == -1)
125  return;
126  capable_ = true;
127 }
128 
129 ///////////////////////////////////////////////////////////////////////////////////////////
130 template <typename PointT> void
132 {
133  if (!capable_)
134  return;
135 
136  if (!points)
138  points->SetDataTypeToFloat ();
139  points->SetNumberOfPoints (cloud_->points.size ());
140 
141  // Add all points
142  double p[3];
143  for (vtkIdType i = 0; i < static_cast<vtkIdType> (cloud_->points.size ()); ++i)
144  {
145  p[0] = cloud_->points[i].normal[0];
146  p[1] = cloud_->points[i].normal[1];
147  p[2] = cloud_->points[i].normal[2];
148 
149  points->SetPoint (i, p);
150  }
151 }
152 
153 #define PCL_INSTANTIATE_PointCloudGeometryHandlerXYZ(T) template class PCL_EXPORTS pcl::visualization::PointCloudGeometryHandlerXYZ<T>;
154 #define PCL_INSTANTIATE_PointCloudGeometryHandlerSurfaceNormal(T) template class PCL_EXPORTS pcl::visualization::PointCloudGeometryHandlerSurfaceNormal<T>;
155 
156 #endif // PCL_POINT_CLOUD_GEOMETRY_HANDLERS_IMPL_HPP_
157 
PointCloudGeometryHandlerXYZ(const PointCloudConstPtr &cloud)
Constructor.
int getFieldIndex(const pcl::PCLPointCloud2 &cloud, const std::string &field_name)
Get the index of a specified field (i.e., dimension/channel)
Definition: io.h:59
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
virtual void getGeometry(vtkSmartPointer< vtkPoints > &points) const
Obtain the actual point geometry for the input dataset in VTK format.
PointCloudGeometryHandlerSurfaceNormal(const PointCloudConstPtr &cloud)
Constructor.
int field_y_idx_
The index of the field holding the Y data.
int field_z_idx_
The index of the field holding the Z data.
Base handler class for PointCloud geometry.
A point structure representing Euclidean xyz coordinates, and the RGB color.
std::vector< pcl::PCLPointField > fields_
The list of fields available for this PointCloud.
int field_x_idx_
The index of the field holding the X data.
bool capable_
True if this handler is capable of handling the input data, false otherwise.
virtual void getGeometry(vtkSmartPointer< vtkPoints > &points) const
Obtain the actual point geometry for the input dataset in VTK format.