unproject.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. obj = igl::opengl2::unproject(win).template cast<typename Derivedobj::Scalar>();
  34. }
  35. template <typename Derivedwin>
  36. IGL_INLINE Eigen::PlainObjectBase<Derivedwin> igl::opengl2::unproject(
  37. const Eigen::PlainObjectBase<Derivedwin> & win)
  38. {
  39. using namespace Eigen;
  40. typedef typename Derivedwin::Scalar Scalar;
  41. Matrix4d MV,P;
  42. Vector4d VPd;
  43. model_proj_viewport(MV,P,VPd);
  44. Vector3d wind = win.template cast<double>();
  45. Vector3d objd = igl::unproject(wind,MV,P,VPd);
  46. return objd.template cast<Scalar>();
  47. }
  48. #ifdef IGL_STATIC_LIBRARY
  49. // Explicit template specialization
  50. // generated by autoexplicit.sh
  51. 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&);
  52. 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> >&);
  53. 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> >&);
  54. 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&);
  55. 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> >&);
  56. #endif