edge_lengths.cpp 5.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@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 "edge_lengths.h"
  9. #include <iostream>
  10. template <typename DerivedV, typename DerivedF, typename DerivedL>
  11. IGL_INLINE void igl::edge_lengths(
  12. const Eigen::PlainObjectBase<DerivedV>& V,
  13. const Eigen::PlainObjectBase<DerivedF>& F,
  14. Eigen::PlainObjectBase<DerivedL>& L)
  15. {
  16. using namespace std;
  17. const int m = F.rows();
  18. // Minimum number of iterms per openmp thread
  19. #ifndef IGL_OMP_MIN_VALUE
  20. # define IGL_OMP_MIN_VALUE 1000
  21. #endif
  22. switch(F.cols())
  23. {
  24. case 2:
  25. {
  26. L.resize(F.rows(),1);
  27. for(int i = 0;i<F.rows();i++)
  28. {
  29. L(i,0) = (V.row(F(i,1))-V.row(F(i,0))).norm();
  30. }
  31. break;
  32. }
  33. case 3:
  34. {
  35. L.resize(m,3);
  36. // loop over faces
  37. #pragma omp parallel for if (m>IGL_OMP_MIN_VALUE)
  38. for(int i = 0;i<m;i++)
  39. {
  40. L(i,0) = (V.row(F(i,1))-V.row(F(i,2))).norm();
  41. L(i,1) = (V.row(F(i,2))-V.row(F(i,0))).norm();
  42. L(i,2) = (V.row(F(i,0))-V.row(F(i,1))).norm();
  43. }
  44. break;
  45. }
  46. case 4:
  47. {
  48. L.resize(m,6);
  49. // loop over faces
  50. #pragma omp parallel for if (m>IGL_OMP_MIN_VALUE)
  51. for(int i = 0;i<m;i++)
  52. {
  53. L(i,0) = (V.row(F(i,3))-V.row(F(i,0))).norm();
  54. L(i,1) = (V.row(F(i,3))-V.row(F(i,1))).norm();
  55. L(i,2) = (V.row(F(i,3))-V.row(F(i,2))).norm();
  56. L(i,3) = (V.row(F(i,1))-V.row(F(i,2))).norm();
  57. L(i,4) = (V.row(F(i,2))-V.row(F(i,0))).norm();
  58. L(i,5) = (V.row(F(i,0))-V.row(F(i,1))).norm();
  59. }
  60. break;
  61. }
  62. default:
  63. {
  64. cerr<< "edge_lengths.h: Error: Simplex size ("<<F.cols()<<
  65. ") not supported"<<endl;
  66. assert(false);
  67. }
  68. }
  69. }
  70. #ifdef IGL_STATIC_LIBRARY
  71. // Explicit template specialization
  72. // generated by autoexplicit.sh
  73. template void igl::edge_lengths<Eigen::Matrix<float, -1, 2, 0, -1, 2>, Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1>, Eigen::Matrix<float, -1, 2, 0, -1, 2> >(Eigen::PlainObjectBase<Eigen::Matrix<float, -1, 2, 0, -1, 2> > const&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, 2, 0, -1, 2> >&);
  74. // generated by autoexplicit.sh
  75. template void igl::edge_lengths<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -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> >&);
  76. // generated by autoexplicit.sh
  77. template void igl::edge_lengths<Eigen::Matrix<double, -1, 2, 0, -1, 2>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 2, 0, -1, 2> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 2, 0, -1, 2> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 2, 0, -1, 2> >&);
  78. // generated by autoexplicit.sh
  79. template void igl::edge_lengths<Eigen::Matrix<double, -1, 2, 0, -1, 2>, Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, 2, 0, -1, 2> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 2, 0, -1, 2> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 2, 0, -1, 2> >&);
  80. // generated by autoexplicit.sh
  81. template void igl::edge_lengths<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 6, 0, -1, 6> >(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, 6, 0, -1, 6> >&);
  82. // generated by autoexplicit.sh
  83. template void igl::edge_lengths<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 3, 0, -1, 3> >(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, 3, 0, -1, 3> >&);
  84. // generated by autoexplicit.sh
  85. template void igl::edge_lengths<Eigen::Matrix<float, -1, 3, 1, -1, 3>, Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1>, Eigen::Matrix<float, -1, 3, 1, -1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> >&);
  86. template void igl::edge_lengths<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -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> >&);
  87. template void igl::edge_lengths<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 4, 0, -1, 4>, Eigen::Matrix<double, -1, 6, 0, -1, 6> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 4, 0, -1, 4> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 6, 0, -1, 6> >&);
  88. template void igl::edge_lengths<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  89. #endif