readSTL.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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_READSTL_H
  9. #define IGL_READSTL_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. namespace igl
  18. {
  19. // Read a mesh from an ascii/binary stl file.
  20. //
  21. // Templates:
  22. // Scalar type for positions and vectors (will be read as double and cast
  23. // to Scalar)
  24. // Inputs:
  25. // filename path to .stl file
  26. // Outputs:
  27. // V double matrix of vertex positions #V*3 by 3
  28. // F index matrix of triangle indices #F by 3
  29. // N double matrix of surface normals #F by 3
  30. // Returns true on success, false on errors
  31. //
  32. // Example:
  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. const std::string & filename,
  40. Eigen::PlainObjectBase<DerivedV> & V,
  41. Eigen::PlainObjectBase<DerivedF> & F,
  42. Eigen::PlainObjectBase<DerivedN> & N);
  43. // Inputs:
  44. // stl_file pointer to already opened .stl file
  45. // Outputs:
  46. // stl_file closed file
  47. template <typename TypeV, typename TypeF, typename TypeN>
  48. IGL_INLINE bool readSTL(
  49. FILE * stl_file,
  50. std::vector<std::vector<TypeV> > & V,
  51. std::vector<std::vector<TypeF> > & F,
  52. std::vector<std::vector<TypeN> > & N);
  53. template <typename TypeV, typename TypeF, typename TypeN>
  54. IGL_INLINE bool readSTL(
  55. const std::string & filename,
  56. std::vector<std::vector<TypeV> > & V,
  57. std::vector<std::vector<TypeF> > & F,
  58. std::vector<std::vector<TypeN> > & N);
  59. }
  60. #ifndef IGL_STATIC_LIBRARY
  61. # include "readSTL.cpp"
  62. #endif
  63. #endif