per_face_normals.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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_PER_FACE_NORMALS_H
  9. #define IGL_PER_FACE_NORMALS_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. namespace igl
  13. {
  14. /// Compute face normals via vertex position list, face list
  15. ///
  16. /// @param[in] V #V by 3 eigen Matrix of mesh vertex 3D positions
  17. /// @param[in] F #F by 3 eigen Matrix of face (triangle) indices
  18. /// @param[in] Z 3 vector normal given to faces with degenerate normal.
  19. /// @param[out] N #F by 3 eigen Matrix of mesh face (triangle) 3D normals
  20. ///
  21. /// #### Example
  22. /// // Give degenerate faces (1/3,1/3,1/3)^0.5
  23. /// per_face_normals(V,F,Vector3d(1,1,1).normalized(),N);
  24. template <typename DerivedV, typename DerivedF, typename DerivedZ, typename DerivedN>
  25. IGL_INLINE void per_face_normals(
  26. const Eigen::MatrixBase<DerivedV>& V,
  27. const Eigen::MatrixBase<DerivedF>& F,
  28. const Eigen::MatrixBase<DerivedZ> & Z,
  29. Eigen::PlainObjectBase<DerivedN> & N);
  30. /// \overload
  31. /// \brief Wrapper with Z = (0,0,0). Note that this means that row norms will be zero
  32. /// (i.e. not 1) for degenerate normals.
  33. template <typename DerivedV, typename DerivedF, typename DerivedN>
  34. IGL_INLINE void per_face_normals(
  35. const Eigen::MatrixBase<DerivedV>& V,
  36. const Eigen::MatrixBase<DerivedF>& F,
  37. Eigen::PlainObjectBase<DerivedN> & N);
  38. /// \overload
  39. /// \brief Special version where order of face indices is guaranteed not to effect
  40. /// output.
  41. template <typename DerivedV, typename DerivedF, typename DerivedN>
  42. IGL_INLINE void per_face_normals_stable(
  43. const Eigen::MatrixBase<DerivedV>& V,
  44. const Eigen::MatrixBase<DerivedF>& F,
  45. Eigen::PlainObjectBase<DerivedN> & N);
  46. /// Per face normals for a general polygon mesh
  47. /// @param[in] V #V by 3 list of mesh vertex positions
  48. /// @param[in] I #I vectorized list of polygon corner indices into rows of some matrix V
  49. /// @param[in] C #polygons+1 list of cumulative polygon sizes so that C(i+1)-C(i) = size of
  50. /// the ith polygon, and so I(C(i)) through I(C(i+1)-1) are the indices of
  51. /// the ith polygon
  52. /// @param[out] N #polygons by 3 list of per face normals
  53. /// @param[out] VV #I+#polygons by 3 list of auxiliary triangle mesh vertex positions
  54. /// @param[out] FF #I by 3 list of triangle indices into rows of VV
  55. /// @param[out] J #I list of indices into original polygons
  56. template <
  57. typename DerivedV,
  58. typename DerivedI,
  59. typename DerivedC,
  60. typename DerivedN,
  61. typename DerivedVV,
  62. typename DerivedFF,
  63. typename DerivedJ>
  64. IGL_INLINE void per_face_normals(
  65. const Eigen::MatrixBase<DerivedV> & V,
  66. const Eigen::MatrixBase<DerivedI> & I,
  67. const Eigen::MatrixBase<DerivedC> & C,
  68. Eigen::PlainObjectBase<DerivedN> & N,
  69. Eigen::PlainObjectBase<DerivedVV> & VV,
  70. Eigen::PlainObjectBase<DerivedFF> & FF,
  71. Eigen::PlainObjectBase<DerivedJ> & J);
  72. }
  73. #ifndef IGL_STATIC_LIBRARY
  74. # include "per_face_normals.cpp"
  75. #endif
  76. #endif