Point Cloud Library (PCL)
1.15.1
Toggle main menu visibility
Loading...
Searching...
No Matches
pcl
impl
pcl_base.hpp
1
/*
2
* Software License Agreement (BSD License)
3
*
4
* Point Cloud Library (PCL) - www.pointclouds.org
5
* Copyright (c) 2012-, Open Perception, Inc.
6
*
7
* All rights reserved.
8
*
9
* Redistribution and use in source and binary forms, with or without
10
* modification, are permitted provided that the following conditions
11
* are met:
12
*
13
* * Redistributions of source code must retain the above copyright
14
* notice, this list of conditions and the following disclaimer.
15
* * Redistributions in binary form must reproduce the above
16
* copyright notice, this list of conditions and the following
17
* disclaimer in the documentation and/or other materials provided
18
* with the distribution.
19
* * Neither the name of the copyright holder(s) nor the names of its
20
* contributors may be used to endorse or promote products derived
21
* from this software without specific prior written permission.
22
*
23
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
* POSSIBILITY OF SUCH DAMAGE.
35
*
36
*/
37
#ifndef PCL_PCL_IMPL_BASE_HPP_
38
#define PCL_PCL_IMPL_BASE_HPP_
39
40
#include <pcl/pcl_base.h>
41
#include <pcl/console/print.h>
42
#include <cstddef>
43
44
///////////////////////////////////////////////////////////////////////////////////////////
45
template
<
typename
Po
int
T>
46
pcl::PCLBase<PointT>::PCLBase
()
47
:
input_
()
48
,
use_indices_
(false)
49
,
fake_indices_
(false)
50
{
51
}
52
53
///////////////////////////////////////////////////////////////////////////////////////////
54
template
<
typename
Po
int
T>
55
pcl::PCLBase<PointT>::PCLBase
(
const
PCLBase
& base)
56
:
input_
(base.
input_
)
57
,
indices_
(base.
indices_
)
58
,
use_indices_
(base.
use_indices_
)
59
,
fake_indices_
(base.
fake_indices_
)
60
{
61
}
62
63
///////////////////////////////////////////////////////////////////////////////////////////
64
template
<
typename
Po
int
T>
void
65
pcl::PCLBase<PointT>::setInputCloud
(
const
PointCloudConstPtr
&cloud)
66
{
67
input_
= cloud;
68
}
69
70
///////////////////////////////////////////////////////////////////////////////////////////
71
template
<
typename
Po
int
T>
void
72
pcl::PCLBase<PointT>::setIndices
(
const
IndicesPtr
&indices)
73
{
74
indices_
= indices;
75
fake_indices_
=
false
;
76
use_indices_
=
true
;
77
}
78
79
///////////////////////////////////////////////////////////////////////////////////////////
80
template
<
typename
Po
int
T>
void
81
pcl::PCLBase<PointT>::setIndices
(
const
IndicesConstPtr
&indices)
82
{
83
indices_
.reset (
new
Indices
(*indices));
84
fake_indices_
=
false
;
85
use_indices_
=
true
;
86
}
87
88
///////////////////////////////////////////////////////////////////////////////////////////
89
template
<
typename
Po
int
T>
void
90
pcl::PCLBase<PointT>::setIndices
(
const
PointIndicesConstPtr
&indices)
91
{
92
indices_
.reset (
new
Indices
(indices->indices));
93
fake_indices_
=
false
;
94
use_indices_
=
true
;
95
}
96
97
///////////////////////////////////////////////////////////////////////////////////////////
98
template
<
typename
Po
int
T>
void
99
pcl::PCLBase<PointT>::setIndices
(std::size_t row_start, std::size_t col_start, std::size_t nb_rows, std::size_t nb_cols)
100
{
101
if
((nb_rows >
input_
->height) || (row_start >
input_
->height))
102
{
103
PCL_ERROR (
"[PCLBase::setIndices] cloud is only %d height\n"
,
input_
->height);
104
return
;
105
}
106
107
if
((nb_cols > input_->width) || (col_start > input_->width))
108
{
109
PCL_ERROR (
"[PCLBase::setIndices] cloud is only %d width\n"
, input_->width);
110
return
;
111
}
112
113
std::size_t row_end = row_start + nb_rows;
114
if
(row_end > input_->height)
115
{
116
PCL_ERROR (
"[PCLBase::setIndices] %d is out of rows range %d\n"
, row_end, input_->height);
117
return
;
118
}
119
120
std::size_t col_end = col_start + nb_cols;
121
if
(col_end > input_->width)
122
{
123
PCL_ERROR (
"[PCLBase::setIndices] %d is out of columns range %d\n"
, col_end, input_->width);
124
return
;
125
}
126
127
indices_.reset (
new
Indices
);
128
indices_->reserve (nb_cols * nb_rows);
129
for
(std::size_t i = row_start; i < row_end; i++)
130
for
(std::size_t j = col_start; j < col_end; j++)
131
indices_->push_back (
static_cast<
int
>
((i * input_->width) + j));
132
fake_indices_ =
false
;
133
use_indices_ =
true
;
134
}
135
136
///////////////////////////////////////////////////////////////////////////////////////////
137
template
<
typename
Po
int
T>
bool
138
pcl::PCLBase<PointT>::initCompute
()
139
{
140
// Check if input was set
141
if
(!
input_
)
142
{
143
PCL_ERROR (
"[initCompute] No input set.\n"
);
144
return
(
false
);
145
}
146
147
// If no point indices have been given, construct a set of indices for the entire input point cloud
148
if
(!
indices_
)
149
{
150
fake_indices_
=
true
;
151
indices_
.reset (
new
Indices
);
152
}
153
154
// If we have a set of fake indices, but they do not match the number of points in the cloud, update them
155
if
(
fake_indices_
&&
indices_
->size () !=
input_
->size ())
156
{
157
const
auto
indices_size =
indices_
->size ();
158
try
159
{
160
indices_
->resize (
input_
->size ());
161
}
162
catch
(
const
std::bad_alloc&)
163
{
164
PCL_ERROR (
"[initCompute] Failed to allocate %lu indices.\n"
,
input_
->size ());
165
return
(
false
);
166
}
167
for
(
auto
i = indices_size; i <
indices_
->size (); ++i) { (*indices_)[i] = i; }
168
}
169
170
return
(
true
);
171
}
172
173
///////////////////////////////////////////////////////////////////////////////////////////
174
template
<
typename
Po
int
T>
bool
175
pcl::PCLBase<PointT>::deinitCompute
()
176
{
177
return
(
true
);
178
}
179
180
#define PCL_INSTANTIATE_PCLBase(T) template class PCL_EXPORTS pcl::PCLBase<T>;
181
182
#endif
//#ifndef PCL_PCL_IMPL_BASE_HPP_
183
pcl::PCLBase::input_
PointCloudConstPtr input_
The input point cloud dataset.
Definition
pcl_base.h:147
pcl::PCLBase::setInputCloud
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
Definition
pcl_base.hpp:65
pcl::PCLBase::PointCloudConstPtr
typename PointCloud::ConstPtr PointCloudConstPtr
Definition
pcl_base.h:74
pcl::PCLBase::indices_
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition
pcl_base.h:150
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::PCLBase::initCompute
bool initCompute()
This method should get called before starting the actual computation.
Definition
pcl_base.hpp:138
pcl::PCLBase::use_indices_
bool use_indices_
Set to true if point indices are used.
Definition
pcl_base.h:153
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:156
pcl::PCLBase::PointIndicesConstPtr
PointIndices::ConstPtr PointIndicesConstPtr
Definition
pcl_base.h:77
pcl::PCLBase::PCLBase
PCLBase()
Empty constructor.
Definition
pcl_base.hpp:46
pcl::PCLBase::deinitCompute
bool deinitCompute()
This method should get called after finishing the actual computation.
Definition
pcl_base.hpp:175
pcl::IndicesPtr
shared_ptr< Indices > IndicesPtr
Definition
pcl_base.h:58
pcl::Indices
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition
types.h:133
pcl::IndicesConstPtr
shared_ptr< const Indices > IndicesConstPtr
Definition
pcl_base.h:59