read_triangle_mesh.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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. #ifndef IGL_READ_TRIANGLE_MESH_H
  9. #define IGL_READ_TRIANGLE_MESH_H
  10. #include "igl_inline.h"
  11. #ifndef IGL_NO_EIGEN
  12. # include <Eigen/Core>
  13. #endif
  14. #include <string>
  15. #include <cstdio>
  16. #include <vector>
  17. // History:
  18. // renamed read -> read_triangle_mesh Daniele 24 June 2014
  19. // return type changed from void to bool Alec 18 Sept 2011
  20. namespace igl
  21. {
  22. // read mesh from an ascii file with automatic detection of file format.
  23. // supported: obj, off, stl, wrl, ply, mesh)
  24. //
  25. // Templates:
  26. // Scalar type for positions and vectors (will be read as double and cast
  27. // to Scalar)
  28. // Index type for indices (will be read as int and cast to Index)
  29. // Scalar type for texture coordinates (will be read as double and cast
  30. // to Scalar)
  31. // Inputs:
  32. // str path to file
  33. // Outputs:
  34. // V eigen double matrix #V by 3
  35. // F eigen int matrix #F by 3
  36. // TC eigen double matrix #TC by 3
  37. // Returns true iff success
  38. template <typename Scalar, typename Index>
  39. IGL_INLINE bool read_triangle_mesh(
  40. const std::string str,
  41. std::vector<std::vector<Scalar> > & V,
  42. std::vector<std::vector<Index> > & F,
  43. std::vector<std::vector<Scalar> > & TC);
  44. #ifndef IGL_NO_EIGEN
  45. template <typename DerivedV, typename DerivedF>
  46. IGL_INLINE bool read_triangle_mesh(
  47. const std::string str,
  48. Eigen::PlainObjectBase<DerivedV>& V,
  49. Eigen::PlainObjectBase<DerivedF>& F,
  50. Eigen::PlainObjectBase<DerivedV>& TC);
  51. // Outputs:
  52. // dir directory path (see pathinfo.h)
  53. // base base name (see pathinfo.h)
  54. // ext extension (see pathinfo.h)
  55. // name filename (see pathinfo.h)
  56. template <typename DerivedV, typename DerivedF>
  57. IGL_INLINE bool read_triangle_mesh(
  58. const std::string str,
  59. Eigen::PlainObjectBase<DerivedV>& V,
  60. Eigen::PlainObjectBase<DerivedF>& F,
  61. Eigen::PlainObjectBase<DerivedV>& TC,
  62. std::string & dir,
  63. std::string & base,
  64. std::string & ext,
  65. std::string & name);
  66. // Inputs:
  67. // ext file extension
  68. // fp pointer to already opened .ext file
  69. // Outputs:
  70. // fp closed file
  71. template <typename DerivedV, typename DerivedF>
  72. IGL_INLINE bool read_triangle_mesh(
  73. const std::string & ext,
  74. FILE * fp,
  75. Eigen::PlainObjectBase<DerivedV>& V,
  76. Eigen::PlainObjectBase<DerivedF>& F,
  77. Eigen::PlainObjectBase<DerivedV>& TC);
  78. #endif
  79. }
  80. #ifndef IGL_STATIC_LIBRARY
  81. # include "read_triangle_mesh.cpp"
  82. #endif
  83. #endif