point_solid_signed_squared_distance.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 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. #include "point_solid_signed_squared_distance.h"
  9. #include "points_inside_component.h"
  10. #include "point_mesh_squared_distance.h"
  11. #include "../../list_to_matrix.h"
  12. #include "../../slice_mask.h"
  13. #include <vector>
  14. #include <Eigen/Core>
  15. template <
  16. typename DerivedQ,
  17. typename DerivedVB,
  18. typename DerivedFB,
  19. typename DerivedD>
  20. IGL_INLINE void igl::copyleft::cgal::point_solid_signed_squared_distance(
  21. const Eigen::PlainObjectBase<DerivedQ> & Q,
  22. const Eigen::PlainObjectBase<DerivedVB> & VB,
  23. const Eigen::PlainObjectBase<DerivedFB> & FB,
  24. Eigen::PlainObjectBase<DerivedD> & D)
  25. {
  26. // compute unsigned distances
  27. Eigen::VectorXi I;
  28. DerivedVB C;
  29. point_mesh_squared_distance<CGAL::Epeck>(Q,VB,FB,D,I,C);
  30. // Collect queries that have non-zero distance
  31. Eigen::Array<bool,Eigen::Dynamic,1> NZ = D.array()!=0;
  32. // Compute sign for non-zero distance queries
  33. DerivedQ QNZ;
  34. slice_mask(Q,NZ,1,QNZ);
  35. Eigen::Array<bool,Eigen::Dynamic,1> DNZ;
  36. igl::copyleft::cgal::points_inside_component(VB,FB,QNZ,DNZ);
  37. // Apply sign to distances
  38. DerivedD S = DerivedD::Zero(Q.rows(),1);
  39. {
  40. int k = 0;
  41. for(int q = 0;q<Q.rows();q++)
  42. {
  43. if(NZ(q))
  44. {
  45. D(q) *= DNZ(k++) ? -1. : 1.;
  46. }
  47. }
  48. }
  49. }