-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathSequencePlayer.qml
More file actions
438 lines (358 loc) · 14 KB
/
SequencePlayer.qml
File metadata and controls
438 lines (358 loc) · 14 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
import QtCore
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Controls 1.0
import MaterialIcons 2.2
import Utils 1.0
/**
* The Sequence Player is a UI for manipulating
* the currently selected (and displayed) viewpoint
* in an ordered set of viewpoints (i.e. a sequence).
*
* The viewpoint manipulation process can be manual
* (for example by dragging a slider to change the current frame)
* or automatic
* (by playing the sequence, i.e. incrementing the current frame at a given time rate).
*/
FloatingPane {
id: root
// Exposed properties
property var sortedViewIds: []
property var viewer: null
property bool isOutputSequence: false
readonly property alias sync3DSelected: m.sync3DSelected
readonly property alias syncFeaturesSelected: m.syncFeaturesSelected
property bool loading: fetchButton.checked || m.playing
property alias settings_SequencePlayer: settings_SequencePlayer
property alias frameId: m.frame
property var frameRange: { "min" : 0, "max" : 0 }
Settings {
id: settings_SequencePlayer
property int maxCacheMemory: viewer && viewer.ramInfo != undefined ? viewer.ramInfo.x / 4 : 0
}
function updateSceneView() {
if (isOutputSequence)
return
if (_currentScene && m.frame >= frameRange.min && m.frame < frameRange.max + 1) {
if (!m.playing && !frameSlider.pressed) {
_currentScene.selectedViewId = sortedViewIds[m.frame]
} else {
_currentScene.pickedViewId = sortedViewIds[m.frame]
if (m.sync3DSelected) {
_currentScene.updateSelectedViewpoint(_currentScene.pickedViewId)
}
}
}
}
onIsOutputSequenceChanged: {
if (!isOutputSequence) {
frameId = frameRange.min
}
}
onSortedViewIdsChanged: {
frameSlider.from = frameRange.min
frameSlider.to = frameRange.max
}
// Sequence player model:
// - current frame
// - data related to automatic sequence playing
QtObject {
id: m
property int frame: frameRange.min
property bool syncFeaturesSelected: true
property bool sync3DSelected: true
property bool playing: false
property bool repeat: false
property real fps: 24
onFrameChanged: {
updateSceneView()
}
onPlayingChanged: {
if (!playing) {
updateSceneView()
} else if (playing && (frame + 1 >= frameRange.max + 1)) {
frame = frameRange.min
}
viewer.playback(playing)
}
}
// Update the frame property
// when the selected view ID is changed externally
Connections {
target: _currentScene
function onSelectedViewIdChanged() {
for (let idx = 0; idx < sortedViewIds.length; idx++) {
if (_currentScene.selectedViewId === sortedViewIds[idx] && (m.frame != idx)) {
m.frame = idx
}
}
}
}
// In play mode
// we use a timer to increment the frame property
// at a given time rate (defined by the fps property)
Timer {
id: timer
repeat: true
running: m.playing && root.visible
interval: 1000 / m.fps
onTriggered: {
if (viewer.imageStatus !== Image.Ready) {
// Wait for current image to be displayed before switching to next image
return
}
let nextIndex = m.frame + 1
if (nextIndex == frameRange.max + 1) {
if (m.repeat) {
m.frame = frameRange.min
return
}
else {
m.playing = false
return
}
}
m.frame = nextIndex
}
}
// Widgets:
// - "Previous Frame" button
// - "Play - Pause" button
// - "Next Frame" button
// - frame label
// - frame slider
// - FPS spin box
// - "Repeat" button
RowLayout {
anchors.fill: parent
IntSelector {
id: frameInput
tooltipText: "Frame"
displayButtons: true
range: frameRange
onValueChanged: {
m.frame = value
}
Binding {
target: frameInput
property: "value"
value: m.frame
when: !frameInput.activeFocus
}
}
MaterialToolButton {
id: playButton
checkable: true
checked: false
text: checked ? MaterialIcons.pause_circle : MaterialIcons.play_circle
font.pointSize: 20
ToolTip.text: checked ? "Pause Player" : "Play Sequence"
onCheckedChanged: {
m.playing = checked
}
Connections {
target: m
function onPlayingChanged() {
playButton.checked = m.playing
}
}
}
TimelineSlider {
id: frameSlider
Layout.fillWidth: true
value: m.frame
stepSize: 1
snapMode: Slider.SnapAlways
live: true
from: frameRange.min
to: frameRange.max
cachedFrames: viewer ? viewer.cachedFrames : []
onValueChanged: {
m.frame = value
}
onPressedChanged: {
if (!pressed) {
updateSceneView()
}
}
ToolTip {
parent: frameSlider.handle
visible: frameSlider.hovered
text: m.frame
}
}
RowLayout {
TextInput {
id: fpsTextInput
Layout.preferredWidth: fpsMetrics.width
selectByMouse: true
text: !focus ? m.fps + " FPS" : m.fps
color: palette.text
onEditingFinished: {
m.fps = parseInt(text)
focus = false
}
}
}
MaterialToolButton {
id: fetchButton
text: MaterialIcons.subscriptions
ToolTip.text: "Fetch"
checkable: true
checked: loading
}
MaterialToolButton {
id: repeatButton
checkable: true
checked: false
text: MaterialIcons.repeat
ToolTip.text: "Repeat"
onCheckedChanged: {
m.repeat = checked
}
}
MaterialToolButton {
id: infoButton
text: MaterialIcons.settings
font.pointSize: 11
padding: 2
onClicked: infoMenu.open()
checkable: true
checked: infoMenu.visible
Popup {
id: infoMenu
y: parent.height
x: -width + parent.width
contentItem: GridLayout {
layoutDirection: Qt.LeftToRight
columns: 2
Column {
id: syncColumn
Layout.alignment: Qt.AlignTop
Text {
text: "<b>Synchronisation:</b>"
color: palette.text
}
CheckBox {
id: syncFeaturePointsCheckBox
text: "Sync Feature Points"
checkable: true
checked: m.syncFeaturesSelected
onCheckedChanged: {
m.syncFeaturesSelected = checked
}
ToolTip.text: "The Feature points will be updated at the same time as the Sequence Player."
ToolTip.visible: hovered
ToolTip.delay: 100
}
CheckBox {
id: sync3DCheckBox
text: "Sync 3D Viewer"
checkable: true
checked: m.sync3DSelected
onCheckedChanged: {
m.sync3DSelected = checked
}
ToolTip.text: "The 3D Viewer will be updated at the same time as the Sequence Player."
ToolTip.visible: hovered
ToolTip.delay: 100
}
}
Column {
id: cacheColumn
Layout.alignment: Qt.AlignTop
Text {
text: "<b>Cache:</b>"
color: palette.text
}
// max cache memory limit
Row {
height: sync3DCheckBox.height
Text {
anchors.verticalCenter: parent.verticalCenter
text: "Max Cache Memory: "
color: palette.text
}
TextField {
id: maxCacheMemoryInput
anchors.verticalCenter: parent.verticalCenter
color: palette.text
text: !focus ? settings_SequencePlayer.maxCacheMemory + " GB" : settings_SequencePlayer.maxCacheMemory
onEditingFinished: {
settings_SequencePlayer.maxCacheMemory = parseInt(text)
focus = false
}
}
}
Text {
height: sync3DCheckBox.height
verticalAlignment: Text.AlignVCenter
text: {
if (viewer && viewer.ramInfo != undefined)
return "Available Memory: " + viewer.ramInfo.x + " GB"
return "Unknown Available Memory"
}
color: palette.text
}
Text {
height: sync3DCheckBox.height
verticalAlignment: Text.AlignVCenter
text: {
// number of cached frames is the difference between the first and last frame of all intervals in the cache
let cachedFrames = viewer ? viewer.cachedFrames : []
let cachedFramesCount = 0
for (let i = 0; i < cachedFrames.length; i++) {
cachedFramesCount += cachedFrames[i].y - cachedFrames[i].x + 1
}
return "Cached Frames: " + (viewer ? cachedFramesCount : "0") + " / " + sortedViewIds.length
}
color: palette.text
}
// do beautiful progress bar
ProgressBar {
id: cacheProgressBar
width: parent.width
from: 0
to: viewer && viewer.ramInfo != undefined ? viewer.ramInfo.x : 0
value: viewer ? settings_SequencePlayer.maxCacheMemory : 0
ToolTip.text: {
let ramMsg = "Max cache memory set: " + settings_SequencePlayer.maxCacheMemory + " GB"
if (viewer && viewer.ramInfo != undefined) {
return ramMsg + "\n" + "on available memory: " + viewer.ramInfo.x + " GB"
}
return ramMsg + ",\n" + "available memory unknown"
}
ToolTip.visible: hovered
ToolTip.delay: 100
}
ProgressBar {
id: occupiedCacheProgressBar
property string occupiedCache: viewer && viewer.ramInfo ? Format.GB2SizeStr(viewer.ramInfo.y) : 0
width: parent.width
from: 0
to: settings_SequencePlayer.maxCacheMemory
value: viewer && viewer.ramInfo != undefined ? viewer.ramInfo.y : 0
ToolTip.text: "Occupied cache: " + occupiedCache + "\n" + "On max cache memory set: " + settings_SequencePlayer.maxCacheMemory + " GB"
ToolTip.visible: hovered
ToolTip.delay: 100
}
}
}
}
}
}
TextMetrics {
id: fpsMetrics
font: fpsTextInput.font
text: "100 FPS"
}
// Action to play/pause the sequence player
Action {
id: playPauseAction
shortcut: "Space"
onTriggered: {
m.playing = !m.playing
}
}
}