readDMAT.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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. #ifndef IGL_READDMAT_H
  9. #define IGL_READDMAT_H
  10. #include "igl_inline.h"
  11. /// @file readDMAT.h
  12. ///
  13. /// .dmat - dense matrices
  14. /// ======================
  15. ///
  16. /// ------------------------------------------------------------------------
  17. ///
  18. /// A .dmat file contains a dense matrix in column major order. It can contain ASCII or binary data. Note that it is uncompressed so binary only reduces the file size by 50%. But writing and reading binary is usually faster. In MATLAB, binary is almost 100x faster.
  19. ///
  20. /// ASCII
  21. /// -----
  22. ///
  23. /// The first line is a header containing:
  24. ///
  25. /// [#cols] [#rows]
  26. ///
  27. /// Then the coefficients are printed in column-major order separated by spaces.
  28. ///
  29. /// Binary
  30. /// ------
  31. ///
  32. /// Binary files will also contain the ascii header, but it should read:
  33. ///
  34. /// 0 0
  35. ///
  36. /// Then there should be another header containing the size of the binary part:
  37. ///
  38. /// [#cols] [#rows]
  39. ///
  40. /// Then coefficients are written in column-major order in Little-endian 8-byte double precision IEEE floating point format.
  41. ///
  42. /// **Note:** Line endings must be `'\n'` aka `char(10)` aka line feeds.
  43. ///
  44. /// #### Example:
  45. ///
  46. /// The matrix m = [1 2 3; 4 5 6];
  47. ///
  48. /// corresponds to a .dmat file containing:
  49. ///
  50. /// 3 2
  51. /// 1 4 2 5 3 6
  52. #include <string>
  53. #include <vector>
  54. #include <Eigen/Core>
  55. namespace igl
  56. {
  57. /// Read a matrix from an .dmat file
  58. ///
  59. /// @param[in] file_name path to .dmat file
  60. /// @param[out] W eigen matrix containing read-in coefficients
  61. /// @return true on success, false on error
  62. ///
  63. template <typename DerivedW>
  64. IGL_INLINE bool readDMAT(const std::string file_name,
  65. Eigen::PlainObjectBase<DerivedW> & W);
  66. /// \overload
  67. template <typename Scalar>
  68. IGL_INLINE bool readDMAT(
  69. const std::string file_name,
  70. std::vector<std::vector<Scalar> > & W);
  71. }
  72. #ifndef IGL_STATIC_LIBRARY
  73. # include "readDMAT.cpp"
  74. #endif
  75. #endif