example.cpp 1.6 KB

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