per_face_normals.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 <utility>
  12. #include <Eigen/Core>
  13. namespace igl
  14. {
  15. // Compute face normals via vertex position list, face list
  16. // Inputs:
  17. // V #V by 3 eigen Matrix of mesh vertex 3D positions
  18. // F #F by 3 eigen Matrix of face (triangle) indices
  19. // Z 3 vector normal given to faces with degenerate normal.
  20. // Output:
  21. // N #F by 3 eigen Matrix of mesh face (triangle) 3D normals
  22. //
  23. // Example:
  24. // // Give degenerate faces (1/3,1/3,1/3)^0.5
  25. // per_face_normals(V,F,Vector3d(1,1,1).normalized(),N);
  26. template <typename DerivedV, typename DerivedF, typename DerivedZ, typename DerivedN>
  27. IGL_INLINE void per_face_normals(
  28. const Eigen::PlainObjectBase<DerivedV>& V,
  29. const Eigen::PlainObjectBase<DerivedF>& F,
  30. const Eigen::PlainObjectBase<DerivedZ> & Z,
  31. Eigen::PlainObjectBase<DerivedN> & N);
  32. // Wrapper with Z = (0,0,0). Note that this means that row norms will be zero
  33. // (i.e. not 1) for degenerate normals.
  34. template <typename DerivedV, typename DerivedF, typename DerivedN>
  35. IGL_INLINE void per_face_normals(
  36. const Eigen::PlainObjectBase<DerivedV>& V,
  37. const Eigen::PlainObjectBase<DerivedF>& F,
  38. Eigen::PlainObjectBase<DerivedN> & N);
  39. }
  40. #ifdef IGL_HEADER_ONLY
  41. # include "per_face_normals.cpp"
  42. #endif
  43. #endif