writeOFF.cpp 1.2 KB

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