Open3D (C++ API)
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 #include <Eigen/Core>
38 #include <string>
39 #include <unordered_map>
40 
41 namespace open3d {
42 namespace visualization {
43 namespace GLHelper {
44 
45 const static std::unordered_map<int, GLenum> texture_format_map_ = {
46  {1, GL_RED}, {3, GL_RGB}, {4, GL_RGBA}};
47 const static std::unordered_map<int, GLenum> texture_type_map_ = {
48  {1, GL_UNSIGNED_BYTE}, {2, GL_UNSIGNED_SHORT}, {4, GL_FLOAT}};
49 
50 typedef Eigen::Matrix<GLfloat, 3, 1, Eigen::ColMajor> GLVector3f;
51 typedef Eigen::Matrix<GLfloat, 4, 1, Eigen::ColMajor> GLVector4f;
52 typedef Eigen::Matrix<GLfloat, 4, 4, Eigen::ColMajor> GLMatrix4f;
53 
54 GLMatrix4f LookAt(const Eigen::Vector3d &eye,
55  const Eigen::Vector3d &lookat,
56  const Eigen::Vector3d &up);
57 
58 GLMatrix4f Perspective(double field_of_view_,
59  double aspect,
60  double z_near,
61  double z_far);
62 
63 GLMatrix4f Ortho(double left,
64  double right,
65  double bottom,
66  double top,
67  double z_near,
68  double z_far);
69 
70 Eigen::Vector3d Project(const Eigen::Vector3d &point,
71  const GLMatrix4f &mvp_matrix,
72  const int width,
73  const int height);
74 
75 Eigen::Vector3d Unproject(const Eigen::Vector3d &screen_point,
76  const GLMatrix4f &mvp_matrix,
77  const int width,
78  const int height);
79 
80 int ColorCodeToPickIndex(const Eigen::Vector4i &color);
81 
82 } // namespace GLHelper
83 } // namespace visualization
84 } // namespace open3d
Eigen::Matrix< GLfloat, 3, 1, Eigen::ColMajor > GLVector3f
Definition: GLHelper.h:50
Eigen::Vector3d Unproject(const Eigen::Vector3d &screen_point, const GLMatrix4f &mvp_matrix, const int width, const int height)
Definition: GLHelper.cpp:102
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
Eigen::Matrix< GLfloat, 4, 1, Eigen::ColMajor > GLVector4f
Definition: GLHelper.h:51
Eigen::Matrix< GLfloat, 4, 4, Eigen::ColMajor > GLMatrix4f
Definition: GLHelper.h:52
math::float4 color
Definition: LineSetBuffers.cpp:46
Eigen::Vector3d Project(const Eigen::Vector3d &point, const GLMatrix4f &mvp_matrix, const int width, const int height)
Definition: GLHelper.cpp:87
GLMatrix4f LookAt(const Eigen::Vector3d &eye, const Eigen::Vector3d &lookat, const Eigen::Vector3d &up)
Definition: GLHelper.cpp:36
Definition: Open3DViewer.h:29
int height
Definition: FilePCD.cpp:70
int width
Definition: FilePCD.cpp:69
GLMatrix4f Ortho(double left, double right, double bottom, double top, double z_near, double z_far)
Definition: GLHelper.cpp:70