00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
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
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
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
00148 saveCloud (argv[p_file_indices[1]], translation, orientation, cloud);
00149 }
00150