writeWRL.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "writeWRL.h"
  2. #include <iostream>
  3. #include <fstream>
  4. template <typename DerivedV, typename DerivedF>
  5. IGL_INLINE bool igl::writeWRL(
  6. const std::string & str,
  7. const Eigen::PlainObjectBase<DerivedV> & V,
  8. const Eigen::PlainObjectBase<DerivedF> & F)
  9. {
  10. using namespace std;
  11. using namespace Eigen;
  12. assert(V.cols() == 3 && "V should have 3 columns");
  13. assert(F.cols() == 3 && "F should have 3 columns");
  14. ofstream s(str);
  15. if(!s.is_open())
  16. {
  17. cerr<<"IOError: writeWRL() could not open "<<str<<endl;
  18. return false;
  19. }
  20. // Append column of -1 to F
  21. Matrix<typename DerivedF::Scalar,Dynamic,4> FF(F.rows(),4);
  22. FF.leftCols(3) = F;
  23. FF.col(3).setConstant(-1);
  24. s<<R"(
  25. DEF default Transform {
  26. translation 0 0 0
  27. children [
  28. Shape {
  29. geometry DEF default-FACES IndexedFaceSet {
  30. ccw TRUE
  31. )"<<
  32. V.format(
  33. IOFormat(
  34. FullPrecision,
  35. DontAlignCols,
  36. " ",",\n","","",
  37. "coord DEF default-COORD Coordinate { point [ \n","]\n}\n"))<<
  38. FF.format(
  39. IOFormat(
  40. FullPrecision,
  41. DontAlignCols,
  42. ",","\n","","",
  43. "coordIndex [ \n"," ]\n"))<<
  44. "}\n}\n]\n}\n";
  45. return true;
  46. }
  47. #ifdef IGL_STATIC_LIBRARY
  48. template bool igl::writeWRL<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> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&);
  49. #endif