readPLY.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #ifndef IGL_READPLY_H
  2. #define IGL_READPLY_H
  3. #include "igl_inline.h"
  4. #include <Eigen/Core>
  5. #include <string>
  6. #include <vector>
  7. #include "tinyply.h"
  8. namespace igl
  9. {
  10. /// Read triangular mesh from ply file, filling in vertex positions, normals
  11. /// and texture coordinates, if available
  12. /// also read additional properties associated with vertex,faces and edges
  13. /// and file comments
  14. ///
  15. /// @tparam Derived* from Eigen matrix parameters
  16. /// @param[in] ply_stream ply file input stream
  17. /// @param[out] V (#V,3) matrix of vertex positions
  18. /// @param[out] F (#F,3) list of face indices into vertex positions
  19. /// @param[out] E (#E,2) list of edge indices into vertex positions
  20. /// @param[out] N (#V,3) list of normals
  21. /// @param[out] UV (#V,2) list of texture coordinates
  22. /// @param[out] VD (#V,*) additional vertex data
  23. /// @param[out] Vheader (#V) list of vertex data headers
  24. /// @param[out] FD (#F,*) additional face data
  25. /// @param[out] Fheader (#F) list of face data headers
  26. /// @param[out] ED (#E,*) additional edge data
  27. /// @param[out] Eheader (#E) list of edge data headers
  28. /// @param[out] comments (*) file comments
  29. /// @return true on success, false on errors
  30. ///
  31. /// \note Unlike previous versions, all matrices are left untouched if they
  32. /// are not read from the file.
  33. template <
  34. typename DerivedV,
  35. typename DerivedF,
  36. typename DerivedE,
  37. typename DerivedN,
  38. typename DerivedUV,
  39. typename DerivedVD,
  40. typename DerivedFD,
  41. typename DerivedED
  42. >
  43. bool readPLY(
  44. std::istream & ply_stream,
  45. Eigen::PlainObjectBase<DerivedV> & V,
  46. Eigen::PlainObjectBase<DerivedF> & F,
  47. Eigen::PlainObjectBase<DerivedF> & E,
  48. Eigen::PlainObjectBase<DerivedN> & N,
  49. Eigen::PlainObjectBase<DerivedUV> & UV,
  50. Eigen::PlainObjectBase<DerivedVD> & VD,
  51. std::vector<std::string> & Vheader,
  52. Eigen::PlainObjectBase<DerivedFD> & FD,
  53. std::vector<std::string> & Fheader,
  54. Eigen::PlainObjectBase<DerivedED> & ED,
  55. std::vector<std::string> & Eheader,
  56. std::vector<std::string> & comments
  57. );
  58. /// \overload
  59. /// @param[in] ply_file ply file name
  60. template <
  61. typename DerivedV,
  62. typename DerivedF,
  63. typename DerivedE,
  64. typename DerivedN,
  65. typename DerivedUV,
  66. typename DerivedVD,
  67. typename DerivedFD,
  68. typename DerivedED
  69. >
  70. bool readPLY(
  71. const std::string& ply_file,
  72. Eigen::PlainObjectBase<DerivedV> & V,
  73. Eigen::PlainObjectBase<DerivedF> & F,
  74. Eigen::PlainObjectBase<DerivedE> & E,
  75. Eigen::PlainObjectBase<DerivedN> & N,
  76. Eigen::PlainObjectBase<DerivedUV> & UV,
  77. Eigen::PlainObjectBase<DerivedVD> & VD,
  78. std::vector<std::string> & VDheader,
  79. Eigen::PlainObjectBase<DerivedFD> & FD,
  80. std::vector<std::string> & FDheader,
  81. Eigen::PlainObjectBase<DerivedED> & ED,
  82. std::vector<std::string> & EDheader,
  83. std::vector<std::string> & comments
  84. );
  85. /// \overload
  86. template <
  87. typename DerivedV,
  88. typename DerivedF,
  89. typename DerivedN,
  90. typename DerivedUV,
  91. typename DerivedVD
  92. >
  93. bool readPLY(
  94. const std::string & filename,
  95. Eigen::PlainObjectBase<DerivedV> & V,
  96. Eigen::PlainObjectBase<DerivedF> & F,
  97. Eigen::PlainObjectBase<DerivedN> & N,
  98. Eigen::PlainObjectBase<DerivedUV> & UV,
  99. Eigen::PlainObjectBase<DerivedVD> & VD,
  100. std::vector<std::string> & Vheader
  101. );
  102. /// \overload
  103. template <
  104. typename DerivedV,
  105. typename DerivedF,
  106. typename DerivedE,
  107. typename DerivedN,
  108. typename DerivedUV
  109. >
  110. bool readPLY(
  111. const std::string & filename,
  112. Eigen::PlainObjectBase<DerivedV> & V,
  113. Eigen::PlainObjectBase<DerivedF> & F,
  114. Eigen::PlainObjectBase<DerivedE> & E,
  115. Eigen::PlainObjectBase<DerivedN> & N,
  116. Eigen::PlainObjectBase<DerivedUV> & UV
  117. );
  118. /// \overload
  119. template <
  120. typename DerivedV,
  121. typename DerivedF
  122. >
  123. bool readPLY(
  124. const std::string & filename,
  125. Eigen::PlainObjectBase<DerivedV> & V,
  126. Eigen::PlainObjectBase<DerivedF> & F
  127. );
  128. /// \overload
  129. template <
  130. typename DerivedV,
  131. typename DerivedF,
  132. typename DerivedE
  133. >
  134. bool readPLY(
  135. const std::string & filename,
  136. Eigen::PlainObjectBase<DerivedV> & V,
  137. Eigen::PlainObjectBase<DerivedF> & F,
  138. Eigen::PlainObjectBase<DerivedE> & E
  139. );
  140. /// \overload
  141. /// @param[in,out] fp pointer to ply file (will be closed)
  142. template <
  143. typename DerivedV,
  144. typename DerivedF
  145. >
  146. IGL_INLINE bool readPLY(
  147. FILE *fp,
  148. Eigen::PlainObjectBase<DerivedV> & V,
  149. Eigen::PlainObjectBase<DerivedF> & F
  150. );
  151. }
  152. #ifndef IGL_STATIC_LIBRARY
  153. # include "readPLY.cpp"
  154. #endif
  155. #endif