/usr/include/pcl-1.7/pcl/common/io.h is in libpcl-dev 1.7.2-14build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 | /*
* 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.
*
* $Id$
*
*/
#ifndef PCL_COMMON_IO_H_
#define PCL_COMMON_IO_H_
#include <string>
#include <pcl/pcl_base.h>
#include <pcl/PointIndices.h>
#include <pcl/conversions.h>
#include <pcl/exceptions.h>
#include <locale>
namespace pcl
{
/** \brief Get the index of a specified field (i.e., dimension/channel)
* \param[in] cloud the the point cloud message
* \param[in] field_name the string defining the field name
* \ingroup common
*/
inline int
getFieldIndex (const pcl::PCLPointCloud2 &cloud, const std::string &field_name)
{
// Get the index we need
for (size_t d = 0; d < cloud.fields.size (); ++d)
if (cloud.fields[d].name == field_name)
return (static_cast<int>(d));
return (-1);
}
/** \brief Get the index of a specified field (i.e., dimension/channel)
* \param[in] cloud the the point cloud message
* \param[in] field_name the string defining the field name
* \param[out] fields a vector to the original \a PCLPointField vector that the raw PointCloud message contains
* \ingroup common
*/
template <typename PointT> inline int
getFieldIndex (const pcl::PointCloud<PointT> &cloud, const std::string &field_name,
std::vector<pcl::PCLPointField> &fields);
/** \brief Get the index of a specified field (i.e., dimension/channel)
* \param[in] field_name the string defining the field name
* \param[out] fields a vector to the original \a PCLPointField vector that the raw PointCloud message contains
* \ingroup common
*/
template <typename PointT> inline int
getFieldIndex (const std::string &field_name,
std::vector<pcl::PCLPointField> &fields);
/** \brief Get the list of available fields (i.e., dimension/channel)
* \param[in] cloud the point cloud message
* \param[out] fields a vector to the original \a PCLPointField vector that the raw PointCloud message contains
* \ingroup common
*/
template <typename PointT> inline void
getFields (const pcl::PointCloud<PointT> &cloud, std::vector<pcl::PCLPointField> &fields);
/** \brief Get the list of available fields (i.e., dimension/channel)
* \param[out] fields a vector to the original \a PCLPointField vector that the raw PointCloud message contains
* \ingroup common
*/
template <typename PointT> inline void
getFields (std::vector<pcl::PCLPointField> &fields);
/** \brief Get the list of all fields available in a given cloud
* \param[in] cloud the the point cloud message
* \ingroup common
*/
template <typename PointT> inline std::string
getFieldsList (const pcl::PointCloud<PointT> &cloud);
/** \brief Get the available point cloud fields as a space separated string
* \param[in] cloud a pointer to the PointCloud message
* \ingroup common
*/
inline std::string
getFieldsList (const pcl::PCLPointCloud2 &cloud)
{
std::string result;
for (size_t i = 0; i < cloud.fields.size () - 1; ++i)
result += cloud.fields[i].name + " ";
result += cloud.fields[cloud.fields.size () - 1].name;
return (result);
}
/** \brief Obtains the size of a specific field data type in bytes
* \param[in] datatype the field data type (see PCLPointField.h)
* \ingroup common
*/
inline int
getFieldSize (const int datatype)
{
switch (datatype)
{
case pcl::PCLPointField::INT8:
case pcl::PCLPointField::UINT8:
return (1);
case pcl::PCLPointField::INT16:
case pcl::PCLPointField::UINT16:
return (2);
case pcl::PCLPointField::INT32:
case pcl::PCLPointField::UINT32:
case pcl::PCLPointField::FLOAT32:
return (4);
case pcl::PCLPointField::FLOAT64:
return (8);
default:
return (0);
}
}
/** \brief Obtain a vector with the sizes of all valid fields (e.g., not "_")
* \param[in] fields the input vector containing the fields
* \param[out] field_sizes the resultant field sizes in bytes
*/
PCL_EXPORTS void
getFieldsSizes (const std::vector<pcl::PCLPointField> &fields,
std::vector<int> &field_sizes);
/** \brief Obtains the type of the PCLPointField from a specific size and type
* \param[in] size the size in bytes of the data field
* \param[in] type a char describing the type of the field ('F' = float, 'I' = signed, 'U' = unsigned)
* \ingroup common
*/
inline int
getFieldType (const int size, char type)
{
type = std::toupper (type, std::locale::classic ());
switch (size)
{
case 1:
if (type == 'I')
return (pcl::PCLPointField::INT8);
if (type == 'U')
return (pcl::PCLPointField::UINT8);
case 2:
if (type == 'I')
return (pcl::PCLPointField::INT16);
if (type == 'U')
return (pcl::PCLPointField::UINT16);
case 4:
if (type == 'I')
return (pcl::PCLPointField::INT32);
if (type == 'U')
return (pcl::PCLPointField::UINT32);
if (type == 'F')
return (pcl::PCLPointField::FLOAT32);
case 8:
return (pcl::PCLPointField::FLOAT64);
default:
return (-1);
}
}
/** \brief Obtains the type of the PCLPointField from a specific PCLPointField as a char
* \param[in] type the PCLPointField field type
* \ingroup common
*/
inline char
getFieldType (const int type)
{
switch (type)
{
case pcl::PCLPointField::INT8:
case pcl::PCLPointField::INT16:
case pcl::PCLPointField::INT32:
return ('I');
case pcl::PCLPointField::UINT8:
case pcl::PCLPointField::UINT16:
case pcl::PCLPointField::UINT32:
return ('U');
case pcl::PCLPointField::FLOAT32:
case pcl::PCLPointField::FLOAT64:
return ('F');
default:
return ('?');
}
}
typedef enum
{
BORDER_CONSTANT = 0, BORDER_REPLICATE = 1,
BORDER_REFLECT = 2, BORDER_WRAP = 3,
BORDER_REFLECT_101 = 4, BORDER_TRANSPARENT = 5,
BORDER_DEFAULT = BORDER_REFLECT_101
} InterpolationType;
/** \brief \return the right index according to the interpolation type.
* \note this is adapted from OpenCV
* \param p the index of point to interpolate
* \param length the top/bottom row or left/right column index
* \param type the requested interpolation
* \throws pcl::BadArgumentException if type is unknown
*/
PCL_EXPORTS int
interpolatePointIndex (int p, int length, InterpolationType type);
/** \brief Concatenate two pcl::PCLPointCloud2.
* \param[in] cloud1 the first input point cloud dataset
* \param[in] cloud2 the second input point cloud dataset
* \param[out] cloud_out the resultant output point cloud dataset
* \return true if successful, false if failed (e.g., name/number of fields differs)
* \ingroup common
*/
PCL_EXPORTS bool
concatenatePointCloud (const pcl::PCLPointCloud2 &cloud1,
const pcl::PCLPointCloud2 &cloud2,
pcl::PCLPointCloud2 &cloud_out);
/** \brief Extract the indices of a given point cloud as a new point cloud
* \param[in] cloud_in the input point cloud dataset
* \param[in] indices the vector of indices representing the points to be copied from \a cloud_in
* \param[out] cloud_out the resultant output point cloud dataset
* \note Assumes unique indices.
* \ingroup common
*/
PCL_EXPORTS void
copyPointCloud (const pcl::PCLPointCloud2 &cloud_in,
const std::vector<int> &indices,
pcl::PCLPointCloud2 &cloud_out);
/** \brief Extract the indices of a given point cloud as a new point cloud
* \param[in] cloud_in the input point cloud dataset
* \param[in] indices the vector of indices representing the points to be copied from \a cloud_in
* \param[out] cloud_out the resultant output point cloud dataset
* \note Assumes unique indices.
* \ingroup common
*/
PCL_EXPORTS void
copyPointCloud (const pcl::PCLPointCloud2 &cloud_in,
const std::vector<int, Eigen::aligned_allocator<int> > &indices,
pcl::PCLPointCloud2 &cloud_out);
/** \brief Copy fields and point cloud data from \a cloud_in to \a cloud_out
* \param[in] cloud_in the input point cloud dataset
* \param[out] cloud_out the resultant output point cloud dataset
* \ingroup common
*/
PCL_EXPORTS void
copyPointCloud (const pcl::PCLPointCloud2 &cloud_in,
pcl::PCLPointCloud2 &cloud_out);
/** \brief Check if two given point types are the same or not. */
template <typename Point1T, typename Point2T> inline bool
isSamePointType ()
{
return (typeid (Point1T) == typeid (Point2T));
}
/** \brief Extract the indices of a given point cloud as a new point cloud
* \param[in] cloud_in the input point cloud dataset
* \param[in] indices the vector of indices representing the points to be copied from \a cloud_in
* \param[out] cloud_out the resultant output point cloud dataset
* \note Assumes unique indices.
* \ingroup common
*/
template <typename PointT> void
copyPointCloud (const pcl::PointCloud<PointT> &cloud_in,
const std::vector<int> &indices,
pcl::PointCloud<PointT> &cloud_out);
/** \brief Extract the indices of a given point cloud as a new point cloud
* \param[in] cloud_in the input point cloud dataset
* \param[in] indices the vector of indices representing the points to be copied from \a cloud_in
* \param[out] cloud_out the resultant output point cloud dataset
* \note Assumes unique indices.
* \ingroup common
*/
template <typename PointT> void
copyPointCloud (const pcl::PointCloud<PointT> &cloud_in,
const std::vector<int, Eigen::aligned_allocator<int> > &indices,
pcl::PointCloud<PointT> &cloud_out);
/** \brief Extract the indices of a given point cloud as a new point cloud
* \param[in] cloud_in the input point cloud dataset
* \param[in] indices the PointIndices structure representing the points to be copied from cloud_in
* \param[out] cloud_out the resultant output point cloud dataset
* \note Assumes unique indices.
* \ingroup common
*/
template <typename PointT> void
copyPointCloud (const pcl::PointCloud<PointT> &cloud_in,
const PointIndices &indices,
pcl::PointCloud<PointT> &cloud_out);
/** \brief Extract the indices of a given point cloud as a new point cloud
* \param[in] cloud_in the input point cloud dataset
* \param[in] indices the vector of indices representing the points to be copied from \a cloud_in
* \param[out] cloud_out the resultant output point cloud dataset
* \note Assumes unique indices.
* \ingroup common
*/
template <typename PointT> void
copyPointCloud (const pcl::PointCloud<PointT> &cloud_in,
const std::vector<pcl::PointIndices> &indices,
pcl::PointCloud<PointT> &cloud_out);
/** \brief Copy all the fields from a given point cloud into a new point cloud
* \param[in] cloud_in the input point cloud dataset
* \param[out] cloud_out the resultant output point cloud dataset
* \ingroup common
*/
template <typename PointInT, typename PointOutT> void
copyPointCloud (const pcl::PointCloud<PointInT> &cloud_in,
pcl::PointCloud<PointOutT> &cloud_out);
/** \brief Extract the indices of a given point cloud as a new point cloud
* \param[in] cloud_in the input point cloud dataset
* \param[in] indices the vector of indices representing the points to be copied from \a cloud_in
* \param[out] cloud_out the resultant output point cloud dataset
* \note Assumes unique indices.
* \ingroup common
*/
template <typename PointInT, typename PointOutT> void
copyPointCloud (const pcl::PointCloud<PointInT> &cloud_in,
const std::vector<int> &indices,
pcl::PointCloud<PointOutT> &cloud_out);
/** \brief Extract the indices of a given point cloud as a new point cloud
* \param[in] cloud_in the input point cloud dataset
* \param[in] indices the vector of indices representing the points to be copied from \a cloud_in
* \param[out] cloud_out the resultant output point cloud dataset
* \note Assumes unique indices.
* \ingroup common
*/
template <typename PointInT, typename PointOutT> void
copyPointCloud (const pcl::PointCloud<PointInT> &cloud_in,
const std::vector<int, Eigen::aligned_allocator<int> > &indices,
pcl::PointCloud<PointOutT> &cloud_out);
/** \brief Extract the indices of a given point cloud as a new point cloud
* \param[in] cloud_in the input point cloud dataset
* \param[in] indices the PointIndices structure representing the points to be copied from cloud_in
* \param[out] cloud_out the resultant output point cloud dataset
* \note Assumes unique indices.
* \ingroup common
*/
template <typename PointInT, typename PointOutT> void
copyPointCloud (const pcl::PointCloud<PointInT> &cloud_in,
const PointIndices &indices,
pcl::PointCloud<PointOutT> &cloud_out);
/** \brief Extract the indices of a given point cloud as a new point cloud
* \param[in] cloud_in the input point cloud dataset
* \param[in] indices the vector of indices representing the points to be copied from cloud_in
* \param[out] cloud_out the resultant output point cloud dataset
* \note Assumes unique indices.
* \ingroup common
*/
template <typename PointInT, typename PointOutT> void
copyPointCloud (const pcl::PointCloud<PointInT> &cloud_in,
const std::vector<pcl::PointIndices> &indices,
pcl::PointCloud<PointOutT> &cloud_out);
/** \brief Copy a point cloud inside a larger one interpolating borders.
* \param[in] cloud_in the input point cloud dataset
* \param[out] cloud_out the resultant output point cloud dataset
* \param top
* \param bottom
* \param left
* \param right
* Position of cloud_in inside cloud_out is given by \a top, \a left, \a bottom \a right.
* \param[in] border_type the interpolating method (pcl::BORDER_XXX)
* BORDER_REPLICATE: aaaaaa|abcdefgh|hhhhhhh
* BORDER_REFLECT: fedcba|abcdefgh|hgfedcb
* BORDER_REFLECT_101: gfedcb|abcdefgh|gfedcba
* BORDER_WRAP: cdefgh|abcdefgh|abcdefg
* BORDER_CONSTANT: iiiiii|abcdefgh|iiiiiii with some specified 'i'
* BORDER_TRANSPARENT: mnopqr|abcdefgh|tuvwxyz where m-r and t-z are orignal values of cloud_out
* \param value
* \throw pcl::BadArgumentException if any of top, bottom, left or right is negative.
* \ingroup common
*/
template <typename PointT> void
copyPointCloud (const pcl::PointCloud<PointT> &cloud_in,
pcl::PointCloud<PointT> &cloud_out,
int top, int bottom, int left, int right,
pcl::InterpolationType border_type, const PointT& value);
/** \brief Concatenate two datasets representing different fields.
*
* \note If the input datasets have overlapping fields (i.e., both contain
* the same fields), then the data in the second cloud (cloud2_in) will
* overwrite the data in the first (cloud1_in).
*
* \param[in] cloud1_in the first input dataset
* \param[in] cloud2_in the second input dataset (overwrites the fields of the first dataset for those that are shared)
* \param[out] cloud_out the resultant output dataset created by the concatenation of all the fields in the input datasets
* \ingroup common
*/
template <typename PointIn1T, typename PointIn2T, typename PointOutT> void
concatenateFields (const pcl::PointCloud<PointIn1T> &cloud1_in,
const pcl::PointCloud<PointIn2T> &cloud2_in,
pcl::PointCloud<PointOutT> &cloud_out);
/** \brief Concatenate two datasets representing different fields.
*
* \note If the input datasets have overlapping fields (i.e., both contain
* the same fields), then the data in the second cloud (cloud2_in) will
* overwrite the data in the first (cloud1_in).
*
* \param[in] cloud1_in the first input dataset
* \param[in] cloud2_in the second input dataset (overwrites the fields of the first dataset for those that are shared)
* \param[out] cloud_out the output dataset created by concatenating all the fields in the input datasets
* \ingroup common
*/
PCL_EXPORTS bool
concatenateFields (const pcl::PCLPointCloud2 &cloud1_in,
const pcl::PCLPointCloud2 &cloud2_in,
pcl::PCLPointCloud2 &cloud_out);
/** \brief Copy the XYZ dimensions of a pcl::PCLPointCloud2 into Eigen format
* \param[in] in the point cloud message
* \param[out] out the resultant Eigen MatrixXf format containing XYZ0 / point
* \ingroup common
*/
PCL_EXPORTS bool
getPointCloudAsEigen (const pcl::PCLPointCloud2 &in, Eigen::MatrixXf &out);
/** \brief Copy the XYZ dimensions from an Eigen MatrixXf into a pcl::PCLPointCloud2 message
* \param[in] in the Eigen MatrixXf format containing XYZ0 / point
* \param[out] out the resultant point cloud message
* \note the method assumes that the PCLPointCloud2 message already has the fields set up properly !
* \ingroup common
*/
PCL_EXPORTS bool
getEigenAsPointCloud (Eigen::MatrixXf &in, pcl::PCLPointCloud2 &out);
namespace io
{
/** \brief swap bytes order of a char array of length N
* \param bytes char array to swap
* \ingroup common
*/
template <std::size_t N> void
swapByte (char* bytes);
/** \brief specialization of swapByte for dimension 1
* \param bytes char array to swap
*/
template <> inline void
swapByte<1> (char* bytes) { bytes[0] = bytes[0]; }
/** \brief specialization of swapByte for dimension 2
* \param bytes char array to swap
*/
template <> inline void
swapByte<2> (char* bytes) { std::swap (bytes[0], bytes[1]); }
/** \brief specialization of swapByte for dimension 4
* \param bytes char array to swap
*/
template <> inline void
swapByte<4> (char* bytes)
{
std::swap (bytes[0], bytes[3]);
std::swap (bytes[1], bytes[2]);
}
/** \brief specialization of swapByte for dimension 8
* \param bytes char array to swap
*/
template <> inline void
swapByte<8> (char* bytes)
{
std::swap (bytes[0], bytes[7]);
std::swap (bytes[1], bytes[6]);
std::swap (bytes[2], bytes[5]);
std::swap (bytes[3], bytes[4]);
}
/** \brief swaps byte of an arbitrary type T casting it to char*
* \param value the data you want its bytes swapped
*/
template <typename T> void
swapByte (T& value)
{
pcl::io::swapByte<sizeof(T)> (reinterpret_cast<char*> (&value));
}
}
}
#include <pcl/common/impl/io.hpp>
#endif //#ifndef PCL_COMMON_IO_H_
|