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