-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Expand file tree
/
Copy pathpcl_base.cpp
More file actions
166 lines (149 loc) · 5.47 KB
/
pcl_base.cpp
File metadata and controls
166 lines (149 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2010-2011, Willow Garage, Inc.
* Copyright (c) 2012-, Open Perception, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the copyright holder(s) nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <algorithm>
#include <numeric>
#include <pcl/impl/pcl_base.hpp>
#include <pcl/common/io.h> // for getFieldSize
///////////////////////////////////////////////////////////////////////////////////////////
pcl::PCLBase<pcl::PCLPointCloud2>::PCLBase ()
: use_indices_ (false)
, fake_indices_ (false)
, field_sizes_ (0)
, x_idx_ (UNAVAILABLE)
, y_idx_ (UNAVAILABLE)
, z_idx_ (UNAVAILABLE)
, x_field_name_ ("x")
, y_field_name_ ("y")
, z_field_name_ ("z")
{
}
///////////////////////////////////////////////////////////////////////////////////////////
void
pcl::PCLBase<pcl::PCLPointCloud2>::setInputCloud (const PCLPointCloud2ConstPtr &cloud)
{
input_ = cloud;
for (std::size_t d = 0; d < cloud->fields.size (); ++d)
{
if (cloud->fields[d].name == x_field_name_)
x_idx_ = d;
if (cloud->fields[d].name == y_field_name_)
y_idx_ = d;
if (cloud->fields[d].name == z_field_name_)
z_idx_ = d;
}
// Obtain the size of datatype
const auto sizeofDatatype = [](const auto& datatype) -> int
{
const auto size = getFieldSize(datatype);
if (size == 0) {
PCL_ERROR("[PCLBase::setInputCloud] Invalid field type (%d)!\n", datatype);
}
return size;
};
// Restrict size of a field to be at-max sizeof(FLOAT64) now to support {U}INT64
field_sizes_.resize(input_->fields.size());
std::transform(input_->fields.begin(), input_->fields.end(), field_sizes_.begin(),
[&sizeofDatatype](const auto& field)
{
return std::min(sizeofDatatype(field.datatype), static_cast<int>(sizeof(double)));
});
}
///////////////////////////////////////////////////////////////////////////////////////////
bool
pcl::PCLBase<pcl::PCLPointCloud2>::deinitCompute ()
{
return (true);
}
///////////////////////////////////////////////////////////////////////////////////////////
bool
pcl::PCLBase<pcl::PCLPointCloud2>::initCompute ()
{
// Check if input was set
if (!input_)
return (false);
// If no point indices have been given, construct a set of indices for the entire input point cloud
if (!indices_)
{
fake_indices_ = true;
indices_.reset (new Indices);
}
// If we have a set of fake indices, but they do not match the number of points in the cloud, update them
if (fake_indices_ && indices_->size () != (static_cast<std::size_t>(input_->width) * static_cast<std::size_t>(input_->height)))
{
const auto indices_size = indices_->size ();
try
{
indices_->resize (static_cast<std::size_t>(input_->width) * static_cast<std::size_t>(input_->height));
}
catch (const std::bad_alloc&)
{
PCL_ERROR ("[initCompute] Failed to allocate %lu indices.\n", (input_->width * input_->height));
return (false);
}
if (indices_size < indices_->size ())
std::iota(indices_->begin () + indices_size, indices_->end (), indices_size);
}
// Set the number of threads
#ifdef _OPENMP
num_threads_ = num_threads_ != 0 ? num_threads_ : omp_get_num_procs();
#else
num_threads_ = 1;
#endif
return (true);
}
///////////////////////////////////////////////////////////////////////////////////////////
void
pcl::PCLBase<pcl::PCLPointCloud2>::setIndices (const IndicesPtr &indices)
{
indices_ = indices;
fake_indices_ = false;
use_indices_ = true;
}
///////////////////////////////////////////////////////////////////////////////////////////
void
pcl::PCLBase<pcl::PCLPointCloud2>::setIndices (const PointIndicesConstPtr &indices)
{
indices_.reset (new Indices(indices->indices));
fake_indices_ = false;
use_indices_ = true;
}
#ifndef PCL_NO_PRECOMPILE
#include <pcl/impl/instantiate.hpp>
#include <pcl/point_types.h>
PCL_INSTANTIATE(PCLBase, PCL_POINT_TYPES)
#endif // PCL_NO_PRECOMPILE