plyheader.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) 2007-2012, Ares Lagae
00006  *  Copyright (c) 2012, Willow Garage, Inc.
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: plyheader.cpp 4024 2012-01-26 12:23:37Z bouffa $
00037  *
00038  */
00039 
00040 #include <fstream>
00041 #include <iostream>
00042 #include <string.h>
00043 #include <string>
00044 #include <stdlib.h>
00045 
00051 int main (int argc, char* argv[])
00052 {
00053   int argi;
00054   for (argi = 1; argi < argc; ++argi) {
00055 
00056     if (argv[argi][0] != '-') {
00057       break;
00058     }
00059     if (argv[argi][1] == 0) {
00060       ++argi;
00061       break;
00062     }
00063     char short_opt, *long_opt, *opt_arg;
00064     if (argv[argi][1] != '-') {
00065       short_opt = argv[argi][1];
00066       opt_arg = &argv[argi][2];
00067       long_opt = &argv[argi][2];
00068       while (*long_opt != '\0') {
00069         ++long_opt;
00070       }
00071     }
00072     else {
00073       short_opt = 0;
00074       long_opt = &argv[argi][2];
00075       opt_arg = long_opt;
00076       while ((*opt_arg != '=') && (*opt_arg != '\0')) {
00077         ++opt_arg;
00078       }
00079       if (*opt_arg == '=') {
00080         *opt_arg++ = '\0';
00081       }
00082     }
00083 
00084     if ((short_opt == 'h') || (strcmp (long_opt, "help") == 0)) {
00085       std::cout << "Usage: plyheader [OPTION] [[INFILE] OUTFILE]\n";
00086       std::cout << "Extract the header from a PLY file.\n";
00087       std::cout << "\n";
00088       std::cout << "  -h, --help       display this help and exit\n";
00089       std::cout << "  -v, --version    output version information and exit\n";
00090       std::cout << "\n";
00091       std::cout << "With no INFILE/OUTFILE, or when INFILE/OUTFILE is -, read standard input/output.\n";
00092       std::cout << "\n";
00093       std::cout << "Report bugs to <www.pointclouds.org/issues>.\n";
00094       return EXIT_SUCCESS;
00095     }
00096 
00097     else if ((short_opt == 'v') || (strcmp (long_opt, "version") == 0)) {
00098       std::cout << "plyheader \n";
00099       std::cout << " Point Cloud Library (PCL) - www.pointclouds.org\n";
00100       std::cout << " Copyright (c) 2007-2012, Ares Lagae\n";
00101       std::cout << " Copyright (c) 2012, Willow Garage, Inc.\n";
00102       std::cout << " All rights reserved.\n";
00103       std::cout << " Redistribution and use in source and binary forms, with or without\n";
00104       std::cout << " modification, are permitted provided that the following conditions\n";
00105       std::cout << " are met:\n";
00106       std::cout << "  * Redistributions of source code must retain the above copyright\n";
00107       std::cout << "    notice, this list of conditions and the following disclaimer.\n";
00108       std::cout << "  * Redistributions in binary form must reproduce the above\n";
00109       std::cout << "    copyright notice, this list of conditions and the following\n";
00110       std::cout << "    disclaimer in the documentation and/or other materials provided\n";
00111       std::cout << "    with the distribution.\n";
00112       std::cout << "  * Neither the name of Willow Garage, Inc. nor the names of its\n";
00113       std::cout << "    contributors may be used to endorse or promote products derived\n";
00114       std::cout << "    from this software without specific prior written permission.\n";
00115       std::cout << " THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n";
00116       std::cout << " \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n";
00117       std::cout << " LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\n";
00118       std::cout << " FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\n";
00119       std::cout << " COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\n";
00120       std::cout << " INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\n";
00121       std::cout << " BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n";
00122       std::cout << " LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n";
00123       std::cout << " CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n";
00124       std::cout << " LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\n";
00125       std::cout << " ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n";
00126       std::cout << " POSSIBILITY OF SUCH DAMAGE.\n";
00127       return EXIT_SUCCESS;
00128     }
00129 
00130     else {
00131       std::cerr << "plyheader: " << "invalid option `" << argv[argi] << "'" << "\n";
00132       std::cerr << "Try `" << argv[0] << " --help' for more information.\n";
00133       return EXIT_FAILURE;
00134     }
00135   }
00136 
00137   int parc = argc - argi;
00138   char** parv = argv + argi;
00139   if (parc > 2) {
00140     std::cerr << "plyheader: " << "too many parameters" << "\n";
00141     std::cerr << "Try `" << argv[0] << " --help' for more information.\n";
00142     return EXIT_FAILURE;
00143   }
00144 
00145   std::ifstream ifstream;
00146   const char* ifilename = "";
00147   if (parc > 0) {
00148     ifilename = parv[0];
00149     if (strcmp (ifilename, "-") != 0) {
00150       ifstream.open (ifilename);
00151       if (!ifstream.is_open ()) {
00152         std::cerr << "plyheader: " << ifilename << ": " << "no such file or directory" << "\n";
00153         return EXIT_FAILURE;
00154       }
00155     }
00156   }
00157 
00158   std::ofstream ofstream;
00159   const char* ofilename = "";
00160   if (parc > 1) {
00161     ofilename = parv[1];
00162     if (strcmp (ofilename, "-") != 0) {
00163       ofstream.open (ofilename);
00164       if (!ofstream.is_open ()) {
00165         std::cerr << "plyheader: " << ofilename << ": " << "could not open file" << "\n";
00166         return EXIT_FAILURE;
00167       }
00168     }
00169   }
00170 
00171   std::istream& istream = ifstream.is_open () ? ifstream : std::cin;
00172   std::ostream& ostream = ofstream.is_open () ? ofstream : std::cout;
00173 
00174   char magic[3];
00175   istream.read (magic, 3);
00176   if (!istream || (magic[0] != 'p') || (magic[1] != 'l') || (magic[2] != 'y')){
00177     return EXIT_FAILURE;
00178   }
00179   istream.ignore (1);
00180   ostream << magic[0] << magic[1] << magic[2] << "\n";
00181   std::string line;
00182   while (std::getline (istream, line)) {
00183     ostream << line << "\n";
00184     if (line == "end_header") {
00185       break;
00186     }
00187   }
00188   return istream ? EXIT_SUCCESS : EXIT_FAILURE;
00189 }


pcl
Author(s): Open Perception
autogenerated on Mon Oct 6 2014 03:16:32