example.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <igl/readOBJ.h>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <functional>
  6. #include <Eigen/Dense>
  7. using namespace igl;
  8. using namespace std;
  9. using namespace Eigen;
  10. // Template:
  11. // T type that can be safely cast to float
  12. // Inputs:
  13. // vv vector of vectors of type T
  14. template <typename T>
  15. void print_vector_of_vectors_as_floats(const std::vector<std::vector<T > > & vv)
  16. {
  17. for(int i = 0;i<vv.size();i++)
  18. {
  19. for(int j = 0;j<vv[i].size();j++)
  20. {
  21. printf("%g ",(float)(vv[i][j]));
  22. }
  23. printf("\n");
  24. }
  25. }
  26. int main(int argc, char * argv[])
  27. {
  28. if(argc <= 1)
  29. {
  30. printf("USAGE:\n ./example [path_1] [path_2] ... [path_n]\n");
  31. return 1;
  32. }
  33. vector<std::vector<double> > V,TC,N;
  34. vector<std::vector<int> > F,FTC,FN;
  35. // loop over arguments
  36. for(int i = 1; i < argc; i++)
  37. {
  38. if(i != 1)
  39. {
  40. printf("-----------------------------------------------------------\n");
  41. }
  42. readOBJ(argv[i],V,TC,N,F,FTC,FN);
  43. cout<<"V=["; print_vector_of_vectors_as_floats(V); cout<<"];"<<endl;
  44. cout<<"TC=["; print_vector_of_vectors_as_floats(TC); cout<<"];"<<endl;
  45. cout<<"N=["; print_vector_of_vectors_as_floats(N); cout<<"];"<<endl;
  46. cout<<"F=["; print_vector_of_vectors_as_floats(F); cout<<"];"<<endl;
  47. cout<<"FTC=[";print_vector_of_vectors_as_floats(FTC);cout<<"];"<<endl;
  48. cout<<"FN=["; print_vector_of_vectors_as_floats(FN); cout<<"];"<<endl;
  49. // Eigen (V,F) style
  50. MatrixXd EV;
  51. MatrixXi EF;
  52. readOBJ(argv[i],EV,EF);
  53. cout<<"EV=["<<EV<<"];"<<endl;
  54. cout<<"EF=["<<EF<<"];"<<endl;
  55. }
  56. return 0;
  57. }