per_face_normals.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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_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. // Inputs:
  16. // V #V by 3 eigen Matrix of mesh vertex 3D positions
  17. // F #F by 3 eigen Matrix of face (triangle) indices
  18. // Z 3 vector normal given to faces with degenerate normal.
  19. // Output:
  20. // N #F by 3 eigen Matrix of mesh face (triangle) 3D normals
  21. //
  22. // Example:
  23. // // Give degenerate faces (1/3,1/3,1/3)^0.5
  24. // per_face_normals(V,F,Vector3d(1,1,1).normalized(),N);
  25. template <typename DerivedV, typename DerivedF, typename DerivedZ, typename DerivedN>
  26. IGL_INLINE void per_face_normals(
  27. const Eigen::MatrixBase<DerivedV>& V,
  28. const Eigen::MatrixBase<DerivedF>& F,
  29. const Eigen::MatrixBase<DerivedZ> & Z,
  30. Eigen::PlainObjectBase<DerivedN> & N);
  31. // 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. // Special version where order of face indices is guaranteed not to effect
  39. // output.
  40. template <typename DerivedV, typename DerivedF, typename DerivedN>
  41. IGL_INLINE void per_face_normals_stable(
  42. const Eigen::MatrixBase<DerivedV>& V,
  43. const Eigen::MatrixBase<DerivedF>& F,
  44. Eigen::PlainObjectBase<DerivedN> & N);
  45. }
  46. #ifndef IGL_STATIC_LIBRARY
  47. # include "per_face_normals.cpp"
  48. #endif
  49. #endif