write_triangle_mesh.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  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::PlainObjectBase<DerivedV>& V,
  21. const Eigen::PlainObjectBase<DerivedF>& F,
  22. const bool ascii)
  23. {
  24. using namespace std;
  25. // dirname, basename, extension and filename
  26. string d,b,e,f;
  27. pathinfo(str,d,b,e,f);
  28. // Convert extension to lower case
  29. std::transform(e.begin(), e.end(), e.begin(), ::tolower);
  30. if(e == "mesh")
  31. {
  32. assert(ascii && ".mesh only supports ascii");
  33. Eigen::MatrixXi _1;
  34. return writeMESH(str,V,_1,F);
  35. }else if(e == "obj")
  36. {
  37. assert(ascii && ".obj only supports ascii");
  38. return writeOBJ(str,V,F);
  39. }else if(e == "off")
  40. {
  41. assert(ascii && ".off only supports ascii");
  42. return writeOFF(str,V,F);
  43. }else if(e == "ply")
  44. {
  45. return writePLY(str,V,F,ascii);
  46. }else if(e == "stl")
  47. {
  48. return writeSTL(str,V,F,ascii);
  49. }else if(e == "wrl")
  50. {
  51. assert(ascii && ".wrl only supports ascii");
  52. return writeWRL(str,V,F);
  53. }else
  54. {
  55. assert("Unsupported file format");
  56. cerr<<"Unsupported file format: ."<<e<<endl;
  57. return false;
  58. }
  59. }
  60. #ifdef IGL_STATIC_LIBRARY
  61. // Explicit template specialization
  62. // generated by autoexplicit.sh
  63. 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::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, const bool);
  64. template bool igl::write_triangle_mesh<Eigen::Matrix<double, 8, 3, 0, 8, 3>, Eigen::Matrix<int, 12, 3, 0, 12, 3> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, 8, 3, 0, 8, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, 12, 3, 0, 12, 3> > const&, bool);
  65. #endif