Loading...
Searching...
No Matches
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>
namespace pcl
{
namespace visualization
{
template <typename PointT>
PointCloudGeometryHandlerXYZ<PointT>::PointCloudGeometryHandlerXYZ (const PointCloudConstPtr &cloud)
: PointCloudGeometryHandler<PointT>::PointCloudGeometryHandler (cloud)
{
field_x_idx_ = pcl::getFieldIndex<PointT> ("x", fields_);
if (field_x_idx_ == UNAVAILABLE)
return;
field_y_idx_ = pcl::getFieldIndex<PointT> ("y", fields_);
if (field_y_idx_ == UNAVAILABLE)
return;
field_z_idx_ = pcl::getFieldIndex<PointT> ("z", fields_);
if (field_z_idx_ == UNAVAILABLE)
return;
capable_ = true;
}
template <typename PointT> void
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_->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_)[i].x;
pts[i * 3 + 1] = (*cloud_)[i].y;
pts[i * 3 + 2] = (*cloud_)[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 (!std::isfinite ((*cloud_)[i].x) || !std::isfinite ((*cloud_)[i].y) || !std::isfinite ((*cloud_)[i].z))
continue;
pts[j * 3 + 0] = (*cloud_)[i].x;
pts[j * 3 + 1] = (*cloud_)[i].y;
pts[j * 3 + 2] = (*cloud_)[i].z;
// Set j and increment
j++;
}
data->SetArray (&pts[0], j * 3, 0);
points->SetData (data);
}
}
template <typename PointT>
PointCloudGeometryHandlerSurfaceNormal<PointT>::PointCloudGeometryHandlerSurfaceNormal (const PointCloudConstPtr &cloud)
: PointCloudGeometryHandler<PointT>::PointCloudGeometryHandler (cloud)
{
field_x_idx_ = pcl::getFieldIndex<PointT> ("normal_x", fields_);
if (field_x_idx_ == UNAVAILABLE)
return;
field_y_idx_ = pcl::getFieldIndex<PointT> ("normal_y", fields_);
if (field_y_idx_ == UNAVAILABLE)
return;
field_z_idx_ = pcl::getFieldIndex<PointT> ("normal_z", fields_);
if (field_z_idx_ == UNAVAILABLE)
return;
capable_ = true;
}
template <typename PointT> void
PointCloudGeometryHandlerSurfaceNormal<PointT>::getGeometry (vtkSmartPointer<vtkPoints> &points) const
{
if (!capable_)
return;
if (!points)
points = vtkSmartPointer<vtkPoints>::New ();
points->SetDataTypeToFloat ();
points->SetNumberOfPoints (cloud_->size ());
// Add all points
double p[3];
for (vtkIdType i = 0; i < static_cast<vtkIdType> (cloud_->size ()); ++i)
{
p[0] = (*cloud_)[i].normal[0];
p[1] = (*cloud_)[i].normal[1];
p[2] = (*cloud_)[i].normal[2];
points->SetPoint (i, p);
}
}
} // namespace visualization
} // namespace pcl
#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::PointCloudGeometryHandler
Base handler class for PointCloud geometry.
Definition point_cloud_geometry_handlers.h:63
pcl::visualization::PointCloudGeometryHandler::fields_
std::vector< pcl::PCLPointField > fields_
The list of fields available for this PointCloud.
Definition point_cloud_geometry_handlers.h:130
pcl::visualization::PointCloudGeometryHandler::field_y_idx_
index_t field_y_idx_
The index of the field holding the Y data.
Definition point_cloud_geometry_handlers.h:124
pcl::visualization::PointCloudGeometryHandler::field_z_idx_
index_t field_z_idx_
The index of the field holding the Z data.
Definition point_cloud_geometry_handlers.h:127
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:118
pcl::visualization::PointCloudGeometryHandler::field_x_idx_
index_t field_x_idx_
The index of the field holding the X data.
Definition point_cloud_geometry_handlers.h:121
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:138
pcl::visualization::PointCloudGeometryHandlerSurfaceNormal::PointCloudGeometryHandlerSurfaceNormal
PointCloudGeometryHandlerSurfaceNormal(const PointCloudConstPtr &cloud)
Constructor.
Definition point_cloud_geometry_handlers.hpp:121
pcl::visualization::PointCloudGeometryHandlerSurfaceNormal::PointCloudConstPtr
typename PointCloud::ConstPtr PointCloudConstPtr
Definition point_cloud_geometry_handlers.h:190
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:70
pcl::visualization::PointCloudGeometryHandlerXYZ::PointCloudGeometryHandlerXYZ
PointCloudGeometryHandlerXYZ(const PointCloudConstPtr &cloud)
Constructor.
Definition point_cloud_geometry_handlers.hpp:53
pcl::visualization::PointCloudGeometryHandlerXYZ::PointCloudConstPtr
typename PointCloud::ConstPtr PointCloudConstPtr
Definition point_cloud_geometry_handlers.h:145
vtkSmartPointer
Definition actor_map.h:51
pcl
Definition convolution.h:46
pcl::UNAVAILABLE
static constexpr index_t UNAVAILABLE
Definition pcl_base.h:62
pcl_macros.h
Defines all the PCL and non-PCL macros used.
pcl::PointXYZRGB
A point structure representing Euclidean xyz coordinates, and the RGB color.
Definition point_types.hpp:594