Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "mainwindow.h"
00032 #include <QFileDialog>
00033 #include <QMessageBox>
00034 #include <QDebug>
00035
00036 MainWindow::MainWindow (QWidget * parent)
00037 :QMainWindow (parent),mi(1000000000),mesh()
00038 {
00039 ui.setupUi (this);
00040 QLayout* tmp = ui.glFrame->layout();
00041
00042
00043
00044 shared = new SharedDataOpenGLContext(mesh,mi,NULL);
00045 shared->setHidden(true);
00046 shared->myInitGL();
00047 connect (ui.drawModeComboBox, SIGNAL (currentIndexChanged(int)),shared, SLOT (passInfoToOpenGL(int)));
00048
00049 for(int ii = 0;ii < 2;++ii)
00050 {
00051 glar[ii] = new GLArea(mesh,shared->feeder,NULL,shared);
00052 connect (shared,SIGNAL(dataReadyToBeRead(MyDrawMode,vcg::GLFeederInfo::ReqAtts&)),glar[ii], SLOT (updateRequested(MyDrawMode,vcg::GLFeederInfo::ReqAtts&)));
00053 tmp->addWidget(glar[ii]);
00054 }
00055
00056 connect (ui.loadMeshPushButton, SIGNAL (clicked()),this, SLOT (chooseMesh()));
00057 connect (ui.loadTetrahedronPushButton, SIGNAL (clicked()),this, SLOT (loadTetrahedron()));
00058 connect (ui.loadDodecahedronPushButton, SIGNAL (clicked()),this, SLOT (loadDodecahedron()));
00059
00060
00061 }
00062
00063
00064 void MainWindow::chooseMesh()
00065 {
00066 mesh.Clear();
00067 QString fileName = QFileDialog::getOpenFileName(this,
00068 tr("Open Mesh"), QDir::currentPath(),
00069 tr("Poly Model (*.ply)"));
00070 int err=vcg::tri::io::ImporterPLY<CMeshO>::Open(mesh,(fileName.toStdString()).c_str());
00071 if(err!=0)
00072 {
00073 const char* errmsg=vcg::tri::io::ImporterPLY<CMeshO>::ErrorMsg(err);
00074 QMessageBox::warning(this,tr("Error Loading Mesh"),QString(errmsg));
00075 }
00076 initMesh(fileName);
00077 }
00078
00079 void MainWindow::loadTetrahedron()
00080 {
00081 mesh.Clear();
00082 vcg::tri::Tetrahedron(mesh);
00083 initMesh(tr("Tethraedron [builtin]"));
00084 }
00085
00086 void MainWindow::loadDodecahedron()
00087 {
00088 mesh.Clear();
00089 vcg::tri::Dodecahedron(mesh);
00090 initMesh(tr("Dodecahedron [builtin]"));
00091 }
00092
00093 void MainWindow::initMesh(QString message)
00094 {
00095 if (shared != NULL)
00096 shared->deAllocateBO();
00097
00098 vcg::tri::UpdateBounding<CMeshO>::Box(mesh);
00099
00100 vcg::tri::UpdateNormal<CMeshO>::PerVertexNormalizedPerFaceNormalized(mesh);
00101 shared->passInfoToOpenGL(ui.drawModeComboBox->currentIndex());
00102 for(size_t ii = 0;ii < 2;++ii)
00103 if (glar[ii] != NULL)
00104 glar[ii]->resetTrackBall();
00105 ui.statusbar->showMessage(message);
00106 }
00107
00108 MainWindow::~MainWindow()
00109 {
00110 for(int ii = 0;ii < 2;++ii)
00111 delete glar[ii];
00112 delete shared;
00113 }