map_vertices_to_circle.cpp 1.4 KB

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