compute_frame_field_bisectors.cpp 4.8 KB

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