10 #include <Eigen/Dense>
14 namespace visualization {
18 {1, GL_RED}, {3, GL_RGB}, {4, GL_RGBA}};
21 {1, GL_UNSIGNED_BYTE}, {2, GL_UNSIGNED_SHORT}, {4, GL_FLOAT}};
32 const Eigen::Vector3d &lookat,
33 const Eigen::Vector3d &up) {
34 Eigen::Vector3d front_dir = (eye - lookat).normalized();
35 Eigen::Vector3d up_dir = up.normalized();
36 Eigen::Vector3d right_dir = up_dir.cross(front_dir).normalized();
37 up_dir = front_dir.cross(right_dir).normalized();
39 Eigen::Matrix4d mat = Eigen::Matrix4d::Zero();
40 mat.block<1, 3>(0, 0) = right_dir.transpose();
41 mat.block<1, 3>(1, 0) = up_dir.transpose();
42 mat.block<1, 3>(2, 0) = front_dir.transpose();
43 mat(0, 3) = -right_dir.dot(eye);
44 mat(1, 3) = -up_dir.dot(eye);
45 mat(2, 3) = -front_dir.dot(eye);
47 return mat.cast<GLfloat>();
54 Eigen::Matrix4d mat = Eigen::Matrix4d::Zero();
55 double fov_rad = field_of_view_ / 180.0 *
M_PI;
56 double tan_half_fov = std::tan(fov_rad / 2.0);
57 mat(0, 0) = 1.0 / aspect / tan_half_fov;
58 mat(1, 1) = 1.0 / tan_half_fov;
59 mat(2, 2) = -(z_far + z_near) / (z_far - z_near);
61 mat(2, 3) = -2.0 * z_far * z_near / (z_far - z_near);
62 return mat.cast<GLfloat>();
71 Eigen::Matrix4d mat = Eigen::Matrix4d::Zero();
72 mat(0, 0) = 2.0 / (right - left);
73 mat(1, 1) = 2.0 / (top - bottom);
74 mat(2, 2) = -2.0 / (z_far - z_near);
75 mat(0, 3) = -(right + left) / (right - left);
76 mat(1, 3) = -(top + bottom) / (top - bottom);
77 mat(2, 3) = -(z_far + z_near) / (z_far - z_near);
79 return mat.cast<GLfloat>();
86 Eigen::Vector4d pos = mvp_matrix.cast<
double>() *
89 return Eigen::Vector3d::Zero();
92 return Eigen::Vector3d((pos(0) * 0.5 + 0.5) * (
double)
width,
93 (pos(1) * 0.5 + 0.5) * (
double)
height,
94 (1.0 + pos(2)) * 0.5);
97 Eigen::Vector3d
Unproject(
const Eigen::Vector3d &screen_point,
101 Eigen::Vector4d
point =
102 mvp_matrix.cast<
double>().inverse() *
103 Eigen::Vector4d(screen_point(0) / (
double)
width * 2.0 - 1.0,
104 screen_point(1) / (
double)
height * 2.0 - 1.0,
105 screen_point(2) * 2.0 - 1.0, 1.0);
106 if (
point(3) == 0.0) {
107 return Eigen::Vector3d::Zero();
110 return point.block<3, 1>(0, 0);
114 if (
color(0) == 255) {
GLMatrix4f LookAt(const Eigen::Vector3d &eye, const Eigen::Vector3d &lookat, const Eigen::Vector3d &up)
const std::unordered_map< int, unsigned int > & GetTextureTypeMap()
GLMatrix4f Perspective(double field_of_view_, double aspect, double z_near, double z_far)
const std::unordered_map< int, unsigned int > & GetTextureFormatMap()
Eigen::Matrix< float, 4, 4, Eigen::ColMajor > GLMatrix4f
static const std::unordered_map< int, unsigned int > texture_type_map_
Eigen::Vector3d Unproject(const Eigen::Vector3d &screen_point, const GLMatrix4f &mvp_matrix, const int width, const int height)
Eigen::Vector3d Project(const Eigen::Vector3d &point, const GLMatrix4f &mvp_matrix, const int width, const int height)
static const std::unordered_map< int, unsigned int > texture_format_map_
int ColorCodeToPickIndex(const Eigen::Vector4i &color)
GLMatrix4f Ortho(double left, double right, double bottom, double top, double z_near, double z_far)
Generic file read and write utility for python interface.
Eigen::Matrix< Index, 4, 1 > Vector4i