map_vertices_to_circle.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Stefan Brugger <stefanbrugger@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 "map_vertices_to_circle.h"
  9. #include "boundary_vertices_sorted.h"
  10. IGL_INLINE void igl::map_vertices_to_circle(
  11. const Eigen::MatrixXd& V,
  12. const Eigen::MatrixXi& F,
  13. const Eigen::VectorXi& bnd,
  14. Eigen::MatrixXd& UV)
  15. {
  16. // Get sorted list of boundary vertices
  17. std::vector<int> interior,map_ij;
  18. map_ij.resize(V.rows());
  19. std::vector<bool> isOnBnd(V.rows(),false);
  20. for (int i = 0; i < bnd.size(); i++)
  21. {
  22. isOnBnd[bnd[i]] = true;
  23. map_ij[bnd[i]] = i;
  24. }
  25. for (int i = 0; i < isOnBnd.size(); i++)
  26. {
  27. if (!isOnBnd[i])
  28. {
  29. map_ij[i] = interior.size();
  30. interior.push_back(i);
  31. }
  32. }
  33. // Map boundary to unit circle
  34. std::vector<double> len(bnd.size());
  35. len[0] = 0.;
  36. for (int i = 1; i < bnd.size(); i++)
  37. {
  38. len[i] = len[i-1] + (V.row(bnd[i-1]) - V.row(bnd[i])).norm();
  39. }
  40. double total_len = len[len.size()-1] + (V.row(bnd[0]) - V.row(bnd[bnd.size()-1])).norm();
  41. UV.resize(bnd.size(),2);
  42. for (int i = 0; i < bnd.size(); i++)
  43. {
  44. double frac = len[i] * 2. * M_PI / total_len;
  45. UV.row(map_ij[bnd[i]]) << cos(frac), sin(frac);
  46. }
  47. }