write_triangle_mesh.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "write_triangle_mesh.h"
  9. #include "pathinfo.h"
  10. #include "writeMESH.h"
  11. #include "writeOBJ.h"
  12. #include "writeOFF.h"
  13. #include "writePLY.h"
  14. #include "writeSTL.h"
  15. #include "writeWRL.h"
  16. #include <iostream>
  17. template <typename DerivedV, typename DerivedF>
  18. IGL_INLINE bool igl::write_triangle_mesh(
  19. const std::string str,
  20. const Eigen::MatrixBase<DerivedV>& V,
  21. const Eigen::MatrixBase<DerivedF>& F,
  22. FileEncoding encoding)
  23. {
  24. // dirname, basename, extension and filename
  25. std::string d,b,e,f;
  26. pathinfo(str,d,b,e,f);
  27. // Convert extension to lower case
  28. std::transform(e.begin(), e.end(), e.begin(), ::tolower);
  29. if(e == "mesh")
  30. {
  31. Eigen::MatrixXi _1;
  32. return writeMESH(str,V,_1,F);
  33. }else if(e == "obj")
  34. {
  35. return writeOBJ(str,V,F);
  36. }else if(e == "off")
  37. {
  38. return writeOFF(str,V,F);
  39. }else if(e == "ply")
  40. {
  41. return writePLY(str,V,F,encoding);
  42. }else if(e == "stl")
  43. {
  44. return writeSTL(str,V,F,encoding);
  45. }else if(e == "wrl")
  46. {
  47. return writeWRL(str,V,F);
  48. }else
  49. {
  50. assert("Unsupported file format");
  51. std::cerr<<"Unsupported file format: ."<<e<<std::endl;
  52. return false;
  53. }
  54. }
  55. #ifdef IGL_STATIC_LIBRARY
  56. // Explicit template instantiation
  57. // generated by autoexplicit.sh
  58. template bool igl::write_triangle_mesh<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, igl::FileEncoding);
  59. // generated by autoexplicit.sh
  60. template bool igl::write_triangle_mesh<Eigen::Matrix<float, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::MatrixBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, igl::FileEncoding);
  61. // generated by autoexplicit.sh
  62. template bool igl::write_triangle_mesh<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, igl::FileEncoding);
  63. // generated by autoexplicit.sh
  64. template bool igl::write_triangle_mesh<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, igl::FileEncoding);
  65. template bool igl::write_triangle_mesh<Eigen::Matrix<double, 8, 3, 0, 8, 3>, Eigen::Matrix<int, 12, 3, 0, 12, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::MatrixBase<Eigen::Matrix<double, 8, 3, 0, 8, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, 12, 3, 0, 12, 3> > const&, igl::FileEncoding);
  66. #endif