read_triangle_mesh.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. // Inputs:
  30. // str path to file
  31. // Outputs:
  32. // V eigen double matrix #V by 3
  33. // F eigen int matrix #F by 3
  34. // Returns true iff success
  35. template <typename Scalar, typename Index>
  36. IGL_INLINE bool read_triangle_mesh(
  37. const std::string str,
  38. std::vector<std::vector<Scalar> > & V,
  39. std::vector<std::vector<Index> > & F);
  40. #ifndef IGL_NO_EIGEN
  41. template <typename DerivedV, typename DerivedF>
  42. IGL_INLINE bool read_triangle_mesh(
  43. const std::string str,
  44. Eigen::PlainObjectBase<DerivedV>& V,
  45. Eigen::PlainObjectBase<DerivedF>& F);
  46. // Outputs:
  47. // dir directory path (see pathinfo.h)
  48. // base base name (see pathinfo.h)
  49. // ext extension (see pathinfo.h)
  50. // name filename (see pathinfo.h)
  51. template <typename DerivedV, typename DerivedF>
  52. IGL_INLINE bool read_triangle_mesh(
  53. const std::string str,
  54. Eigen::PlainObjectBase<DerivedV>& V,
  55. Eigen::PlainObjectBase<DerivedF>& F,
  56. std::string & dir,
  57. std::string & base,
  58. std::string & ext,
  59. std::string & name);
  60. // Inputs:
  61. // ext file extension
  62. // fp pointer to already opened .ext file
  63. // Outputs:
  64. // fp closed file
  65. template <typename DerivedV, typename DerivedF>
  66. IGL_INLINE bool read_triangle_mesh(
  67. const std::string & ext,
  68. FILE * fp,
  69. Eigen::PlainObjectBase<DerivedV>& V,
  70. Eigen::PlainObjectBase<DerivedF>& F);
  71. #endif
  72. }
  73. #ifndef IGL_STATIC_LIBRARY
  74. # include "read_triangle_mesh.cpp"
  75. #endif
  76. #endif