writeWRL.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "writeWRL.h"
  9. #include <iostream>
  10. #include <fstream>
  11. template <typename DerivedV, typename DerivedF>
  12. IGL_INLINE bool igl::writeWRL(
  13. const std::string & str,
  14. const Eigen::PlainObjectBase<DerivedV> & V,
  15. const Eigen::PlainObjectBase<DerivedF> & F)
  16. {
  17. using namespace std;
  18. using namespace Eigen;
  19. assert(V.cols() == 3 && "V should have 3 columns");
  20. assert(F.cols() == 3 && "F should have 3 columns");
  21. ofstream s(str);
  22. if(!s.is_open())
  23. {
  24. cerr<<"IOError: writeWRL() could not open "<<str<<endl;
  25. return false;
  26. }
  27. // Append column of -1 to F
  28. Matrix<typename DerivedF::Scalar,Dynamic,4> FF(F.rows(),4);
  29. FF.leftCols(3) = F;
  30. FF.col(3).setConstant(-1);
  31. s<<R"(
  32. DEF default Transform {
  33. translation 0 0 0
  34. children [
  35. Shape {
  36. geometry DEF default-FACES IndexedFaceSet {
  37. ccw TRUE
  38. )"<<
  39. V.format(
  40. IOFormat(
  41. FullPrecision,
  42. DontAlignCols,
  43. " ",",\n","","",
  44. "coord DEF default-COORD Coordinate { point [ \n","]\n}\n"))<<
  45. FF.format(
  46. IOFormat(
  47. FullPrecision,
  48. DontAlignCols,
  49. ",","\n","","",
  50. "coordIndex [ \n"," ]\n"))<<
  51. "}\n}\n]\n}\n";
  52. return true;
  53. }
  54. #ifdef IGL_STATIC_LIBRARY
  55. 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&);
  56. #endif