writeOBJ.h 690 B

123456789101112131415161718192021222324252627282930
  1. //
  2. // IGL Lib - Simple C++ mesh library
  3. //
  4. // Copyright 2011, Daniele Panozzo. All rights reserved.
  5. #ifndef WRITEOBJ_H
  6. #define WRITEOBJ_H
  7. #include <Eigen/Core>
  8. #include <string>
  9. #include <iostream>
  10. #include <fstream>
  11. namespace igl
  12. {
  13. // Write a mesh in an ascii obj file
  14. void writeOBJ(std::string str, Eigen::MatrixXd& V, Eigen::MatrixXi& F)
  15. {
  16. std::ofstream s(str.c_str());
  17. for(int i=0;i<V.rows();++i)
  18. s << "v " << V(i,0) << " " << V(i,1) << " " << V(i,2) << std::endl;
  19. for(int i=0;i<F.rows();++i)
  20. s << "f " << F(i,0)+1 << " " << F(i,1)+1 << " " << F(i,2)+1 << std::endl;
  21. s.close();
  22. }
  23. }
  24. #endif