MeshNormals.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. ///|/ Copyright (c) Prusa Research 2022 Tomáš Mészáros @tamasmeszaros
  2. ///|/
  3. ///|/ PrusaSlicer is released under the terms of the AGPLv3 or higher
  4. ///|/
  5. #ifndef MESHNORMALS_HPP
  6. #define MESHNORMALS_HPP
  7. #include "AABBMesh.hpp"
  8. #include "libslic3r/Execution/ExecutionSeq.hpp"
  9. #include "libslic3r/Execution/ExecutionTBB.hpp"
  10. namespace Slic3r {
  11. // Get a good approximation of the normal for any picking point on the mesh.
  12. // For points projecting to a face, this is the face normal, but when the
  13. // picking point is on an edge or a vertex of the mesh, the normal is the
  14. // normalized sum of each unique face normal (works nicely). The eps parameter
  15. // gives a tolerance for how close a sample point has to be to an edge or
  16. // vertex to start considering neighboring faces for the resulting normal.
  17. Vec3d get_normal(const AABBMesh &mesh,
  18. const Vec3d &picking_point,
  19. double eps = 0.05);
  20. using PointSet = Eigen::MatrixXd;
  21. // Calculate the normals for the selected points (from 'points' set) on the
  22. // mesh. This will call squared distance for each point.
  23. template<class Ex>
  24. Eigen::MatrixXd normals(
  25. Ex ex_policy,
  26. const PointSet &points,
  27. const AABBMesh &convert_mesh,
  28. double eps = 0.05, // min distance from edges
  29. std::function<void()> throw_on_cancel = []() {},
  30. const std::vector<unsigned> &selected_points = {});
  31. extern template Eigen::MatrixXd normals(
  32. ExecutionSeq policy,
  33. const PointSet &points,
  34. const AABBMesh &convert_mesh,
  35. double eps,
  36. std::function<void()> throw_on_cancel,
  37. const std::vector<unsigned> &selected_points);
  38. extern template Eigen::MatrixXd normals(
  39. ExecutionTBB policy,
  40. const PointSet &points,
  41. const AABBMesh &convert_mesh,
  42. double eps,
  43. std::function<void()> throw_on_cancel,
  44. const std::vector<unsigned> &selected_points);
  45. } // namespace Slic3r
  46. #endif // MESHNORMALS_HPP