Open3D (C++ API)  0.11.0
GLHelper.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 // Avoid warning caused by redefinition of APIENTRY macro
30 // defined also in glfw3.h
31 #ifdef _WIN32
32 #include <windows.h>
33 #endif
34 
35 #include <GL/glew.h> // Make sure glew.h is included before gl.h
36 #include <GLFW/glfw3.h>
37 
38 #include <Eigen/Core>
39 #include <string>
40 #include <unordered_map>
41 
42 namespace open3d {
43 namespace visualization {
44 namespace gl_util {
45 
46 const static std::unordered_map<int, GLenum> texture_format_map_ = {
47  {1, GL_RED}, {3, GL_RGB}, {4, GL_RGBA}};
48 const static std::unordered_map<int, GLenum> texture_type_map_ = {
49  {1, GL_UNSIGNED_BYTE}, {2, GL_UNSIGNED_SHORT}, {4, GL_FLOAT}};
50 
51 typedef Eigen::Matrix<GLfloat, 3, 1, Eigen::ColMajor> GLVector3f;
52 typedef Eigen::Matrix<GLfloat, 4, 1, Eigen::ColMajor> GLVector4f;
53 typedef Eigen::Matrix<GLfloat, 4, 4, Eigen::ColMajor> GLMatrix4f;
54 
55 GLMatrix4f LookAt(const Eigen::Vector3d &eye,
56  const Eigen::Vector3d &lookat,
57  const Eigen::Vector3d &up);
58 
59 GLMatrix4f Perspective(double field_of_view_,
60  double aspect,
61  double z_near,
62  double z_far);
63 
64 GLMatrix4f Ortho(double left,
65  double right,
66  double bottom,
67  double top,
68  double z_near,
69  double z_far);
70 
71 Eigen::Vector3d Project(const Eigen::Vector3d &point,
72  const GLMatrix4f &mvp_matrix,
73  const int width,
74  const int height);
75 
76 Eigen::Vector3d Unproject(const Eigen::Vector3d &screen_point,
77  const GLMatrix4f &mvp_matrix,
78  const int width,
79  const int height);
80 
81 int ColorCodeToPickIndex(const Eigen::Vector4i &color);
82 
83 } // namespace gl_util
84 } // namespace visualization
85 } // namespace open3d
Eigen::Vector3d Project(const Eigen::Vector3d &point, const GLMatrix4f &mvp_matrix, const int width, const int height)
Definition: GLHelper.cpp:87
Eigen::Matrix< GLfloat, 4, 4, Eigen::ColMajor > GLMatrix4f
Definition: GLHelper.h:53
Eigen::Matrix< GLfloat, 4, 1, Eigen::ColMajor > GLVector4f
Definition: GLHelper.h:52
Eigen::Vector3d Unproject(const Eigen::Vector3d &screen_point, const GLMatrix4f &mvp_matrix, const int width, const int height)
Definition: GLHelper.cpp:102
math::float4 color
Definition: LineSetBuffers.cpp:63
Eigen::Matrix< GLfloat, 3, 1, Eigen::ColMajor > GLVector3f
Definition: GLHelper.h:51
GLMatrix4f LookAt(const Eigen::Vector3d &eye, const Eigen::Vector3d &lookat, const Eigen::Vector3d &up)
Definition: GLHelper.cpp:36
int ColorCodeToPickIndex(const Eigen::Vector4i &color)
Definition: GLHelper.cpp:118
GLMatrix4f Perspective(double field_of_view_, double aspect, double z_near, double z_far)
Definition: GLHelper.cpp:55
Definition: PinholeCameraIntrinsic.cpp:35
int height
Definition: FilePCD.cpp:72
GLMatrix4f Ortho(double left, double right, double bottom, double top, double z_near, double z_far)
Definition: GLHelper.cpp:70
int width
Definition: FilePCD.cpp:71