readSTL.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 <vector>
  16. namespace igl
  17. {
  18. // Read a mesh from an ascii/binary stl file.
  19. //
  20. // Templates:
  21. // Scalar type for positions and vectors (will be read as double and cast
  22. // to Scalar)
  23. // Inputs:
  24. // filename path to .obj file
  25. // Outputs:
  26. // V double matrix of vertex positions #F*3 by 3
  27. // F index matrix of triangle indices #F by 3
  28. // N double matrix of vertex positions #F by 3
  29. // Returns true on success, false on errors
  30. //
  31. // Example:
  32. // bool success = readSTL(filename,temp_V,F,N);
  33. // remove_duplicate_vertices(temp_V,0,V,SVI,SVJ);
  34. // for_each(F.data(),F.data()+F.size(),[&SVJ](int & f){f=SVJ(f);});
  35. // writeOBJ("Downloads/cat.obj",V,F);
  36. template <typename DerivedV, typename DerivedF, typename DerivedN>
  37. IGL_INLINE bool readSTL(
  38. const std::string & filename,
  39. Eigen::PlainObjectBase<DerivedV> & V,
  40. Eigen::PlainObjectBase<DerivedF> & F,
  41. Eigen::PlainObjectBase<DerivedN> & N);
  42. template <typename TypeV, typename TypeF, typename TypeN>
  43. IGL_INLINE bool readSTL(
  44. const std::string & filename,
  45. std::vector<std::vector<TypeV> > & V,
  46. std::vector<std::vector<TypeF> > & F,
  47. std::vector<std::vector<TypeN> > & N);
  48. }
  49. #ifndef IGL_STATIC_LIBRARY
  50. # include "readSTL.cpp"
  51. #endif
  52. #endif