writeOFF.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 "writeOFF.h"
  9. #include <cstdio>
  10. // write mesh to an ascii off file
  11. template <typename DerivedV, typename DerivedF>
  12. IGL_INLINE bool igl::writeOFF(
  13. const std::string fname,
  14. const Eigen::PlainObjectBase<DerivedV>& V,
  15. const Eigen::PlainObjectBase<DerivedF>& F)
  16. {
  17. FILE *fp = fopen (fname.c_str(), "w");
  18. if (!fp)
  19. {
  20. fprintf (stderr, "writeOFF(): could not open file %s", fname.c_str());
  21. return false;
  22. }
  23. fprintf (fp, "OFF\n%d %d 0\n", (int) V.rows(), (int) F.rows());
  24. for (int i = 0; i < V.rows(); i++)
  25. {
  26. fprintf(
  27. fp,
  28. "%0.17g %0.17g %0.17g\n",
  29. (double)V(i,0),
  30. (double)V(i,1),
  31. (double)V(i,2));
  32. }
  33. for (int i = 0; i < F.rows(); i++)
  34. fprintf (fp, "3 %d %d %d\n", F(i,0), F(i,1), F(i,2));
  35. fclose (fp);
  36. return true;
  37. }
  38. #ifndef IGL_HEADER_ONLY
  39. // Explicit template specialization
  40. // generated by autoexplicit.sh
  41. template bool igl::writeOFF<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&);
  42. template bool igl::writeOFF<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > const&);
  43. template bool igl::writeOFF<Eigen::Matrix<float, -1, 3, 1, -1, 3>, Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > const&);
  44. #endif