upsample.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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. #ifndef IGL_UPSAMPLE_H
  9. #define IGL_UPSAMPLE_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <Eigen/Sparse>
  13. // History:
  14. // changed templates from generic matrices to PlainObjectBase Alec May 7, 2011
  15. namespace igl
  16. {
  17. /// Subdivide without moving vertices: Given the triangle mesh [V, F],
  18. /// where n_verts = V.rows(), computes newV and a sparse matrix S s.t.
  19. /// [newV, newF] is the subdivided mesh where newV = S*V.
  20. ///
  21. /// @param[in] n_verts an integer (number of mesh vertices)
  22. /// @param[in] F an m by 3 matrix of integers of triangle faces
  23. /// @param[out] S a sparse matrix (will become the subdivision matrix)
  24. /// @param[out] newF a matrix containing the new faces
  25. template <
  26. typename DerivedF,
  27. typename SType,
  28. typename DerivedNF>
  29. IGL_INLINE void upsample(
  30. const int n_verts,
  31. const Eigen::MatrixBase<DerivedF>& F,
  32. Eigen::SparseMatrix<SType>& S,
  33. Eigen::PlainObjectBase<DerivedNF>& NF);
  34. /// Subdivide a mesh without moving vertices: loop subdivision but odd
  35. /// vertices stay put and even vertices are just edge midpoints
  36. ///
  37. /// @tparam MatV matrix for vertex positions, e.g. MatrixXd
  38. /// @tparam MatF matrix for vertex positions, e.g. MatrixXi
  39. /// @param[in] V #V by dim mesh vertices
  40. /// @param[in] F #F by 3 mesh triangles
  41. /// @param[out] NV new vertex positions, V is guaranteed to be at top
  42. /// @param[out] NF new list of face indices
  43. ///
  44. /// \note V should not be the same as NV,
  45. /// \note F should not be the same as NF, use other proto
  46. ///
  47. /// \pre assumes (V,F) is edge-manifold.
  48. template <
  49. typename DerivedV,
  50. typename DerivedF,
  51. typename DerivedNV,
  52. typename DerivedNF>
  53. IGL_INLINE void upsample(
  54. const Eigen::MatrixBase<DerivedV>& V,
  55. const Eigen::MatrixBase<DerivedF>& F,
  56. Eigen::PlainObjectBase<DerivedNV>& NV,
  57. Eigen::PlainObjectBase<DerivedNF>& NF,
  58. const int number_of_subdivs = 1);
  59. // Virtually in place wrapper
  60. template <
  61. typename MatV,
  62. typename MatF>
  63. IGL_INLINE void upsample(
  64. MatV& V,
  65. MatF& F,
  66. const int number_of_subdivs = 1);
  67. }
  68. #ifndef IGL_STATIC_LIBRARY
  69. # include "upsample.cpp"
  70. #endif
  71. #endif