per_vertex_normals.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_VERTEX_NORMALS_H
  9. #define IGL_PER_VERTEX_NORMALS_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. // Note: It would be nice to support more or all of the methods here:
  13. // "A comparison of algorithms for vertex normal computation"
  14. namespace igl
  15. {
  16. enum PerVertexNormalsWeightingType
  17. {
  18. // Incident face normals have uniform influence on vertex normal
  19. PER_VERTEX_NORMALS_WEIGHTING_TYPE_UNIFORM = 0,
  20. // Incident face normals are averaged weighted by area
  21. PER_VERTEX_NORMALS_WEIGHTING_TYPE_AREA = 1,
  22. // Incident face normals are averaged weighted by incident angle of vertex
  23. PER_VERTEX_NORMALS_WEIGHTING_TYPE_ANGLE = 2,
  24. // Area weights
  25. PER_VERTEX_NORMALS_WEIGHTING_TYPE_DEFAULT = 3,
  26. NUM_PER_VERTEX_NORMALS_WEIGHTING_TYPE = 4
  27. };
  28. // Compute vertex normals via vertex position list, face list
  29. // Inputs:
  30. // V #V by 3 eigen Matrix of mesh vertex 3D positions
  31. // F #F by 3 eigne Matrix of face (triangle) indices
  32. // weighting Weighting type
  33. // Output:
  34. // N #V by 3 eigen Matrix of mesh vertex 3D normals
  35. template <typename DerivedV, typename DerivedF>
  36. IGL_INLINE void per_vertex_normals(
  37. const Eigen::PlainObjectBase<DerivedV>& V,
  38. const Eigen::PlainObjectBase<DerivedF>& F,
  39. const igl::PerVertexNormalsWeightingType weighting,
  40. Eigen::PlainObjectBase<DerivedV> & N);
  41. // Without weighting
  42. template <typename DerivedV, typename DerivedF>
  43. IGL_INLINE void per_vertex_normals(
  44. const Eigen::PlainObjectBase<DerivedV>& V,
  45. const Eigen::PlainObjectBase<DerivedF>& F,
  46. Eigen::PlainObjectBase<DerivedV> & N);
  47. // Inputs:
  48. // FN #F by 3 matrix of face (triangle) normals
  49. template <typename DerivedV, typename DerivedF, typename DerivedFN, typename DerivedN>
  50. IGL_INLINE void per_vertex_normals(
  51. const Eigen::PlainObjectBase<DerivedV>& V,
  52. const Eigen::PlainObjectBase<DerivedF>& F,
  53. const PerVertexNormalsWeightingType weighting,
  54. const Eigen::PlainObjectBase<DerivedFN>& FN,
  55. Eigen::PlainObjectBase<DerivedN> & N);
  56. // Without weighting
  57. template <typename DerivedV, typename DerivedF>
  58. IGL_INLINE void per_vertex_normals(
  59. const Eigen::PlainObjectBase<DerivedV>& V,
  60. const Eigen::PlainObjectBase<DerivedF>& F,
  61. const Eigen::PlainObjectBase<DerivedV>& FN,
  62. Eigen::PlainObjectBase<DerivedV> & N);
  63. }
  64. #ifndef IGL_STATIC_LIBRARY
  65. # include "per_vertex_normals.cpp"
  66. #endif
  67. #endif