Advertisement
SUGIYAMA

☆pcd_concatenate_pcd

Oct 9th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.28 KB | None | 0 0
  1. /*
  2.  * Software License Agreement (BSD License)
  3.  *
  4.  *  Point Cloud Library (PCL) - www.pointclouds.org
  5.  *  Copyright (c) 2010, Willow Garage, Inc.
  6.  *  Copyright (c) 2012-, Open Perception, Inc.
  7.  *
  8.  *  All rights reserved.
  9.  *
  10.  *  Redistribution and use in source and binary forms, with or without
  11.  *  modification, are permitted provided that the following conditions
  12.  *  are met:
  13.  *
  14.  *   * Redistributions of source code must retain the above copyright
  15.  *     notice, this list of conditions and the following disclaimer.
  16.  *   * Redistributions in binary form must reproduce the above
  17.  *     copyright notice, this list of conditions and the following
  18.  *     disclaimer in the documentation and/or other materials provided
  19.  *     with the distribution.
  20.  *   * Neither the name of the copyright holder(s) nor the names of its
  21.  *     contributors may be used to endorse or promote products derived
  22.  *     from this software without specific prior written permission.
  23.  *
  24.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25.  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26.  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  27.  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  28.  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  29.  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  30.  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  31.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32.  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33.  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  34.  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35.  *  POSSIBILITY OF SUCH DAMAGE.
  36.  *
  37.  * $Id$
  38.  *
  39.  */
  40.  
  41. /**
  42.  
  43. @b pcd_concatenate_points exemplifies how to concatenate the points of two PointClouds having the same fields.
  44.  
  45. **/
  46.  
  47. #include <iostream>
  48. #include <pcl/console/time.h>
  49. #include <pcl/io/pcd_io.h>
  50. #include <pcl/point_types.h>
  51.  
  52. Eigen::Vector4f    translation;
  53. Eigen::Quaternionf orientation;
  54.  
  55. ////////////////////////////////////////////////////////////////////////////////
  56. /** \brief Parse command line arguments for file names.
  57.   * Returns: a vector with file names indices.
  58.   * \param argc
  59.   * \param argv
  60.   * \param extension
  61.   */
  62. std::vector<int>
  63. parseFileExtensionArgument (int argc, char** argv, std::string extension)
  64. {
  65.   std::vector<int> indices;
  66.   for (int i = 1; i < argc; ++i)
  67.   {
  68.     std::string fname = std::string (argv[i]);
  69.    
  70.     // Needs to be at least 4: .ext
  71.     if (fname.size () <= 4)
  72.       continue;
  73.    
  74.     // For being case insensitive
  75.     std::transform (fname.begin (), fname.end (), fname.begin (), tolower);
  76.     std::transform (extension.begin (), extension.end (), extension.begin (), tolower);
  77.    
  78.     // Check if found
  79.     std::string::size_type it;
  80.     if ((it = fname.find (extension)) != std::string::npos)
  81.     {
  82.       // Additional check: we want to be able to differentiate between .p and .png
  83.       if ((extension.size () - (fname.size () - it)) == 0)
  84.         indices.push_back (i);
  85.     }
  86.   }
  87.   return (indices);
  88. }
  89.  
  90. bool
  91. loadCloud (const std::string &filename, pcl::PCLPointCloud2 &cloud)
  92. {
  93.   using namespace pcl::console;
  94.   TicToc tt;
  95.   print_highlight ("Loading "); print_value ("%s ", filename.c_str ());
  96.  
  97.   tt.tic ();
  98.   if (pcl::io::loadPCDFile (filename, cloud, translation, orientation) < 0)
  99.     return (false);
  100.   print_info ("[done, "); print_value ("%g", tt.toc ()); print_info (" ms : "); print_value ("%d", cloud.width * cloud.height); print_info (" points]\n");
  101.   print_info ("Available dimensions: "); print_value ("%s\n", pcl::getFieldsList (cloud).c_str ());
  102.  
  103.   return (true);
  104. }
  105.  
  106. void
  107. saveCloud (const std::string &filename, const pcl::PCLPointCloud2 &output)
  108. {
  109.   using namespace pcl::console;
  110.   TicToc tt;
  111.   tt.tic ();
  112.  
  113.   print_highlight ("Saving "); print_value ("%s ", filename.c_str ());
  114.  
  115.   pcl::PCDWriter w;
  116.   w.writeBinaryCompressed (filename, output, translation, orientation);
  117.  
  118.   print_info ("[done, "); print_value ("%g", tt.toc ()); print_info (" ms : "); print_value ("%d", output.width * output.height); print_info (" points]\n");
  119. }
  120.  
  121.  
  122. /* ---[ */
  123. int
  124. main (int argc, char** argv)
  125. char output_fname[2048];
  126. {
  127.   if (argc < 2)
  128.   {
  129.     std::cerr << "Syntax is: " << argv[0] << " <filename 1..N.pcd>" << std::endl;
  130.     std::cerr << "Result will be saved to output.pcd" << std::endl;
  131.     return (-1);
  132.   }
  133.  
  134.   std::vector<int> file_indices = parseFileExtensionArgument (argc, argv, ".pcd");
  135.  
  136.   //pcl::PointCloud<pcl::PointXYZ> cloud_all;
  137.   pcl::PCLPointCloud2 cloud_all;
  138.   for (size_t i = 0; i < file_indices.size (); ++i)
  139.   {
  140.     // Load the Point Cloud
  141.     pcl::PCLPointCloud2 cloud;
  142.     loadCloud (argv[file_indices[i]], cloud);
  143.     //pcl::PointCloud<pcl::PointXYZ> cloud;
  144.     //pcl::io::loadPCDFile (argv[file_indices[i]], cloud);
  145.     //cloud_all += cloud;
  146.     pcl::concatenatePointCloud (cloud_all, cloud, cloud_all);
  147.     PCL_INFO ("Total number of points so far: %u. Total data size: %zu bytes.\n", cloud_all.width * cloud_all.height, cloud_all.data.size ());
  148.   }
  149. std::cout << "Output file name:";
  150. std::cin >> output_fname;
  151.   saveCloud(output_fname,cloud_all);
  152.  
  153.   return (0);
  154. }
  155. /* ]--- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement