-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewerUI.cpp
More file actions
453 lines (353 loc) · 14.8 KB
/
Copy pathviewerUI.cpp
File metadata and controls
453 lines (353 loc) · 14.8 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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
#include"viewerUI.h"
//#include"simpleViewer.h"
#include<iostream>
using namespace std;
viewerUI::viewerUI()
{
openAction = new QAction(tr("&Open"), this);
saveAction = new QAction(tr("&Save"), this);
exitAction = new QAction(tr("E&xit"), this);
flatShadedAction = new QAction(tr("&FlatShaded"),this);
smoothShadedAction = new QAction(tr("&SmoothShaded"),this);
wireFrameAction = new QAction(tr("&WireFrame"),this);
catmullAction = new QAction(tr("&Catmull"),this);
butterflyAction = new QAction(tr("&Butterfly"),this);
wireShadeAction= new QAction(tr("Wi&reFrameShading"),this);
simplifyAction=new QAction(tr("S&implification"),this);
segmentAction=new QAction(tr("Se&gmentation"),this);
loadSegmentsAction=new QAction(tr("&Load Segments"),this);
refreshColorsAction=new QAction(tr("Refresh &Colors"),this);
//okButtonAction=new QAction(this);
// connect(okButtonAction, SIGNAL(QPushButton::clicked()),this,SLOT(buttonn()));
connect(openAction, SIGNAL(triggered()), this, SLOT(open()));
connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
connect(exitAction, SIGNAL(triggered()), this, SLOT(quit()));
connect(flatShadedAction,SIGNAL(triggered()),this,SLOT(flatShadeOn()));
connect(smoothShadedAction,SIGNAL(triggered()),this,SLOT(smoothShadeOn()));
connect(wireFrameAction,SIGNAL(triggered()),this,SLOT(wireFrameOn()));
connect(catmullAction,SIGNAL(triggered()),this,SLOT(dummy()));
connect(butterflyAction,SIGNAL(triggered()),this,SLOT(dummy()));
connect(wireShadeAction,SIGNAL(triggered()),this,SLOT(wireShadeOn()));
connect(simplifyAction,SIGNAL(triggered()),this,SLOT(simplification()));
connect(segmentAction,SIGNAL(triggered()),this,SLOT(segmentation()));
connect(loadSegmentsAction,SIGNAL(triggered()),this,SLOT(loadSegments()));
connect(refreshColorsAction,SIGNAL(triggered()),this,SLOT(refreshColors()));
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(openAction);
fileMenu->addAction(saveAction);
fileMenu->addSeparator();
fileMenu->addAction(exitAction);
operationsMenu = menuBar()->addMenu(tr("&Operations"));
operationsMenu->addAction(flatShadedAction);
operationsMenu->addAction(smoothShadedAction);
//operationsMenu->addSeparator();
operationsMenu->addAction(wireFrameAction);
operationsMenu->addAction(wireShadeAction);
operationsMenu->addAction(simplifyAction);
operationsMenu->addAction(segmentAction);
operationsMenu->addAction(loadSegmentsAction);
operationsMenu->addAction(refreshColorsAction);
subdivisionMenu=operationsMenu->addMenu(tr("Sub&division"));
subdivisionMenu->addAction(catmullAction);
subdivisionMenu->addAction(butterflyAction);
// textEdit = new QTextEdit;
// setCentralWidget(textEdit);
viewer = new Viewer;
setCentralWidget(viewer);
setWindowTitle(tr("mesh"));
}
void viewerUI::refreshColors()
{
viewer->refreshColorsSeg();
}
void viewerUI::loadSegments()
{
// std::cout<<"Load segments "<<std::endl;
cout<<"Open Segment File"<<endl;
std::vector<int> tempVec;
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
tr("seg files (*.seg)"));
if (fileName != "") {
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) {
QMessageBox::critical(this, tr("Error"), tr("Could not open file"));
return;
}
QTextStream in(&file);
while (!in.atEnd()) {
QStringList list;
QString line = in.readLine();
list=line.split(" ");
//std::cout<<list.size()<<std::endl;
tempVec.push_back(list[0].toInt());
}
//assert(tempVec.size()==viewer->getFaceListSize());
if(tempVec.size()!=viewer->getFaceListSize())
{
std::cout<<"Match not found "<<std::endl;
return;
}
std::cout<<"hahhaha "<<std::endl;
viewer->addingSegments(tempVec);
}
}
void viewerUI::open()
{
cout<<"Open"<<endl;
// QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
// tr("smf files (*.smf)"));
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
tr("off files (*.off)"));
if (fileName != "") {
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) {
QMessageBox::critical(this, tr("Error"), tr("Could not open file"));
return;
}
viewer->clearAll();
QTextStream in(&file);
/***********************************/
QString line1 = in.readLine();
QString line2 = in.readLine();
QStringList list2;
list2=line2.split(" ");
int noVertices=list2[0].toInt();
int noTriangles=list2[1].toInt();
int i=1;
int j=1;
while (!in.atEnd()) {
QStringList list;
QString line = in.readLine();
list=line.split(" ");
// std::cout<<list.size()<<std::endl;
if(i<=noVertices)
{
Point3 point;
point.x=list[0].toFloat();
point.y=list[1].toFloat();
point.z=list[2].toFloat();
viewer->insertPoint(point);
i++;
}else if(j<=noTriangles)
{
assert(list[0].toInt()==3);
Face3 face;
face.p1=list[1].toInt()+1;
face.p2=list[2].toInt()+1;
face.p3=list[3].toInt()+1;
viewer->insertFace(face);
j++;
}
/*
if(list.size()>=4 && list[0][0]!='#')
{
//qDebug()<<list;
if(list.contains(QString('v')))
{
Point3 point;
point.x=list[1].toFloat();
point.y=list[2].toFloat();
point.z=list[3].toFloat();
viewer->insertPoint(point);
}else{
Face3 face;
face.p1=list[1].toInt();
face.p2=list[2].toInt();
face.p3=list[3].toInt();
viewer->insertFace(face);
}
}*/
}
viewer->calculateMedian();
viewer->calculateFaceNormal();
viewer->calculateVertexNormal();
viewer->createHalfEdgeStructure();
viewer->makeDualGraph();
viewer->calculateCentroids();
viewer->calculateAvgWtheta();
// viewer->testingHalfEdge();
viewer->calculatingPlaneEq();//for quadrics
viewer->initiatingQuadrics();
}
//viewer->printAll();
}
void viewerUI::save()
{
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), "",
tr("smf files (*.smf)"));
if (fileName != "") {
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
return;
} else {
viewer->startSavingArr();
QTextStream out(&file);
out << "# " << viewer->getVertexArrSize() << " " << viewer->getFaceArrSize() << "\n";
for(int i=0;i<viewer->getVertexArrSize();i++)
{
Point3 temp=viewer->getPoint(i);
out << "v " << temp.x << " " << temp.y << " " << temp.z << "\n";
}
for(int i=0;i<viewer->getFaceArrSize();i++)
{
Face3 temp2=viewer->getFace(i);
out << "f " << temp2.p1+1 << " " << temp2.p2+1<< " " << temp2.p3+1 << "\n";
}
// out << "The magic number is: " << 49 << "\n";
file.close();
}
}
}
void viewerUI::quit()
{
QMessageBox messageBox;
messageBox.setWindowTitle(tr("mesh"));
messageBox.setText(tr("Do you really want to quit?"));
messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
messageBox.setDefaultButton(QMessageBox::No);
if (messageBox.exec() == QMessageBox::Yes)
{
this->close();
//qApp->quit();
}
}
void viewerUI::dummy()
{
cout<<"Doesn't work!"<<endl;
}
void viewerUI::wireFrameOn()
{
viewer->setWireFlag(1);
viewer->setWireShadeFlag(0);
}
void viewerUI::flatShadeOn()
{
viewer->setWireFlag(0);
viewer->setWireShadeFlag(0);
viewer->setShadingFlag(0);
}
void viewerUI::smoothShadeOn()
{
viewer->setWireFlag(0);
viewer->setWireShadeFlag(0);
viewer->setShadingFlag(1);
}
void viewerUI::wireShadeOn()
{
viewer->setWireShadeFlag(1);
viewer->setWireFlag(0);
}
void viewerUI::simplification()
{
createPopup();
popupWidget->show();
}
void viewerUI::createPopup2()
{
integerLabel2 = new QLabel(tr("Enter the threshold for adding edges"));
integerLabel1 = new QLabel(tr("Enter the threshold for removing edges"));
integerLabel3 = new QLabel(tr("Enter the number of iterations for fixing segments"));
integerSpinBox3 = new QDoubleSpinBox;
integerSpinBox4 = new QDoubleSpinBox;
integerSpinBox5 = new QSpinBox;
okButton = new QPushButton;
spinBoxLayout = new QVBoxLayout;
popupWidget = new QWidget;
integerSpinBox3->setRange(-1.0, 1.05);
integerSpinBox3->setSingleStep(0.05);
integerSpinBox3->setValue(-1.0);
integerSpinBox4->setRange(0.0,1.05);
integerSpinBox4->setSingleStep(0.05);
integerSpinBox4->setValue(0.2);
integerSpinBox5->setRange(0,100);
integerSpinBox5->setSingleStep(1);
integerSpinBox5->setValue(1);
okButton->setText("Start");
connect(okButton, SIGNAL(clicked()),this, SLOT(segmentButton()));
//okButton->addAction(okButtonAction);
spinBoxLayout->addWidget(integerLabel2);
spinBoxLayout->addWidget(integerSpinBox3);
spinBoxLayout->addWidget(integerLabel1);
spinBoxLayout->addWidget(integerSpinBox4);
spinBoxLayout->addWidget(integerLabel3);
spinBoxLayout->addWidget(integerSpinBox5);
spinBoxLayout->addWidget(okButton);
popupWidget->setWindowFlags(Qt::Popup);
popupWidget->setWindowFlags(Qt::Dialog);
popupWidget->setWindowFlags(Qt::Window);
popupWidget->setWindowTitle("Inputs for Segmentation Algorithm");
popupWidget->setLayout(spinBoxLayout);
popupWidget->move(300,300);
}
void viewerUI::createPopup()
{
unsigned int faceSize=viewer->getFaceListSize();
integerLabel1 = new QLabel(tr("Enter number of triangles desired(between "
"%1 and %2)").arg(3).arg(faceSize));
integerLabel2 = new QLabel(tr("Enter the value for K"));
integerSpinBox1 = new QSpinBox;
integerSpinBox2 = new QSpinBox;
okButton = new QPushButton;
spinBoxLayout = new QVBoxLayout;
popupWidget = new QWidget;
integerSpinBox1->setRange(3, faceSize);
integerSpinBox1->setSingleStep(5);
integerSpinBox1->setValue(faceSize-1);
integerSpinBox2->setRange(1, faceSize);
integerSpinBox2->setSingleStep(1);
integerSpinBox2->setValue(10);
//integerSpinBox1->setWindowTitle("Number of Triangles");
okButton->setText("Decimate");
connect(okButton, SIGNAL(clicked()),this, SLOT(buttonn()));
//okButton->addAction(okButtonAction);
spinBoxLayout->addWidget(integerLabel2);
spinBoxLayout->addWidget(integerSpinBox2);
spinBoxLayout->addWidget(integerLabel1);
spinBoxLayout->addWidget(integerSpinBox1);
spinBoxLayout->addWidget(okButton);
popupWidget->setWindowFlags(Qt::Popup);
popupWidget->setWindowFlags(Qt::Dialog);
popupWidget->setWindowFlags(Qt::Window);
popupWidget->setWindowTitle("Inputs for Simplification Algorithm");
popupWidget->setLayout(spinBoxLayout);
popupWidget->move(300,300);
}
void viewerUI::buttonn()
{
std::cout<<"Number of triangles selected "<<integerSpinBox1->value()<<std::endl;
int no=integerSpinBox1->value();
std::cout<<"Value of K "<<integerSpinBox2->value()<<std::endl;
int k=integerSpinBox2->value();
popupWidget->close();
viewer->simplifyMesh(k,no);
}
void viewerUI::segmentButton()
{
/* std::cout<<"segment button is pressed "<<std::endl;
int k=integerSpinBox2->value();
for(int i=0;i<k;i++)
{
viewerUI *viewerUI2=new viewerUI;
viewerUI2->show();
viewerUI2->viewer->copyObject(this->viewer);
// viewerUI2->viewer->draw();
}
*/
float thresh1=integerSpinBox3->value();
float thresh2=integerSpinBox4->value();
float k=integerSpinBox5->value();
popupWidget->close();
if(thresh1!=-1.0)
{
viewer->addRemoveEdges(thresh1,thresh2);
}
viewer->fixingArtifacts(k);
}
void viewerUI::segmentation()
{
// viewer->addRemoveEdges();
//Building the dual graph(Adjancey list)
//viewer->makeDualGraph();
createPopup2();
popupWidget->show();
}