|
Point Cloud Library (PCL)
1.4.0
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2010-2011, Willow Garage, Inc. 00006 * 00007 * All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 00013 * * Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * * Redistributions in binary form must reproduce the above 00016 * copyright notice, this list of conditions and the following 00017 * disclaimer in the documentation and/or other materials provided 00018 * with the distribution. 00019 * * Neither the name of Willow Garage, Inc. nor the names of its 00020 * contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00029 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00032 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00033 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 * $Id: pcd_io.h 3751 2011-12-31 23:18:12Z rusu $ 00037 * 00038 */ 00039 00040 #ifndef PCL_IO_PCD_IO_H_ 00041 #define PCL_IO_PCD_IO_H_ 00042 00043 #include <pcl/point_cloud.h> 00044 #include "pcl/io/file_io.h" 00045 00046 namespace pcl 00047 { 00052 class PCL_EXPORTS PCDReader : public FileReader 00053 { 00054 public: 00056 PCDReader() : FileReader() {} 00058 ~PCDReader() {} 00080 enum 00081 { 00082 PCD_V6 = 0, 00083 PCD_V7 = 1 00084 }; 00085 00103 int 00104 readHeader (const std::string &file_name, sensor_msgs::PointCloud2 &cloud, 00105 Eigen::Vector4f &origin, Eigen::Quaternionf &orientation, int &pcd_version, 00106 int &data_type, int &data_idx); 00107 00115 int 00116 read (const std::string &file_name, sensor_msgs::PointCloud2 &cloud, 00117 Eigen::Vector4f &origin, Eigen::Quaternionf &orientation, int &pcd_version); 00118 00129 int 00130 read (const std::string &file_name, sensor_msgs::PointCloud2 &cloud); 00131 00136 template<typename PointT> inline int 00137 read (const std::string &file_name, pcl::PointCloud<PointT> &cloud) 00138 { 00139 sensor_msgs::PointCloud2 blob; 00140 int pcd_version; 00141 int res = read (file_name, blob, cloud.sensor_origin_, cloud.sensor_orientation_, 00142 pcd_version); 00143 00144 // Exit in case of error 00145 if (res < 0) 00146 return res; 00147 pcl::fromROSMsg (blob, cloud); 00148 return 0; 00149 } 00150 }; 00151 00156 class PCL_EXPORTS PCDWriter : public FileWriter 00157 { 00158 public: 00159 PCDWriter() : FileWriter(), map_synchronization_(false) {} 00160 ~PCDWriter() {} 00161 00170 void 00171 setMapSynchronization (bool sync) 00172 { 00173 map_synchronization_ = sync; 00174 } 00175 00181 std::string 00182 generateHeaderBinary (const sensor_msgs::PointCloud2 &cloud, 00183 const Eigen::Vector4f &origin, 00184 const Eigen::Quaternionf &orientation); 00185 00191 std::string 00192 generateHeaderBinaryCompressed (const sensor_msgs::PointCloud2 &cloud, 00193 const Eigen::Vector4f &origin, 00194 const Eigen::Quaternionf &orientation); 00195 00201 std::string 00202 generateHeaderASCII (const sensor_msgs::PointCloud2 &cloud, 00203 const Eigen::Vector4f &origin, 00204 const Eigen::Quaternionf &orientation); 00205 00211 template <typename PointT> static std::string 00212 generateHeader (const pcl::PointCloud<PointT> &cloud, 00213 const int nr_points = std::numeric_limits<int>::max ()); 00214 00221 std::string 00222 generateHeaderEigen (const pcl::PointCloud<Eigen::MatrixXf> &cloud, 00223 const int nr_points = std::numeric_limits<int>::max ()); 00224 00241 int 00242 writeASCII (const std::string &file_name, const sensor_msgs::PointCloud2 &cloud, 00243 const Eigen::Vector4f &origin = Eigen::Vector4f::Zero (), 00244 const Eigen::Quaternionf &orientation = Eigen::Quaternionf::Identity (), 00245 const int precision = 8); 00246 00253 int 00254 writeBinary (const std::string &file_name, const sensor_msgs::PointCloud2 &cloud, 00255 const Eigen::Vector4f &origin = Eigen::Vector4f::Zero (), 00256 const Eigen::Quaternionf &orientation = Eigen::Quaternionf::Identity ()); 00257 00264 int 00265 writeBinaryCompressed (const std::string &file_name, const sensor_msgs::PointCloud2 &cloud, 00266 const Eigen::Vector4f &origin = Eigen::Vector4f::Zero (), 00267 const Eigen::Quaternionf &orientation = Eigen::Quaternionf::Identity ()); 00268 00286 inline int 00287 write (const std::string &file_name, const sensor_msgs::PointCloud2 &cloud, 00288 const Eigen::Vector4f &origin = Eigen::Vector4f::Zero (), 00289 const Eigen::Quaternionf &orientation = Eigen::Quaternionf::Identity (), 00290 const bool binary = false) 00291 { 00292 if (binary) 00293 return (writeBinary (file_name, cloud, origin, orientation)); 00294 else 00295 return (writeASCII (file_name, cloud, origin, orientation, 8)); 00296 } 00297 00313 inline int 00314 write (const std::string &file_name, const sensor_msgs::PointCloud2::ConstPtr &cloud, 00315 const Eigen::Vector4f &origin = Eigen::Vector4f::Zero (), 00316 const Eigen::Quaternionf &orientation = Eigen::Quaternionf::Identity (), 00317 const bool binary = false) 00318 { 00319 return (write (file_name, *cloud, origin, orientation, binary)); 00320 } 00321 00326 template <typename PointT> int 00327 writeBinary (const std::string &file_name, 00328 const pcl::PointCloud<PointT> &cloud); 00329 00334 template <typename PointT> int 00335 writeBinaryCompressed (const std::string &file_name, 00336 const pcl::PointCloud<PointT> &cloud); 00337 00343 int 00344 writeBinaryCompressedEigen (const std::string &file_name, 00345 const pcl::PointCloud<Eigen::MatrixXf> &cloud); 00346 00352 template <typename PointT> int 00353 writeBinary (const std::string &file_name, 00354 const pcl::PointCloud<PointT> &cloud, 00355 const std::vector<int> &indices); 00356 00362 template <typename PointT> int 00363 writeASCII (const std::string &file_name, 00364 const pcl::PointCloud<PointT> &cloud, 00365 const int precision = 8); 00366 00373 template <typename PointT> int 00374 writeASCII (const std::string &file_name, 00375 const pcl::PointCloud<PointT> &cloud, 00376 const std::vector<int> &indices, 00377 const int precision = 8); 00378 00392 template<typename PointT> inline int 00393 write (const std::string &file_name, 00394 const pcl::PointCloud<PointT> &cloud, 00395 const bool binary = false) 00396 { 00397 if (binary) 00398 return (writeBinary<PointT> (file_name, cloud)); 00399 else 00400 return (writeASCII<PointT> (file_name, cloud)); 00401 } 00402 00417 template<typename PointT> inline int 00418 write (const std::string &file_name, 00419 const pcl::PointCloud<PointT> &cloud, 00420 const std::vector<int> &indices, 00421 bool binary = false) 00422 { 00423 if (binary) 00424 return (writeBinary<PointT> (file_name, cloud, indices)); 00425 else 00426 return (writeASCII<PointT> (file_name, cloud, indices)); 00427 } 00428 00429 private: 00430 00432 bool map_synchronization_; 00433 }; 00434 00435 namespace io 00436 { 00446 inline int 00447 loadPCDFile (const std::string &file_name, sensor_msgs::PointCloud2 &cloud) 00448 { 00449 pcl::PCDReader p; 00450 return (p.read (file_name, cloud)); 00451 } 00452 00461 inline int 00462 loadPCDFile (const std::string &file_name, sensor_msgs::PointCloud2 &cloud, 00463 Eigen::Vector4f &origin, Eigen::Quaternionf &orientation) 00464 { 00465 pcl::PCDReader p; 00466 int pcd_version; 00467 return (p.read (file_name, cloud, origin, orientation, pcd_version)); 00468 } 00469 00475 template<typename PointT> inline int 00476 loadPCDFile (const std::string &file_name, pcl::PointCloud<PointT> &cloud) 00477 { 00478 pcl::PCDReader p; 00479 return (p.read (file_name, cloud)); 00480 } 00481 00497 inline int 00498 savePCDFile (const std::string &file_name, const sensor_msgs::PointCloud2 &cloud, 00499 const Eigen::Vector4f &origin = Eigen::Vector4f::Zero (), 00500 const Eigen::Quaternionf &orientation = Eigen::Quaternionf::Identity (), 00501 const bool binary_mode = false) 00502 { 00503 PCDWriter w; 00504 return (w.write (file_name, cloud, origin, orientation, binary_mode)); 00505 } 00506 00521 template<typename PointT> inline int 00522 savePCDFile (const std::string &file_name, const pcl::PointCloud<PointT> &cloud, bool binary_mode = false) 00523 { 00524 PCDWriter w; 00525 return (w.write<PointT> (file_name, cloud, binary_mode)); 00526 } 00527 00544 template<typename PointT> inline int 00545 savePCDFileASCII (const std::string &file_name, const pcl::PointCloud<PointT> &cloud) 00546 { 00547 PCDWriter w; 00548 return (w.write<PointT> (file_name, cloud, false)); 00549 } 00550 00560 template<typename PointT> inline int 00561 savePCDFileBinary (const std::string &file_name, const pcl::PointCloud<PointT> &cloud) 00562 { 00563 PCDWriter w; 00564 return (w.write<PointT> (file_name, cloud, true)); 00565 } 00566 00584 template<typename PointT> int 00585 savePCDFile (const std::string &file_name, 00586 const pcl::PointCloud<PointT> &cloud, 00587 const std::vector<int> &indices, 00588 const bool binary_mode = false) 00589 { 00590 // Save the data 00591 PCDWriter w; 00592 return (w.write<PointT> (file_name, cloud, indices, binary_mode)); 00593 } 00594 }; 00595 } 00596 00597 #include "pcl/io/impl/pcd_io.hpp" 00598 00599 #endif //#ifndef PCL_IO_PCD_IO_H_
1.7.6.1