per_vertex_normals.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 <
  36. typename DerivedV,
  37. typename DerivedF,
  38. typename DerivedN>
  39. IGL_INLINE void per_vertex_normals(
  40. const Eigen::MatrixBase<DerivedV>& V,
  41. const Eigen::MatrixBase<DerivedF>& F,
  42. const igl::PerVertexNormalsWeightingType weighting,
  43. Eigen::PlainObjectBase<DerivedN> & N);
  44. // Without weighting
  45. template <
  46. typename DerivedV,
  47. typename DerivedF,
  48. typename DerivedN>
  49. IGL_INLINE void per_vertex_normals(
  50. const Eigen::MatrixBase<DerivedV>& V,
  51. const Eigen::MatrixBase<DerivedF>& F,
  52. Eigen::PlainObjectBase<DerivedN> & N);
  53. // Inputs:
  54. // FN #F by 3 matrix of face (triangle) normals
  55. template <typename DerivedV, typename DerivedF, typename DerivedFN, typename DerivedN>
  56. IGL_INLINE void per_vertex_normals(
  57. const Eigen::MatrixBase<DerivedV>& V,
  58. const Eigen::MatrixBase<DerivedF>& F,
  59. const PerVertexNormalsWeightingType weighting,
  60. const Eigen::MatrixBase<DerivedFN>& FN,
  61. Eigen::PlainObjectBase<DerivedN> & N);
  62. // Without weighting
  63. template <
  64. typename DerivedV,
  65. typename DerivedF,
  66. typename DerivedFN,
  67. typename DerivedN>
  68. IGL_INLINE void per_vertex_normals(
  69. const Eigen::MatrixBase<DerivedV>& V,
  70. const Eigen::MatrixBase<DerivedF>& F,
  71. const Eigen::MatrixBase<DerivedFN>& FN,
  72. Eigen::PlainObjectBase<DerivedN> & N);
  73. }
  74. #ifndef IGL_STATIC_LIBRARY
  75. # include "per_vertex_normals.cpp"
  76. #endif
  77. #endif