writeOFF.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #include "writeOFF.h"
  2. #include <cstdio>
  3. // write mesh to an ascii off file
  4. template <typename DerivedV, typename DerivedF>
  5. IGL_INLINE bool igl::writeOFF(
  6. const std::string fname,
  7. const Eigen::PlainObjectBase<DerivedV>& V,
  8. const Eigen::PlainObjectBase<DerivedF>& F)
  9. {
  10. FILE *fp = fopen (fname.c_str(), "w");
  11. if (!fp)
  12. {
  13. fprintf (stderr, "writeOFF(): could not open file %s", fname.c_str());
  14. return false;
  15. }
  16. fprintf (fp, "OFF\n%d %d 0\n", (int) V.rows(), (int) F.rows());
  17. for (int i = 0; i < V.rows(); i++)
  18. fprintf (fp, "%f %f %f\n", V(i,0), V(i,1), V(i,2));
  19. for (int i = 0; i < F.rows(); i++)
  20. fprintf (fp, "3 %d %d %d\n", F(i,0), F(i,1), F(i,2));
  21. fclose (fp);
  22. return true;
  23. }
  24. #ifndef IGL_HEADER_ONLY
  25. // Explicit template specialization
  26. // generated by autoexplicit.sh
  27. 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&);
  28. 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&);
  29. #endif