unproject_onto_mesh.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@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 "unproject_onto_mesh.h"
  9. #include "EmbreeIntersector.h"
  10. #include <igl/unproject.h>
  11. #include <igl/embree/unproject_in_mesh.h>
  12. #include <vector>
  13. IGL_INLINE bool igl::unproject_onto_mesh(
  14. const Eigen::Vector2f& pos,
  15. const Eigen::MatrixXi& F,
  16. const Eigen::Matrix4f& model,
  17. const Eigen::Matrix4f& proj,
  18. const Eigen::Vector4f& viewport,
  19. const igl::EmbreeIntersector & ei,
  20. int& fid,
  21. int& vid)
  22. {
  23. using namespace std;
  24. using namespace Eigen;
  25. MatrixXd obj;
  26. vector<igl::Hit> hits;
  27. unproject_in_mesh(pos,model,proj,viewport,ei,obj,hits);
  28. if (hits.size()> 0)
  29. {
  30. Vector3d bc(1.0-hits[0].u-hits[0].v, hits[0].u, hits[0].v);
  31. int i;
  32. bc.maxCoeff(&i);
  33. fid = hits[0].id;
  34. vid = F(fid,i);
  35. return true;
  36. }
  37. return false;
  38. }
  39. #ifdef IGL_STATIC_LIBRARY
  40. #endif