project.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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. #ifndef IGL_PROJECT_H
  9. #define IGL_PROJECT_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Dense>
  12. namespace igl
  13. {
  14. /// Eigen reimplementation of gluProject
  15. /// @param[in] obj* 3D objects' x, y, and z coordinates respectively
  16. /// @param[in] model model matrix
  17. /// @param[in] proj projection matrix
  18. /// @param[in] viewport viewport vector
  19. /// @return screen space x, y, and z coordinates respectively
  20. template <typename Scalar>
  21. IGL_INLINE Eigen::Matrix<Scalar,3,1> project(
  22. const Eigen::Matrix<Scalar,3,1>& obj,
  23. const Eigen::Matrix<Scalar,4,4>& model,
  24. const Eigen::Matrix<Scalar,4,4>& proj,
  25. const Eigen::Matrix<Scalar,4,1>& viewport);
  26. /// \overload
  27. ///
  28. /// @param[in] V #V by 3 list of object points
  29. /// @param[in] model model matrix
  30. /// @param[in] proj projection matrix
  31. /// @param[in] viewport viewport vector
  32. /// @param[out] P #V by 3 list of screen space points
  33. ///
  34. /// \bug The compiler will not complain if V and P are Vector3d, but the result
  35. /// will be incorrect.
  36. ///
  37. /// ####Example:
  38. /// \code{cpp}
  39. /// igl::opengl::glfw::Viewer vr;
  40. /// ...
  41. /// igl::project(V,vr.core().view,vr.core().proj,vr.core().viewport,P);
  42. /// \endcode
  43. template <typename DerivedV, typename DerivedM, typename DerivedN, typename DerivedO, typename DerivedP>
  44. IGL_INLINE void project(
  45. const Eigen::MatrixBase<DerivedV>& V,
  46. const Eigen::MatrixBase<DerivedM>& model,
  47. const Eigen::MatrixBase<DerivedN>& proj,
  48. const Eigen::MatrixBase<DerivedO>& viewport,
  49. Eigen::PlainObjectBase<DerivedP> & P);
  50. }
  51. #ifndef IGL_STATIC_LIBRARY
  52. # include "project.cpp"
  53. #endif
  54. #endif