-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwindow.cpp
87 lines (71 loc) · 2.17 KB
/
window.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* stair-step-detector
* Copyright (c) 2021 Peter Nebe ([email protected])
*
* This file is part of stair-step-detector.
*
* stair-step-detector is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* stair-step-detector is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with stair-step-detector. If not, see <https://www.gnu.org/licenses/>.
*/
#include "window.h"
#include "configuration.h"
namespace stairs
{
namespace
{
const Configuration::Streams __streams;
int calcWindowWidth()
{
return __streams.infrared.width + __streams.depth.width;
}
int calcWindowHeight()
{
return __streams.infrared.height;
}
inline ::rect makeRect(int x, int y, int w, int h)
{
return{ static_cast<float>(x),
static_cast<float>(y),
static_cast<float>(w),
static_cast<float>(h) };
}
} // namespace
Window::Window(const char* title)
: window(calcWindowWidth(), calcWindowHeight(), title),
_colorMap(2) // WhiteToBlack
{
_viewport[viewportId::infrared] = makeRect(0, 0, __streams.infrared.width, __streams.infrared.height);
_viewport[viewportId::depth] = makeRect(__streams.infrared.width, 0, __streams.depth.width, __streams.depth.height);
glfwSetWindowAttrib(*this, GLFW_RESIZABLE, GL_FALSE);
}
void Window::show(const Camera::Frameset &frames)
{
auto infrared = frames.infraredFrame();
auto depth = _colorMap.colorize(frames.depthFrame());
window::show(infrared, _viewport[viewportId::infrared]);
window::show(depth, _viewport[viewportId::depth]);
}
void Window::setViewport(int viewportId) const
{
set_viewport(_viewport[viewportId]);
}
void Window::waitClose()
{
glfwSwapBuffers(*this);
while(!glfwWindowShouldClose(*this))
{
glfwWaitEvents();
glfwSwapBuffers(*this);
}
}
} /* namespace stairs */