readSTL.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  4. // Copyright (C) 2020 Jérémie Dumas <[email protected]>
  5. //
  6. // This Source Code Form is subject to the terms of the Mozilla Public License
  7. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  8. // obtain one at http://mozilla.org/MPL/2.0/.
  9. #ifndef IGL_READSTL_H
  10. #define IGL_READSTL_H
  11. #include "igl_inline.h"
  12. #ifndef IGL_NO_EIGEN
  13. # include <Eigen/Core>
  14. #endif
  15. #include <string>
  16. #include <istream>
  17. #include <vector>
  18. #include <array>
  19. namespace igl
  20. {
  21. /// Read a mesh from an ascii/binary stl file.
  22. ///
  23. /// @tparam Scalar type for positions and vectors (will be read as double and cast
  24. /// to Scalar)
  25. /// @param[in] filename path to .stl file
  26. /// @param[out] V double matrix of vertex positions #V*3 by 3
  27. /// @param[out] F index matrix of triangle indices #F by 3
  28. /// @param[out] N double matrix of surface normals #F by 3
  29. /// @return true on success, false on errors
  30. ///
  31. /// #### Example
  32. ///
  33. /// bool success = readSTL(filename,temp_V,F,N);
  34. /// remove_duplicate_vertices(temp_V,0,V,SVI,SVJ);
  35. /// for_each(F.data(),F.data()+F.size(),[&SVJ](int & f){f=SVJ(f);});
  36. /// writeOBJ("Downloads/cat.obj",V,F);
  37. template <typename DerivedV, typename DerivedF, typename DerivedN>
  38. IGL_INLINE bool readSTL(
  39. std::istream &input,
  40. Eigen::PlainObjectBase<DerivedV> & V,
  41. Eigen::PlainObjectBase<DerivedF> & F,
  42. Eigen::PlainObjectBase<DerivedN> & N);
  43. /// \overload
  44. template <typename TypeV, typename TypeF, typename TypeN>
  45. IGL_INLINE bool readSTL(
  46. std::istream &input,
  47. std::vector<std::array<TypeV, 3> > & V,
  48. std::vector<std::array<TypeF, 3> > & F,
  49. std::vector<std::array<TypeN, 3> > & N);
  50. /// \overload
  51. /// @param[in,out] fp pointer to ply file (will be closed)
  52. template <typename DerivedV, typename DerivedF, typename DerivedN>
  53. IGL_INLINE bool readSTL(
  54. FILE * fp,
  55. Eigen::PlainObjectBase<DerivedV> & V,
  56. Eigen::PlainObjectBase<DerivedF> & F,
  57. Eigen::PlainObjectBase<DerivedN> & N);
  58. }
  59. #ifndef IGL_STATIC_LIBRARY
  60. # include "readSTL.cpp"
  61. #endif
  62. #endif