triangle_fan.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Alec Jacobson <[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. #include "triangle_fan.h"
  9. #include "exterior_edges.h"
  10. #include "list_to_matrix.h"
  11. template <typename DerivedE, typename Derivedcap>
  12. IGL_INLINE void igl::triangle_fan(
  13. const Eigen::MatrixBase<DerivedE> & E,
  14. Eigen::PlainObjectBase<Derivedcap> & cap)
  15. {
  16. // Handle lame base case
  17. if(E.size() == 0)
  18. {
  19. cap.resize(0,E.cols()+1);
  20. return;
  21. }
  22. // "Triangulate" aka "close" the E trivially with facets
  23. // Note: in 2D we need to know if E endpoints are incoming or
  24. // outgoing (left or right). Thus this will not work.
  25. assert(E.cols() == 2);
  26. // Arbitrary starting vertex
  27. //int s = E(int(((double)rand() / RAND_MAX)*E.rows()),0);
  28. int s = E(rand()%E.rows(),0);
  29. std::vector<std::vector<int> > lcap;
  30. for(int i = 0;i<E.rows();i++)
  31. {
  32. // Skip edges incident on s (they would be zero-area)
  33. if(E(i,0) == s || E(i,1) == s)
  34. {
  35. continue;
  36. }
  37. std::vector<int> e(3);
  38. e[0] = s;
  39. e[1] = E(i,0);
  40. e[2] = E(i,1);
  41. lcap.push_back(e);
  42. }
  43. list_to_matrix(lcap,cap);
  44. }
  45. #if IGL_STATIC_LIBRARY
  46. // Explicit template instantiation
  47. // generated by autoexplicit.sh
  48. template void igl::triangle_fan<Eigen::Matrix<int, -1, 2, 0, -1, 2>, Eigen::Matrix<int, -1, -1, 0, -1, -1>>(Eigen::MatrixBase<Eigen::Matrix<int, -1, 2, 0, -1, 2>> const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1>>&);
  49. #endif