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