|
Point Cloud Library (PCL)
1.5.1
|
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 4702 2012-02-23 09:39:33Z gedikli $ 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 00106 int 00107 readHeader (const std::string &file_name, sensor_msgs::PointCloud2 &cloud, 00108 Eigen::Vector4f &origin, Eigen::Quaternionf &orientation, int &pcd_version, 00109 int &data_type, int &data_idx); 00110 00129 int 00130 readHeaderEigen (const std::string &file_name, pcl::PointCloud<Eigen::MatrixXf> &cloud, 00131 int &pcd_version, int &data_type, int &data_idx); 00132 00140 int 00141 read (const std::string &file_name, sensor_msgs::PointCloud2 &cloud, 00142 Eigen::Vector4f &origin, Eigen::Quaternionf &orientation, int &pcd_version); 00143 00154 int 00155 read (const std::string &file_name, sensor_msgs::PointCloud2 &cloud); 00156 00161 template<typename PointT> int 00162 read (const std::string &file_name, pcl::PointCloud<PointT> &cloud) 00163 { 00164 sensor_msgs::PointCloud2 blob; 00165 int pcd_version; 00166 int res = read (file_name, blob, cloud.sensor_origin_, cloud.sensor_orientation_, 00167 pcd_version); 00168 00169 // Exit in case of error 00170 if (res < 0) 00171 return (res); 00172 pcl::fromROSMsg (blob, cloud); 00173 return (0); 00174 } 00175 00183 int 00184 readEigen (const std::string &file_name, pcl::PointCloud<Eigen::MatrixXf> &cloud); 00185 }; 00186 00191 class PCL_EXPORTS PCDWriter : public FileWriter 00192 { 00193 public: 00194 PCDWriter() : FileWriter(), map_synchronization_(false) {} 00195 ~PCDWriter() {} 00196 00205 void 00206 setMapSynchronization (bool sync) 00207 { 00208 map_synchronization_ = sync; 00209 } 00210 00216 std::string 00217 generateHeaderBinary (const sensor_msgs::PointCloud2 &cloud, 00218 const Eigen::Vector4f &origin, 00219 const Eigen::Quaternionf &orientation); 00220 00226 std::string 00227 generateHeaderBinaryCompressed (const sensor_msgs::PointCloud2 &cloud, 00228 const Eigen::Vector4f &origin, 00229 const Eigen::Quaternionf &orientation); 00230 00236 std::string 00237 generateHeaderASCII (const sensor_msgs::PointCloud2 &cloud, 00238 const Eigen::Vector4f &origin, 00239 const Eigen::Quaternionf &orientation); 00240 00246 template <typename PointT> static std::string 00247 generateHeader (const pcl::PointCloud<PointT> &cloud, 00248 const int nr_points = std::numeric_limits<int>::max ()); 00249 00259 std::string 00260 generateHeaderEigen (const pcl::PointCloud<Eigen::MatrixXf> &cloud, 00261 const int nr_points = std::numeric_limits<int>::max ()); 00262 00279 int 00280 writeASCII (const std::string &file_name, const sensor_msgs::PointCloud2 &cloud, 00281 const Eigen::Vector4f &origin = Eigen::Vector4f::Zero (), 00282 const Eigen::Quaternionf &orientation = Eigen::Quaternionf::Identity (), 00283 const int precision = 8); 00284 00291 int 00292 writeBinary (const std::string &file_name, const sensor_msgs::PointCloud2 &cloud, 00293 const Eigen::Vector4f &origin = Eigen::Vector4f::Zero (), 00294 const Eigen::Quaternionf &orientation = Eigen::Quaternionf::Identity ()); 00295 00302 int 00303 writeBinaryCompressed (const std::string &file_name, const sensor_msgs::PointCloud2 &cloud, 00304 const Eigen::Vector4f &origin = Eigen::Vector4f::Zero (), 00305 const Eigen::Quaternionf &orientation = Eigen::Quaternionf::Identity ()); 00306 00324 inline int 00325 write (const std::string &file_name, const sensor_msgs::PointCloud2 &cloud, 00326 const Eigen::Vector4f &origin = Eigen::Vector4f::Zero (), 00327 const Eigen::Quaternionf &orientation = Eigen::Quaternionf::Identity (), 00328 const bool binary = false) 00329 { 00330 if (binary) 00331 return (writeBinary (file_name, cloud, origin, orientation)); 00332 else 00333 return (writeASCII (file_name, cloud, origin, orientation, 8)); 00334 } 00335 00351 inline int 00352 write (const std::string &file_name, const sensor_msgs::PointCloud2::ConstPtr &cloud, 00353 const Eigen::Vector4f &origin = Eigen::Vector4f::Zero (), 00354 const Eigen::Quaternionf &orientation = Eigen::Quaternionf::Identity (), 00355 const bool binary = false) 00356 { 00357 return (write (file_name, *cloud, origin, orientation, binary)); 00358 } 00359 00364 template <typename PointT> int 00365 writeBinary (const std::string &file_name, 00366 const pcl::PointCloud<PointT> &cloud); 00367 00376 int 00377 writeBinaryEigen (const std::string &file_name, 00378 const pcl::PointCloud<Eigen::MatrixXf> &cloud); 00379 00384 template <typename PointT> int 00385 writeBinaryCompressed (const std::string &file_name, 00386 const pcl::PointCloud<PointT> &cloud); 00387 00396 int 00397 writeBinaryCompressedEigen (const std::string &file_name, 00398 const pcl::PointCloud<Eigen::MatrixXf> &cloud); 00399 00405 template <typename PointT> int 00406 writeBinary (const std::string &file_name, 00407 const pcl::PointCloud<PointT> &cloud, 00408 const std::vector<int> &indices); 00409 00415 template <typename PointT> int 00416 writeASCII (const std::string &file_name, 00417 const pcl::PointCloud<PointT> &cloud, 00418 const int precision = 8); 00419 00429 int 00430 writeASCIIEigen (const std::string &file_name, 00431 const pcl::PointCloud<Eigen::MatrixXf> &cloud, 00432 const int precision = 8); 00433 00440 template <typename PointT> int 00441 writeASCII (const std::string &file_name, 00442 const pcl::PointCloud<PointT> &cloud, 00443 const std::vector<int> &indices, 00444 const int precision = 8); 00445 00459 template<typename PointT> inline int 00460 write (const std::string &file_name, 00461 const pcl::PointCloud<PointT> &cloud, 00462 const bool binary = false) 00463 { 00464 if (binary) 00465 return (writeBinary<PointT> (file_name, cloud)); 00466 else 00467 return (writeASCII<PointT> (file_name, cloud)); 00468 } 00469 00484 template<typename PointT> inline int 00485 write (const std::string &file_name, 00486 const pcl::PointCloud<PointT> &cloud, 00487 const std::vector<int> &indices, 00488 bool binary = false) 00489 { 00490 if (binary) 00491 return (writeBinary<PointT> (file_name, cloud, indices)); 00492 else 00493 return (writeASCII<PointT> (file_name, cloud, indices)); 00494 } 00495 00496 private: 00498 bool map_synchronization_; 00499 00500 typedef std::pair<std::string, pcl::ChannelProperties> pair_channel_properties; 00504 struct ChannelPropertiesComparator 00505 { 00506 bool 00507 operator()(const pair_channel_properties &lhs, const pair_channel_properties &rhs) 00508 { 00509 return (lhs.second.offset < rhs.second.offset); 00510 } 00511 }; 00512 }; 00513 00514 namespace io 00515 { 00525 inline int 00526 loadPCDFile (const std::string &file_name, sensor_msgs::PointCloud2 &cloud) 00527 { 00528 pcl::PCDReader p; 00529 return (p.read (file_name, cloud)); 00530 } 00531 00540 inline int 00541 loadPCDFile (const std::string &file_name, sensor_msgs::PointCloud2 &cloud, 00542 Eigen::Vector4f &origin, Eigen::Quaternionf &orientation) 00543 { 00544 pcl::PCDReader p; 00545 int pcd_version; 00546 return (p.read (file_name, cloud, origin, orientation, pcd_version)); 00547 } 00548 00554 template<typename PointT> inline int 00555 loadPCDFile (const std::string &file_name, pcl::PointCloud<PointT> &cloud) 00556 { 00557 pcl::PCDReader p; 00558 return (p.read (file_name, cloud)); 00559 } 00560 00576 inline int 00577 savePCDFile (const std::string &file_name, const sensor_msgs::PointCloud2 &cloud, 00578 const Eigen::Vector4f &origin = Eigen::Vector4f::Zero (), 00579 const Eigen::Quaternionf &orientation = Eigen::Quaternionf::Identity (), 00580 const bool binary_mode = false) 00581 { 00582 PCDWriter w; 00583 return (w.write (file_name, cloud, origin, orientation, binary_mode)); 00584 } 00585 00600 template<typename PointT> inline int 00601 savePCDFile (const std::string &file_name, const pcl::PointCloud<PointT> &cloud, bool binary_mode = false) 00602 { 00603 PCDWriter w; 00604 return (w.write<PointT> (file_name, cloud, binary_mode)); 00605 } 00606 00623 template<typename PointT> inline int 00624 savePCDFileASCII (const std::string &file_name, const pcl::PointCloud<PointT> &cloud) 00625 { 00626 PCDWriter w; 00627 return (w.write<PointT> (file_name, cloud, false)); 00628 } 00629 00639 template<typename PointT> inline int 00640 savePCDFileBinary (const std::string &file_name, const pcl::PointCloud<PointT> &cloud) 00641 { 00642 PCDWriter w; 00643 return (w.write<PointT> (file_name, cloud, true)); 00644 } 00645 00663 template<typename PointT> int 00664 savePCDFile (const std::string &file_name, 00665 const pcl::PointCloud<PointT> &cloud, 00666 const std::vector<int> &indices, 00667 const bool binary_mode = false) 00668 { 00669 // Save the data 00670 PCDWriter w; 00671 return (w.write<PointT> (file_name, cloud, indices, binary_mode)); 00672 } 00673 } 00674 } 00675 00676 #include "pcl/io/impl/pcd_io.hpp" 00677 00678 #endif //#ifndef PCL_IO_PCD_IO_H_
1.8.0