writeBF.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 Alec Jacobson <[email protected]>
  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::MatrixBase<DerivedWI> & WI,
  18. const Eigen::MatrixBase<DerivedP> & P,
  19. const Eigen::MatrixBase<DerivedO> & O)
  20. {
  21. const int n = WI.rows();
  22. assert(n == WI.rows() && "WI must have n rows");
  23. assert(n == P.rows() && "P must have n rows");
  24. assert(n == O.rows() && "O must have n rows");
  25. Eigen::MatrixXd WIPO(n,1+1+3);
  26. for(int i = 0;i<n;i++)
  27. {
  28. WIPO(i,0) = WI(i);
  29. WIPO(i,1) = P(i);
  30. WIPO(i,2+0) = O(i,0);
  31. WIPO(i,2+1) = O(i,1);
  32. WIPO(i,2+2) = O(i,2);
  33. }
  34. std::ofstream s(filename);
  35. if(!s.is_open())
  36. {
  37. fprintf(stderr,"IOError: writeBF() could not open %s\n",filename.c_str());
  38. return false;
  39. }
  40. s<<
  41. WIPO.format(Eigen::IOFormat(Eigen::FullPrecision,Eigen::DontAlignCols," ","\n","","","","\n"));
  42. return true;
  43. }
  44. #ifdef IGL_STATIC_LIBRARY
  45. 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::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&);
  46. #endif