-
Notifications
You must be signed in to change notification settings - Fork 0
/
SceneManager.cpp
411 lines (324 loc) · 13 KB
/
SceneManager.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
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
#include "SceneManager.h"
#include "CollageGraphics.h"
///////////////////////////////////////////////////////////////////////////////////////////////
//
// Name: SceneManager.h
//
// Author: Mike Conway
//
// Description: Top level class that defines a scene manager. The scene manager is in charge of describing the display environment,
// including corners, stitch lines, and aspects of the display that can effect the display of images, such as thumbnail walls and magnification walls.
//
// This class is differentiated from the CollageLayoutManager, which lays out content within the parameters set by the SceneManager.
///////////////////////////////////////////////////////////////////////////////////////////////
// scenemanager constructor intitializes values
// params: collageGraphics - handle to the CollageGraphics object
SceneManager::SceneManager(CollageGraphics* collageGraphics)
{
padPixelsBetweenDisplays = 0;
toroidalDisplay = false;
padForBoundaries = false;
calculated = false;
this->collageGraphics = collageGraphics;
availableSingleDisplayHeight = 0;
availableSingleDisplayWidth = 0;
totalDisplayWidth = 0;
totalDisplayHeight = 0;
}
// get the vector of SceneDisplayGroups, these are groups collections of physical displays (a row of monitors or projectors)
std::vector<SceneDisplayGroup*> SceneManager::GetSceneDisplayGroups(void) {
return sceneDisplayGroups;
}
// SceneManager destructor will clean up displays and display groups
SceneManager::~SceneManager(void)
{
for (int i = 0; i < (int)sceneDisplayGroups.size(); i++) {
delete sceneDisplayGroups[i];
}
}
// after configuring all displays into groups, invoke this method to calculate the dimensions and attributes
// of the scene
void SceneManager::CalculateScene(void) {
if (sceneDisplayGroups.size() == 0) {
throw SceneManagerException("no display groups in scene manager");
}
// for each scene group, calculate the dimensions based on the individual displays
for (int i = 0; i < (int)sceneDisplayGroups.size(); i++) {
sceneDisplayGroups[i]->CalculateDisplayGroup();
}
// check a display to get the available width and height
if (sceneDisplayGroups.size() == 0) {
throw SceneManagerException("no display groups when calculating scene");
} else if (sceneDisplayGroups[0]->GetSceneDisplays()->size() == 0) {
throw SceneManagerException("no displays in display group when calculating scene");
} else {
this->availableSingleDisplayWidth = sceneDisplayGroups[0]->GetSceneDisplays()->at(0)->GetAvailableWidthInPixels();
this->availableSingleDisplayHeight = sceneDisplayGroups[0]->GetSceneDisplays()->at(0)->GetAvailableHeightInPixels();
}
// TODO: this is stub code contrived to calculate the total display width and height, it's really hard coded
// for the scr dimensions, but could be enhanced to calculate other display configurations - MCC
totalDisplayWidth = 12288;
totalDisplayHeight = 768;
calculated = true;
}
bool SceneManager::IsCalculated(void) {
return this->calculated;
}
// get the number of available displays that fit a specified display role.
unsigned int SceneManager::GetNumberOfDisplaysByRole(SceneManager::DisplayRole displayRole) {
unsigned int count = 0;
for (int i = 0; i < (int)sceneDisplayGroups.size(); i++) {
for (int j = 0; j < (int)sceneDisplayGroups[i]->GetSceneDisplays()->size(); j++) {
if (sceneDisplayGroups[i]->GetSceneDisplays()->at(j)->GetDisplayRole() == displayRole) {
count++;
}
}
}
return count;
}
// get the effetive width of a display (all displays are assumed to be of the same dimension), accounting for
// padding if that is specified.
unsigned int SceneManager::GetAvailableSingleDisplayWidth(void) {
return availableSingleDisplayWidth;
}
// get the effetive height of a display (all displays are assumed to be of the same dimension), accounting for
// padding if that is specified.
unsigned int SceneManager::GetAvailableSingleDisplayHeight(void) {
return availableSingleDisplayHeight;
}
// get the total width of all displays
unsigned int SceneManager::GetTotalDisplayWidth(void) {
return totalDisplayWidth;
}
// get the total height of all displays
unsigned int SceneManager::GetTotalDisplayHeight(void) {
return totalDisplayHeight;
}
// accessor to number of pixles to pad between displays (e.g. a stitch line buffer or corner)
unsigned int SceneManager::GetPadPixelsBetweenDisplays(void) {
return this->padPixelsBetweenDisplays;
}
// accessor indicates whether to pad for the boundaries
bool SceneManager::IsPadForBoundaries(void) {
return this->padForBoundaries;
}
/////////////////////////////////////////////////////////////
// SceneDisplayGroup members - a group of related displays (a row or surface)
/////////////////////////////////////////////////////////////
SceneDisplayGroup::SceneDisplayGroup(SceneManager* sceneManager)
{
this->sceneManager = sceneManager;
//widthInPixels = 0;
//heightInPixels = 0;
xOrigin = 0;
yOrigin = 0;
xThru = 0;
yThru = 0;
groupName = "display group";
}
// SceneDisplayGroups destructor will clean SceneDisplays
SceneDisplayGroup::~SceneDisplayGroup(void)
{
for (int i = 0; i < (int)sceneDisplays.size(); i++) {
delete sceneDisplays[i];
}
}
// Set the displays in this group to a certain display role
void SceneDisplayGroup::SetGroupToDisplayRole(SceneManager::DisplayRole displayRole){
for (int i = 0; i < (int)sceneDisplays.size(); i++) {
sceneDisplays[i]->SetDisplayRole(displayRole);
}
}
// Setter for a displayable name for this group
void SceneDisplayGroup::SetGroupName(std::string groupName) {
this->groupName = groupName;
}
// Bounce thru the display groups and calculate their stuff
void SceneDisplayGroup::CalculateDisplayGroup(void) {
if (sceneDisplays.size() == 0) {
throw SceneManagerException("no displays in display group");
}
for (int i = 0; i < (int)sceneDisplays.size(); i++) {
sceneDisplays[i]->CalculateSceneDisplay();
}
// set the bounds for this scene group based on the constituent displays
xOrigin = sceneDisplays.front()->GetXOrigin();
yOrigin = sceneDisplays.front()->GetYOrigin();
xThru = sceneDisplays.back()->GetXThru();
yThru = sceneDisplays.back()->GetYThru();
}
std::vector<SceneDisplay*>* SceneDisplayGroup::GetSceneDisplays(void) {
return &sceneDisplays;
}
// accessor for the x origin of the display (upper left is 0,0)
unsigned int SceneDisplayGroup::GetXOrigin(void) {
return xOrigin;
}
// accessor for the y origin of the display (upper left is 0,0)
unsigned int SceneDisplayGroup::GetYOrigin(void) {
return yOrigin;
}
// accessor for the last x pixel displayed
unsigned int SceneDisplayGroup::GetXThru(void) {
return xThru;
}
// accessor for the last y pixel displayed
unsigned int SceneDisplayGroup::GetYThru(void) {
return yThru;
}
SceneManager* SceneDisplayGroup::GetSceneManager(void) {
return sceneManager;
}
/////////////////////////////////////////////////////////////
// SceneDisplay members - a projector or display that makes up a group
/////////////////////////////////////////////////////////////
//Scene Display constructor, initialze variables to defaults
SceneDisplay::SceneDisplay(SceneDisplayGroup* sceneDisplayGroup) {
this->sceneDisplayGroup = sceneDisplayGroup;
widthInPixels=0;
heightInPixels=0;
xOrigin=0;
yOrigin=0;
xOriginInScale = 0.0;
yOriginInScale = 0.0;
xThru=0;
yThru=0;
displayRole=SceneManager::SM_THUMBNAIL_DISPLAY;
}
// Scene Display destructor
SceneDisplay::~SceneDisplay(void) {
}
// calculate dimensions for this display, otehr settings
void SceneDisplay::CalculateSceneDisplay(void) {
// calculate the absolute x,y boundaries based on the origin and dimensions
xThru = xOrigin + widthInPixels - 1;
yThru = yOrigin + heightInPixels - 1;
if (xThru == 0 || yThru == 0) {
throw SceneManagerException("cannot have a zero width display");
}
}
// accessor for the SceneDisplayGroup that this SceneDisplay is in
SceneDisplayGroup* SceneDisplay::GetSceneDisplayGroup(void) {
return sceneDisplayGroup;
}
void SceneDisplay::SetWidthInPixels(unsigned int widthInPixels) {
this->widthInPixels = widthInPixels;
}
void SceneDisplay::SetHeightInPixels(unsigned int heightInPixels) {
this->heightInPixels = heightInPixels;
}
void SceneDisplay::SetXOrigin(unsigned int xOrigin) {
this->xOrigin = xOrigin;
}
void SceneDisplay::SetYOrigin(unsigned int yOrigin) {
this->yOrigin = yOrigin;
}
void SceneDisplay::SetDisplayRole(SceneManager::DisplayRole displayRole) {
this->displayRole = displayRole;
}
// accessor for the x origin of the display (upper left is 0,0)
unsigned int SceneDisplay::GetXOrigin(void) {
return xOrigin;
}
// accessor for the x origin of the display (upper left is 0,0) with padding adjusted
unsigned int SceneDisplay::GetPaddedXOrigin(void) {
if (sceneDisplayGroup->GetSceneManager()->IsPadForBoundaries()) {
return xOrigin + sceneDisplayGroup->GetSceneManager()->GetPadPixelsBetweenDisplays();
} else {
return xOrigin;
}
}
// accessor for the y origin of the display (upper left is 0,0) with padding adjusted
unsigned int SceneDisplay::GetPaddedYOrigin(void) {
if (sceneDisplayGroup->GetSceneManager()->IsPadForBoundaries()) {
return yOrigin + sceneDisplayGroup->GetSceneManager()->GetPadPixelsBetweenDisplays();
} else {
return yOrigin;
}
}
// accessor for the scaled (versus pixels) x origin of the display (upper left is 0,0) with padding adjusted
double SceneDisplay::GetPaddedXOriginInScale(void) {
if (sceneDisplayGroup->GetSceneManager()->IsPadForBoundaries()) {
return (xOrigin + sceneDisplayGroup->GetSceneManager()->GetPadPixelsBetweenDisplays()) / sceneDisplayGroup->GetSceneManager()->GetTotalDisplayWidth();
} else {
return xOrigin / sceneDisplayGroup->GetSceneManager()->GetTotalDisplayWidth();
}
}
// accessor for the scaled (versus pixels) y origin of the display (upper left is 0,0) with padding adjusted
double SceneDisplay::GetPaddedYOriginInScale(void) {
if (sceneDisplayGroup->GetSceneManager()->IsPadForBoundaries()) {
return (yOrigin + sceneDisplayGroup->GetSceneManager()->GetPadPixelsBetweenDisplays()) / sceneDisplayGroup->GetSceneManager()->GetTotalDisplayHeight();
} else {
return yOrigin / sceneDisplayGroup->GetSceneManager()->GetTotalDisplayHeight();
}
}
// accessor for the scaled (versus pixels) x origin of the display (upper left is 0,0)
double SceneDisplay::GetXOriginInScale(void) {
return xOrigin / sceneDisplayGroup->GetSceneManager()->GetTotalDisplayWidth();
}
// accessor for the scaled (versus pixels) y origin of the display (upper left is 0,0)
double SceneDisplay::GetYOriginInScale(void) {
return yOrigin / sceneDisplayGroup->GetSceneManager()->GetTotalDisplayHeight();
}
// accessor for the y origin of the display (upper left is 0,0)
unsigned int SceneDisplay::GetYOrigin(void) {
return yOrigin;
}
// accessor for the last x pixel displayed
unsigned int SceneDisplay::GetXThru(void) {
return xThru;
}
// accessor for the last y pixel displayed
unsigned int SceneDisplay::GetYThru(void) {
return yThru;
}
// accessor for the display role
SceneManager::DisplayRole SceneDisplay::GetDisplayRole(void) {
return displayRole;
}
// accessor returns width of this display in pixels
unsigned int SceneDisplay::GetWidthInPixels(void) {
return widthInPixels;
}
// accessor returns height of this display in pixels
unsigned int SceneDisplay::GetHeightInPixels(void) {
return heightInPixels;
}
// accessor for the available width, taking into account any padding
unsigned int SceneDisplay::GetAvailableWidthInPixels(void) {
unsigned int retWidth = 0;
if (sceneDisplayGroup->GetSceneManager()->IsPadForBoundaries()) {
retWidth = widthInPixels - (sceneDisplayGroup->GetSceneManager()->GetPadPixelsBetweenDisplays() * 2);
} else {
retWidth = widthInPixels;
}
return retWidth;
}
// accessor for the available height, taking into account any padding
unsigned int SceneDisplay::GetAvailableHeightInPixels(void) {
unsigned int retHeight = 0;
if (sceneDisplayGroup->GetSceneManager()->IsPadForBoundaries()) {
retHeight = heightInPixels - (sceneDisplayGroup->GetSceneManager()->GetPadPixelsBetweenDisplays() * 2);
} else {
retHeight = heightInPixels;
}
return retHeight;
}
// compute the x,y center of this display
// return: Vec2D with the x,y coordinates of the absolute display center
Vec2 SceneDisplay::GetDisplayCenter(void) {
double x = xOrigin + widthInPixels * .5;
double y = yOrigin + heightInPixels * .5;
return Vec2(x,y);
}
/////////////////////////////////////////////////////////////
// SceneManagerException - general exeption for scene manager processing
/////////////////////////////////////////////////////////////
SceneManagerException::SceneManagerException(std::string message) {
this->message = message;
}
SceneManagerException::~SceneManagerException(void) {
}
std::string SceneManagerException::GetMessage(void) {
return this->message;
}