read.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // IGL Lib - Simple C++ mesh library
  3. //
  4. // Copyright 2011, Daniele Panozzo. All rights reserved.
  5. // History:
  6. // return type changed from void to bool Alec 18 Sept 2011
  7. #ifndef IGL_READ_H
  8. #define IGL_READ_H
  9. #include <Eigen/Core>
  10. #include <string>
  11. namespace igl
  12. {
  13. // read mesh from an ascii file with automatic detection of file format. supported: obj, off)
  14. // Inputs:
  15. // str path to .obj/.off file
  16. // Outputs:
  17. // V eigen double matrix #V by 3
  18. // F eigen int matrix #F by 3
  19. inline bool read(const std::string str, Eigen::MatrixXd& V, Eigen::MatrixXi& F);
  20. }
  21. // Implementation
  22. #include <readOBJ.h>
  23. #include <readOFF.h>
  24. inline bool igl::read(const std::string str, Eigen::MatrixXd& V, Eigen::MatrixXi& F)
  25. {
  26. const char* p;
  27. for (p = str.c_str(); *p != '\0'; p++)
  28. ;
  29. while (*p != '.')
  30. p--;
  31. if (!strcmp(p, ".obj") || !strcmp(p, ".OBJ"))
  32. {
  33. return igl::readOBJ(str,V,F);
  34. }else if (!strcmp(p, ".off") || !strcmp(p, ".OFF"))
  35. {
  36. return igl::readOFF(str,V,F);
  37. }else
  38. {
  39. fprintf(stderr,"read() does not recognize extension: %s\n",p);
  40. return false;
  41. }
  42. }
  43. #endif