compute_frame_field_bisectors.cpp 4.4 KB

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