comb_frame_field.cpp 3.9 KB

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