project.cpp 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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 "project.h"
  9. #include "../project.h"
  10. #include "gl.h"
  11. #include "glu.h"
  12. #include <iostream>
  13. IGL_INLINE int igl::opengl2::project(
  14. const double objX,
  15. const double objY,
  16. const double objZ,
  17. double* winX,
  18. double* winY,
  19. double* winZ)
  20. {
  21. using namespace std;
  22. // Put model, projection, and viewport matrices into double arrays
  23. double MV[16];
  24. double P[16];
  25. int VP[4];
  26. glGetDoublev(GL_MODELVIEW_MATRIX, MV);
  27. glGetDoublev(GL_PROJECTION_MATRIX, P);
  28. glGetIntegerv(GL_VIEWPORT, VP);
  29. int ret = gluProject(objX,objY,objZ,MV,P,VP,winX,winY,winZ);
  30. return ret;
  31. }
  32. template <typename Derivedobj, typename Derivedwin>
  33. IGL_INLINE int igl::opengl2::project(
  34. const Eigen::PlainObjectBase<Derivedobj> & obj,
  35. Eigen::PlainObjectBase<Derivedwin> & win)
  36. {
  37. assert(obj.size() >= 3);
  38. Eigen::Vector3d dobj(obj(0),obj(1),obj(2));
  39. Eigen::Vector3d dwin;
  40. int ret = igl::opengl2::project(dobj(0),dobj(1),dobj(2),
  41. &dwin.data()[0],
  42. &dwin.data()[1],
  43. &dwin.data()[2]);
  44. win(0) = dwin(0);
  45. win(1) = dwin(1);
  46. win(2) = dwin(2);
  47. return ret;
  48. }
  49. template <typename Derivedobj>
  50. IGL_INLINE Derivedobj igl::opengl2::project(
  51. const Eigen::PlainObjectBase<Derivedobj> & obj)
  52. {
  53. Derivedobj win;
  54. igl::opengl2::project(obj,win);
  55. return win;
  56. }
  57. #ifdef IGL_STATIC_LIBRARY
  58. // Explicit template instantiation
  59. template int igl::opengl2::project<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> >&);
  60. template int igl::opengl2::project<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> >&);
  61. template int igl::opengl2::project<Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, 1, 3, 1, 1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> >&);
  62. template Eigen::Matrix<double, 3, 1, 0, 3, 1> igl::opengl2::project<Eigen::Matrix<double, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&);
  63. template Eigen::Matrix<float, 3, 1, 0, 3, 1> igl::opengl2::project<Eigen::Matrix<float, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > const&);
  64. template Eigen::Matrix<double, 1, -1, 1, 1, -1> igl::opengl2::project<Eigen::Matrix<double, 1, -1, 1, 1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 1, -1, 1, 1, -1> > const&);
  65. template Eigen::Matrix<double, 1, 3, 1, 1, 3> igl::opengl2::project<Eigen::Matrix<double, 1, 3, 1, 1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&);
  66. template Eigen::Matrix<double, 1, 2, 1, 1, 2> igl::opengl2::project<Eigen::Matrix<double, 1, 2, 1, 1, 2> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 2, 1, 1, 2> > const&);
  67. template Eigen::Matrix<double, 2, 1, 0, 2, 1> igl::opengl2::project<Eigen::Matrix<double, 2, 1, 0, 2, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 2, 1, 0, 2, 1> > const&);
  68. #endif