writeOFF.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. {
  19. fprintf(
  20. fp,
  21. "%0.17g %0.17g %0.17g\n",
  22. (double)V(i,0),
  23. (double)V(i,1),
  24. (double)V(i,2));
  25. }
  26. for (int i = 0; i < F.rows(); i++)
  27. fprintf (fp, "3 %d %d %d\n", F(i,0), F(i,1), F(i,2));
  28. fclose (fp);
  29. return true;
  30. }
  31. #ifndef IGL_HEADER_ONLY
  32. // Explicit template specialization
  33. // generated by autoexplicit.sh
  34. 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&);
  35. 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&);
  36. 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&);
  37. #endif