compute_frame_field_bisectors.cpp 4.8 KB

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