-
Notifications
You must be signed in to change notification settings - Fork 2
/
EL3DWindow.cpp
494 lines (451 loc) · 14 KB
/
EL3DWindow.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
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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
// Copyright 2012-2013 UT-Battelle, LLC. See LICENSE.txt for more information.
#include "EL3DWindow.h"
#include "ELRenderOptions.h"
#include <QMouseEvent>
#include <QToolBar>
#include <QAction>
#include <QActionGroup>
#include <QKeyEvent>
#include <eavlColorTable.h>
#include <eavlPlot.h>
#include <eavl3DWindow.h>
#include <eavlScene.h>
#include <eavlTextAnnotation.h>
#include <eavlSceneRendererSimpleGL.h>
#include <eavlSceneRendererGL.h>
#include <eavlSceneRendererSimpleRT.h>
#include <eavlSceneRendererSimpleVR.h>
#include <eavlSceneRendererSimplePVR.h>
#include <eavlSceneRendererRT.h>
#include <eavlRenderSurfaceGL.h>
#include <eavlWorldAnnotatorGL.h>
#include <cfloat>
// ****************************************************************************
// Constructor: EL3DWindow::EL3DWindow
//
// Programmer: Jeremy Meredith
// Creation: August 16, 2012
//
// Modifications:
// ****************************************************************************
EL3DWindow::EL3DWindow(ELWindowManager *parent)
: QGLWidget(parent)
{
setFormat(QGLFormat(QGL::SampleBuffers));
settings = NULL;
mousedown = false;
shiftKey = false;
lastx = lasty = -1;
showghosts = false;
showmesh = false;
scene = new eavl3DScene();
window = new eavl3DWindow(eavlColor(0.15, 0.0, 0.25),
new eavlRenderSurfaceGL,
scene,
new eavlSceneRendererGL,
new eavlWorldAnnotatorGL);
// force creation
GetSettings();
}
// ****************************************************************************
// Method: EL3DWindow::SetPipeline
//
// Purpose:
/// Set the pipeline this window is showing.
//
// Arguments:
// index the index of the pipeline
// p the pipeline to show
//
// Programmer: Jeremy Meredith
// Creation: August 16, 2012
//
// Modifications:
// ****************************************************************************
void
EL3DWindow::PipelineUpdated(Pipeline *pipe)
{
settings->PipelineUpdated(pipe);
UpdatePlots();
ResetView();
}
// ****************************************************************************
// Method: EL3DWindow::CurrentPipelineChanged
//
// Purpose:
/// Tell this window what the currently-edited pipeline index is.
//
// Arguments:
// index the new pipeline being edited
//
// Programmer: Jeremy Meredith
// Creation: August 16, 2012
//
// Modifications:
// ****************************************************************************
void
EL3DWindow::CurrentPipelineChanged(int)
{
/*
//cerr << "EL3DWindow::CurrentPipelineChanged\n";
currentPipeline = index;
UpdatePlots();
if (watchedPipelines[0])
updateGL();
*/
}
// ****************************************************************************
// Method: EL3DWindow::initializeGL
//
// Purpose:
/// QGLWidget method for initializing various OpenGL things.
//
// Arguments:
// none
//
// Programmer: Jeremy Meredith
// Creation: August 16, 2012
//
// Modifications:
// ****************************************************************************
void
EL3DWindow::initializeGL()
{
}
bool
EL3DWindow::UpdatePlots()
{
//cerr << "EL2DWindow::UpdatePlots\n";
bool shoulddraw = false;
scene->plots.clear();
for (unsigned int i=0; i<settings->plots.size(); i++)
{
Plot &p = settings->plots[i];
if (!p.pipe || p.pipe->results.size() == 0)
continue;
p.CreateEAVLPlot();
if (!p.eavlplot)
continue;
shoulddraw = true;
scene->plots.push_back(p.eavlplot);
}
return shoulddraw;
}
// ****************************************************************************
// Method: EL3DWindow::ResetView
//
// Purpose:
/// Sets up the camera based on the current pipelines.
//
// Arguments:
// w,h new width, height
//
// Programmer: Jeremy Meredith
// Creation: August 16, 2012
//
// Modifications:
// ****************************************************************************
void
EL3DWindow::ResetView()
{
//cerr << "EL3DWindow::ResetView\n";
UpdatePlots();
scene->ResetView(window);
updateGL();
}
// ****************************************************************************
// Method: EL3DWindow::paintGL
//
// Purpose:
/// QGLWidget method for when the window needs to be painter.
/// This does all the drawing.
//
// Arguments:
// none
//
// Programmer: Jeremy Meredith
// Creation: August 16, 2012
//
// Modifications:
// Jeremy Meredith, Thu Nov 29 12:19:33 EST 2012
// Added nodal surface normal lighting support.
//
// ****************************************************************************
void
EL3DWindow::paintGL()
{
bool shoulddraw = UpdatePlots();
///\todo: note: there's some issue where this method is getting
/// called before it's supposed to be. (I believe it's from
/// my use of updateGL() in other methods in this class when
/// e.g. the variable or other settings change.) If we continue
/// on anyway, then something bad happens, such as creating
/// a texture with either the wrong thread or before the context
/// is ready, which makes the texture unusable. A safe test
/// we currently use before proceeding is simply whether or
/// not any of the plots have data, because we know everything
/// is safely initialized since the user was able to hit Execute.
if (!shoulddraw)
return;
// okay, we think it's safe to proceed now!
window->Paint();
#if 0
// various tests of font rendering
glEnable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
static eavlTextAnnotation *t1=NULL,*t1b=NULL,*t1c=NULL, *t2a=NULL,*t2b=NULL,*t3=NULL,*t3b=NULL, *t4=NULL,*t4b=NULL;
if (!t1)
{
t1 = new eavlScreenTextAnnotation(window,"Test 2D text, [] height=0.05 near upper-left corner (-.9,.9)",
eavlColor::white, .05,
-.9, 0.9);
t1b = new eavlScreenTextAnnotation(window,"Test 2D text, [] height=0.05 at (-.9,.85) should be immediately below other 2D text",
eavlColor::white, .05,
-.9, 0.85);
t1c = new eavlScreenTextAnnotation(window,"Test 2D text, [] height=0.05 at (-.9,-.9) oriented at 90 degrees",
eavlColor::white, .05,
-.9,-.9, 90.);
t2a = new eavlWorldTextAnnotation(window,"Test 3D text (You), height=1.0 in 3D space at (-5,0,0), diagonal along X=Z, Y=up",
eavlColor::white,
1.0,
-5,0,0,
-1,0,1,
0,1,0);
t2b = new eavlWorldTextAnnotation(window,"Test 3D text (You), height=1.0 in 3D space at (0,0,-5), diagonal along X=Z, Y=up",
eavlColor::white,
1.0,
0,0,-5,
-1,0,1,
0,1,0);
t3 = new eavlBillboardTextAnnotation(window,"Test 3D billboard text, height=0.05 in screen space at (0,5,0)",
eavlColor::white,
.05,
0,5,0, true);
t3b = new eavlBillboardTextAnnotation(window,"Test 3D billboard text, height=1.0 in 3D space at (0,-12,0)",
eavlColor::white,
1.0,
0,-12,0, false);
t4 = new eavlBillboardTextAnnotation(window,"Test 3D billboard text, height in screen space at 90deg",
eavlColor::white,
.05,
0,5,0, true, 90.0);
t4b = new eavlBillboardTextAnnotation(window,"Test 3D billboard text, height in 3D space at 90deg",
eavlColor::white,
1.0,
0,-12,0, false, 90.0);
}
t1->Render(window->view);
t1b->Render(window->view);
t1c->Render(window->view);
t2a->Render(window->view);
t2b->Render(window->view);
t3->Render(window->view);
t3b->Render(window->view);
t4->Render(window->view);
t4b->Render(window->view);
#endif
}
// ****************************************************************************
// Method: EL3DWindow::resizeGL
//
// Purpose:
/// QGLWidget method for when the window is created or resized.
/// Here, set the aspect and gl viewport.
//
// Arguments:
// w,h new width, height
//
// Programmer: Jeremy Meredith
// Creation: August 16, 2012
//
// Modifications:
// ****************************************************************************
void
EL3DWindow::resizeGL(int w, int h)
{
window->Resize(w,h);
}
// ****************************************************************************
// Method: EL3DWindow::mousePressEvent
//
// Purpose:
/// Mouse button is now down; start interaction.
//
// Arguments:
// mev the mouse event
//
// Programmer: Jeremy Meredith
// Creation: August 15, 2012
//
// Modifications:
// ****************************************************************************
void
EL3DWindow::mousePressEvent(QMouseEvent *mev)
{
shiftKey = (mev->modifiers() & Qt::ShiftModifier);
makeCurrent();
lastx = mev->x();
lasty = mev->y();
mousedown = true;
//updateGL();
}
// ****************************************************************************
// Method: EL3DWindow::mouseMoveEvent
//
// Purpose:
/// Mouse is moved (while mouse is down). Change camera.
//
// Arguments:
// mev the mouse event
//
// Programmer: Jeremy Meredith
// Creation: August 15, 2012
//
// Modifications:
// ****************************************************************************
void
EL3DWindow::mouseMoveEvent(QMouseEvent *mev)
{
makeCurrent();
int x = mev->x();
int y = mev->y();
if (mousedown)
{
double x1 = ((double(lastx*2)/double(width())) - 1.0);
double y1 = -((double(lasty*2)/double(height())) - 1.0);
double x2 = ((double( x *2)/double(width())) - 1.0);
double y2 = -((double( y *2)/double(height())) - 1.0);
if (mev->buttons() & Qt::LeftButton)
{
if (shiftKey)
{
double dx = x2-x1;
double dy = y2-y1;
window->view.Pan3D(dx, dy);
}
else
{
window->view.TrackballRotate(x1,y1, x2,y2);
}
}
else if (mev->buttons() & Qt::MidButton)
{
double zoom = y2-y1;
if (shiftKey)
{
window->view.MoveForward3d(zoom);
}
else
{
window->view.Zoom3D(zoom);
}
}
// No: we want a popup menu instead!
//else if (mev->buttons() & Qt::RightButton)
//{
//}
//renderer->resetProgress();
updateGL();
}
lastx = x;
lasty = y;
}
// ****************************************************************************
// Method: EL3DWindow::mouseReleaseEvent
//
// Purpose:
/// Mouse button is no longer down; finish interaction.
//
// Arguments:
// mev the mouse event
//
// Programmer: Jeremy Meredith
// Creation: August 15, 2012
//
// Modifications:
// ****************************************************************************
void
EL3DWindow::mouseReleaseEvent(QMouseEvent *)
{
makeCurrent();
mousedown = false;
shiftKey = false;
//updateGL();
}
// ****************************************************************************
// Method: EL3DWindow::GetSettings
//
// Purpose:
/// Return the settings for this window, creating and connecting
/// signals/slots if necessary.
//
// Arguments:
// none
//
// Programmer: Jeremy Meredith
// Creation: August 16, 2012
//
// Modifications:
// ****************************************************************************
QWidget *
EL3DWindow::GetSettings()
{
if (!settings)
{
settings = new ELPlotList;
connect(settings, SIGNAL(SomethingChanged()),
this, SLOT(SomethingChanged()));
}
return settings;
}
// ****************************************************************************
// Method:
//
// Purpose:
///
//
// Arguments:
//
//
// Programmer: Jeremy Meredith
// Creation: March 12, 2013
//
// Modifications:
// ****************************************************************************
void
EL3DWindow::SomethingChanged()
{
updateGL();
}
void
EL3DWindow::SetRendererType(const QString &type)
{
if (type == "OpenGL")
window->SetSceneRenderer(new eavlSceneRendererGL);
if (type == "OpenGL (simple)")
window->SetSceneRenderer(new eavlSceneRendererSimpleGL);
else if (type == "RayTrace (simple")
window->SetSceneRenderer(new eavlSceneRendererSimpleRT);
else if (type == "RayTrace")
window->SetSceneRenderer(new eavlSceneRendererRT);
else if (type == "Volume")
window->SetSceneRenderer(new eavlSceneRendererSimpleVR);
else if (type == "Volume (parallel)")
window->SetSceneRenderer(new eavlSceneRendererSimplePVR);
else
;
}
void
EL3DWindow::SetRendererOptions(Attribute *atts)
{
RenderingAttributes *r = dynamic_cast<RenderingAttributes*>(atts);
if (!r)
return;
eavlSceneRenderer *sr = window->GetSceneRenderer();
sr->SetAmbientCoefficient(r->Ka);
sr->SetDiffuseCoefficient(r->Kd);
sr->SetSpecularCoefficient(r->Ks);
sr->SetLightDirection(r->Lx, r->Ly, r->Lz);
sr->SetEyeLight(r->eyeLight);
//sr->SetPointRadius(r->pointRadius);
}