per_face_normals.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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::PlainObjectBase<DerivedV>& V,
  28. const Eigen::PlainObjectBase<DerivedF>& F,
  29. const Eigen::PlainObjectBase<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::PlainObjectBase<DerivedV>& V,
  36. const Eigen::PlainObjectBase<DerivedF>& F,
  37. Eigen::PlainObjectBase<DerivedN> & N);
  38. }
  39. #ifndef IGL_STATIC_LIBRARY
  40. # include "per_face_normals.cpp"
  41. #endif
  42. #endif