writeWRL.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. // Explicit template specialization
  56. // generated by autoexplicit.sh
  57. template bool igl::writeWRL<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&);
  58. // generated by autoexplicit.sh
  59. template bool igl::writeWRL<Eigen::Matrix<double, 8, 3, 0, 8, 3>, Eigen::Matrix<int, 12, 3, 0, 12, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 8, 3, 0, 8, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, 12, 3, 0, 12, 3> > const&);
  60. 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&);
  61. #endif