mainwindow.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 * VCGLib                                                            o o     *
00003 * Visual and Computer Graphics Library                            o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2007                                                \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *   
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
00021 *                                                                           *
00022 ****************************************************************************/
00023 /****************************************************************************
00024 History
00025 
00026 $Log: not supported by cvs2svn $
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     //parent is set to NULL in order to avoid QT bug on MAC (business as usual...).
00043     //The QGLWidget are destroyed by hand in the MainWindow destructor...
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         //from toolFrame to glArea through mainwindow
00060 
00061 }
00062 
00063 // mesh chooser file dialog
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         // update bounding box
00098         vcg::tri::UpdateBounding<CMeshO>::Box(mesh);
00099         // update Normals
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 }


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:32:53