Loading...
Searching...
No Matches
pcl_base.h
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2010-2012, Willow Garage, Inc.
* 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.
*
*/
#pragma once
#if defined __GNUC__
# pragma GCC system_header
#endif
// Include PCL macros such as PCL_ERROR, PCL_MAKE_ALIGNED_OPERATOR_NEW, etc
#include <pcl/memory.h>
#include <pcl/pcl_macros.h>
// Point Cloud message includes. Needed everywhere.
#include <pcl/point_cloud.h>
#include <pcl/PointIndices.h>
#include <pcl/PCLPointCloud2.h>
#include <pcl/types.h>
namespace pcl
{
// definitions used everywhere
using IndicesPtr = shared_ptr<Indices>;
using IndicesConstPtr = shared_ptr<const Indices>;
//Used to denote that a value has not been set for an index_t variable
static constexpr index_t UNAVAILABLE = static_cast<index_t>(-1);
/////////////////////////////////////////////////////////////////////////////////////////
/** \brief PCL base class. Implements methods that are used by most PCL algorithms.
* \ingroup common
*/
template <typename PointT>
class PCLBase
{
public:
using PointCloud = pcl::PointCloud<PointT>;
using PointCloudPtr = typename PointCloud::Ptr;
using PointCloudConstPtr = typename PointCloud::ConstPtr;
using PointIndicesPtr = PointIndices::Ptr;
using PointIndicesConstPtr = PointIndices::ConstPtr;
/** \brief Empty constructor. */
PCLBase ();
/** \brief Copy constructor. */
PCLBase (const PCLBase& base);
/** \brief Destructor. */
virtual ~PCLBase () = default;
/** \brief Provide a pointer to the input dataset
* \param[in] cloud the const boost shared pointer to a PointCloud message
*/
virtual void
setInputCloud (const PointCloudConstPtr &cloud);
/** \brief Get a pointer to the input point cloud dataset. */
inline PointCloudConstPtr const
getInputCloud () const { return (input_); }
/** \brief Provide a pointer to the vector of indices that represents the input data.
* \param[in] indices a pointer to the indices that represent the input data.
*/
virtual void
setIndices (const IndicesPtr &indices);
/** \brief Provide a pointer to the vector of indices that represents the input data.
* \param[in] indices a pointer to the indices that represent the input data.
*/
virtual void
setIndices (const IndicesConstPtr &indices);
/** \brief Provide a pointer to the vector of indices that represents the input data.
* \param[in] indices a pointer to the indices that represent the input data.
*/
virtual void
setIndices (const PointIndicesConstPtr &indices);
/** \brief Set the indices for the points laying within an interest region of
* the point cloud.
* \note you shouldn't call this method on unorganized point clouds!
* \param[in] row_start the offset on rows
* \param[in] col_start the offset on columns
* \param[in] nb_rows the number of rows to be considered row_start included
* \param[in] nb_cols the number of columns to be considered col_start included
*/
virtual void
setIndices (std::size_t row_start, std::size_t col_start, std::size_t nb_rows, std::size_t nb_cols);
/** \brief Get a pointer to the vector of indices used. */
inline IndicesPtr
getIndices () { return (indices_); }
/** \brief Get a pointer to the vector of indices used. */
inline IndicesConstPtr const
getIndices () const { return (indices_); }
/** \brief Override PointCloud operator[] to shorten code
* \note this method can be called instead of (*input_)[(*indices_)[pos]]
* or (*input_)[(*indices_)[pos]]
* \param[in] pos position in indices_ vector
*/
inline const PointT& operator[] (std::size_t pos) const
{
return ((*input_)[(*indices_)[pos]]);
}
protected:
/** \brief The input point cloud dataset. */
PointCloudConstPtr input_;
/** \brief A pointer to the vector of point indices to use. */
IndicesPtr indices_;
/** \brief Set to true if point indices are used. */
bool use_indices_;
/** \brief If no set of indices are given, we construct a set of fake indices that mimic the input PointCloud. */
bool fake_indices_;
/** \brief This method should get called before starting the actual computation.
*
* Internally, initCompute() does the following:
* - checks if an input dataset is given, and returns false otherwise
* - checks whether a set of input indices has been given. Returns true if yes.
* - if no input indices have been given, a fake set is created, which will be used until:
* - either a new set is given via setIndices(), or
* - a new cloud is given that has a different set of points. This will trigger an update on the set of fake indices
*/
bool
initCompute ();
/** \brief This method should get called after finishing the actual computation.
*/
bool
deinitCompute ();
public:
PCL_MAKE_ALIGNED_OPERATOR_NEW
};
/////////////////////////////////////////////////////////////////////////////////////////
template <>
class PCL_EXPORTS PCLBase<pcl::PCLPointCloud2>
{
public:
using PCLPointCloud2 = pcl::PCLPointCloud2;
using PCLPointCloud2Ptr = PCLPointCloud2::Ptr;
using PCLPointCloud2ConstPtr = PCLPointCloud2::ConstPtr;
using PointIndicesPtr = PointIndices::Ptr;
using PointIndicesConstPtr = PointIndices::ConstPtr;
/** \brief Empty constructor. */
PCLBase ();
/** \brief destructor. */
virtual ~PCLBase () = default;
/** \brief Provide a pointer to the input dataset
* \param cloud the const boost shared pointer to a PointCloud message
*/
void
setInputCloud (const PCLPointCloud2ConstPtr &cloud);
/** \brief Get a pointer to the input point cloud dataset. */
inline PCLPointCloud2ConstPtr const
getInputCloud () const { return (input_); }
/** \brief Provide a pointer to the vector of indices that represents the input data.
* \param[in] indices a pointer to the indices that represent the input data.
*/
void
setIndices (const IndicesPtr &indices);
/** \brief Provide a pointer to the vector of indices that represents the input data.
* \param[in] indices a pointer to the indices that represent the input data.
*/
void
setIndices (const PointIndicesConstPtr &indices);
/** \brief Get a pointer to the vector of indices used. */
inline IndicesPtr const
getIndices () const { return (indices_); }
protected:
/** \brief The input point cloud dataset. */
PCLPointCloud2ConstPtr input_;
/** \brief A pointer to the vector of point indices to use. */
IndicesPtr indices_;
/** \brief Set to true if point indices are used. */
bool use_indices_;
/** \brief If no set of indices are given, we construct a set of fake indices that mimic the input PointCloud. */
bool fake_indices_;
/** \brief The size of each individual field. */
std::vector<uindex_t> field_sizes_;
/** \brief The x-y-z fields indices. */
index_t x_idx_, y_idx_, z_idx_;
/** \brief The desired x-y-z field names. */
std::string x_field_name_, y_field_name_, z_field_name_;
bool initCompute ();
bool deinitCompute ();
public:
PCL_MAKE_ALIGNED_OPERATOR_NEW
};
}
#ifdef PCL_NO_PRECOMPILE
#include <pcl/impl/pcl_base.hpp>
#endif
pcl::PCLBase< pcl::PCLPointCloud2 >::fake_indices_
bool fake_indices_
If no set of indices are given, we construct a set of fake indices that mimic the input PointCloud.
Definition pcl_base.h:234
pcl::PCLBase< pcl::PCLPointCloud2 >::setIndices
void setIndices(const PointIndicesConstPtr &indices)
Provide a pointer to the vector of indices that represents the input data.
pcl::PCLBase< pcl::PCLPointCloud2 >::getIndices
IndicesPtr const getIndices() const
Get a pointer to the vector of indices used.
Definition pcl_base.h:221
pcl::PCLBase< pcl::PCLPointCloud2 >::field_sizes_
std::vector< uindex_t > field_sizes_
The size of each individual field.
Definition pcl_base.h:237
pcl::PCLBase< pcl::PCLPointCloud2 >::PCLPointCloud2Ptr
PCLPointCloud2::Ptr PCLPointCloud2Ptr
Definition pcl_base.h:185
pcl::PCLBase< pcl::PCLPointCloud2 >::setIndices
void setIndices(const IndicesPtr &indices)
Provide a pointer to the vector of indices that represents the input data.
pcl::PCLBase< pcl::PCLPointCloud2 >::use_indices_
bool use_indices_
Set to true if point indices are used.
Definition pcl_base.h:231
pcl::PCLBase< pcl::PCLPointCloud2 >::input_
PCLPointCloud2ConstPtr input_
The input point cloud dataset.
Definition pcl_base.h:225
pcl::PCLBase< pcl::PCLPointCloud2 >::indices_
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition pcl_base.h:228
pcl::PCLBase< pcl::PCLPointCloud2 >::y_field_name_
std::string y_field_name_
Definition pcl_base.h:243
pcl::PCLBase< pcl::PCLPointCloud2 >::initCompute
bool initCompute()
pcl::PCLBase< pcl::PCLPointCloud2 >::PCLBase
PCLBase()
Empty constructor.
pcl::PCLBase< pcl::PCLPointCloud2 >::PointIndicesConstPtr
PointIndices::ConstPtr PointIndicesConstPtr
Definition pcl_base.h:189
pcl::PCLBase< pcl::PCLPointCloud2 >::z_field_name_
std::string z_field_name_
Definition pcl_base.h:243
pcl::PCLBase< pcl::PCLPointCloud2 >::x_field_name_
std::string x_field_name_
The desired x-y-z field names.
Definition pcl_base.h:243
pcl::PCLBase< pcl::PCLPointCloud2 >::~PCLBase
virtual ~PCLBase()=default
destructor.
pcl::PCLBase< pcl::PCLPointCloud2 >::setInputCloud
void setInputCloud(const PCLPointCloud2ConstPtr &cloud)
Provide a pointer to the input dataset.
pcl::PCLBase< pcl::PCLPointCloud2 >::PointIndicesPtr
PointIndices::Ptr PointIndicesPtr
Definition pcl_base.h:188
pcl::PCLBase< pcl::PCLPointCloud2 >::getInputCloud
PCLPointCloud2ConstPtr const getInputCloud() const
Get a pointer to the input point cloud dataset.
Definition pcl_base.h:205
pcl::PCLBase< pcl::PCLPointCloud2 >::y_idx_
index_t y_idx_
Definition pcl_base.h:240
pcl::PCLBase< pcl::PCLPointCloud2 >::deinitCompute
bool deinitCompute()
pcl::PCLBase< pcl::PCLPointCloud2 >::z_idx_
index_t z_idx_
Definition pcl_base.h:240
pcl::PCLBase< pcl::PCLPointCloud2 >::x_idx_
index_t x_idx_
The x-y-z fields indices.
Definition pcl_base.h:240
pcl::PCLBase< pcl::PCLPointCloud2 >::PCLPointCloud2ConstPtr
PCLPointCloud2::ConstPtr PCLPointCloud2ConstPtr
Definition pcl_base.h:186
pcl::PCLBase< pcl::PCLPointCloud2 >::PCLPointCloud2
pcl::PCLPointCloud2 PCLPointCloud2
Definition pcl_base.h:184
pcl::PCLBase< PointInT >::input_
PointCloudConstPtr input_
Definition pcl_base.h:147
pcl::PCLBase::setInputCloud
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
Definition pcl_base.hpp:65
pcl::PCLBase::operator[]
const PointT & operator[](std::size_t pos) const
Override PointCloud operator[] to shorten code.
Definition pcl_base.h:140
pcl::PCLBase::setIndices
virtual void setIndices(const IndicesConstPtr &indices)
Provide a pointer to the vector of indices that represents the input data.
Definition pcl_base.hpp:81
pcl::PCLBase::PointCloudPtr
typename PointCloud::Ptr PointCloudPtr
Definition pcl_base.h:73
pcl::PCLBase::setIndices
virtual void setIndices(std::size_t row_start, std::size_t col_start, std::size_t nb_rows, std::size_t nb_cols)
Set the indices for the points laying within an interest region of the point cloud.
Definition pcl_base.hpp:99
pcl::PCLBase::PointCloudConstPtr
typename PointCloud::ConstPtr PointCloudConstPtr
Definition pcl_base.h:74
pcl::PCLBase::PointCloud
pcl::PointCloud< PointT > PointCloud
Definition pcl_base.h:72
pcl::PCLBase::PCLBase
PCLBase(const PCLBase &base)
Copy constructor.
Definition pcl_base.hpp:55
pcl::PCLBase::getInputCloud
PointCloudConstPtr const getInputCloud() const
Get a pointer to the input point cloud dataset.
Definition pcl_base.h:96
pcl::PCLBase< PointInT >::indices_
IndicesPtr indices_
Definition pcl_base.h:150
pcl::PCLBase::setIndices
virtual void setIndices(const IndicesPtr &indices)
Provide a pointer to the vector of indices that represents the input data.
Definition pcl_base.hpp:72
pcl::PCLBase::getIndices
IndicesConstPtr const getIndices() const
Get a pointer to the vector of indices used.
Definition pcl_base.h:133
pcl::PCLBase::initCompute
bool initCompute()
This method should get called before starting the actual computation.
Definition pcl_base.hpp:138
pcl::PCLBase::~PCLBase
virtual ~PCLBase()=default
Destructor.
pcl::PCLBase< PointInT >::use_indices_
bool use_indices_
Definition pcl_base.h:153
pcl::PCLBase< PointInT >::fake_indices_
bool fake_indices_
Definition pcl_base.h:156
pcl::PCLBase::PointIndicesConstPtr
PointIndices::ConstPtr PointIndicesConstPtr
Definition pcl_base.h:77
pcl::PCLBase::getIndices
IndicesPtr getIndices()
Get a pointer to the vector of indices used.
Definition pcl_base.h:129
pcl::PCLBase::PCLBase
PCLBase()
Empty constructor.
Definition pcl_base.hpp:46
pcl::PCLBase::setIndices
virtual void setIndices(const PointIndicesConstPtr &indices)
Provide a pointer to the vector of indices that represents the input data.
Definition pcl_base.hpp:90
pcl::PCLBase::deinitCompute
bool deinitCompute()
This method should get called after finishing the actual computation.
Definition pcl_base.hpp:175
pcl::PCLBase::PointIndicesPtr
PointIndices::Ptr PointIndicesPtr
Definition pcl_base.h:76
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition point_cloud.h:174
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition point_cloud.h:414
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition point_cloud.h:415
PCL_MAKE_ALIGNED_OPERATOR_NEW
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition memory.h:86
memory.h
Defines functions, macros and traits for allocating and using memory.
pcl
Definition convolution.h:46
pcl::index_t
detail::int_type_t< detail::index_type_size, detail::index_type_signed > index_t
Type used for an index in PCL.
Definition types.h:112
pcl::UNAVAILABLE
static constexpr index_t UNAVAILABLE
Definition pcl_base.h:62
pcl::IndicesPtr
shared_ptr< Indices > IndicesPtr
Definition pcl_base.h:58
pcl::IndicesConstPtr
shared_ptr< const Indices > IndicesConstPtr
Definition pcl_base.h:59
pcl_macros.h
Defines all the PCL and non-PCL macros used.
pcl::PCLPointCloud2
Definition PCLPointCloud2.h:17
pcl::PCLPointCloud2::Ptr
shared_ptr< ::pcl::PCLPointCloud2 > Ptr
Definition PCLPointCloud2.h:35
pcl::PCLPointCloud2::ConstPtr
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
Definition PCLPointCloud2.h:36
pcl::PointIndices::Ptr
shared_ptr< ::pcl::PointIndices > Ptr
Definition PointIndices.h:13
pcl::PointIndices::ConstPtr
shared_ptr< const ::pcl::PointIndices > ConstPtr
Definition PointIndices.h:14
types.h
Defines basic non-point types used by PCL.