43 #include <pcl/conversions.h>
44 #include <pcl/common/concatenate.h>
45 #include <pcl/common/copy_point.h>
46 #include <pcl/common/io.h>
51 template <
typename Po
intT>
int
53 const std::string &field_name,
54 std::vector<pcl::PCLPointField> &fields)
56 return getFieldIndex<PointT>(field_name, fields);
60 template <
typename Po
intT>
int
62 std::vector<pcl::PCLPointField> &fields)
64 fields = getFields<PointT> ();
65 const auto& ref = fields;
66 return pcl::getFieldIndex<PointT> (field_name, ref);
70 template <
typename Po
intT>
int
72 const std::vector<pcl::PCLPointField> &fields)
74 const auto result = std::find_if(fields.begin (), fields.end (),
75 [&field_name](
const auto& field) { return field.name == field_name; });
76 if (result == fields.end ())
82 template <
typename Po
intT>
void
85 fields = getFields<PointT> ();
89 template <
typename Po
intT>
void
92 fields = getFields<PointT> ();
96 template <
typename Po
intT> std::vector<pcl::PCLPointField>
99 std::vector<pcl::PCLPointField> fields;
106 template <
typename Po
intT> std::string
110 const auto fields = getFields<PointT>();
112 for (std::size_t i = 0; i < fields.size () - 1; ++i)
113 result += fields[i].name +
" ";
114 result += fields[fields.size () - 1].name;
121 template <
typename Po
intInT,
typename Po
intOutT>
void
126 for (std::size_t i = 0; i < cloud_in.
size (); ++i)
131 template <
typename Po
intT>
void
136 std::copy (cloud_in.
data(), cloud_in.
data() + cloud_in.
size (), cloud_out.
data());
141 template <
typename Po
intInT,
typename Po
intOutT>
void
154 if (!cloud_in.
empty ())
159 template <
typename Po
intT,
typename IndicesVectorAllocator>
void
165 if (indices.size () == cloud_in.
size ())
167 cloud_out = cloud_in;
173 cloud_out.
reserve (indices.size ());
175 cloud_out.
width = indices.size ();
182 for (
const auto& index : indices)
187 template <
typename Po
intInT,
typename Po
intOutT,
typename IndicesVectorAllocator>
void
193 cloud_out.
resize (indices.size ());
195 cloud_out.
width = indices.size ();
202 for (std::size_t i = 0; i < indices.size (); ++i)
203 copyPoint (cloud_in[indices[i]], cloud_out[i]);
207 template <
typename Po
intT>
void
216 template <
typename Po
intInT,
typename Po
intOutT>
void
225 template <
typename Po
intT>
void
227 const std::vector<pcl::PointIndices> &indices,
230 std::size_t nr_p = 0;
231 for (
const auto &index : indices)
232 nr_p += index.indices.size ();
235 if (nr_p == cloud_in.
size ())
237 cloud_out = cloud_in;
245 cloud_out.
width = nr_p;
252 for (
const auto &cluster_index : indices)
255 for (
const auto &index : cluster_index.indices)
264 template <
typename Po
intInT,
typename Po
intOutT>
void
266 const std::vector<pcl::PointIndices> &indices,
269 const auto nr_p = std::accumulate(indices.begin (), indices.end (), 0,
270 [](
const auto& acc,
const auto& index) { return index.indices.size() + acc; });
273 if (nr_p == cloud_in.
size ())
282 cloud_out.
width = nr_p;
290 for (
const auto &cluster_index : indices)
293 for (
const auto &index : cluster_index.indices)
295 copyPoint (cloud_in[index], cloud_out[cp]);
302 template <
typename Po
intIn1T,
typename Po
intIn2T,
typename Po
intOutT>
void
307 using FieldList1 =
typename pcl::traits::fieldList<PointIn1T>::type;
308 using FieldList2 =
typename pcl::traits::fieldList<PointIn2T>::type;
310 if (cloud1_in.
size () != cloud2_in.
size ())
312 PCL_ERROR (
"[pcl::concatenateFields] The number of points in the two input datasets differs!\n");
327 for (std::size_t i = 0; i < cloud_out.
size (); ++i)
336 template <
typename Po
intT>
void
340 if (top < 0 || left < 0 || bottom < 0 || right < 0)
342 std::string faulty = (top < 0) ?
"top" : (left < 0) ?
"left" : (bottom < 0) ?
"bottom" :
"right";
347 if (top == 0 && left == 0 && bottom == 0 && right == 0)
348 cloud_out = cloud_in;
353 cloud_out.
width = cloud_in.
width + left + right;
365 PointT* out_inner = out + cloud_out.
width*top + left;
366 for (std::uint32_t i = 0; i < cloud_in.
height; i++, out_inner += cloud_out.
width, in += cloud_in.
width)
368 if (out_inner != in) {
369 std::copy(in, in + cloud_in.
width, out_inner);
380 std::vector<int> padding (cloud_out.
width - cloud_in.
width);
381 int right = cloud_out.
width - cloud_in.
width - left;
384 for (
int i = 0; i < left; i++)
387 for (
int i = 0; i < right; i++)
392 PointT* out_inner = out + cloud_out.
width*top + left;
394 for (std::uint32_t i = 0; i < cloud_in.
height; i++, out_inner += cloud_out.
width, in += cloud_in.
width)
396 if (out_inner != in) {
397 std::copy(in, in + cloud_in.
width, out_inner);
400 for (
int j = 0; j < left; j++)
401 out_inner[j - left] = in[padding[j]];
403 for (
int j = 0; j < right; j++)
404 out_inner[j + cloud_in.
width] = in[padding[j + left]];
407 for (
int i = 0; i < top; i++)
410 std::copy(out + (j+top) * cloud_out.
width, out + (j+top) * cloud_out.
width + cloud_out.
width,
411 out + i*cloud_out.
width);
414 for (
int i = 0; i < bottom; i++)
417 std::copy(out + (j+top)*cloud_out.
width, out + (j+top)*cloud_out.
width + cloud_out.
width,
418 out + (i + cloud_in.
height + top)*cloud_out.
width);
423 PCL_ERROR (
"[pcl::copyPointCloud] Unhandled interpolation type %d!\n", border_type);
428 int right = cloud_out.
width - cloud_in.
width - left;
430 std::vector<PointT> buff (cloud_out.
width, value);
431 PointT* buff_ptr = buff.data();
434 PointT* out_inner = out + cloud_out.
width*top + left;
436 for (std::uint32_t i = 0; i < cloud_in.
height; i++, out_inner += cloud_out.
width, in += cloud_in.
width)
438 if (out_inner != in) {
439 std::copy(in, in + cloud_in.
width, out_inner);
442 std::copy(buff_ptr, buff_ptr + left, out_inner - left);
443 std::copy(buff_ptr, buff_ptr + right, out_inner + cloud_in.
width);
446 for (
int i = 0; i < top; i++)
448 std::copy(buff_ptr, buff_ptr + cloud_out.
width, out + i*cloud_out.
width);
451 for (
int i = 0; i < bottom; i++)
453 std::copy(buff_ptr, buff_ptr + cloud_out.
width,
454 out + (i + cloud_in.
height + top)*cloud_out.
width);
An exception that is thrown when the arguments number or type is wrong/unhandled.
PointCloud represents the base class in PCL for storing collections of 3D points.
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields).
void resize(std::size_t count)
Resizes the container to contain count elements.
Eigen::Quaternionf sensor_orientation_
Sensor acquisition pose (rotation).
void transient_push_back(const PointT &pt)
Insert a new point in the cloud, at the end of the container.
std::uint32_t width
The point cloud width (if organized as an image-structure).
pcl::PCLHeader header
The point cloud header.
std::uint32_t height
The point cloud height (if organized as an image-structure).
void clear()
Removes all points in a cloud and sets the width and height to 0.
Eigen::Vector4f sensor_origin_
Sensor acquisition pose (origin/translation).
void reserve(std::size_t n)
std::string getFieldsList(const pcl::PointCloud< PointT > &)
Get the list of all fields available in a given cloud.
void copyPoint(const PointInT &point_in, PointOutT &point_out)
Copy the fields of a source point into a target point.
void concatenateFields(const pcl::PointCloud< PointIn1T > &cloud1_in, const pcl::PointCloud< PointIn2T > &cloud2_in, pcl::PointCloud< PointOutT > &cloud_out)
Concatenate two datasets representing different fields.
void copyPointCloud(const pcl::PointCloud< PointInT > &cloud_in, pcl::PointCloud< PointOutT > &cloud_out)
Copy all the fields from a given point cloud into a new point cloud.
void copyPointCloudMemcpy(const pcl::PointCloud< PointInT > &cloud_in, pcl::PointCloud< PointOutT > &cloud_out)
float distance(const PointT &p1, const PointT &p2)
int getFieldIndex(const pcl::PointCloud< PointT > &, const std::string &field_name, std::vector< pcl::PCLPointField > &fields)
PCL_EXPORTS int interpolatePointIndex(int p, int length, InterpolationType type)
std::vector< index_t, Allocator > IndicesAllocator
Type used for indices in PCL.
void getFields(const pcl::PointCloud< PointT > &, std::vector< pcl::PCLPointField > &fields)
Helper functor structure for concatenate.
A point structure representing Euclidean xyz coordinates, and the RGB color.