add vcglib
This commit is contained in:
1 parent
6f6c0c8eb7
commit
af8100f851
1537 files changed
+634197
No files matched your search
@@ -0,0 +1,232 @@
|
||||
/****************************************************************************
|
||||
* VCGLib o o *
|
||||
* Visual and Computer Graphics Library o o *
|
||||
* _ O _ *
|
||||
* Copyright(C) 2007 \/)\/ *
|
||||
* Visual Computing Lab /\/| *
|
||||
* ISTI - Italian National Research Council | *
|
||||
* \ *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* 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 (http://www.gnu.org/licenses/gpl.txt) *
|
||||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.1 2007/10/18 08:52:06 benedetti
|
||||
Initial release.
|
||||
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "glarea.h"
|
||||
#include <QKeyEvent>
|
||||
#include <QKeyEvent>
|
||||
#include <QWheelEvent>
|
||||
#include <wrap/qt/trackball.h>
|
||||
#include <cassert>
|
||||
#include <wrap/gl/trimesh.h>
|
||||
#include "mainwindow.h"
|
||||
|
||||
GLArea::GLArea (SharedDataOpenGLContext* sharedcontext,MainWindow* parent)
|
||||
:QGLWidget(NULL,sharedcontext),parwin(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
GLArea::~GLArea()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GLArea::initializeGL()
|
||||
{
|
||||
makeCurrent();
|
||||
glewExperimental=GL_TRUE;
|
||||
glewInit();
|
||||
glClearColor(0, 0, 0, 0);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_NORMALIZE);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
GLenum err = glGetError();
|
||||
assert(err == GL_NO_ERROR);
|
||||
doneCurrent();
|
||||
}
|
||||
|
||||
void GLArea::resizeGL (int w, int h)
|
||||
{
|
||||
makeCurrent();
|
||||
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
|
||||
doneCurrent();
|
||||
//initializeGL();
|
||||
}
|
||||
|
||||
void GLArea::paintGL ()
|
||||
{
|
||||
if (parwin == NULL)
|
||||
return;
|
||||
SharedDataOpenGLContext::MultiViewManager* man = parwin->getMultiviewerManager();
|
||||
if (man == NULL)
|
||||
return;
|
||||
CMeshO& mesh = parwin->currentMesh();
|
||||
//glt.m = &mesh;
|
||||
makeCurrent();
|
||||
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
gluPerspective(25, GLArea::width()/(float)GLArea::height(), 0.1, 100);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
gluLookAt(0,0,5, 0,0,0, 0,1,0);
|
||||
track.center=vcg::Point3f(0, 0, 0);
|
||||
track.radius= 1;
|
||||
track.GetView();
|
||||
track.Apply();
|
||||
glPushMatrix();
|
||||
if (mesh.VN() > 0)
|
||||
{
|
||||
float d=2.0f/mesh.bbox.Diag();
|
||||
vcg::glScale(d);
|
||||
glTranslate(-mesh.bbox.Center());
|
||||
man->draw(context());
|
||||
}
|
||||
glPopMatrix();
|
||||
|
||||
track.DrawPostApply();
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glPopAttrib();
|
||||
|
||||
GLenum err = glGetError();
|
||||
assert(err == GL_NO_ERROR);
|
||||
}
|
||||
|
||||
void GLArea::keyReleaseEvent (QKeyEvent * e)
|
||||
{
|
||||
e->ignore ();
|
||||
if (e->key () == Qt::Key_Control)
|
||||
track.ButtonUp (QT2VCG (Qt::NoButton, Qt::ControlModifier));
|
||||
if (e->key () == Qt::Key_Shift)
|
||||
track.ButtonUp (QT2VCG (Qt::NoButton, Qt::ShiftModifier));
|
||||
if (e->key () == Qt::Key_Alt)
|
||||
track.ButtonUp (QT2VCG (Qt::NoButton, Qt::AltModifier));
|
||||
makeCurrent();
|
||||
updateGL ();
|
||||
doneCurrent();
|
||||
}
|
||||
|
||||
void GLArea::keyPressEvent (QKeyEvent * e)
|
||||
{
|
||||
e->ignore ();
|
||||
if (e->key () == Qt::Key_Control)
|
||||
track.ButtonDown (QT2VCG (Qt::NoButton, Qt::ControlModifier));
|
||||
if (e->key () == Qt::Key_Shift)
|
||||
track.ButtonDown (QT2VCG (Qt::NoButton, Qt::ShiftModifier));
|
||||
if (e->key () == Qt::Key_Alt)
|
||||
track.ButtonDown (QT2VCG (Qt::NoButton, Qt::AltModifier));
|
||||
makeCurrent();
|
||||
updateGL ();
|
||||
doneCurrent();
|
||||
}
|
||||
|
||||
void GLArea::mousePressEvent (QMouseEvent * e)
|
||||
{
|
||||
e->accept ();
|
||||
setFocus ();
|
||||
track.MouseDown (QT2VCG_X(this,e), QT2VCG_Y(this,e), QT2VCG (e->button (), e->modifiers ()));
|
||||
makeCurrent();
|
||||
updateGL ();
|
||||
doneCurrent();
|
||||
}
|
||||
|
||||
void GLArea::mouseMoveEvent (QMouseEvent * e)
|
||||
{
|
||||
if (e->buttons ()) {
|
||||
track.MouseMove (QT2VCG_X(this,e), QT2VCG_Y(this,e));
|
||||
makeCurrent();
|
||||
updateGL ();
|
||||
doneCurrent();
|
||||
}
|
||||
}
|
||||
|
||||
void GLArea::mouseReleaseEvent (QMouseEvent * e)
|
||||
{
|
||||
track.MouseUp (QT2VCG_X(this,e), QT2VCG_Y(this,e), QT2VCG (e->button (), e->modifiers ()));
|
||||
makeCurrent();
|
||||
updateGL ();
|
||||
doneCurrent();
|
||||
}
|
||||
|
||||
void GLArea::wheelEvent (QWheelEvent * e)
|
||||
{
|
||||
const int WHEEL_STEP = 120;
|
||||
track.MouseWheel (e->delta () / float (WHEEL_STEP), QTWheel2VCG (e->modifiers ()));
|
||||
makeCurrent();
|
||||
updateGL ();
|
||||
doneCurrent();
|
||||
}
|
||||
|
||||
void GLArea::resetTrackBall()
|
||||
{
|
||||
track.Reset();
|
||||
makeCurrent();
|
||||
updateGL();
|
||||
doneCurrent();
|
||||
}
|
||||
|
||||
|
||||
|
||||
SharedDataOpenGLContext::SharedDataOpenGLContext(CMeshO& mesh,vcg::QtThreadSafeMemoryInfo& mi,QWidget* parent)
|
||||
:QGLWidget(parent),manager(mesh,mi,100000)
|
||||
{
|
||||
}
|
||||
|
||||
SharedDataOpenGLContext::~SharedDataOpenGLContext()
|
||||
{
|
||||
}
|
||||
|
||||
void SharedDataOpenGLContext::myInitGL()
|
||||
{
|
||||
makeCurrent();
|
||||
glewInit();
|
||||
doneCurrent();
|
||||
}
|
||||
|
||||
void SharedDataOpenGLContext::deAllocateBO()
|
||||
{
|
||||
makeCurrent();
|
||||
manager.removeAllViewsAndDeallocateBO();
|
||||
doneCurrent();
|
||||
}
|
||||
|
||||
void SharedDataOpenGLContext::setPerViewRendAtts( QGLContext* viewid,vcg::GLMeshAttributesInfo::PRIMITIVE_MODALITY_MASK mm,vcg::GLMeshAttributesInfo::RendAtts& atts )
|
||||
{
|
||||
manager.setPerViewInfo(viewid,mm,atts);
|
||||
}
|
||||
|
||||
void SharedDataOpenGLContext::manageBuffers()
|
||||
{
|
||||
makeCurrent();
|
||||
manager.manageBuffers();
|
||||
doneCurrent();
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/****************************************************************************
|
||||
* VCGLib o o *
|
||||
* Visual and Computer Graphics Library o o *
|
||||
* _ O _ *
|
||||
* Copyright(C) 2007 \/)\/ *
|
||||
* Visual Computing Lab /\/| *
|
||||
* ISTI - Italian National Research Council | *
|
||||
* \ *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* 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 (http://www.gnu.org/licenses/gpl.txt) *
|
||||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.1 2007/10/18 08:52:06 benedetti
|
||||
Initial release.
|
||||
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef GLAREA_H_
|
||||
#define GLAREA_H_
|
||||
|
||||
/// Opengl related imports
|
||||
#include <GL/glew.h>
|
||||
#include <QGLWidget>
|
||||
|
||||
/// wrapper imports
|
||||
#include <wrap/gui/trackball.h>
|
||||
#include <wrap/qt/qt_thread_safe_memory_info.h>
|
||||
#include <wrap/qt/qt_thread_safe_mesh_attributes_multi_viewer_bo_manager.h>
|
||||
#include <wrap/gl/trimesh.h>
|
||||
#include "mesh.h"
|
||||
|
||||
class MainWindow;
|
||||
|
||||
class SharedDataOpenGLContext : public QGLWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
typedef vcg::QtThreadSafeGLMeshAttributesMultiViewerBOManager<CMeshO,QGLContext*> MultiViewManager;
|
||||
|
||||
SharedDataOpenGLContext(CMeshO& mesh,vcg::QtThreadSafeMemoryInfo& mi,QWidget* parent = 0);
|
||||
~SharedDataOpenGLContext();
|
||||
|
||||
void myInitGL();
|
||||
void deAllocateBO();
|
||||
void setPerViewRendAtts(QGLContext* view,vcg::GLMeshAttributesInfo::PRIMITIVE_MODALITY_MASK mm,vcg::GLMeshAttributesInfo::RendAtts& atts);
|
||||
void manageBuffers();
|
||||
MultiViewManager manager;
|
||||
};
|
||||
|
||||
|
||||
class GLArea:public QGLWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
GLArea (SharedDataOpenGLContext* sharedcontext,MainWindow* parent);
|
||||
~GLArea();
|
||||
void resetTrackBall();
|
||||
//unsigned int getId() const {return areaid;}
|
||||
/// we chose a subset of the available drawing modes
|
||||
|
||||
signals:
|
||||
/// signal for setting the statusbar message
|
||||
void setStatusBar(QString message);
|
||||
void updateRenderModalityRequested(int);
|
||||
protected:
|
||||
/// opengl initialization and drawing calls
|
||||
void initializeGL ();
|
||||
void resizeGL (int w, int h);
|
||||
void paintGL ();
|
||||
/// keyboard and mouse event callbacks
|
||||
void keyReleaseEvent(QKeyEvent * e);
|
||||
void keyPressEvent(QKeyEvent * e);
|
||||
void mousePressEvent(QMouseEvent*e);
|
||||
void mouseMoveEvent(QMouseEvent*e);
|
||||
void mouseReleaseEvent(QMouseEvent*e);
|
||||
void wheelEvent(QWheelEvent*e);
|
||||
|
||||
private:
|
||||
MainWindow* parwin;
|
||||
/// the active manipulator
|
||||
vcg::Trackball track;
|
||||
/// mesh data structure initializer
|
||||
void initMesh(QString message);
|
||||
//unsigned int areaid;
|
||||
//vcg::GlTrimesh<CMeshO> glt;
|
||||
};
|
||||
|
||||
#endif /*GLAREA_H_ */
|
||||
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
* VCGLib o o *
|
||||
* Visual and Computer Graphics Library o o *
|
||||
* _ O _ *
|
||||
* Copyright(C) 2007 \/)\/ *
|
||||
* Visual Computing Lab /\/| *
|
||||
* ISTI - Italian National Research Council | *
|
||||
* \ *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* 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 (http://www.gnu.org/licenses/gpl.txt) *
|
||||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* Minimal QT trimesh viewer
|
||||
*
|
||||
* This sample shows how to use togheter:
|
||||
* - the Opengl module in QT using the designer
|
||||
* - the trimesh loading and initialization
|
||||
* - basic usage of the default manipulators (the "Trackball")
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
#include "mainwindow.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
MainWindow mw;
|
||||
mw.show();
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
/****************************************************************************
|
||||
* VCGLib o o *
|
||||
* Visual and Computer Graphics Library o o *
|
||||
* _ O _ *
|
||||
* Copyright(C) 2007 \/)\/ *
|
||||
* Visual Computing Lab /\/| *
|
||||
* ISTI - Italian National Research Council | *
|
||||
* \ *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* 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 (http://www.gnu.org/licenses/gpl.txt) *
|
||||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "glarea.h"
|
||||
#include <QGridLayout>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
#include <QTime>
|
||||
|
||||
QProgressBar *MainWindow::qb;
|
||||
QStatusBar* MainWindow::sb;
|
||||
|
||||
MainWindow::MainWindow (QWidget * parent)
|
||||
:QMainWindow (parent),mi(2000000000),mesh()
|
||||
{
|
||||
ui.setupUi (this);
|
||||
initTable();
|
||||
QGridLayout* grid = new QGridLayout();
|
||||
//parent is set to NULL in order to avoid QT bug on MAC (business as usual...).
|
||||
//The QGLWidget are destroyed by hand in the MainWindow destructor...
|
||||
shared = new SharedDataOpenGLContext(mesh,mi,NULL);
|
||||
shared->setHidden(true);
|
||||
shared->myInitGL();
|
||||
|
||||
for(unsigned int ii = 0;ii < 2;++ii)
|
||||
{
|
||||
rendbox[ii] = new QComboBox(this);
|
||||
for(QMap<MyDrawMode,QString>::iterator it = stringrendtable.begin();it != stringrendtable.end();++it)
|
||||
rendbox[ii]->addItem(it.value());
|
||||
rendbox[ii]->setCurrentIndex((int) MDM_SMOOTH);
|
||||
glar[ii] = new GLArea(shared,this);
|
||||
connect(rendbox[ii],SIGNAL(activated(int)),glar[ii],SIGNAL(updateRenderModalityRequested(int)));
|
||||
connect(glar[ii],SIGNAL(updateRenderModalityRequested(int)),this,SLOT(updateRenderModality(int)));
|
||||
//connect(shared,SIGNAL(dataReadyToBeRead(MyDrawMode,vcg::GLFeederInfo::ReqAtts&)),glar[ii], SLOT(updateRequested(MyDrawMode,vcg::GLFeederInfo::ReqAtts&)));
|
||||
grid->addWidget(rendbox[ii],0,ii,1,1,Qt::AlignRight);
|
||||
grid->addWidget(glar[ii],1,ii,1,1);
|
||||
}
|
||||
ui.glbox->setLayout(grid);
|
||||
|
||||
connect(ui.actionLoad_Mesh,SIGNAL(triggered()),this,SLOT(chooseMesh()));
|
||||
connect (ui.actionLoad_Tetrahedron, SIGNAL (triggered()),this, SLOT (loadTetrahedron()));
|
||||
connect (ui.actionLoad_Dodecahedron, SIGNAL (triggered()),this, SLOT (loadDodecahedron()));
|
||||
|
||||
sb = statusBar();
|
||||
qb=new QProgressBar(this);
|
||||
qb->setMaximum(100);
|
||||
qb->setMinimum(0);
|
||||
qb->reset();
|
||||
statusBar()->addPermanentWidget(qb,0);
|
||||
}
|
||||
|
||||
// mesh chooser file dialog
|
||||
void MainWindow::chooseMesh()
|
||||
{
|
||||
mesh.Clear();
|
||||
QString plyext("ply");
|
||||
QString objext("obj");
|
||||
QString extoptions = QString("Poly Model (*.") + plyext + ");;OBJ Model (*." + objext + ")";
|
||||
QString fileName = QFileDialog::getOpenFileName(this,
|
||||
tr("Open Mesh"), QDir::currentPath(),
|
||||
extoptions);
|
||||
QFileInfo fi(fileName);
|
||||
QTime loadingtime;
|
||||
loadingtime.start();
|
||||
int err=0;
|
||||
|
||||
if (fi.suffix() == plyext)
|
||||
err=vcg::tri::io::ImporterPLY<CMeshO>::Open(mesh,(fileName.toStdString()).c_str(),qCallBack);
|
||||
else
|
||||
if (fi.suffix() == objext)
|
||||
{
|
||||
int loadmask;
|
||||
err=vcg::tri::io::ImporterOBJ<CMeshO>::Open(mesh,(fileName.toStdString()).c_str(),loadmask,qCallBack);
|
||||
}
|
||||
int msec = loadingtime.elapsed();
|
||||
if(err!=0)
|
||||
{
|
||||
const char* errmsg=vcg::tri::io::ImporterPLY<CMeshO>::ErrorMsg(err);
|
||||
QMessageBox::warning(this,tr("Error Loading Mesh"),QString(errmsg));
|
||||
}
|
||||
QString msg = fileName + " vtx: " + QString::number(mesh.VN()) + " fcs: " + QString::number(mesh.FN()) + " loading time: " + QString::number(msec) + " msec";
|
||||
initMesh(msg);
|
||||
}
|
||||
|
||||
void MainWindow::loadTetrahedron()
|
||||
{
|
||||
mesh.Clear();
|
||||
vcg::tri::Tetrahedron(mesh);
|
||||
initMesh(tr("Tethraedron [builtin]"));
|
||||
}
|
||||
|
||||
void MainWindow::loadDodecahedron()
|
||||
{
|
||||
mesh.Clear();
|
||||
vcg::tri::Dodecahedron(mesh);
|
||||
initMesh(tr("Dodecahedron [builtin]"));
|
||||
}
|
||||
|
||||
void MainWindow::initMesh(QString& message)
|
||||
{
|
||||
if (shared != NULL)
|
||||
shared->deAllocateBO();
|
||||
// update bounding box
|
||||
vcg::tri::UpdateBounding<CMeshO>::Box(mesh);
|
||||
// update Normals
|
||||
vcg::tri::UpdateNormal<CMeshO>::PerVertexNormalizedPerFaceNormalized(mesh);
|
||||
QTime rdsetuptime;
|
||||
rdsetuptime.start();
|
||||
for(unsigned int ii = 0;ii < 2;++ii)
|
||||
if ((glar[ii] != NULL) && (rendbox[ii] != NULL))
|
||||
{
|
||||
glar[ii]->resetTrackBall();
|
||||
MyDrawMode mdm = (MyDrawMode) rendbox[ii]->currentIndex();
|
||||
QMap<MyDrawMode,QPair<vcg::GLMeshAttributesInfo::PRIMITIVE_MODALITY_MASK, vcg::GLMeshAttributesInfo::RendAtts> >::iterator it = rendtable.find(mdm);
|
||||
if (it == rendtable.end())
|
||||
return;
|
||||
shared->setPerViewRendAtts(glar[ii]->context(),it.value().first,it.value().second);
|
||||
}
|
||||
shared->manageBuffers();
|
||||
for(unsigned int ii = 0;ii < 2;++ii)
|
||||
glar[ii]->updateGL();
|
||||
qb->reset();
|
||||
int msec = rdsetuptime.elapsed();
|
||||
message += " bo creation: " + QString::number(msec) + " msec";
|
||||
statusBar()->showMessage(message);
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::updateRenderModality(int clickedindex)
|
||||
{
|
||||
GLArea* glasender = qobject_cast<GLArea*>(sender());
|
||||
if (glasender == NULL)
|
||||
return;
|
||||
updateRenderModality(glasender,clickedindex);
|
||||
}
|
||||
|
||||
void MainWindow::updateRenderModality( GLArea* area,int clickedindex )
|
||||
{
|
||||
if ((shared == NULL) || (area == NULL))
|
||||
return;
|
||||
MyDrawMode mdm = (MyDrawMode) clickedindex;
|
||||
QMap<MyDrawMode,QPair<vcg::GLMeshAttributesInfo::PRIMITIVE_MODALITY_MASK, vcg::GLMeshAttributesInfo::RendAtts> >::iterator it = rendtable.find(mdm);
|
||||
if (it == rendtable.end())
|
||||
return;
|
||||
shared->setPerViewRendAtts(area->context(),it.value().first,it.value().second);
|
||||
shared->manageBuffers();
|
||||
for(unsigned int ii = 0;ii < 2;++ii)
|
||||
glar[ii]->updateGL();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
for(int ii = 0;ii < 2;++ii)
|
||||
delete glar[ii];
|
||||
delete shared;
|
||||
}
|
||||
|
||||
void MainWindow::initTable()
|
||||
{
|
||||
stringrendtable[MDM_SMOOTH] = QString("Solid Smooth");
|
||||
stringrendtable[MDM_FLAT] = QString("Solid Flat");
|
||||
stringrendtable[MDM_WIRE] = QString("Wire");
|
||||
stringrendtable[MDM_POINTS] = QString("Points");
|
||||
stringrendtable[MDM_QUAD_WIRE] = QString("Wire Quad");
|
||||
stringrendtable[MDM_QUAD_SMOOTH_WIRE] = QString("Wire Solid Smooth Quad");
|
||||
|
||||
vcg::GLMeshAttributesInfo::PRIMITIVE_MODALITY_MASK mmask = vcg::GLMeshAttributesInfo::PR_SOLID;
|
||||
vcg::GLMeshAttributesInfo::RendAtts ratts;
|
||||
ratts[vcg::GLMeshAttributesInfo::ATT_NAMES::ATT_VERTPOSITION] = true;
|
||||
ratts[vcg::GLMeshAttributesInfo::ATT_NAMES::ATT_VERTNORMAL] = true;
|
||||
rendtable[MDM_SMOOTH] = qMakePair(mmask,ratts);
|
||||
ratts.reset(true);
|
||||
ratts[vcg::GLMeshAttributesInfo::ATT_NAMES::ATT_FACENORMAL] = true;
|
||||
rendtable[MDM_FLAT] = qMakePair(mmask,ratts);
|
||||
ratts.reset(true);
|
||||
mmask = vcg::GLMeshAttributesInfo::PR_WIREFRAME_TRIANGLES;
|
||||
rendtable[MDM_WIRE] = qMakePair(mmask,ratts);
|
||||
ratts.reset(true);
|
||||
mmask = vcg::GLMeshAttributesInfo::PR_POINTS;
|
||||
ratts[vcg::GLMeshAttributesInfo::ATT_NAMES::ATT_VERTNORMAL] = true;
|
||||
rendtable[MDM_POINTS] = qMakePair(mmask,ratts);
|
||||
ratts.reset(true);
|
||||
mmask = vcg::GLMeshAttributesInfo::PR_WIREFRAME_EDGES;
|
||||
rendtable[MDM_QUAD_WIRE] = qMakePair(mmask,ratts);
|
||||
ratts.reset(true);
|
||||
mmask = vcg::GLMeshAttributesInfo::PR_WIREFRAME_EDGES | vcg::GLMeshAttributesInfo::PR_SOLID;
|
||||
ratts[vcg::GLMeshAttributesInfo::ATT_NAMES::ATT_VERTNORMAL] = true;
|
||||
rendtable[MDM_QUAD_SMOOTH_WIRE] = qMakePair(mmask,ratts);
|
||||
}
|
||||
|
||||
bool MainWindow::qCallBack(const int pos, const char * str)
|
||||
{
|
||||
int static lastPos=-1;
|
||||
if(pos==lastPos) return true;
|
||||
lastPos=pos;
|
||||
|
||||
static QTime currTime = QTime::currentTime();
|
||||
if(currTime.elapsed()< 100) return true;
|
||||
currTime.start();
|
||||
sb->showMessage(str,5000);
|
||||
qb->show();
|
||||
qb->setEnabled(true);
|
||||
qb->setValue(pos);
|
||||
sb->update();
|
||||
qApp->processEvents();
|
||||
return true;
|
||||
}
|
||||
|
||||
SharedDataOpenGLContext::MultiViewManager* MainWindow::getMultiviewerManager()
|
||||
{
|
||||
if (shared == NULL)
|
||||
return NULL;
|
||||
return &(shared->manager);
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/****************************************************************************
|
||||
* VCGLib o o *
|
||||
* Visual and Computer Graphics Library o o *
|
||||
* _ O _ *
|
||||
* Copyright(C) 2007 \/)\/ *
|
||||
* Visual Computing Lab /\/| *
|
||||
* ISTI - Italian National Research Council | *
|
||||
* \ *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* 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 (http://www.gnu.org/licenses/gpl.txt) *
|
||||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
|
||||
****************************************************************************/
|
||||
#ifndef MAINWINDOW_H_
|
||||
#define MAINWINDOW_H_
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <QGLContext>
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include "mesh.h"
|
||||
#include <wrap/gl/gl_mesh_attributes_info.h>
|
||||
#include <wrap/qt/qt_thread_safe_mesh_attributes_multi_viewer_bo_manager.h>
|
||||
#include <wrap/qt/qt_thread_safe_memory_info.h>
|
||||
#include <QProgressBar>
|
||||
#include <QStatusBar>
|
||||
#include <QComboBox>
|
||||
#include "glarea.h"
|
||||
enum MyDrawMode{MDM_SMOOTH=0,MDM_POINTS,MDM_WIRE,MDM_FLAT,MDM_QUAD_WIRE,MDM_QUAD_SMOOTH_WIRE};
|
||||
|
||||
|
||||
|
||||
class MainWindow:public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MainWindow(QWidget * parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
CMeshO& currentMesh() {return mesh;}
|
||||
SharedDataOpenGLContext::MultiViewManager* getMultiviewerManager();
|
||||
void updateRenderModality(GLArea* area,int clickedindex);
|
||||
static bool qCallBack(const int pos, const char * str);
|
||||
public slots:
|
||||
void chooseMesh();
|
||||
void loadTetrahedron();
|
||||
void loadDodecahedron();
|
||||
void initMesh(QString& message);
|
||||
void updateRenderModality(int clickedindex);
|
||||
signals:
|
||||
void loadMesh(QString newMesh);
|
||||
void updateRenderModalityRequested(int);
|
||||
private:
|
||||
void initTable();
|
||||
Ui::mainWindow ui;
|
||||
GLArea* glar[2];
|
||||
SharedDataOpenGLContext* shared;
|
||||
vcg::QtThreadSafeMemoryInfo mi;
|
||||
QComboBox* rendbox[2];
|
||||
/// the active mesh instance
|
||||
CMeshO mesh;
|
||||
QMap<MyDrawMode,QString> stringrendtable;
|
||||
QMap<MyDrawMode,QPair<vcg::GLMeshAttributesInfo::PRIMITIVE_MODALITY_MASK,vcg::GLMeshAttributesInfo::RendAtts> > rendtable;
|
||||
static QProgressBar* qb;
|
||||
static QStatusBar* sb;
|
||||
};
|
||||
|
||||
#endif /*MAINWINDOW_H_ */
|
||||
@@ -0,0 +1,82 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>mainWindow</class>
|
||||
<widget class="QMainWindow" name="mainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>715</width>
|
||||
<height>579</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Trimesh QT</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QVBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QWidget" name="glbox" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>715</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
<property name="title">
|
||||
<string>File</string>
|
||||
</property>
|
||||
<addaction name="actionLoad_Mesh"/>
|
||||
<addaction name="actionLoad_Tetrahedron"/>
|
||||
<addaction name="actionLoad_Dodecahedron"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionClose"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
</widget>
|
||||
<action name="actionLoad_Mesh">
|
||||
<property name="text">
|
||||
<string>Load Mesh</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLoad_Tetrahedron">
|
||||
<property name="text">
|
||||
<string>Load Tetrahedron</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLoad_Dodecahedron">
|
||||
<property name="text">
|
||||
<string>Load Dodecahedron</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionClose">
|
||||
<property name="text">
|
||||
<string>Close</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef MESH_H
|
||||
#define MESH_H
|
||||
|
||||
/// vcg imports
|
||||
#include <vcg/complex/complex.h>
|
||||
#include <vcg/complex/algorithms/update/bounding.h>
|
||||
#include <vcg/complex/algorithms/update/normal.h>
|
||||
#include <vcg/complex/algorithms/create/platonic.h>
|
||||
|
||||
#include <wrap/io_trimesh/import.h>
|
||||
|
||||
using namespace vcg;
|
||||
class CFaceO;
|
||||
class CVertexO;
|
||||
class CEdgeO;
|
||||
|
||||
struct MyUsedTypes : public UsedTypes<Use<CVertexO> ::AsVertexType, vcg::Use<CEdgeO >::AsEdgeType,
|
||||
Use<CFaceO> ::AsFaceType>{};
|
||||
|
||||
/// compositing wanted proprieties
|
||||
class CVertexO : public vcg::Vertex< MyUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::BitFlags>{};
|
||||
class CFaceO : public vcg::Face< MyUsedTypes, vcg::face::VertexRef, vcg::face::Normal3f, vcg::face::BitFlags > {};
|
||||
class CEdgeO : public vcg::Edge<MyUsedTypes,vcg::edge::BitFlags,vcg::edge::EVAdj,vcg::edge::EEAdj>{};
|
||||
class CMeshO : public vcg::tri::TriMesh< std::vector<CVertexO>, std::vector<CFaceO>,std::vector<CEdgeO> >
|
||||
{
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,51 @@
|
||||
# Base options
|
||||
TEMPLATE = app
|
||||
LANGUAGE = C++
|
||||
|
||||
# QT modules
|
||||
QT += opengl
|
||||
|
||||
# Executable name
|
||||
TARGET = trimesh_qt
|
||||
|
||||
# Directories
|
||||
DESTDIR = .
|
||||
UI_DIR = build/ui
|
||||
MOC_DIR = build/moc
|
||||
OBJECTS_DIR = build/obj
|
||||
|
||||
# Lib headers
|
||||
INCLUDEPATH += .
|
||||
INCLUDEPATH += ../../..
|
||||
|
||||
# Lib sources
|
||||
SOURCES += ../../../wrap/ply/plylib.cpp
|
||||
SOURCES += ../../../wrap/gui/trackball.cpp
|
||||
SOURCES += ../../../wrap/gui/trackmode.cpp
|
||||
|
||||
|
||||
# Compile glew
|
||||
DEFINES += GLEW_STATIC
|
||||
INCLUDEPATH += ../../../../lib/glew/include
|
||||
SOURCES += ../../../../lib/glew/src/glew.c
|
||||
|
||||
# Awful problem with windows..
|
||||
win32{
|
||||
DEFINES += NOMINMAX
|
||||
}
|
||||
|
||||
# Input
|
||||
HEADERS += mainwindow.h
|
||||
HEADERS += glarea.h
|
||||
|
||||
|
||||
|
||||
SOURCES += main.cpp
|
||||
SOURCES += mainwindow.cpp
|
||||
SOURCES += glarea.cpp
|
||||
|
||||
FORMS += mainwindow.ui
|
||||
|
||||
linux-g++:LIBS += -lGLU
|
||||
linux-g++-32:LIBS += -lGLU
|
||||
linux-g++-64:LIBS += -lGLU
|
||||
Reference in new issue
Block a user