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;
105 template <
typename CloudT>
inline std::vector<pcl::PCLPointField>
108 return pcl::getFields<typename CloudT::PointType>();
112 template <>
inline std::vector<pcl::PCLPointField>
118 template <
typename Po
intT> std::string
122 const auto fields = getFields<PointT>();
124 for (std::size_t i = 0; i < fields.size () - 1; ++i)
125 result += fields[i].name +
" ";
126 result += fields[fields.size () - 1].name;
141 return static_cast<RType
>(*
reinterpret_cast<const DType*
>(p));
144 template <
typename T> T
point_field_as (
const std::uint8_t* data,
const std::uint8_t type)
147 case pcl::PCLPointField::PointFieldTypes::FLOAT32:
148 return reinterpret_and_cast<float, T>(data);
150 case pcl::PCLPointField::PointFieldTypes::UINT8:
151 return reinterpret_and_cast<std::uint8_t, T>(data);
153 case pcl::PCLPointField::PointFieldTypes::UINT16:
154 return reinterpret_and_cast<std::uint16_t, T>(data);
156 case pcl::PCLPointField::PointFieldTypes::UINT32:
157 return reinterpret_and_cast<std::uint32_t, T>(data);
159 case pcl::PCLPointField::PointFieldTypes::UINT64:
160 return reinterpret_and_cast<std::uint64_t, T>(data);
162 case pcl::PCLPointField::PointFieldTypes::BOOL:
163 return reinterpret_and_cast<bool, T>(data);
165 case pcl::PCLPointField::PointFieldTypes::FLOAT64:
166 return reinterpret_and_cast<double, T>(data);
168 case pcl::PCLPointField::PointFieldTypes::INT16:
169 return reinterpret_and_cast<std::int16_t, T>(data);
171 case pcl::PCLPointField::PointFieldTypes::INT32:
172 return reinterpret_and_cast<std::int32_t, T>(data);
174 case pcl::PCLPointField::PointFieldTypes::INT64:
175 return reinterpret_and_cast<std::int64_t, T>(data);
187 template <
typename Po
intInT,
typename Po
intOutT>
void
192 for (std::size_t i = 0; i < cloud_in.
size (); ++i)
197 template <
typename Po
intT>
void
202 std::copy (cloud_in.
data(), cloud_in.
data() + cloud_in.
size (), cloud_out.
data());
207 template <
typename Po
intInT,
typename Po
intOutT>
void
220 if (!cloud_in.
empty ())
225 template <
typename Po
intT,
typename IndicesVectorAllocator>
void
231 if (indices.size () == cloud_in.
size ())
233 cloud_out = cloud_in;
239 cloud_out.
reserve (indices.size ());
241 cloud_out.
width = indices.size ();
248 for (
const auto& index : indices)
253 template <
typename Po
intInT,
typename Po
intOutT,
typename IndicesVectorAllocator>
void
259 cloud_out.
resize (indices.size ());
261 cloud_out.
width = indices.size ();
268 for (std::size_t i = 0; i < indices.size (); ++i)
269 copyPoint (cloud_in[indices[i]], cloud_out[i]);
273 template <
typename Po
intT>
void
282 template <
typename Po
intInT,
typename Po
intOutT>
void
291 template <
typename Po
intT>
void
293 const std::vector<pcl::PointIndices> &indices,
296 std::size_t nr_p = 0;
297 for (
const auto &index : indices)
298 nr_p += index.indices.size ();
301 if (nr_p == cloud_in.
size ())
303 cloud_out = cloud_in;
311 cloud_out.
width = nr_p;
318 for (
const auto &cluster_index : indices)
321 for (
const auto &index : cluster_index.indices)
330 template <
typename Po
intInT,
typename Po
intOutT>
void
332 const std::vector<pcl::PointIndices> &indices,
335 const auto nr_p = std::accumulate(indices.begin (), indices.end (), 0,
336 [](
const auto& acc,
const auto& index) { return index.indices.size() + acc; });
339 if (nr_p == cloud_in.
size ())
348 cloud_out.
width = nr_p;
356 for (
const auto &cluster_index : indices)
359 for (
const auto &index : cluster_index.indices)
361 copyPoint (cloud_in[index], cloud_out[cp]);
368 template <
typename Po
intIn1T,
typename Po
intIn2T,
typename Po
intOutT>
void
373 using FieldList1 =
typename pcl::traits::fieldList<PointIn1T>::type;
374 using FieldList2 =
typename pcl::traits::fieldList<PointIn2T>::type;
376 if (cloud1_in.
size () != cloud2_in.
size ())
378 PCL_ERROR (
"[pcl::concatenateFields] The number of points in the two input datasets differs!\n");
393 for (std::size_t i = 0; i < cloud_out.
size (); ++i)
402 template <
typename Po
intT>
void
406 if (top < 0 || left < 0 || bottom < 0 || right < 0)
408 std::string faulty = (top < 0) ?
"top" : (left < 0) ?
"left" : (bottom < 0) ?
"bottom" :
"right";
413 if (top == 0 && left == 0 && bottom == 0 && right == 0)
414 cloud_out = cloud_in;
419 cloud_out.
width = cloud_in.
width + left + right;
431 PointT* out_inner = out + cloud_out.
width*top + left;
432 for (std::uint32_t i = 0; i < cloud_in.
height; i++, out_inner += cloud_out.
width, in += cloud_in.
width)
434 if (out_inner != in) {
435 std::copy(in, in + cloud_in.
width, out_inner);
446 std::vector<int> padding (cloud_out.
width - cloud_in.
width);
447 int right = cloud_out.
width - cloud_in.
width - left;
450 for (
int i = 0; i < left; i++)
453 for (
int i = 0; i < right; i++)
458 PointT* out_inner = out + cloud_out.
width*top + left;
460 for (std::uint32_t i = 0; i < cloud_in.
height; i++, out_inner += cloud_out.
width, in += cloud_in.
width)
462 if (out_inner != in) {
463 std::copy(in, in + cloud_in.
width, out_inner);
466 for (
int j = 0; j < left; j++)
467 out_inner[j - left] = in[padding[j]];
469 for (
int j = 0; j < right; j++)
470 out_inner[j + cloud_in.
width] = in[padding[j + left]];
473 for (
int i = 0; i < top; i++)
476 std::copy(out + (j+top) * cloud_out.
width, out + (j+top) * cloud_out.
width + cloud_out.
width,
477 out + i*cloud_out.
width);
480 for (
int i = 0; i < bottom; i++)
483 std::copy(out + (j+top)*cloud_out.
width, out + (j+top)*cloud_out.
width + cloud_out.
width,
484 out + (i + cloud_in.
height + top)*cloud_out.
width);
489 PCL_ERROR (
"[pcl::copyPointCloud] Unhandled interpolation type %d!\n", border_type);
494 int right = cloud_out.
width - cloud_in.
width - left;
496 std::vector<PointT> buff (cloud_out.
width, value);
497 PointT* buff_ptr = buff.data();
500 PointT* out_inner = out + cloud_out.
width*top + left;
502 for (std::uint32_t i = 0; i < cloud_in.
height; i++, out_inner += cloud_out.
width, in += cloud_in.
width)
504 if (out_inner != in) {
505 std::copy(in, in + cloud_in.
width, out_inner);
508 std::copy(buff_ptr, buff_ptr + left, out_inner - left);
509 std::copy(buff_ptr, buff_ptr + right, out_inner + cloud_in.
width);
512 for (
int i = 0; i < top; i++)
514 std::copy(buff_ptr, buff_ptr + cloud_out.
width, out + i*cloud_out.
width);
517 for (
int i = 0; i < bottom; i++)
519 std::copy(buff_ptr, buff_ptr + cloud_out.
width,
520 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)
T point_field_as(const std::uint8_t *data, const std::uint8_t type)
Get the value of a point field from raw data pointer and field type.
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.
RType reinterpret_and_cast(const std::uint8_t *p)
reinterpret a pointer as a type, dereference it, and return result as target type
void getFields(const pcl::PointCloud< PointT > &, std::vector< pcl::PCLPointField > &fields)
Helper functor structure for concatenate.
std::vector<::pcl::PCLPointField > fields
A point structure representing Euclidean xyz coordinates, and the RGB color.