example.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include <igl/svd.h>
  2. #include <cstdlib>
  3. #include <Accelerate/Accelerate.h>
  4. #include <cstdio>
  5. /* Auxiliary routines prototypes */
  6. extern void print_matrix( char* desc, int m, int n, double* a, int lda );
  7. /* Parameters */
  8. void print3x3(const char * s, double * a)
  9. {
  10. printf("%s =\n",s);
  11. for(int i = 0;i<3;i++)
  12. {
  13. for(int j = 0;j<3;j++)
  14. {
  15. printf("%g ",a[j*3+i]);
  16. }
  17. printf("\n");
  18. }
  19. printf("\n");
  20. }
  21. int main(int argc, char * argv[])
  22. {
  23. //// List of rest positions
  24. //// (0,1)
  25. //// / \
  26. //// / \
  27. //// / \
  28. //// / \
  29. //// (-1,0)-----(1,0)
  30. ////
  31. //double rest[3][3] = {
  32. // {-1,0,0},
  33. // {1,0,0},
  34. // {0,1,0}};
  35. //// List of pose positions
  36. ////
  37. //// (0,1)
  38. //// | \
  39. //// | \
  40. //// | (1,0)
  41. //// | /
  42. //// | /
  43. //// (0,-1)
  44. //double pose[3][3] = {
  45. // {0,1,0},
  46. // {0,-1,0},
  47. // {1,0,0}};
  48. //// Compute covariance matrix C
  49. //double C[3*3];
  50. //// Initialize to zero
  51. //for(int i = 0;i<3*3;i++)
  52. //{
  53. // C[i] = 0;
  54. //}
  55. //// Loop over vertices
  56. //for(int i = 0;i<3;i++)
  57. //{
  58. // // Compute outer product rest[i] * pose[i]
  59. // // Loop over coordinates
  60. // for(int j = 0;j<3;j++)
  61. // {
  62. // // Loop over coordinates
  63. // for(int k = 0;k<3;k++)
  64. // {
  65. // C[k*3+j] = rest[i][j] * pose[i][k];
  66. // }
  67. // }
  68. //}
  69. //print3x3("C",C);
  70. //
  71. //double C[3*3] = {8,3,4,1,5,9,6,7,2};
  72. double C[3*3] = {5242.55,3364,-0,-8170.15,-5242.56,0,-0,-0,0};
  73. double u[3*3],s[3],vt[3*3];
  74. print3x3("C",C);
  75. // Compute SVD of C
  76. igl::svd3x3(C,u,s,vt);
  77. print3x3("u",u);
  78. print3x3("vt",vt);
  79. // Compute R = u*vt
  80. double R[3*3];
  81. const double _3 = 3;
  82. const double _1 = 1;
  83. cblas_dgemm(CblasColMajor, CblasNoTrans,CblasNoTrans,3,3,3,1,u,3,vt,3,1,R,3);
  84. print3x3("RT (transposed to be row-major)",R);
  85. return 0;
  86. }