Point Cloud Library (PCL)  1.11.0-dev
pcl_base.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2012, 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 the copyright holder(s) 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 
41 #if defined __GNUC__
42 # pragma GCC system_header
43 #endif
44 
45 // Include PCL macros such as PCL_ERROR, PCL_MAKE_ALIGNED_OPERATOR_NEW, etc
46 #include <pcl/memory.h>
47 #include <pcl/pcl_macros.h>
48 
49 #include <Eigen/StdVector>
50 #include <Eigen/Core>
51 
52 // Point Cloud message includes. Needed everywhere.
53 #include <pcl/point_cloud.h>
54 #include <pcl/PointIndices.h>
55 #include <pcl/PCLPointCloud2.h>
56 #include <pcl/types.h>
57 
58 namespace pcl
59 {
60  // definitions used everywhere
61  using IndicesPtr = shared_ptr<Indices>;
62  using IndicesConstPtr = shared_ptr<const Indices>;
63 
64  //Used to denote that a value has not been set for an index_t variable
65  static constexpr index_t UNAVAILABLE = static_cast<index_t>(-1);
66 
67  /////////////////////////////////////////////////////////////////////////////////////////
68  /** \brief PCL base class. Implements methods that are used by most PCL algorithms.
69  * \ingroup common
70  */
71  template <typename PointT>
72  class PCLBase
73  {
74  public:
76  using PointCloudPtr = typename PointCloud::Ptr;
78 
81 
82  /** \brief Empty constructor. */
83  PCLBase ();
84 
85  /** \brief Copy constructor. */
86  PCLBase (const PCLBase& base);
87 
88  /** \brief Destructor. */
89  virtual ~PCLBase () = default;
90 
91  /** \brief Provide a pointer to the input dataset
92  * \param[in] cloud the const boost shared pointer to a PointCloud message
93  */
94  virtual void
95  setInputCloud (const PointCloudConstPtr &cloud);
96 
97  /** \brief Get a pointer to the input point cloud dataset. */
98  inline PointCloudConstPtr const
99  getInputCloud () const { return (input_); }
100 
101  /** \brief Provide a pointer to the vector of indices that represents the input data.
102  * \param[in] indices a pointer to the indices that represent the input data.
103  */
104  virtual void
105  setIndices (const IndicesPtr &indices);
106 
107  /** \brief Provide a pointer to the vector of indices that represents the input data.
108  * \param[in] indices a pointer to the indices that represent the input data.
109  */
110  virtual void
111  setIndices (const IndicesConstPtr &indices);
112 
113  /** \brief Provide a pointer to the vector of indices that represents the input data.
114  * \param[in] indices a pointer to the indices that represent the input data.
115  */
116  virtual void
117  setIndices (const PointIndicesConstPtr &indices);
118 
119  /** \brief Set the indices for the points laying within an interest region of
120  * the point cloud.
121  * \note you shouldn't call this method on unorganized point clouds!
122  * \param[in] row_start the offset on rows
123  * \param[in] col_start the offset on columns
124  * \param[in] nb_rows the number of rows to be considered row_start included
125  * \param[in] nb_cols the number of columns to be considered col_start included
126  */
127  virtual void
128  setIndices (std::size_t row_start, std::size_t col_start, std::size_t nb_rows, std::size_t nb_cols);
129 
130  /** \brief Get a pointer to the vector of indices used. */
131  inline IndicesPtr
132  getIndices () { return (indices_); }
133 
134  /** \brief Get a pointer to the vector of indices used. */
135  inline IndicesConstPtr const
136  getIndices () const { return (indices_); }
137 
138  /** \brief Override PointCloud operator[] to shorten code
139  * \note this method can be called instead of (*input_)[(*indices_)[pos]]
140  * or (*input_)[(*indices_)[pos]]
141  * \param[in] pos position in indices_ vector
142  */
143  inline const PointT& operator[] (std::size_t pos) const
144  {
145  return ((*input_)[(*indices_)[pos]]);
146  }
147 
148  protected:
149  /** \brief The input point cloud dataset. */
151 
152  /** \brief A pointer to the vector of point indices to use. */
154 
155  /** \brief Set to true if point indices are used. */
157 
158  /** \brief If no set of indices are given, we construct a set of fake indices that mimic the input PointCloud. */
160 
161  /** \brief This method should get called before starting the actual computation.
162  *
163  * Internally, initCompute() does the following:
164  * - checks if an input dataset is given, and returns false otherwise
165  * - checks whether a set of input indices has been given. Returns true if yes.
166  * - if no input indices have been given, a fake set is created, which will be used until:
167  * - either a new set is given via setIndices(), or
168  * - a new cloud is given that has a different set of points. This will trigger an update on the set of fake indices
169  */
170  bool
171  initCompute ();
172 
173  /** \brief This method should get called after finishing the actual computation.
174  */
175  bool
176  deinitCompute ();
177 
178  public:
180  };
181 
182  /////////////////////////////////////////////////////////////////////////////////////////
183  template <>
185  {
186  public:
190 
193 
194  /** \brief Empty constructor. */
195  PCLBase ();
196 
197  /** \brief destructor. */
198  virtual ~PCLBase () = default;
199 
200  /** \brief Provide a pointer to the input dataset
201  * \param cloud the const boost shared pointer to a PointCloud message
202  */
203  void
204  setInputCloud (const PCLPointCloud2ConstPtr &cloud);
205 
206  /** \brief Get a pointer to the input point cloud dataset. */
207  inline PCLPointCloud2ConstPtr const
208  getInputCloud () const { return (input_); }
209 
210  /** \brief Provide a pointer to the vector of indices that represents the input data.
211  * \param[in] indices a pointer to the indices that represent the input data.
212  */
213  void
214  setIndices (const IndicesPtr &indices);
215 
216  /** \brief Provide a pointer to the vector of indices that represents the input data.
217  * \param[in] indices a pointer to the indices that represent the input data.
218  */
219  void
220  setIndices (const PointIndicesConstPtr &indices);
221 
222  /** \brief Get a pointer to the vector of indices used. */
223  inline IndicesPtr const
224  getIndices () const { return (indices_); }
225 
226  protected:
227  /** \brief The input point cloud dataset. */
229 
230  /** \brief A pointer to the vector of point indices to use. */
232 
233  /** \brief Set to true if point indices are used. */
235 
236  /** \brief If no set of indices are given, we construct a set of fake indices that mimic the input PointCloud. */
238 
239  /** \brief The size of each individual field. */
240  std::vector<int> field_sizes_;
241 
242  /** \brief The x-y-z fields indices. */
243  index_t x_idx_, y_idx_, z_idx_;
244 
245  /** \brief The desired x-y-z field names. */
246  std::string x_field_name_, y_field_name_, z_field_name_;
247 
248  bool initCompute ();
249  bool deinitCompute ();
250  public:
252  };
253 }
254 
255 #ifdef PCL_NO_PRECOMPILE
256 #include <pcl/impl/pcl_base.hpp>
257 #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:237
pcl::UNAVAILABLE
static constexpr index_t UNAVAILABLE
Definition: pcl_base.h:65
pcl_macros.h
Defines all the PCL and non-PCL macros used.
pcl
Definition: convolution.h:46
pcl::IndicesPtr
shared_ptr< Indices > IndicesPtr
Definition: pcl_base.h:61
pcl::PCLBase< PointXYZRGB >::PointCloudConstPtr
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:77
pcl::PCLBase::PCLBase
PCLBase()
Empty constructor.
Definition: pcl_base.hpp:46
pcl::PCLBase::input_
PointCloudConstPtr input_
The input point cloud dataset.
Definition: pcl_base.h:150
pcl::PCLBase< PointXYZRGB >::PointCloudPtr
typename PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:76
pcl::PCLPointCloud2::Ptr
shared_ptr< ::pcl::PCLPointCloud2 > Ptr
Definition: PCLPointCloud2.h:34
pcl::PCLBase< pcl::PCLPointCloud2 >::use_indices_
bool use_indices_
Set to true if point indices are used.
Definition: pcl_base.h:234
types.h
Defines basic non-point types used by PCL.
pcl::IndicesConstPtr
shared_ptr< const Indices > IndicesConstPtr
Definition: pcl_base.h:62
pcl::PCLBase::getIndices
IndicesPtr getIndices()
Get a pointer to the vector of indices used.
Definition: pcl_base.h:132
pcl::PCLBase::operator[]
const PointT & operator[](std::size_t pos) const
Override PointCloud operator[] to shorten code.
Definition: pcl_base.h:143
pcl::PCLBase
PCL base class.
Definition: pcl_base.h:72
pcl::PCLBase< PointXYZRGB >::PointIndicesConstPtr
PointIndices::ConstPtr PointIndicesConstPtr
Definition: pcl_base.h:80
pcl::PCLBase< pcl::PCLPointCloud2 >::PCLPointCloud2ConstPtr
PCLPointCloud2::ConstPtr PCLPointCloud2ConstPtr
Definition: pcl_base.h:189
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: projection_matrix.h:53
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:120
pcl::PCLBase< pcl::PCLPointCloud2 >::getInputCloud
const PCLPointCloud2ConstPtr getInputCloud() const
Get a pointer to the input point cloud dataset.
Definition: pcl_base.h:208
pcl::PCLBase::use_indices_
bool use_indices_
Set to true if point indices are used.
Definition: pcl_base.h:156
pcl::PCLBase::setInputCloud
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
Definition: pcl_base.hpp:65
pcl::PointXYZRGB
A point structure representing Euclidean xyz coordinates, and the RGB color.
Definition: point_types.hpp:628
pcl::PCLBase< pcl::PCLPointCloud2 >::indices_
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition: pcl_base.h:231
pcl::PointIndices::ConstPtr
shared_ptr< const ::pcl::PointIndices > ConstPtr
Definition: PointIndices.h:16
pcl::PCLBase< pcl::PCLPointCloud2 >::PCLPointCloud2Ptr
PCLPointCloud2::Ptr PCLPointCloud2Ptr
Definition: pcl_base.h:188
pcl::PointIndicesConstPtr
PointIndices::ConstPtr PointIndicesConstPtr
Definition: PointIndices.h:27
pcl::PCLPointCloud2::ConstPtr
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
Definition: PCLPointCloud2.h:35
pcl::PCLBase< pcl::PCLPointCloud2 >::input_
PCLPointCloud2ConstPtr input_
The input point cloud dataset.
Definition: pcl_base.h:228
pcl::PCLBase< pcl::PCLPointCloud2 >::field_sizes_
std::vector< int > field_sizes_
The size of each individual field.
Definition: pcl_base.h:240
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_MAKE_ALIGNED_OPERATOR_NEW
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
pcl::PCLBase< pcl::PCLPointCloud2 >::PointIndicesPtr
PointIndices::Ptr PointIndicesPtr
Definition: pcl_base.h:191
pcl::PCLBase::~PCLBase
virtual ~PCLBase()=default
Destructor.
pcl::PointIndices::Ptr
shared_ptr< ::pcl::PointIndices > Ptr
Definition: PointIndices.h:15
pcl::PCLPointCloud2
Definition: PCLPointCloud2.h:15
pcl::PCLBase< pcl::PCLPointCloud2 >::z_field_name_
std::string z_field_name_
Definition: pcl_base.h:246
pcl::PCLBase::getInputCloud
const PointCloudConstPtr getInputCloud() const
Get a pointer to the input point cloud dataset.
Definition: pcl_base.h:99
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:429
pcl::PCLBase::deinitCompute
bool deinitCompute()
This method should get called after finishing the actual computation.
Definition: pcl_base.hpp:171
pcl::PCLBase::indices_
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition: pcl_base.h:153
pcl::PCLBase< pcl::PCLPointCloud2 >::PointIndicesConstPtr
PointIndices::ConstPtr PointIndicesConstPtr
Definition: pcl_base.h:192
pcl::PCLBase::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:159
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:430
pcl::PCLBase< pcl::PCLPointCloud2 >::z_idx_
index_t z_idx_
Definition: pcl_base.h:243
pcl::PCLBase< PointXYZRGB >::PointIndicesPtr
PointIndices::Ptr PointIndicesPtr
Definition: pcl_base.h:79
pcl::PCLBase::initCompute
bool initCompute()
This method should get called before starting the actual computation.
Definition: pcl_base.hpp:138
pcl::PCLBase::getIndices
const IndicesConstPtr getIndices() const
Get a pointer to the vector of indices used.
Definition: pcl_base.h:136
pcl::PCLBase< pcl::PCLPointCloud2 >::getIndices
const IndicesPtr getIndices() const
Get a pointer to the vector of indices used.
Definition: pcl_base.h:224
memory.h
Defines functions, macros and traits for allocating and using memory.
PCL_EXPORTS
#define PCL_EXPORTS
Definition: pcl_macros.h:331