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