unproject.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 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 "unproject.h"
  9. #include "model_proj_viewport.h"
  10. #include "../unproject.h"
  11. #include "../opengl/OpenGL_convenience.h"
  12. #include <Eigen/Dense>
  13. #include <Eigen/LU>
  14. IGL_INLINE void igl::opengl2::unproject(
  15. const double winX,
  16. const double winY,
  17. const double winZ,
  18. double* objX,
  19. double* objY,
  20. double* objZ)
  21. {
  22. Eigen::Vector3d obj;
  23. igl::opengl2::unproject(Eigen::Vector3d(winX,winY,winZ),obj);
  24. *objX = obj(0);
  25. *objY = obj(1);
  26. *objZ = obj(2);
  27. }
  28. template <typename Derivedwin, typename Derivedobj>
  29. IGL_INLINE void igl::opengl2::unproject(
  30. const Eigen::PlainObjectBase<Derivedwin> & win,
  31. Eigen::PlainObjectBase<Derivedobj> & obj)
  32. {
  33. const auto ret = igl::opengl2::unproject(win);
  34. obj = ret.template cast<typename Derivedobj::Scalar>();
  35. }
  36. template <typename Derivedwin>
  37. IGL_INLINE Eigen::PlainObjectBase<Derivedwin> igl::opengl2::unproject(
  38. const Eigen::PlainObjectBase<Derivedwin> & win)
  39. {
  40. using namespace Eigen;
  41. typedef typename Derivedwin::Scalar Scalar;
  42. Matrix4d MV,P;
  43. Vector4d VPd;
  44. model_proj_viewport(MV,P,VPd);
  45. Vector3d wind = win.template cast<double>();
  46. Vector3d objd = igl::unproject(wind,MV,P,VPd);
  47. return objd.template cast<Scalar>();
  48. }
  49. #ifdef IGL_STATIC_LIBRARY
  50. // Explicit template specialization
  51. // generated by autoexplicit.sh
  52. template Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > igl::opengl2::unproject<Eigen::Matrix<double, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&);
  53. template void igl::opengl2::unproject<Eigen::Matrix<double, 3, 1, 0, 3, 1>, Eigen::Matrix<float, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> >&);
  54. template void igl::opengl2::unproject<Eigen::Matrix<float, 3, 1, 0, 3, 1>, Eigen::Matrix<float, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> >&);
  55. template Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > igl::opengl2::unproject<Eigen::Matrix<float, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > const&);
  56. template void igl::opengl2::unproject<Eigen::Matrix<double, 3, 1, 0, 3, 1>, Eigen::Matrix<double, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> >&);
  57. #endif