comb_frame_field.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>, Olga Diamanti <olga.diam@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. #include "comb_frame_field.h"
  9. #include "local_basis.h"
  10. template <typename DerivedV, typename DerivedF, typename DerivedP>
  11. IGL_INLINE void igl::comb_frame_field(const Eigen::PlainObjectBase<DerivedV> &V,
  12. const Eigen::PlainObjectBase<DerivedF> &F,
  13. const Eigen::PlainObjectBase<DerivedP> &PD1,
  14. const Eigen::PlainObjectBase<DerivedP> &PD2,
  15. const Eigen::PlainObjectBase<DerivedP> &BIS1_combed,
  16. const Eigen::PlainObjectBase<DerivedP> &BIS2_combed,
  17. Eigen::PlainObjectBase<DerivedP> &PD1_combed,
  18. Eigen::PlainObjectBase<DerivedP> &PD2_combed)
  19. {
  20. Eigen::PlainObjectBase<DerivedV> B1, B2, B3;
  21. igl::local_basis(V,F,B1,B2,B3);
  22. PD1_combed.resize(BIS1_combed.rows(),3);
  23. PD2_combed.resize(BIS2_combed.rows(),3);
  24. for (unsigned i=0; i<PD1.rows();++i)
  25. {
  26. Eigen::Matrix<typename DerivedP::Scalar,4,3> DIRs;
  27. DIRs <<
  28. PD1.row(i),
  29. -PD1.row(i),
  30. PD2.row(i),
  31. -PD2.row(i);
  32. std::vector<double> a(4);
  33. double a_combed = atan2(B2.row(i).dot(BIS1_combed.row(i)),B1.row(i).dot(BIS1_combed.row(i)));
  34. // center on the combed sector center
  35. for (unsigned j=0;j<4;++j)
  36. {
  37. a[j] = atan2(B2.row(i).dot(DIRs.row(j)),B1.row(i).dot(DIRs.row(j))) - a_combed;
  38. //make it positive by adding some multiple of 2pi
  39. a[j] += ceil (std::max(0., -a[j]) / (M_PI*2.)) * (M_PI*2.);
  40. //take modulo 2pi
  41. a[j] = fmod(a[j], (M_PI*2.));
  42. }
  43. // now the max is u and the min is v
  44. int m = std::min_element(a.begin(),a.end())-a.begin();
  45. int M = std::max_element(a.begin(),a.end())-a.begin();
  46. assert(
  47. ((m>=0 && m<=1) && (M>=2 && M<=3))
  48. ||
  49. ((m>=2 && m<=3) && (M>=0 && M<=1))
  50. );
  51. PD1_combed.row(i) = DIRs.row(m);
  52. PD2_combed.row(i) = DIRs.row(M);
  53. }
  54. // PD1_combed = BIS1_combed;
  55. // PD2_combed = BIS2_combed;
  56. }
  57. #ifdef IGL_STATIC_LIBRARY
  58. // Explicit template specialization
  59. #endif