upsample.h 2.6 KB

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