compute_frame_field_bisectors.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "compute_frame_field_bisectors.h"
  2. #include "igl/local_basis.h"
  3. template <typename DerivedV, typename DerivedF>
  4. IGL_INLINE void igl::compute_frame_field_bisectors(
  5. const Eigen::PlainObjectBase<DerivedV>& V,
  6. const Eigen::PlainObjectBase<DerivedF>& F,
  7. const Eigen::PlainObjectBase<DerivedV>& B1,
  8. const Eigen::PlainObjectBase<DerivedV>& B2,
  9. const Eigen::PlainObjectBase<DerivedV>& PD1,
  10. const Eigen::PlainObjectBase<DerivedV>& PD2,
  11. Eigen::PlainObjectBase<DerivedV>& BIS1,
  12. Eigen::PlainObjectBase<DerivedV>& BIS2)
  13. {
  14. BIS1.resize(PD1.rows(),3);
  15. BIS2.resize(PD1.rows(),3);
  16. for (unsigned i=0; i<PD1.rows();++i)
  17. {
  18. // project onto the tangent plane and convert to angle
  19. // Convert to angle
  20. double a1 = atan2(B2.row(i).dot(PD1.row(i)),B1.row(i).dot(PD1.row(i)));
  21. //make it positive by adding some multiple of 2pi
  22. a1 += ceil (std::max(0., -a1) / (M_PI*2.)) * (M_PI*2.);
  23. //take modulo 2pi
  24. a1 = fmod(a1, (M_PI*2.));
  25. double a2 = atan2(B2.row(i).dot(PD2.row(i)),B1.row(i).dot(PD2.row(i)));
  26. //make it positive by adding some multiple of 2pi
  27. a2 += ceil (std::max(0., -a2) / (M_PI*2.)) * (M_PI*2.);
  28. //take modulo 2pi
  29. a2 = fmod(a2, (M_PI*2.));
  30. double b1 = (a1+a2)/2.0;
  31. //make it positive by adding some multiple of 2pi
  32. b1 += ceil (std::max(0., -b1) / (M_PI*2.)) * (M_PI*2.);
  33. //take modulo 2pi
  34. b1 = fmod(b1, (M_PI*2.));
  35. double b2 = b1+(M_PI/2.);
  36. //make it positive by adding some multiple of 2pi
  37. b2 += ceil (std::max(0., -b2) / (M_PI*2.)) * (M_PI*2.);
  38. //take modulo 2pi
  39. b2 = fmod(b2, (M_PI*2.));
  40. BIS1.row(i) = cos(b1) * B1.row(i) + sin(b1) * B2.row(i);
  41. BIS2.row(i) = cos(b2) * B1.row(i) + sin(b2) * B2.row(i);
  42. }
  43. }
  44. template <typename DerivedV, typename DerivedF>
  45. IGL_INLINE void igl::compute_frame_field_bisectors(
  46. const Eigen::PlainObjectBase<DerivedV>& V,
  47. const Eigen::PlainObjectBase<DerivedF>& F,
  48. const Eigen::PlainObjectBase<DerivedV>& PD1,
  49. const Eigen::PlainObjectBase<DerivedV>& PD2,
  50. Eigen::PlainObjectBase<DerivedV>& BIS1,
  51. Eigen::PlainObjectBase<DerivedV>& BIS2)
  52. {
  53. Eigen::PlainObjectBase<DerivedV> B1, B2, B3;
  54. igl::local_basis(V,F,B1,B2,B3);
  55. compute_frame_field_bisectors( V, F, B1, B2, PD1, PD2, BIS1, BIS2);
  56. }
  57. #ifndef IGL_HEADER_ONLY
  58. #endif