obj2raw.cpp
Go to the documentation of this file.
00001 #include <cstdlib>
00002 #include <cstring>
00003 #include <fstream>
00004 #include <vector>
00005 #include <iostream>
00006 
00007 #include <tr1/functional>
00008 
00009 #include <obj.hpp>
00010 
00011 #ifdef HAVE_CONFIG_H
00012 #  include <config.h>
00013 #endif
00014 
00015 class obj_to_raw_converter
00016 {
00017 public:
00018   obj_to_raw_converter() {}
00019   bool convert(std::istream& istream, std::ostream& ostream);
00020 private:
00021   void info_callback(const std::string& filename, std::size_t line_number, const std::string& message);
00022   void warning_callback(const std::string& filename, std::size_t line_number, const std::string& message);
00023   void error_callback(const std::string& filename, std::size_t line_number, const std::string& message);
00024   void geometric_vertex_callback(obj::float_type x, obj::float_type y, obj::float_type z);
00025   void texture_vertex_callback(obj::float_type u, obj::float_type v);
00026   void vertex_normal_callback(obj::float_type x, obj::float_type y, obj::float_type z);
00027   void triangular_face_geometric_vertices_callback(obj::index_type v1, obj::index_type v2, obj::index_type v3);
00028   void triangular_face_geometric_vertices_texture_vertices_callback(const obj::index_2_tuple_type& v1_vt1, const obj::index_2_tuple_type& v2_vt2, const obj::index_2_tuple_type& v3_vt3);
00029   void triangular_face_geometric_vertices_vertex_normals_callback(const obj::index_2_tuple_type& v1_vn1, const obj::index_2_tuple_type& v2_vn2, const obj::index_2_tuple_type& v3_vn3);
00030   void triangular_face_geometric_vertices_texture_vertices_vertex_normals_callback(const obj::index_3_tuple_type& v1_vt1_vn1, const obj::index_3_tuple_type& v2_vt2_vn2, const obj::index_3_tuple_type& v3_vt3_vn3);
00031   void quadrilateral_face_geometric_vertices_callback(obj::index_type v1, obj::index_type v2, obj::index_type v3, obj::index_type v4);
00032   void quadrilateral_face_geometric_vertices_texture_vertices_callback(const obj::index_2_tuple_type& v1_vt1, const obj::index_2_tuple_type& v2_vt2, const obj::index_2_tuple_type& v3_vt3, const obj::index_2_tuple_type& v4_vt4);
00033   void quadrilateral_face_geometric_vertices_vertex_normals_callback(const obj::index_2_tuple_type& v1_vn1, const obj::index_2_tuple_type& v2_vn2, const obj::index_2_tuple_type& v3_vn3, const obj::index_2_tuple_type& v4_vn4);
00034   void quadrilateral_face_geometric_vertices_texture_vertices_vertex_normals_callback(const obj::index_3_tuple_type& v1_vt1_vn1, const obj::index_3_tuple_type& v2_vt2_vn2, const obj::index_3_tuple_type& v3_vt3_vn3, const obj::index_3_tuple_type& v4_vt4_vn4);
00035   void polygonal_face_geometric_vertices_begin_callback(obj::index_type v1, obj::index_type v2, obj::index_type v3);
00036   void polygonal_face_geometric_vertices_vertex_callback(obj::index_type v);
00037   void polygonal_face_geometric_vertices_end_callback();
00038   void polygonal_face_geometric_vertices_texture_vertices_begin_callback(const obj::index_2_tuple_type& v1_vt1, const obj::index_2_tuple_type& v2_vt2, const obj::index_2_tuple_type& v3_vt3);
00039   void polygonal_face_geometric_vertices_texture_vertices_vertex_callback(const obj::index_2_tuple_type& v_vt);
00040   void polygonal_face_geometric_vertices_texture_vertices_end_callback();
00041   void polygonal_face_geometric_vertices_vertex_normals_begin_callback(const obj::index_2_tuple_type& v1_vn1, const obj::index_2_tuple_type& v2_vn2, const obj::index_2_tuple_type& v3_vn3);
00042   void polygonal_face_geometric_vertices_vertex_normals_vertex_callback(const obj::index_2_tuple_type& v_vn);
00043   void polygonal_face_geometric_vertices_vertex_normals_end_callback();
00044   void polygonal_face_geometric_vertices_texture_vertices_vertex_normals_begin_callback(const obj::index_3_tuple_type& v1_vt1_vn1, const obj::index_3_tuple_type& v2_vt2_vn2, const obj::index_3_tuple_type& v3_vt3_vn3);
00045   void polygonal_face_geometric_vertices_texture_vertices_vertex_normals_vertex_callback(const obj::index_3_tuple_type& v_vt_vn);
00046   void polygonal_face_geometric_vertices_texture_vertices_vertex_normals_end_callback();
00047   void group_name_callback(const std::string& group_name);
00048   void smoothing_group_callback(obj::size_type group_number);
00049   void object_name_callback(const std::string& object_name);
00050   void material_library_callback(const std::string& filename);
00051   void material_name_callback(const std::string& material_name);
00052   void comment_callback(const std::string& comment);
00053   std::ostream* ostream_;
00054   std::vector<std::tr1::tuple<obj::float_type, obj::float_type, obj::float_type> > vertices_;
00055 };
00056 
00057 void obj_to_raw_converter::info_callback(const std::string& filename, std::size_t line_number, const std::string& message)
00058 {
00059   std::cerr << filename << ":" << line_number << ": " << "info: " << message << std::endl;
00060 }
00061 
00062 void obj_to_raw_converter::warning_callback(const std::string& filename, std::size_t line_number, const std::string& message)
00063 {
00064   std::cerr << filename << ":" << line_number << ": " << "warning: " << message << std::endl;
00065 }
00066 
00067 void obj_to_raw_converter::error_callback(const std::string& filename, std::size_t line_number, const std::string& message)
00068 {
00069   std::cerr << filename << ":" << line_number << ": " << "error: " << message << std::endl;
00070 }
00071 
00072 void obj_to_raw_converter::geometric_vertex_callback(obj::float_type x, obj::float_type y, obj::float_type z)
00073 {
00074   vertices_.push_back(std::tr1::tuple<obj::float_type, obj::float_type, obj::float_type >(x, y, z));
00075 }
00076 
00077 void obj_to_raw_converter::texture_vertex_callback(obj::float_type u, obj::float_type v)
00078 {
00079 }
00080 
00081 void obj_to_raw_converter::vertex_normal_callback(obj::float_type x, obj::float_type y, obj::float_type z)
00082 {
00083 }
00084 
00085 void obj_to_raw_converter::triangular_face_geometric_vertices_callback(obj::index_type v1, obj::index_type v2, obj::index_type v3)
00086 {
00087   (*ostream_) << std::tr1::get<0>(vertices_[v1 - 1])
00088        << " " << std::tr1::get<1>(vertices_[v1 - 1])
00089        << " " << std::tr1::get<2>(vertices_[v1 - 1])
00090        << " " << std::tr1::get<0>(vertices_[v2 - 1])
00091        << " " << std::tr1::get<1>(vertices_[v2 - 1])
00092        << " " << std::tr1::get<2>(vertices_[v2 - 1])
00093        << " " << std::tr1::get<0>(vertices_[v3 - 1])
00094        << " " << std::tr1::get<1>(vertices_[v3 - 1])
00095        << " " << std::tr1::get<2>(vertices_[v3 - 1]) << "\n";
00096 }
00097 
00098 void obj_to_raw_converter::triangular_face_geometric_vertices_texture_vertices_callback(const obj::index_2_tuple_type& v1_vt1, const obj::index_2_tuple_type& v2_vt2, const obj::index_2_tuple_type& v3_vt3)
00099 {
00100   (*ostream_) << std::tr1::get<0>(vertices_[std::tr1::get<0>(v1_vt1) - 1])
00101        << " " << std::tr1::get<1>(vertices_[std::tr1::get<0>(v1_vt1) - 1])
00102        << " " << std::tr1::get<2>(vertices_[std::tr1::get<0>(v1_vt1) - 1])
00103        << " " << std::tr1::get<0>(vertices_[std::tr1::get<0>(v2_vt2) - 1])
00104        << " " << std::tr1::get<1>(vertices_[std::tr1::get<0>(v2_vt2) - 1])
00105        << " " << std::tr1::get<2>(vertices_[std::tr1::get<0>(v2_vt2) - 1])
00106        << " " << std::tr1::get<0>(vertices_[std::tr1::get<0>(v3_vt3) - 1])
00107        << " " << std::tr1::get<1>(vertices_[std::tr1::get<0>(v3_vt3) - 1])
00108        << " " << std::tr1::get<2>(vertices_[std::tr1::get<0>(v3_vt3) - 1]) << "\n";
00109 }
00110 
00111 void obj_to_raw_converter::triangular_face_geometric_vertices_vertex_normals_callback(const obj::index_2_tuple_type& v1_vn1, const obj::index_2_tuple_type& v2_vn2, const obj::index_2_tuple_type& v3_vn3)
00112 {
00113   (*ostream_) << std::tr1::get<0>(vertices_[std::tr1::get<0>(v1_vn1) - 1])
00114        << " " << std::tr1::get<1>(vertices_[std::tr1::get<0>(v1_vn1) - 1])
00115        << " " << std::tr1::get<2>(vertices_[std::tr1::get<0>(v1_vn1) - 1])
00116        << " " << std::tr1::get<0>(vertices_[std::tr1::get<0>(v2_vn2) - 1])
00117        << " " << std::tr1::get<1>(vertices_[std::tr1::get<0>(v2_vn2) - 1])
00118        << " " << std::tr1::get<2>(vertices_[std::tr1::get<0>(v2_vn2) - 1])
00119        << " " << std::tr1::get<0>(vertices_[std::tr1::get<0>(v3_vn3) - 1])
00120        << " " << std::tr1::get<1>(vertices_[std::tr1::get<0>(v3_vn3) - 1])
00121        << " " << std::tr1::get<2>(vertices_[std::tr1::get<0>(v3_vn3) - 1]) << "\n";
00122 }
00123 
00124 void obj_to_raw_converter::triangular_face_geometric_vertices_texture_vertices_vertex_normals_callback(const obj::index_3_tuple_type& v1_vt1_vn1, const obj::index_3_tuple_type& v2_vt2_vn2, const obj::index_3_tuple_type& v3_vt3_vn3)
00125 {
00126   (*ostream_) << std::tr1::get<0>(vertices_[std::tr1::get<0>(v1_vt1_vn1) - 1])
00127        << " " << std::tr1::get<1>(vertices_[std::tr1::get<0>(v1_vt1_vn1) - 1])
00128        << " " << std::tr1::get<2>(vertices_[std::tr1::get<0>(v1_vt1_vn1) - 1])
00129        << " " << std::tr1::get<0>(vertices_[std::tr1::get<0>(v2_vt2_vn2) - 1])
00130        << " " << std::tr1::get<1>(vertices_[std::tr1::get<0>(v2_vt2_vn2) - 1])
00131        << " " << std::tr1::get<2>(vertices_[std::tr1::get<0>(v2_vt2_vn2) - 1])
00132        << " " << std::tr1::get<0>(vertices_[std::tr1::get<0>(v3_vt3_vn3) - 1])
00133        << " " << std::tr1::get<1>(vertices_[std::tr1::get<0>(v3_vt3_vn3) - 1])
00134        << " " << std::tr1::get<2>(vertices_[std::tr1::get<0>(v3_vt3_vn3) - 1]) << "\n";
00135 }
00136 
00137 void obj_to_raw_converter::quadrilateral_face_geometric_vertices_callback(obj::index_type v1, obj::index_type v2, obj::index_type v3, obj::index_type v4)
00138 {
00139 }
00140 
00141 void obj_to_raw_converter::quadrilateral_face_geometric_vertices_texture_vertices_callback(const obj::index_2_tuple_type& v1_vt1, const obj::index_2_tuple_type& v2_vt2, const obj::index_2_tuple_type& v3_vt3, const obj::index_2_tuple_type& v4_vt4)
00142 {
00143 }
00144 
00145 void obj_to_raw_converter::quadrilateral_face_geometric_vertices_vertex_normals_callback(const obj::index_2_tuple_type& v1_vn1, const obj::index_2_tuple_type& v2_vn2, const obj::index_2_tuple_type& v3_vn3, const obj::index_2_tuple_type& v4_vn4)
00146 {
00147 }
00148 
00149 void obj_to_raw_converter::quadrilateral_face_geometric_vertices_texture_vertices_vertex_normals_callback(const obj::index_3_tuple_type& v1_vt1_vn1, const obj::index_3_tuple_type& v2_vt2_vn2, const obj::index_3_tuple_type& v3_vt3_vn3, const obj::index_3_tuple_type& v4_vt4_vn4)
00150 {
00151 }
00152 
00153 void obj_to_raw_converter::polygonal_face_geometric_vertices_begin_callback(obj::index_type v1, obj::index_type v2, obj::index_type v3)
00154 {
00155 }
00156 
00157 void obj_to_raw_converter::polygonal_face_geometric_vertices_vertex_callback(obj::index_type v)
00158 {
00159 }
00160 
00161 void obj_to_raw_converter::polygonal_face_geometric_vertices_end_callback()
00162 {
00163 }
00164 
00165 void obj_to_raw_converter::polygonal_face_geometric_vertices_texture_vertices_begin_callback(const obj::index_2_tuple_type& v1_vt1, const obj::index_2_tuple_type& v2_vt2, const obj::index_2_tuple_type& v3_vt3)
00166 {
00167 }
00168 
00169 void obj_to_raw_converter::polygonal_face_geometric_vertices_texture_vertices_vertex_callback(const obj::index_2_tuple_type& v_vt)
00170 {
00171 }
00172 
00173 void obj_to_raw_converter::polygonal_face_geometric_vertices_texture_vertices_end_callback()
00174 {
00175 }
00176 
00177 void obj_to_raw_converter::polygonal_face_geometric_vertices_vertex_normals_begin_callback(const obj::index_2_tuple_type& v1_vn1, const obj::index_2_tuple_type& v2_vn2, const obj::index_2_tuple_type& v3_vn3)
00178 {
00179 }
00180 
00181 void obj_to_raw_converter::polygonal_face_geometric_vertices_vertex_normals_vertex_callback(const obj::index_2_tuple_type& v_vn)
00182 {
00183 }
00184 
00185 void obj_to_raw_converter::polygonal_face_geometric_vertices_vertex_normals_end_callback()
00186 {
00187 }
00188 
00189 void obj_to_raw_converter::polygonal_face_geometric_vertices_texture_vertices_vertex_normals_begin_callback(const obj::index_3_tuple_type& v1_vt1_vn1, const obj::index_3_tuple_type& v2_vt2_vn2, const obj::index_3_tuple_type& v3_vt3_vn3)
00190 {
00191 }
00192 
00193 void obj_to_raw_converter::polygonal_face_geometric_vertices_texture_vertices_vertex_normals_vertex_callback(const obj::index_3_tuple_type& v_vt_vn)
00194 {
00195 }
00196 
00197 void obj_to_raw_converter::polygonal_face_geometric_vertices_texture_vertices_vertex_normals_end_callback()
00198 {
00199 }
00200 
00201 void obj_to_raw_converter::group_name_callback(const std::string& group_name)
00202 {
00203 }
00204 
00205 void obj_to_raw_converter::smoothing_group_callback(obj::size_type group_number)
00206 {
00207 }
00208 
00209 void obj_to_raw_converter::object_name_callback(const std::string& object_name)
00210 {
00211 }
00212 
00213 void obj_to_raw_converter::material_library_callback(const std::string& filename)
00214 {
00215 }
00216 
00217 void obj_to_raw_converter::material_name_callback(const std::string& material_name)
00218 {
00219 }
00220 
00221 void obj_to_raw_converter::comment_callback(const std::string& comment)
00222 {
00223 }
00224 
00225 bool obj_to_raw_converter::convert(std::istream& istream, std::ostream& ostream)
00226 {
00227   using namespace std::tr1::placeholders;
00228 
00229   obj::obj_parser::flags_type obj_parser_flags = 0;
00230   obj_parser_flags |= obj::obj_parser::triangulate_faces;
00231   obj_parser_flags |= obj::obj_parser::translate_negative_indices;
00232 
00233   obj::obj_parser obj_parser(obj_parser_flags);
00234 
00235   std::string ifilename;
00236 
00237   obj_parser.info_callback(std::tr1::bind(&obj_to_raw_converter::info_callback, this, ifilename, _1, _2));
00238   obj_parser.warning_callback(std::tr1::bind(&obj_to_raw_converter::warning_callback, this, ifilename, _1, _2));
00239   obj_parser.error_callback(std::tr1::bind(&obj_to_raw_converter::error_callback, this, ifilename, _1, _2));
00240 
00241   obj_parser.geometric_vertex_callback(std::tr1::bind(&obj_to_raw_converter::geometric_vertex_callback, this, _1, _2, _3));
00242   obj_parser.texture_vertex_callback(std::tr1::bind(&obj_to_raw_converter::texture_vertex_callback, this, _1, _2));
00243   obj_parser.vertex_normal_callback(std::tr1::bind(&obj_to_raw_converter::vertex_normal_callback, this, _1, _2, _3));
00244   obj_parser.face_callbacks(
00245     std::tr1::bind(&obj_to_raw_converter::triangular_face_geometric_vertices_callback, this, _1, _2, _3),
00246     std::tr1::bind(&obj_to_raw_converter::triangular_face_geometric_vertices_texture_vertices_callback, this, _1, _2, _3),
00247     std::tr1::bind(&obj_to_raw_converter::triangular_face_geometric_vertices_vertex_normals_callback, this, _1, _2, _3),
00248     std::tr1::bind(&obj_to_raw_converter::triangular_face_geometric_vertices_texture_vertices_vertex_normals_callback, this, _1, _2, _3),
00249     std::tr1::bind(&obj_to_raw_converter::quadrilateral_face_geometric_vertices_callback, this, _1, _2, _3, _4),
00250     std::tr1::bind(&obj_to_raw_converter::quadrilateral_face_geometric_vertices_texture_vertices_callback, this, _1, _2, _3, _4),
00251     std::tr1::bind(&obj_to_raw_converter::quadrilateral_face_geometric_vertices_vertex_normals_callback, this, _1, _2, _3, _4),
00252     std::tr1::bind(&obj_to_raw_converter::quadrilateral_face_geometric_vertices_texture_vertices_vertex_normals_callback, this, _1, _2, _3, _4),
00253     std::tr1::bind(&obj_to_raw_converter::polygonal_face_geometric_vertices_begin_callback, this, _1, _2, _3),
00254     std::tr1::bind(&obj_to_raw_converter::polygonal_face_geometric_vertices_vertex_callback, this, _1),
00255     std::tr1::bind(&obj_to_raw_converter::polygonal_face_geometric_vertices_end_callback, this),
00256     std::tr1::bind(&obj_to_raw_converter::polygonal_face_geometric_vertices_texture_vertices_begin_callback, this, _1, _2, _3),
00257     std::tr1::bind(&obj_to_raw_converter::polygonal_face_geometric_vertices_texture_vertices_vertex_callback, this, _1),
00258     std::tr1::bind(&obj_to_raw_converter::polygonal_face_geometric_vertices_texture_vertices_end_callback, this),
00259     std::tr1::bind(&obj_to_raw_converter::polygonal_face_geometric_vertices_vertex_normals_begin_callback, this, _1, _2, _3),
00260     std::tr1::bind(&obj_to_raw_converter::polygonal_face_geometric_vertices_vertex_normals_vertex_callback, this, _1),
00261     std::tr1::bind(&obj_to_raw_converter::polygonal_face_geometric_vertices_vertex_normals_end_callback, this),
00262     std::tr1::bind(&obj_to_raw_converter::polygonal_face_geometric_vertices_texture_vertices_vertex_normals_begin_callback, this, _1, _2, _3),
00263     std::tr1::bind(&obj_to_raw_converter::polygonal_face_geometric_vertices_texture_vertices_vertex_normals_vertex_callback, this, _1),
00264     std::tr1::bind(&obj_to_raw_converter::polygonal_face_geometric_vertices_texture_vertices_vertex_normals_end_callback, this)
00265   );
00266   obj_parser.group_name_callback(std::tr1::bind(&obj_to_raw_converter::group_name_callback, this, _1));
00267   obj_parser.smoothing_group_callback(std::tr1::bind(&obj_to_raw_converter::smoothing_group_callback, this, _1));
00268   obj_parser.object_name_callback(std::tr1::bind(&obj_to_raw_converter::object_name_callback, this, _1));
00269   obj_parser.material_library_callback(std::tr1::bind(&obj_to_raw_converter::material_library_callback, this, _1));
00270   obj_parser.material_name_callback(std::tr1::bind(&obj_to_raw_converter::material_name_callback, this, _1));
00271   obj_parser.comment_callback(std::tr1::bind(&obj_to_raw_converter::comment_callback, this, _1));
00272 
00273   ostream_ = &ostream;
00274 
00275   return obj_parser.parse(istream);
00276 }
00277 
00278 int main(int argc, char* argv[])
00279 {
00280   int argi;
00281   for (argi = 1; argi < argc; ++argi) {
00282 
00283     if (argv[argi][0] != '-') {
00284       break;
00285     }
00286     if (argv[argi][1] == 0) {
00287       ++argi;
00288       break;
00289     }
00290     char short_opt, *long_opt, *opt_arg;
00291     if (argv[argi][1] != '-') {
00292       short_opt = argv[argi][1];
00293       opt_arg = &argv[argi][2];
00294       long_opt = &argv[argi][2];
00295       while (*long_opt != '\0') {
00296         ++long_opt;
00297       }
00298     }
00299     else {
00300       short_opt = 0;
00301       long_opt = &argv[argi][2];
00302       opt_arg = long_opt;
00303       while ((*opt_arg != '=') && (*opt_arg != '\0')) {
00304         ++opt_arg;
00305       }
00306       if (*opt_arg == '=') {
00307         *opt_arg++ = '\0';
00308       }
00309     }
00310 
00311     if ((short_opt == 'h') || (std::strcmp(long_opt, "help") == 0)) {
00312       std::cout << "Usage: obj2raw [OPTION] [[INFILE] OUTFILE]\n";
00313       std::cout << "Convert from OBJ to POV-Ray RAW triangle format.\n";
00314       std::cout << "\n";
00315       std::cout << "  -h, --help       display this help and exit\n";
00316       std::cout << "  -v, --version    output version information and exit\n";
00317       std::cout << "\n";
00318       std::cout << "With no INFILE/OUTFILE, or when INFILE/OUTFILE is -, read standard input/output.\n";
00319       std::cout << "\n";
00320       std::cout << "Report bugs to <" << PACKAGE_BUGREPORT << ">.\n";
00321       return EXIT_SUCCESS;
00322     }
00323 
00324     else if ((short_opt == 'v') || (std::strcmp(long_opt, "version") == 0)) {
00325       std::cout << "obj2raw (" << PACKAGE_NAME << ") " << PACKAGE_VERSION << "\n";
00326       std::cout << "Copyright (C) 2007 " << PACKAGE_AUTHOR << "\n";
00327       std::cout << "\n";
00328       std::cout << "This program is free software; you can redistribute it and/or modify\n";
00329       std::cout << "it under the terms of the GNU General Public License as published by\n";
00330       std::cout << "the Free Software Foundation; either version 2 of the License, or\n";
00331       std::cout << "(at your option) any later version.\n";
00332       std::cout << "\n";
00333       std::cout << "This program is distributed in the hope that it will be useful,\n";
00334       std::cout << "but WITHOUT ANY WARRANTY; without even the implied warranty of\n";
00335       std::cout << "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n";
00336       std::cout << "GNU General Public License for more details.\n";
00337       std::cout << "\n";
00338       std::cout << "You should have received a copy of the GNU General Public License\n";
00339       std::cout << "along with this program; if not, write to the Free Software\n";
00340       std::cout << "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n";
00341       return EXIT_SUCCESS;
00342     }
00343 
00344     else {
00345       std::cerr << "obj2raw: " << "invalid option `" << argv[argi] << "'" << "\n";
00346       std::cerr << "Try `" << argv[0] << " --help' for more information.\n";
00347       return EXIT_FAILURE;
00348     }
00349   }
00350 
00351   int parc = argc - argi;
00352   char** parv = argv + argi;
00353   if (parc > 2) {
00354     std::cerr << "obj2raw: " << "too many parameters" << "\n";
00355     std::cerr << "Try `" << argv[0] << " --help' for more information.\n";
00356     return EXIT_FAILURE;
00357   }
00358 
00359   std::ifstream ifstream;
00360   const char* ifilename = "";
00361   if (parc > 0) {
00362     ifilename = parv[0];
00363     if (std::strcmp(ifilename, "-") != 0) {
00364       ifstream.open(ifilename);
00365       if (!ifstream.is_open()) {
00366         std::cerr << "obj2raw: " << ifilename << ": " << "no such file or directory" << "\n";
00367         return EXIT_FAILURE;
00368       }
00369     }
00370   }
00371 
00372   std::ofstream ofstream;
00373   const char* ofilename = "";
00374   if (parc > 1) {
00375     ofilename = parv[1];
00376     if (std::strcmp(ofilename, "-") != 0) {
00377       ofstream.open(ofilename);
00378       if (!ofstream.is_open()) {
00379         std::cerr << "obj2raw: " << ofilename << ": " << "could not open file" << "\n";
00380         return EXIT_FAILURE;
00381       }
00382     }
00383   }
00384 
00385   std::istream& istream = ifstream.is_open() ? ifstream : std::cin;
00386   std::ostream& ostream = ofstream.is_open() ? ofstream : std::cout;
00387 
00388   class obj_to_raw_converter obj_to_raw_converter;
00389   return obj_to_raw_converter.convert(istream, ostream);
00390 }


libobj
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:19