point_solid_signed_squared_distance.cpp 2.2 KB

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