writeOFF.h 859 B

12345678910111213141516171819202122232425262728293031323334
  1. //
  2. // IGL Lib - Simple C++ mesh library
  3. //
  4. // Copyright 2011, Daniele Panozzo. All rights reserved.
  5. #ifndef WRITEOFF_H
  6. #define WRITEOFF_H
  7. #include <Eigen/Core>
  8. #include <string>
  9. namespace igl
  10. {
  11. // write mesh to an ascii off file
  12. inline void writeOFF (std::string fname, Eigen::MatrixXd& V, Eigen::MatrixXi& F)
  13. {
  14. FILE *fp = fopen (fname.c_str(), "w");
  15. if (!fp)
  16. fprintf (stderr, "writeOFF(): could not open file %s", fname.c_str());
  17. fprintf (fp, "OFF\n%d %d 0\n", (int) V.rows(), (int) F.rows());
  18. for (unsigned i = 0; i < V.rows(); i++)
  19. fprintf (fp, "%f %f %f\n", V(i,0), V(i,1), V(i,2));
  20. for (unsigned i = 0; i < F.rows(); i++)
  21. fprintf (fp, "3 %d %d %d\n", F(i,0), F(i,1), F(i,2));
  22. fclose (fp);
  23. }
  24. }
  25. #endif