writeOFF.h 991 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //
  2. // IGL Lib - Simple C++ mesh library
  3. //
  4. // Copyright 2011, Daniele Panozzo. All rights reserved.
  5. #ifndef IGL_WRITEOFF_H
  6. #define IGL_WRITEOFF_H
  7. #include <Eigen/Core>
  8. #include <string>
  9. namespace igl
  10. {
  11. inline bool writeOFF(const std::string fname, const Eigen::MatrixXd& V, const Eigen::MatrixXi& F);
  12. }
  13. // Implementation
  14. // write mesh to an ascii off file
  15. inline bool igl::writeOFF(const std::string fname, const Eigen::MatrixXd& V, const Eigen::MatrixXi& 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 (unsigned i = 0; i < V.rows(); i++)
  25. fprintf (fp, "%f %f %f\n", V(i,0), V(i,1), V(i,2));
  26. for (unsigned 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. #endif