writeBF.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 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 "writeBF.h"
  9. #include <fstream>
  10. #include <cassert>
  11. template <
  12. typename DerivedWI,
  13. typename DerivedP,
  14. typename DerivedO>
  15. IGL_INLINE bool igl::writeBF(
  16. const std::string & filename,
  17. const Eigen::PlainObjectBase<DerivedWI> & WI,
  18. const Eigen::PlainObjectBase<DerivedP> & P,
  19. const Eigen::PlainObjectBase<DerivedO> & O)
  20. {
  21. using namespace Eigen;
  22. using namespace std;
  23. const int n = WI.rows();
  24. assert(n == WI.rows() && "WI must have n rows");
  25. assert(n == P.rows() && "P must have n rows");
  26. assert(n == O.rows() && "O must have n rows");
  27. MatrixXd WIPO(n,1+1+3);
  28. for(int i = 0;i<n;i++)
  29. {
  30. WIPO(i,0) = WI(i);
  31. WIPO(i,1) = P(i);
  32. WIPO(i,2+0) = O(i,0);
  33. WIPO(i,2+1) = O(i,1);
  34. WIPO(i,2+2) = O(i,2);
  35. }
  36. ofstream s(filename);
  37. if(!s.is_open())
  38. {
  39. fprintf(stderr,"IOError: writeBF() could not open %s\n",filename.c_str());
  40. return false;
  41. }
  42. s<<
  43. WIPO.format(IOFormat(FullPrecision,DontAlignCols," ","\n","","","","\n"));
  44. return true;
  45. }
  46. #ifdef IGL_STATIC_LIBRARY
  47. template bool igl::writeBF<Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&);
  48. #endif