360toPerspective/cpp/include/frame_conversions.hpp

35 lines
1.9 KiB
C++

#ifndef H_frame_conversions
#define H_frame_conversions
#include <Eigen/Dense>
#include <cmath>
/// @brief Converts a spherical vector [r, theta, phi] in ISO convention (theta=0 is Z+) to a cartesian vector.
Eigen::Vector3d sph2cart(const Eigen::Vector3d & sph);
/// @brief Converts a cartesian vector to a spherical vector [r, theta, phi] in ISO convention (theta=0 is Z+).
Eigen::Vector3d cart2sph(const Eigen::Vector3d & cart);
/// @brief Converts equirectangular coordinates to spherical coordinates.
/// @param i Row in the equirectangular image.
/// @param j Column in the equirectangular image.
/// @param width Width of the equirectangular image.
/// @param height Height of the equirectangular image.
/// @return A spherical vector [r, theta, phi] in ISO convention (theta=0 is Z+).
Eigen::Vector3d equirectangular2sph(unsigned int i, unsigned int j, unsigned int width, unsigned int height);
/// @brief Converts spherical coordinates to pixel coordinates of an equirectangular image.
/// @param p_sph A spherical vector [r, theta, phi] in ISO convention (theta=0 is Z+).
/// @param width Width of the equirectangular image.
/// @param height Height of the equirectangular image.
/// @return A 2D vector of floating point numbers [i, j] representing the pixel coordinates of the equirectangular image.
Eigen::Vector2d sph2equirectangular_d(Eigen::Vector3d const& p_sph, unsigned int width, unsigned int height);
/// @brief Converts spherical coordinates to pixel coordinates of an equirectangular image.
/// @param p_sph A spherical vector [r, theta, phi] in ISO convention (theta=0 is Z+).
/// @param width Width of the equirectangular image.
/// @param height Height of the equirectangular image.
/// @return A 2D vector of integers [i, j] representing the pixel coordinates of the equirectangular image.
Eigen::Vector2i sph2equirectangular_i(Eigen::Vector3d const& p_sph, unsigned int width, unsigned int height);
#endif