map_vertices_to_circle.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 "PI.h"
  10. IGL_INLINE void igl::map_vertices_to_circle(
  11. const Eigen::MatrixXd& V,
  12. const Eigen::VectorXi& bnd,
  13. Eigen::MatrixXd& UV)
  14. {
  15. // Get sorted list of boundary vertices
  16. std::vector<int> interior,map_ij;
  17. map_ij.resize(V.rows());
  18. std::vector<bool> isOnBnd(V.rows(),false);
  19. for (int i = 0; i < bnd.size(); i++)
  20. {
  21. isOnBnd[bnd[i]] = true;
  22. map_ij[bnd[i]] = i;
  23. }
  24. for (int i = 0; i < (int)isOnBnd.size(); i++)
  25. {
  26. if (!isOnBnd[i])
  27. {
  28. map_ij[i] = interior.size();
  29. interior.push_back(i);
  30. }
  31. }
  32. // Map boundary to unit circle
  33. std::vector<double> len(bnd.size());
  34. len[0] = 0.;
  35. for (int i = 1; i < bnd.size(); i++)
  36. {
  37. len[i] = len[i-1] + (V.row(bnd[i-1]) - V.row(bnd[i])).norm();
  38. }
  39. double total_len = len[len.size()-1] + (V.row(bnd[0]) - V.row(bnd[bnd.size()-1])).norm();
  40. UV.resize(bnd.size(),2);
  41. for (int i = 0; i < bnd.size(); i++)
  42. {
  43. double frac = len[i] * 2. * igl::PI / total_len;
  44. UV.row(map_ij[bnd[i]]) << cos(frac), sin(frac);
  45. }
  46. }