pcd_change_viewpoint.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2012-, Open Perception, 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 the copyright holder(s) 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: normal_estimation.cpp 4990 2012-03-09 08:30:36Z rusu $
00037  *
00038  */
00039 
00040 #include <pcl/PCLPointCloud2.h>
00041 #include <pcl/io/pcd_io.h>
00042 #include <pcl/features/normal_3d.h>
00043 #include <pcl/console/print.h>
00044 #include <pcl/console/parse.h>
00045 #include <pcl/console/time.h>
00046 
00047 using namespace pcl;
00048 using namespace pcl::io;
00049 using namespace pcl::console;
00050 
00051 void
00052 printHelp (int, char **argv)
00053 {
00054   print_error ("Syntax is: %s input.pcd output.pcd <options>\n", argv[0]);
00055   print_info ("  where options are:\n");
00056   print_info ("                     -viewpoint Tx,Ty,Tz,Qw,Qx,Qy,Qz\n");
00057 }
00058 
00059 bool
00060 loadCloud (const std::string &filename, pcl::PCLPointCloud2 &cloud)
00061 {
00062   Eigen::Vector4f    translation;
00063   Eigen::Quaternionf orientation;
00064 
00065   TicToc tt;
00066   print_highlight ("Loading "); print_value ("%s ", filename.c_str ());
00067 
00068   tt.tic ();
00069   if (loadPCDFile (filename, cloud, translation, orientation) < 0)
00070     return (false);
00071   print_info ("[done, "); print_value ("%g", tt.toc ()); print_info (" ms : "); print_value ("%d", cloud.width * cloud.height); print_info (" points]\n");
00072   print_info ("VIEWPOINT information is: "); 
00073   print_value ("%.2f %.2f %.2f / %.2f %.2f %.2f %.2f\n", 
00074       translation.x (), translation.y (), translation.z (),
00075       orientation.w (), orientation.x (), orientation.y (), orientation.z ());
00076 
00077   return (true);
00078 }
00079 
00080 void
00081 saveCloud (const std::string &filename, 
00082            const Eigen::Vector4f    &translation,
00083            const Eigen::Quaternionf &orientation,
00084            const pcl::PCLPointCloud2 &output)
00085 {
00086   TicToc tt;
00087   tt.tic ();
00088 
00089   print_highlight ("Saving "); print_value ("%s ", filename.c_str ());
00090 
00091   PCDWriter w;
00092   w.writeBinaryCompressed (filename, output, translation, orientation);
00093   
00094   print_info ("[done, "); print_value ("%g", tt.toc ()); print_info (" ms : "); print_value ("%d", output.width * output.height); print_info (" points]\n");
00095 }
00096 
00097 /* ---[ */
00098 int
00099 main (int argc, char** argv)
00100 {
00101   print_info ("Change viewpoint information in a PCD file. For more information, use: %s -h\n", argv[0]);
00102 
00103   if (argc < 4)
00104   {
00105     printHelp (argc, argv);
00106     return (-1);
00107   }
00108 
00109   Eigen::Vector4f    translation = Eigen::Vector4f::Zero ();
00110   Eigen::Quaternionf orientation = Eigen::Quaternionf::Identity ();
00111 
00112   std::vector<float> values;
00113   if (parse_x_arguments (argc, argv, "-viewpoint", values) > -1)
00114   {
00115     if (values.size () == 7)
00116     {
00117       translation = Eigen::Vector4f (values[0], values[1], values[2], 0.0f);
00118       orientation = Eigen::Quaternionf (values[3], values[4], values[5], values[6]);
00119     }
00120     else
00121     {
00122       print_error ("Wrong number of values given (%zu): ", values.size ());
00123       print_error ("The VIEWPOINT specified with -viewpoint must contain 7 elements (tx, ty, tz, qw, qx, qy, qz).\n");
00124       return (-1);
00125     }
00126   }
00127 
00128   // Parse the command line arguments for .pcd files
00129   std::vector<int> p_file_indices;
00130   p_file_indices = parse_file_extension_argument (argc, argv, ".pcd");
00131   if (p_file_indices.size () != 2)
00132   {
00133     print_error ("Need one input PCD file and one output PCD file to continue.\n");
00134     return (-1);
00135   }
00136 
00137   // Load the first file
00138   pcl::PCLPointCloud2 cloud;
00139   if (!loadCloud (argv[p_file_indices[0]], cloud)) 
00140     return (-1);
00141 
00142   print_info ("Saving output PCD file with the following VIEWPOINT information: "); 
00143   print_value ("%.2f %.2f %.2f / %.2f %.2f %.2f %.2f\n", 
00144       translation.x (), translation.y (), translation.z (),
00145       orientation.w (), orientation.x (), orientation.y (), orientation.z ());
00146 
00147   // Save into the second file
00148   saveCloud (argv[p_file_indices[1]], translation, orientation, cloud);
00149 }
00150 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:27:52