point_cloud_geometry_handlers.hpp
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2012-, Open Perception, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the copyright holder(s) nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Id: point_cloud_handlers.hpp 7678 2012-10-22 20:54:04Z rusu $
*
*/
#ifndef PCL_POINT_CLOUD_GEOMETRY_HANDLERS_IMPL_HPP_
#define PCL_POINT_CLOUD_GEOMETRY_HANDLERS_IMPL_HPP_
#include <pcl/pcl_macros.h>
///////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT>
pcl::visualization::PointCloudGeometryHandlerXYZ<PointT>::PointCloudGeometryHandlerXYZ (const PointCloudConstPtr &cloud)
: pcl::visualization::PointCloudGeometryHandler<PointT>::PointCloudGeometryHandler (cloud)
{
field_x_idx_ = pcl::getFieldIndex (*cloud, "x", fields_);
if (field_x_idx_ == -1)
return;
field_y_idx_ = pcl::getFieldIndex (*cloud, "y", fields_);
if (field_y_idx_ == -1)
return;
field_z_idx_ = pcl::getFieldIndex (*cloud, "z", fields_);
if (field_z_idx_ == -1)
return;
capable_ = true;
}
///////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::visualization::PointCloudGeometryHandlerXYZ<PointT>::getGeometry (vtkSmartPointer<vtkPoints> &points) const
{
if (!capable_)
return;
if (!points)
points = vtkSmartPointer<vtkPoints>::New ();
points->SetDataTypeToFloat ();
vtkSmartPointer<vtkFloatArray> data = vtkSmartPointer<vtkFloatArray>::New ();
data->SetNumberOfComponents (3);
vtkIdType nr_points = cloud_->points.size ();
// Add all points
vtkIdType j = 0; // true point index
float* pts = static_cast<float*> (malloc (nr_points * 3 * sizeof (float)));
// If the dataset has no invalid values, just copy all of them
if (cloud_->is_dense)
{
for (vtkIdType i = 0; i < nr_points; ++i)
{
pts[i * 3 + 0] = cloud_->points[i].x;
pts[i * 3 + 1] = cloud_->points[i].y;
pts[i * 3 + 2] = cloud_->points[i].z;
}
data->SetArray (&pts[0], nr_points * 3, 0);
points->SetData (data);
}
// Need to check for NaNs, Infs, ec
else
{
for (vtkIdType i = 0; i < nr_points; ++i)
{
// Check if the point is invalid
if (!pcl_isfinite (cloud_->points[i].x) || !pcl_isfinite (cloud_->points[i].y) || !pcl_isfinite (cloud_->points[i].z))
continue;
pts[j * 3 + 0] = cloud_->points[i].x;
pts[j * 3 + 1] = cloud_->points[i].y;
pts[j * 3 + 2] = cloud_->points[i].z;
// Set j and increment
j++;
}
data->SetArray (&pts[0], j * 3, 0);
points->SetData (data);
}
}
///////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT>
pcl::visualization::PointCloudGeometryHandlerSurfaceNormal<PointT>::PointCloudGeometryHandlerSurfaceNormal (const PointCloudConstPtr &cloud)
: pcl::visualization::PointCloudGeometryHandler<PointT>::PointCloudGeometryHandler (cloud)
{
field_x_idx_ = pcl::getFieldIndex (*cloud, "normal_x", fields_);
if (field_x_idx_ == -1)
return;
field_y_idx_ = pcl::getFieldIndex (*cloud, "normal_y", fields_);
if (field_y_idx_ == -1)
return;
field_z_idx_ = pcl::getFieldIndex (*cloud, "normal_z", fields_);
if (field_z_idx_ == -1)
return;
capable_ = true;
}
///////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::visualization::PointCloudGeometryHandlerSurfaceNormal<PointT>::getGeometry (vtkSmartPointer<vtkPoints> &points) const
{
if (!capable_)
return;
if (!points)
points = vtkSmartPointer<vtkPoints>::New ();
points->SetDataTypeToFloat ();
points->SetNumberOfPoints (cloud_->points.size ());
// Add all points
double p[3];
for (vtkIdType i = 0; i < static_cast<vtkIdType> (cloud_->points.size ()); ++i)
{
p[0] = cloud_->points[i].normal[0];
p[1] = cloud_->points[i].normal[1];
p[2] = cloud_->points[i].normal[2];
points->SetPoint (i, p);
}
}
#define PCL_INSTANTIATE_PointCloudGeometryHandlerXYZ(T) template class PCL_EXPORTS pcl::visualization::PointCloudGeometryHandlerXYZ<T>;
#define PCL_INSTANTIATE_PointCloudGeometryHandlerSurfaceNormal(T) template class PCL_EXPORTS pcl::visualization::PointCloudGeometryHandlerSurfaceNormal<T>;
#endif // PCL_POINT_CLOUD_GEOMETRY_HANDLERS_IMPL_HPP_
pcl::visualization::PointCloudGeometryHandlerXYZ::PointCloudGeometryHandlerXYZ
PointCloudGeometryHandlerXYZ(const PointCloudConstPtr &cloud)
Constructor.
Definition: point_cloud_geometry_handlers.hpp:46
pcl::visualization::PointCloudGeometryHandler::cloud_
PointCloudConstPtr cloud_
A pointer to the input dataset.
Definition: point_cloud_geometry_handlers.h:112
pcl::visualization::PointCloudGeometryHandler::PointCloudConstPtr
PointCloud::ConstPtr PointCloudConstPtr
Definition: point_cloud_geometry_handlers.h:66
pcl::getFieldIndex
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
vtkSmartPointer
Definition: actor_map.h:50
pcl
Definition: convolution.h:45
pcl::visualization::PointCloudGeometryHandlerSurfaceNormal::PointCloudGeometryHandlerSurfaceNormal
PointCloudGeometryHandlerSurfaceNormal(const PointCloudConstPtr &cloud)
Constructor.
Definition: point_cloud_geometry_handlers.hpp:114
pcl::visualization::PointCloudGeometryHandlerSurfaceNormal::getGeometry
virtual void getGeometry(vtkSmartPointer< vtkPoints > &points) const
Obtain the actual point geometry for the input dataset in VTK format.
Definition: point_cloud_geometry_handlers.hpp:131
pcl::visualization::PointCloudGeometryHandler::field_y_idx_
int field_y_idx_
The index of the field holding the Y data.
Definition: point_cloud_geometry_handlers.h:123
pcl::visualization::PointCloudGeometryHandler::field_z_idx_
int field_z_idx_
The index of the field holding the Z data.
Definition: point_cloud_geometry_handlers.h:126
pcl::visualization::PointCloudGeometryHandler
Base handler class for PointCloud geometry.
Definition: point_cloud_geometry_handlers.h:61
pcl::PointXYZRGB
A point structure representing Euclidean xyz coordinates, and the RGB color.
Definition: point_types.hpp:606
pcl::visualization::PointCloudGeometryHandlerXYZ::getGeometry
virtual void getGeometry(vtkSmartPointer< vtkPoints > &points) const
Obtain the actual point geometry for the input dataset in VTK format.
Definition: point_cloud_geometry_handlers.hpp:63
pcl::visualization::PointCloudGeometryHandler::fields_
std::vector< pcl::PCLPointField > fields_
The list of fields available for this PointCloud.
Definition: point_cloud_geometry_handlers.h:129
pcl::visualization::PointCloudGeometryHandler::field_x_idx_
int field_x_idx_
The index of the field holding the X data.
Definition: point_cloud_geometry_handlers.h:120
pcl::visualization::PointCloudGeometryHandler::capable_
bool capable_
True if this handler is capable of handling the input data, false otherwise.
Definition: point_cloud_geometry_handlers.h:117