upsample.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. #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. // Inputs:
  22. // n_verts an integer (number of mesh vertices)
  23. // F an m by 3 matrix of integers of triangle faces
  24. // Outputs:
  25. // S a sparse matrix (will become the subdivision matrix)
  26. // newF a matrix containing the new faces
  27. template <
  28. typename DerivedF,
  29. typename SType,
  30. typename DerivedNF>
  31. IGL_INLINE void upsample(
  32. const int n_verts,
  33. const Eigen::PlainObjectBase<DerivedF>& F,
  34. Eigen::SparseMatrix<SType>& S,
  35. Eigen::PlainObjectBase<DerivedNF>& NF);
  36. // Subdivide a mesh without moving vertices: loop subdivision but odd
  37. // vertices stay put and even vertices are just edge midpoints
  38. //
  39. // Templates:
  40. // MatV matrix for vertex positions, e.g. MatrixXd
  41. // MatF matrix for vertex positions, e.g. MatrixXi
  42. // Inputs:
  43. // V #V by dim mesh vertices
  44. // F #F by 3 mesh triangles
  45. // Outputs:
  46. // NV new vertex positions, V is guaranteed to be at top
  47. // NF new list of face indices
  48. //
  49. // NOTE: V should not be the same as NV,
  50. // NOTE: F should not be the same as NF, use other proto
  51. //
  52. // Known issues:
  53. // - assumes (V,F) is edge-manifold.
  54. template <
  55. typename DerivedV,
  56. typename DerivedF,
  57. typename DerivedNV,
  58. typename DerivedNF>
  59. IGL_INLINE void upsample(
  60. const Eigen::PlainObjectBase<DerivedV>& V,
  61. const Eigen::PlainObjectBase<DerivedF>& F,
  62. Eigen::PlainObjectBase<DerivedNV>& NV,
  63. Eigen::PlainObjectBase<DerivedNF>& NF,
  64. const int number_of_subdivs = 1);
  65. // Virtually in place wrapper
  66. template <
  67. typename MatV,
  68. typename MatF>
  69. IGL_INLINE void upsample(
  70. MatV& V,
  71. MatF& F,
  72. const int number_of_subdivs = 1);
  73. }
  74. #ifndef IGL_STATIC_LIBRARY
  75. # include "upsample.cpp"
  76. #endif
  77. #endif