compute_frame_field_bisectors.cpp 3.3 KB

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