-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathScreenWidget.cpp
531 lines (448 loc) · 17.8 KB
/
ScreenWidget.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
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
/* $Id$ */
/*
*
* Copyright (C) 2001-2004 EPFL (Swiss Federal Institute of Technology,
* Lausanne) This program 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 2 of
* the License, or (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* In addition, as a special exception, EPFL gives permission to link
* the code of this program with the Qt non-commercial edition library
* (or with modified versions of Qt non-commercial edition that use the
* same license as Qt non-commercial edition), and distribute linked
* combinations including the two. You must obey the GNU General
* Public License in all respects for all of the code used other than
* Qt non-commercial edition. If you modify this file, you may extend
* this exception to your version of the file, but you are not
* obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Authors : Nicolas Aspert, Diego Santa-Cruz and Davy Jacquet
*
* Web site : http://mesh.epfl.ch
*
* Reference :
* "MESH : Measuring Errors between Surfaces using the Hausdorff distance"
* in Proceedings of IEEE Intl. Conf. on Multimedia and Expo (ICME) 2002,
* vol. I, pp. 705-708, available on http://mesh.epfl.ch
*
*/
#include <ScreenWidget.h>
#include <qhbox.h>
#include <qlayout.h>
#include <qaction.h>
#include <qapplication.h>
#include <qmessagebox.h>
#include <qmenubar.h>
#include <qpushbutton.h>
#include <qradiobutton.h>
#include <qhbuttongroup.h>
#include <qvbuttongroup.h>
#include <qvgroupbox.h>
#include <qcheckbox.h>
#include <qstring.h>
#include <qlabel.h>
#include <Lighted3DViewerWidget.h>
#include <Error3DViewerWidget.h>
#include <ColorMapWidget.h>
#include <mesh.h>
#include <mesh_run.h>
ScreenWidget::ScreenWidget(struct model_error *model1,
struct model_error *model2,
const struct args *pargs,
QWidget *parent,
const char *name ):QWidget(parent,name) {
QAction *fileQuitAction;
QPushButton *lineSwitch1, *lineSwitch2;
QMenuBar *mainBar;
QPopupMenu *fileMenu, *infoMenu, *helpMenu;
QHBox *frameModel1, *frameModel2;
QHBox *qhbTimer;
QGridLayout *bigGrid, *smallGrid;
Lighted3DViewerWidget *glModel2; // Right GLWidget
Error3DViewerWidget *glModel1; // Left GLWidget
ColorMapWidget *errorColorBar;
QPushButton *quitBut;
QRadioButton *verrBut, *fmerrBut, *serrBut;
QRadioButton *linBut, *logBut;
QRadioButton *gsBut, *hsvBut;
QButtonGroup *dispInfoGrp=NULL, *histoGrp=NULL, *histoColGrp=NULL, *rmodGrp;
QCheckBox *qcbLight;
QVGroupBox *qgbTimer;
QLabel *qlM1Name, *qlM2Name, *qlTimer;
QString tmp;
int do_texture = pargs->do_texture;
const float p = 0.95f; // max proportion of screen to use
const float wLF = 0.2f; // proportion for width of Line/Fill switch
const float wSync = 0.3f; // proportion for width of Sync. switch
const float wQ = 0.15f; // proportion for width of Quit button
int max_ds; // maximum downsampling value
int i;
tmp.sprintf("MESH %s - Visualization", version);
setCaption(tmp);
setMinimumWidth(400); // this is a reasonable assumption... and
// we need it to have a correct appearance of
// all the buttons in this widget (in fact
// only when using Qt >= 3.0.0)
fileQuitAction = new QAction( "Quit", "Quit", CTRL+Key_Q, this, "quit" );
connect(fileQuitAction, SIGNAL(activated()) ,
qApp, SLOT(closeAllWindows()));
// Create the 'File' menu
mainBar = new QMenuBar(this);
fileMenu = new QPopupMenu(this);
mainBar->insertItem("&File",fileMenu);
fileQuitAction->addTo(fileMenu);
// Create the 'Info' menu
infoMenu = new QPopupMenu(this);
// save the adresses of these structures for later
locMod1 = model1;
locMod2 = model2;
mainBar->insertItem("&Info", infoMenu);
infoMenu->insertItem("Left model information", this,
SLOT(infoLeftModel()));
infoMenu->insertItem("Right model information", this,
SLOT(infoRightModel()));
//Create the 'Help' menu
helpMenu = new QPopupMenu(this);
mainBar->insertItem("&Help", helpMenu);
helpMenu->insertItem("&Key utilities", this, SLOT(aboutKeys()),CTRL+Key_H);
helpMenu->insertItem("&Bug", this, SLOT(aboutBugs()));
helpMenu->insertItem("&About", this, SLOT(aboutMesh()));
// --------------
// Create the GUI
// --------------
// Create frames to put around the OpenGL widgets
tmp.sprintf("%s", pargs->m1_fname);
qlM1Name = new QLabel(tmp, this);
frameModel1 = new QHBox(this, "frameModel1");
frameModel1->setFrameStyle(QFrame::Sunken | QFrame::Panel);
frameModel1->setLineWidth(2);
tmp.sprintf("%s", pargs->m2_fname);
qlM2Name = new QLabel(tmp, this);
frameModel2 = new QHBox(this, "frameModel2");
frameModel2->setFrameStyle(QFrame::Sunken | QFrame::Panel);
frameModel2->setLineWidth(2);
glModel1 = new Error3DViewerWidget(model1, (bool)do_texture,
frameModel1, "ErrorViewer");
glModel1->setFocusPolicy(StrongFocus);
glModel2 = new Lighted3DViewerWidget(model2,
frameModel2, "LightedViewer");
glModel2->setFocusPolicy(StrongFocus);
errorColorBar = new ColorMapWidget(model1, this, "errorColorBar");
// This is to synchronize the viewpoints of the two models
// We need to pass the viewing matrix from one RawWidget
// to another
connect(glModel1, SIGNAL(transferViewParams(double,double,double,double*)),
glModel2, SLOT(setViewParams(double,double,double,double*)));
connect(glModel2, SIGNAL(transferViewParams(double,double,double,double*)),
glModel1, SLOT(setViewParams(double,double,double,double*)));
// Build synchro and quit buttons
syncBut = new QPushButton("Synchronize\nviewpoints", this);
syncBut->setToggleButton(TRUE);
syncBut->setMinimumWidth((int)(minimumWidth()*wSync));
connect(syncBut, SIGNAL(toggled(bool)),
glModel1, SLOT(switchSync(bool)));
connect(syncBut, SIGNAL(toggled(bool)),
glModel2, SLOT(switchSync(bool)));
connect(glModel1, SIGNAL(toggleSync()),syncBut, SLOT(toggle()));
connect(glModel2, SIGNAL(toggleSync()),syncBut, SLOT(toggle()));
quitBut = new QPushButton("Quit", this);
connect(quitBut, SIGNAL(clicked()), this, SLOT(close()));
quitBut->setMinimumWidth((int)(minimumWidth()*wQ));
// Build the two line/fill toggle buttons
lineSwitch1 = new QPushButton("Line/Fill", this);
lineSwitch1->setToggleButton(TRUE);
lineSwitch1->setMinimumWidth((int)(minimumWidth()*wLF));
connect(lineSwitch1, SIGNAL(toggled(bool)),
glModel1, SLOT(setLine(bool)));
connect(glModel1, SIGNAL(toggleLine()),lineSwitch1, SLOT(toggle()));
lineSwitch2 = new QPushButton("Line/Fill", this);
lineSwitch2->setToggleButton(TRUE);
lineSwitch2->setMinimumWidth((int)(minimumWidth()*wLF));
connect(lineSwitch2, SIGNAL(toggled(bool)),
glModel2, SLOT(setLine(bool)));
connect(glModel2, SIGNAL(toggleLine()),lineSwitch2, SLOT(toggle()));
// Build the checkboxes for right-model parameters
rmodGrp = new QVButtonGroup("Right model", this);
qcbInvNorm = new QCheckBox("Invert normals", rmodGrp);
connect(qcbInvNorm, SIGNAL(toggled(bool)),
glModel2, SLOT(invertNormals(bool)));
connect(glModel2, SIGNAL(toggleNormals()),qcbInvNorm,
SLOT(toggle()));
rmodGrp->insert(qcbInvNorm);
qcbTwoSide = new QCheckBox("One-sided material", rmodGrp);
connect(qcbTwoSide, SIGNAL(toggled(bool)),
glModel2, SLOT(setTwoSidedMaterial(bool)));
connect(glModel2, SIGNAL(toggleTwoSidedMaterial()),qcbTwoSide,
SLOT(toggle()));
rmodGrp->insert(qcbTwoSide);
qcbLight = new QCheckBox("Light mode", rmodGrp);
if (model2->mesh->normals) { // parameters make sense if the
// model has normals...
qcbLight->setChecked(TRUE);
connect(qcbLight, SIGNAL(toggled(bool)),
glModel2, SLOT(setLight(bool)));
connect(glModel2, SIGNAL(toggleLight()), qcbLight, SLOT(toggle()));
connect(qcbLight, SIGNAL(toggled(bool)),
this, SLOT(updatecbStatus(bool)));
}
else
qcbLight->setDisabled(TRUE);
rmodGrp->insert(qcbLight);
// Build error mode selection buttons
dispInfoGrp = new QVButtonGroup("Displayed information (left)",this);
dispInfoGrp->layout()->setMargin(3);
verrBut = new QRadioButton("Vertex error", dispInfoGrp);
verrBut->setChecked(TRUE);
fmerrBut = new QRadioButton("Face mean error", dispInfoGrp);
serrBut = new QRadioButton("Sample error", dispInfoGrp);
dispInfoGrp->insert(verrBut, Error3DViewerWidget::VERTEX_ERROR);
dispInfoGrp->insert(fmerrBut, Error3DViewerWidget::MEAN_FACE_ERROR);
dispInfoGrp->insert(serrBut, Error3DViewerWidget::SAMPLE_ERROR);
if (!do_texture)
serrBut->setDisabled(TRUE);
connect(dispInfoGrp, SIGNAL(clicked(int)),
glModel1, SLOT(setErrorMode(int)));
connect(dispInfoGrp, SIGNAL(clicked(int)),
this, SLOT(disableSlider(int)));
// Build downsampling control
for (i=0, max_ds=1; i<model1->mesh->num_faces; i++) {
if (model1->fe[i].sample_freq > max_ds)
max_ds = model1->fe[i].sample_freq;
}
// This is needed s.t. we can add children widget to the GroupBox
qgbSlider = new
QHGroupBox(tmp.sprintf("Subsampling factor of the error = %d", max_ds),
this);
qslidDispSampDensity = new QSlider(1, max_ds, 1, max_ds,
QSlider::Horizontal, qgbSlider);
qslidDispSampDensity->setTickInterval((max_ds-1)/5);
qslidDispSampDensity->setTickmarks(QSlider::Both);
qslidDispSampDensity->setTracking(FALSE);
glModel1->setVEDownSampling(max_ds); // Initialization
qspSampDensity = new QSpinBox(1, max_ds, 1, qgbSlider);
qspSampDensity->setValue(max_ds);
// Connect the slider and spinbox to a 'phony' slot s.t. we avoid
// loops between valueChanged signals and setValue slots
connect(qspSampDensity, SIGNAL(valueChanged(int)), this,
SLOT(trapChanges(int)));
connect(qslidDispSampDensity, SIGNAL(valueChanged(int)), this,
SLOT(trapChanges(int)));
// The dsValChange signal is emitted once when there has been a real
// change
connect(this, SIGNAL(dsValChange(int)),
glModel1, SLOT(setVEDownSampling(int)));
// Build the demo mode stuff (toggle + speed vario.)
qgbTimer = new QVGroupBox("Demo mode parameters", this);
qhbTimer = new QHBox(qgbTimer);
qspTimerSpeed = new QSpinBox(1, 100, 1, qhbTimer);
qlTimer = new QLabel("Speed", qhbTimer);
qcbTimer = new QCheckBox("Demo mode on/off", qgbTimer);
qcbTimer->setChecked(FALSE);
connect(qcbTimer, SIGNAL(toggled(bool)), glModel1,
SLOT(setTimer(bool)));
connect(qcbTimer, SIGNAL(toggled(bool)), glModel2,
SLOT(setTimer(bool)));
connect(qspTimerSpeed, SIGNAL(valueChanged(int)), glModel1,
SLOT(changeSpeed(int)));
connect(qspTimerSpeed, SIGNAL(valueChanged(int)), glModel2,
SLOT(changeSpeed(int)));
connect(glModel1, SIGNAL(toggleTimer()), qcbTimer, SLOT(toggle()));
connect(glModel2, SIGNAL(toggleTimer()), qcbTimer, SLOT(toggle()));
connect(qcbTimer, SIGNAL(toggled(bool)), this, SLOT(disableSync(bool)));
// Build scale selection buttons for the histogram
histoGrp = new QVButtonGroup("X scale",this);
linBut = new QRadioButton("Linear", histoGrp);
linBut->setChecked(TRUE);
logBut = new QRadioButton("Log", histoGrp);
histoGrp->insert(linBut, ColorMapWidget::LIN_SCALE);
histoGrp->insert(logBut, ColorMapWidget::LOG_SCALE);
connect(histoGrp, SIGNAL(clicked(int)),
errorColorBar, SLOT(doHistogram(int)));
// Build the colorspace selection button for the histogram
histoColGrp = new QVButtonGroup("Colormap", this);
hsvBut = new QRadioButton("HSV",histoColGrp);
hsvBut->setChecked(TRUE);
gsBut = new QRadioButton("Gray", histoColGrp);
histoColGrp->insert(hsvBut, ColorMapWidget::HSV);
histoColGrp->insert(gsBut, ColorMapWidget::GRAYSCALE);
connect(histoColGrp, SIGNAL(clicked(int)),
errorColorBar, SLOT(setColorMap(int)));
connect(histoColGrp, SIGNAL(clicked(int)),
glModel1, SLOT(setColorMap(int)));
// Build the topmost grid layout
bigGrid = new QGridLayout (this, 4, 7, 5, -1);
bigGrid->setMenuBar(mainBar);
bigGrid->addWidget(errorColorBar, 1, 0);
bigGrid->addMultiCellWidget(qlM1Name, 0, 0, 1, 3, Qt::AlignCenter);
bigGrid->addMultiCellWidget(qlM2Name, 0, 0, 4, 6, Qt::AlignCenter);
bigGrid->addMultiCellWidget(frameModel1, 1, 1, 1, 3);
bigGrid->addMultiCellWidget(frameModel2, 1, 1, 4, 6);
bigGrid->addWidget(lineSwitch1, 2, 2, Qt::AlignCenter);
bigGrid->addWidget(lineSwitch2, 2, 5, Qt::AlignCenter);
bigGrid->addMultiCellWidget(syncBut, 2, 2, 3, 4, Qt::AlignCenter);
bigGrid->addWidget(histoGrp, 2, 0, Qt::AlignTop);
bigGrid->addWidget(histoColGrp, 3, 0, Qt::AlignTop);
// sub layout for dispInfoGrp and Quit button -> avoid resize problems
smallGrid = new QGridLayout(1, 6, 3);
smallGrid->addWidget(dispInfoGrp, 0, 0, Qt::AlignCenter);
smallGrid->addMultiCellWidget(qgbSlider, 0, 0, 1, 2, Qt::AlignCenter);
smallGrid->addWidget(qgbTimer, 0, 3, Qt::AlignCenter);
smallGrid->addWidget(rmodGrp, 0, 4, Qt::AlignCenter);
smallGrid->addWidget(quitBut, 0, 5, Qt::AlignCenter);
bigGrid->addMultiCellLayout(smallGrid, 3, 3, 1, 6);
// Now set a sensible default widget size
QSize prefSize = layout()->sizeHint();
QSize screenSize = QApplication::desktop()->size();
if (prefSize.width() > p*screenSize.width()) {
prefSize.setWidth((int)(p*screenSize.width()));
}
if (prefSize.height() > p*screenSize.height()) {
prefSize.setHeight((int)(p*screenSize.height()));
}
resize(prefSize.width(),prefSize.height());
}
void ScreenWidget::infoLeftModel()
{
infoModel(locMod1, LEFT_MODEL);
}
void ScreenWidget::infoRightModel()
{
infoModel(locMod2, RIGHT_MODEL);
}
void ScreenWidget::infoModel(struct model_error *model, int id)
{
QString tmp, fullText;
fullText.sprintf("%d vertices\n%d triangles\n", model->mesh->num_vert,
model->mesh->num_faces);
// Orientable model ?
if (model->info->orientable)
fullText += "Orientable model\n";
else
fullText += "Non-orientable model\n";
// Manifold model ?
if (model->info->manifold)
fullText += "Manifold model\n";
else
fullText += "Non-manifold model\n";
// Closed model ?
if (model->info->closed)
fullText += "Closed model\n";
else
fullText += "Non-closed model\n";
fullText += tmp.sprintf("%d connected component(s)\n",
model->info->n_disjoint_parts);
if (model->info->n_degenerate > 0)
fullText += tmp.sprintf("%d degenerate triangle(s)\n",
model->info->n_degenerate);
switch(id) {
case LEFT_MODEL:
QMessageBox::information(this, "Left Model Information", fullText);
break;
case RIGHT_MODEL:
QMessageBox::information(this, "Right Model Information", fullText);
break;
default:
QMessageBox::warning(this, "Error", "Invalid paremeter !!\n");
break;
}
}
void ScreenWidget::changeGroupBoxTitle(int n)
{
QString tmp;
qgbSlider->setTitle(tmp.sprintf("Subsampling factor of the error = %d", n));
}
void ScreenWidget::disableSlider(int errMode)
{
switch (errMode) {
case (Error3DViewerWidget::VERTEX_ERROR):
qgbSlider->setDisabled(FALSE);
break;
case (Error3DViewerWidget::MEAN_FACE_ERROR):
case (Error3DViewerWidget::SAMPLE_ERROR):
qgbSlider->setDisabled(TRUE);
break;
default: /* should never get here */
break;
}
return;
}
void ScreenWidget::disableSync(bool state) {
if (state)
syncBut->setDisabled(TRUE);
else
syncBut->setDisabled(FALSE);
}
void ScreenWidget::trapChanges(int n)
{
int slv = qslidDispSampDensity->value(); // value of the slider
int spv = qspSampDensity->value(); // value of the spinbox
bool hasChanged = FALSE;
if (slv == n && spv == n)
return;
if (slv != n) {
qslidDispSampDensity->setValue(n);
hasChanged = TRUE;
}
if (spv != n) {
qspSampDensity->setValue(n);
hasChanged = TRUE;
}
if (hasChanged) {
changeGroupBoxTitle(n);
emit dsValChange(n);
}
}
void ScreenWidget::updatecbStatus(bool state) {
if (!state) { // no light
qcbTwoSide->setDisabled(TRUE);
qcbInvNorm->setDisabled(TRUE);
} else {
qcbTwoSide->setDisabled(FALSE);
qcbInvNorm->setDisabled(FALSE);
}
}
void ScreenWidget::aboutMesh()
{
QString msg;
msg.sprintf("MESH version %s\n"
"Copyright (C) %s\n"
"Authors: Nicolas Aspert, Diego Santa Cruz, Davy Jacquet\n\n"
"This is free software; see the source for copying conditions.\n"
"There is NO warranty; not even for MERCHANTABILITY or\n"
"FITNESS FOR A PARTICULAR PURPOSE.",
version, copyright);
QMessageBox::about(this, "MESH", msg);
}
void ScreenWidget::aboutKeys()
{
QMessageBox::about( this, "Key bindings",
"T : Toggle demo mode\n"
"F1: Toggle Wireframe/Fill\n"
"F2: Toggle lighting (right model only)\n"
"F3: Toggle viewpoint synchronization\n"
"F4: Invert normals (right model only)\n"
"F5: Toggle two sided material (right model only)");
}
void ScreenWidget::aboutBugs()
{
QMessageBox::about( this, "Bug",
"If you found a bug, please send an e-mail to :\n"
"Nicolas.Aspert@epfl.ch and/or\n"
"Diego.SantaCruz@epfl.ch");
}
void ScreenWidget::quit()
{
QApplication::exit(0);
}