comb_frame_field.cpp 3.9 KB

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