Point Cloud Library (PCL)  1.8.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 #ifndef PCL_PCL_BASE_H_
39 #define PCL_PCL_BASE_H_
40 
41 #if defined __GNUC__
42 # pragma GCC system_header
43 #endif
44 
45 // Include PCL macros such as PCL_ERROR, 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  typedef boost::shared_ptr <std::vector<int> > IndicesPtr;
61  typedef boost::shared_ptr <const std::vector<int> > IndicesConstPtr;
62 
63  /////////////////////////////////////////////////////////////////////////////////////////
64  /** \brief PCL base class. Implements methods that are used by most PCL algorithms.
65  * \ingroup common
66  */
67  template <typename PointT>
68  class PCLBase
69  {
70  public:
72  typedef typename PointCloud::Ptr PointCloudPtr;
74 
75  typedef boost::shared_ptr<PointIndices> PointIndicesPtr;
76  typedef boost::shared_ptr<PointIndices const> PointIndicesConstPtr;
77 
78  /** \brief Empty constructor. */
79  PCLBase ();
80 
81  /** \brief Copy constructor. */
82  PCLBase (const PCLBase& base);
83 
84  /** \brief Destructor. */
85  virtual ~PCLBase ()
86  {
87  input_.reset ();
88  indices_.reset ();
89  }
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 (size_t row_start, size_t col_start, size_t nb_rows, size_t nb_cols);
129 
130  /** \brief Get a pointer to the vector of indices used. */
131  inline IndicesPtr const
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_->points[(*indices_)[pos]]
141  * \param[in] pos position in indices_ vector
142  */
143  inline const PointT& operator[] (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:
179  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
180  };
181 
182  /////////////////////////////////////////////////////////////////////////////////////////
183  template <>
184  class PCL_EXPORTS PCLBase<pcl::PCLPointCloud2>
185  {
186  public:
188  typedef boost::shared_ptr<PCLPointCloud2> PCLPointCloud2Ptr;
189  typedef boost::shared_ptr<PCLPointCloud2 const> PCLPointCloud2ConstPtr;
190 
191  typedef boost::shared_ptr<PointIndices> PointIndicesPtr;
192  typedef boost::shared_ptr<PointIndices const> PointIndicesConstPtr;
193 
194  /** \brief Empty constructor. */
195  PCLBase ();
196 
197  /** \brief destructor. */
198  virtual ~PCLBase()
199  {
200  input_.reset ();
201  indices_.reset ();
202  }
203 
204  /** \brief Provide a pointer to the input dataset
205  * \param cloud the const boost shared pointer to a PointCloud message
206  */
207  void
208  setInputCloud (const PCLPointCloud2ConstPtr &cloud);
209 
210  /** \brief Get a pointer to the input point cloud dataset. */
211  inline PCLPointCloud2ConstPtr const
212  getInputCloud () { return (input_); }
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 IndicesPtr &indices);
219 
220  /** \brief Provide a pointer to the vector of indices that represents the input data.
221  * \param[in] indices a pointer to the indices that represent the input data.
222  */
223  void
224  setIndices (const PointIndicesConstPtr &indices);
225 
226  /** \brief Get a pointer to the vector of indices used. */
227  inline IndicesPtr const
228  getIndices () { return (indices_); }
229 
230  protected:
231  /** \brief The input point cloud dataset. */
233 
234  /** \brief A pointer to the vector of point indices to use. */
236 
237  /** \brief Set to true if point indices are used. */
239 
240  /** \brief If no set of indices are given, we construct a set of fake indices that mimic the input PointCloud. */
242 
243  /** \brief The size of each individual field. */
244  std::vector<int> field_sizes_;
245 
246  /** \brief The x-y-z fields indices. */
247  int x_idx_, y_idx_, z_idx_;
248 
249  /** \brief The desired x-y-z field names. */
250  std::string x_field_name_, y_field_name_, z_field_name_;
251 
252  bool initCompute ();
253  bool deinitCompute ();
254  public:
255  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
256  };
257 }
258 
259 #ifdef PCL_NO_PRECOMPILE
260 #include <pcl/impl/pcl_base.hpp>
261 #endif
262 
263 #endif //#ifndef PCL_PCL_BASE_H_
IndicesPtr const getIndices()
Get a pointer to the vector of indices used.
Definition: pcl_base.h:228
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:73
IndicesPtr const getIndices()
Get a pointer to the vector of indices used.
Definition: pcl_base.h:132
boost::shared_ptr< PCLPointCloud2 > PCLPointCloud2Ptr
Definition: pcl_base.h:188
pcl::PCLPointCloud2 PCLPointCloud2
Definition: pcl_base.h:187
std::vector< int > field_sizes_
The size of each individual field.
Definition: pcl_base.h:244
boost::shared_ptr< std::vector< int > > IndicesPtr
Definition: pcl_base.h:60
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
PCLPointCloud2ConstPtr const getInputCloud()
Get a pointer to the input point cloud dataset.
Definition: pcl_base.h:212
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition: pcl_base.h:153
bool use_indices_
Set to true if point indices are used.
Definition: pcl_base.h:156
boost::shared_ptr< ::pcl::PCLPointCloud2 const > PCLPointCloud2ConstPtr
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:241
boost::shared_ptr< PointIndices > PointIndicesPtr
Definition: pcl_base.h:75
IndicesConstPtr const getIndices() const
Get a pointer to the vector of indices used.
Definition: pcl_base.h:136
virtual ~PCLBase()
destructor.
Definition: pcl_base.h:198
bool initCompute()
This method should get called before starting the actual computation.
Definition: pcl_base.hpp:139
PointCloudConstPtr const getInputCloud() const
Get a pointer to the input point cloud dataset.
Definition: pcl_base.h:99
boost::shared_ptr< PointIndices const > PointIndicesConstPtr
Definition: pcl_base.h:192
const PointT & operator[](size_t pos) const
Override PointCloud operator[] to shorten code.
Definition: pcl_base.h:143
PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:72
boost::shared_ptr< PCLPointCloud2 const > PCLPointCloud2ConstPtr
Definition: pcl_base.h:189
pcl::PointCloud< PointT > PointCloud
Definition: pcl_base.h:71
boost::shared_ptr< PointIndices > PointIndicesPtr
Definition: pcl_base.h:191
boost::shared_ptr< PointIndices const > PointIndicesConstPtr
Definition: pcl_base.h:76
PCL base class.
Definition: pcl_base.h:68
bool use_indices_
Set to true if point indices are used.
Definition: pcl_base.h:238
boost::shared_ptr< ::pcl::PointIndices const > PointIndicesConstPtr
Definition: PointIndices.h:27
bool deinitCompute()
This method should get called after finishing the actual computation.
Definition: pcl_base.hpp:174
virtual void setIndices(const IndicesPtr &indices)
Provide a pointer to the vector of indices that represents the input data.
Definition: pcl_base.hpp:73
PCLBase()
Empty constructor.
Definition: pcl_base.hpp:46
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition: pcl_base.h:235
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
Definition: pcl_base.hpp:66
boost::shared_ptr< const std::vector< int > > IndicesConstPtr
Definition: pcl_base.h:61
PointCloudConstPtr input_
The input point cloud dataset.
Definition: pcl_base.h:150
A point structure representing Euclidean xyz coordinates, and the RGB color.
PCLPointCloud2ConstPtr input_
The input point cloud dataset.
Definition: pcl_base.h:232
virtual ~PCLBase()
Destructor.
Definition: pcl_base.h:85
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