From e671856039b9f545235bb0f4c5772e452b0997d4 Mon Sep 17 00:00:00 2001 From: granzuglia Date: Fri, 6 May 2016 02:23:45 +0000 Subject: [PATCH] updated the rendering example using the new rendering system --- apps/sample/trimesh_QT_shared/glarea.cpp | 151 ++++++------- apps/sample/trimesh_QT_shared/glarea.h | 42 ++-- apps/sample/trimesh_QT_shared/mainwindow.cpp | 178 +++++++++++++--- apps/sample/trimesh_QT_shared/mainwindow.h | 34 ++- apps/sample/trimesh_QT_shared/mainwindow.ui | 183 +++------------- apps/sample/trimesh_QT_shared/mesh.h | 8 +- .../trimesh_QT_shared/ml_scene_renderer.cpp | 201 ------------------ .../trimesh_QT_shared/ml_scene_renderer.h | 97 --------- .../ml_thread_safe_memory_info.cpp | 65 ------ .../ml_thread_safe_memory_info.h | 55 ----- apps/sample/trimesh_QT_shared/trimesh_qt.pro | 5 - 11 files changed, 297 insertions(+), 722 deletions(-) delete mode 100644 apps/sample/trimesh_QT_shared/ml_scene_renderer.cpp delete mode 100644 apps/sample/trimesh_QT_shared/ml_scene_renderer.h delete mode 100644 apps/sample/trimesh_QT_shared/ml_thread_safe_memory_info.cpp delete mode 100644 apps/sample/trimesh_QT_shared/ml_thread_safe_memory_info.h diff --git a/apps/sample/trimesh_QT_shared/glarea.cpp b/apps/sample/trimesh_QT_shared/glarea.cpp index 381f4bb2..2121bd7c 100644 --- a/apps/sample/trimesh_QT_shared/glarea.cpp +++ b/apps/sample/trimesh_QT_shared/glarea.cpp @@ -37,20 +37,18 @@ Initial release. #include #include #include +#include +#include "mainwindow.h" -#ifdef Q_OS_MAC -#define glGenVertexArrays glGenVertexArraysAPPLE -#define glBindVertexArray glBindVertexArrayAPPLE -#define glDeleteVertexArrays glDeleteVertexArraysAPPLE -#endif - -GLArea::GLArea (CMeshO& m, MLThreadSafeGLMeshAttributesFeeder& feed,QWidget* parent,QGLWidget* sharedcont) - :QGLWidget (parent,sharedcont),mesh(m),feeder(feed),rq(),drawmode(MDM_SMOOTH) +GLArea::GLArea (SharedDataOpenGLContext* sharedcontext,MainWindow* parent) + :QGLWidget(NULL,sharedcontext),parwin(parent) { + } GLArea::~GLArea() { + } void GLArea::initializeGL() @@ -65,21 +63,31 @@ void GLArea::initializeGL() 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); - //GLenum err = glGetError(); - //assert(err == GL_NO_ERROR); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glPushMatrix(); @@ -91,33 +99,16 @@ void GLArea::paintGL () 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(); - float d=2.0f/mesh.bbox.Diag(); - vcg::glScale(d); - glTranslate(-mesh.bbox.Center()); - - if (mesh.VN() > 0) - { - switch(drawmode) - { - case MDM_SMOOTH: - case MDM_FLAT: - feeder.drawTriangles(rq); - case MDM_WIRE: - feeder.drawWire(rq); - break; - case MDM_POINTS: - feeder.drawPoints(rq); - break; - case MDM_FLATWIRE: - feeder.drawFlatWire(rq); - break; - default: - break; - } - } + 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(); @@ -125,7 +116,7 @@ void GLArea::paintGL () glMatrixMode(GL_PROJECTION); glPopMatrix(); glPopAttrib(); - //doneCurrent(); + GLenum err = glGetError(); assert(err == GL_NO_ERROR); } @@ -139,7 +130,9 @@ void GLArea::keyReleaseEvent (QKeyEvent * e) 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) @@ -151,7 +144,9 @@ void GLArea::keyPressEvent (QKeyEvent * e) 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) @@ -159,103 +154,79 @@ 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 (); -} - -void GLArea::updateRequested(MyDrawMode md,vcg::GLFeederInfo::ReqAtts& reqatts) -{ - drawmode = md; - rq = reqatts; - updateGL(); + doneCurrent(); } void GLArea::resetTrackBall() { - makeCurrent(); track.Reset(); - updateGL(); + makeCurrent(); + updateGL(); doneCurrent(); } -SharedDataOpenGLContext::SharedDataOpenGLContext( CMeshO& mesh,MLThreadSafeMemoryInfo& mi,QWidget* parent /*= 0*/ ) - :QGLWidget(parent),feeder(mesh,mi,100000) +SharedDataOpenGLContext::SharedDataOpenGLContext(CMeshO& mesh,vcg::QtThreadSafeMemoryInfo& mi,QWidget* parent) + :QGLWidget(parent),manager(mesh,mi,100000) { } SharedDataOpenGLContext::~SharedDataOpenGLContext() { - deAllocateBO(); } void SharedDataOpenGLContext::myInitGL() { makeCurrent(); glewInit(); - doneCurrent(); -} - -void SharedDataOpenGLContext::passInfoToOpenGL(int mode) -{ - makeCurrent(); - MyDrawMode drawmode = static_cast(mode); - //_tsbm.setUpBuffers(); - vcg::GLFeederInfo::ReqAtts req; - bool allocated = false; - switch(drawmode) - { - case MDM_SMOOTH: - case MDM_WIRE: - req[vcg::GLFeederInfo::ATT_VERTPOSITION] = true; - req[vcg::GLFeederInfo::ATT_VERTNORMAL] = true; - req[vcg::GLFeederInfo::ATT_VERTINDEX] = true; - req.primitiveModality() = vcg::GLFeederInfo::PR_TRIANGLES; - break; - case MDM_POINTS: - req[vcg::GLFeederInfo::ATT_VERTPOSITION] = true; - req[vcg::GLFeederInfo::ATT_VERTNORMAL] = true; - req.primitiveModality() = vcg::GLFeederInfo::PR_POINTS; - break; - case MDM_FLAT: - case MDM_FLATWIRE: - req[vcg::GLFeederInfo::ATT_VERTPOSITION] = true; - req[vcg::GLFeederInfo::ATT_FACENORMAL] = true; - req.primitiveModality() = vcg::GLFeederInfo::PR_TRIANGLES; - break; - default: - break; - } - vcg::GLFeederInfo::ReqAtts rq = feeder.setupRequestedAttributes(req,allocated); - doneCurrent(); - emit dataReadyToBeRead(drawmode,rq); - + doneCurrent(); } void SharedDataOpenGLContext::deAllocateBO() { - makeCurrent(); - feeder.deAllocateBO(); - doneCurrent(); + 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(); +} \ No newline at end of file diff --git a/apps/sample/trimesh_QT_shared/glarea.h b/apps/sample/trimesh_QT_shared/glarea.h index 47ed9f0a..f7325db7 100644 --- a/apps/sample/trimesh_QT_shared/glarea.h +++ b/apps/sample/trimesh_QT_shared/glarea.h @@ -39,47 +39,44 @@ Initial release. /// wrapper imports #include - - +#include +#include +#include #include "mesh.h" -#include "ml_scene_renderer.h" -/// declaring edge and face type - -enum MyDrawMode{MDM_SMOOTH=0,MDM_POINTS,MDM_WIRE,MDM_FLATWIRE,MDM_FLAT}; +class MainWindow; class SharedDataOpenGLContext : public QGLWidget { Q_OBJECT public: - SharedDataOpenGLContext(CMeshO& mesh,MLThreadSafeMemoryInfo& mi,QWidget* parent = 0); + typedef vcg::QtThreadSafeGLMeshAttributesMultiViewerBOManager MultiViewManager; + + SharedDataOpenGLContext(CMeshO& mesh,vcg::QtThreadSafeMemoryInfo& mi,QWidget* parent = 0); ~SharedDataOpenGLContext(); void myInitGL(); void deAllocateBO(); - - MLThreadSafeGLMeshAttributesFeeder feeder; - -public slots: - /// widget-based user interaction slots - void passInfoToOpenGL(int mode); - -signals: - void dataReadyToBeRead(MyDrawMode,vcg::GLFeederInfo::ReqAtts&); + 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 (CMeshO& m,MLThreadSafeGLMeshAttributesFeeder& feed,QWidget* parent = NULL,QGLWidget* sharedcont = NULL); + GLArea (SharedDataOpenGLContext* sharedcontext,MainWindow* parent); ~GLArea(); void resetTrackBall(); + //unsigned int getId() const {return areaid;} /// we choosed a subset of the avaible drawing modes signals: /// signal for setting the statusbar message void setStatusBar(QString message); + void updateRenderModalityRequested(int); protected: /// opengl initialization and drawing calls void initializeGL (); @@ -92,18 +89,15 @@ protected: void mouseMoveEvent(QMouseEvent*e); void mouseReleaseEvent(QMouseEvent*e); void wheelEvent(QWheelEvent*e); -public slots: - void updateRequested(MyDrawMode,vcg::GLFeederInfo::ReqAtts&); + private: - /// the active mesh instance - CMeshO& mesh; + MainWindow* parwin; /// the active manipulator vcg::Trackball track; /// mesh data structure initializer void initMesh(QString message); - MyDrawMode drawmode; - MLThreadSafeGLMeshAttributesFeeder& feeder; - vcg::GLFeederInfo::ReqAtts rq; + //unsigned int areaid; + //vcg::GlTrimesh glt; }; #endif /*GLAREA_H_ */ diff --git a/apps/sample/trimesh_QT_shared/mainwindow.cpp b/apps/sample/trimesh_QT_shared/mainwindow.cpp index 4f019d59..d3db2f38 100644 --- a/apps/sample/trimesh_QT_shared/mainwindow.cpp +++ b/apps/sample/trimesh_QT_shared/mainwindow.cpp @@ -29,51 +29,86 @@ $Log: not supported by cvs2svn $ #include "mainwindow.h" +#include "glarea.h" +#include #include #include #include +#include + +QProgressBar *MainWindow::qb; +QStatusBar* MainWindow::sb; MainWindow::MainWindow (QWidget * parent) - :QMainWindow (parent),mi(1000000000),mesh() + :QMainWindow (parent),mi(2000000000),mesh() { ui.setupUi (this); - QLayout* tmp = ui.glFrame->layout(); - + 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(); - connect (ui.drawModeComboBox, SIGNAL (currentIndexChanged(int)),shared, SLOT (passInfoToOpenGL(int))); + shared->myInitGL(); - for(int ii = 0;ii < 2;++ii) + for(unsigned int ii = 0;ii < 2;++ii) { - glar[ii] = new GLArea(mesh,shared->feeder,NULL,shared); - connect (shared,SIGNAL(dataReadyToBeRead(MyDrawMode,vcg::GLFeederInfo::ReqAtts&)),glar[ii], SLOT (updateRequested(MyDrawMode,vcg::GLFeederInfo::ReqAtts&))); - tmp->addWidget(glar[ii]); - } + rendbox[ii] = new QComboBox(this); + for(QMap::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.loadMeshPushButton, SIGNAL (clicked()),this, SLOT (chooseMesh())); - connect (ui.loadTetrahedronPushButton, SIGNAL (clicked()),this, SLOT (loadTetrahedron())); - connect (ui.loadDodecahedronPushButton, SIGNAL (clicked()),this, SLOT (loadDodecahedron())); - //from toolFrame to glArea through mainwindow + 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(), - tr("Poly Model (*.ply)")); - int err=vcg::tri::io::ImporterPLY::Open(mesh,(fileName.toStdString()).c_str()); + extoptions); + QFileInfo fi(fileName); + QTime loadingtime; + loadingtime.start(); + int err=0; + + if (fi.suffix() == plyext) + err=vcg::tri::io::ImporterPLY::Open(mesh,(fileName.toStdString()).c_str(),qCallBack); + else + if (fi.suffix() == objext) + { + int loadmask; + err=vcg::tri::io::ImporterOBJ::Open(mesh,(fileName.toStdString()).c_str(),loadmask,qCallBack); + } + int msec = loadingtime.elapsed(); if(err!=0) { const char* errmsg=vcg::tri::io::ImporterPLY::ErrorMsg(err); QMessageBox::warning(this,tr("Error Loading Mesh"),QString(errmsg)); } - initMesh(fileName); + QString msg = fileName + " vtx: " + QString::number(mesh.VN()) + " fcs: " + QString::number(mesh.FN()) + " loading time: " + QString::number(msec) + " msec"; + initMesh(msg); } void MainWindow::loadTetrahedron() @@ -90,7 +125,7 @@ void MainWindow::loadDodecahedron() initMesh(tr("Dodecahedron [builtin]")); } -void MainWindow::initMesh(QString message) +void MainWindow::initMesh(QString& message) { if (shared != NULL) shared->deAllocateBO(); @@ -98,16 +133,111 @@ void MainWindow::initMesh(QString message) vcg::tri::UpdateBounding::Box(mesh); // update Normals vcg::tri::UpdateNormal::PerVertexNormalizedPerFaceNormalized(mesh); - shared->passInfoToOpenGL(ui.drawModeComboBox->currentIndex()); - for(size_t ii = 0;ii < 2;++ii) - if (glar[ii] != NULL) - glar[ii]->resetTrackBall(); - ui.statusbar->showMessage(message); + 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 >::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(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 >::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) + 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); +} diff --git a/apps/sample/trimesh_QT_shared/mainwindow.h b/apps/sample/trimesh_QT_shared/mainwindow.h index 34358177..e7bf04d4 100644 --- a/apps/sample/trimesh_QT_shared/mainwindow.h +++ b/apps/sample/trimesh_QT_shared/mainwindow.h @@ -29,33 +29,55 @@ $Log: not supported by cvs2svn $ #ifndef MAINWINDOW_H_ #define MAINWINDOW_H_ +#include +#include #include "ui_mainwindow.h" + +#include "mesh.h" +#include +#include +#include +#include +#include +#include #include "glarea.h" -#include "ml_thread_safe_memory_info.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(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 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; - MLThreadSafeMemoryInfo mi; + vcg::QtThreadSafeMemoryInfo mi; + QComboBox* rendbox[2]; /// the active mesh instance CMeshO mesh; + QMap stringrendtable; + QMap > rendtable; + static QProgressBar* qb; + static QStatusBar* sb; }; #endif /*MAINWINDOW_H_ */ diff --git a/apps/sample/trimesh_QT_shared/mainwindow.ui b/apps/sample/trimesh_QT_shared/mainwindow.ui index 75e8e073..25fc537b 100644 --- a/apps/sample/trimesh_QT_shared/mainwindow.ui +++ b/apps/sample/trimesh_QT_shared/mainwindow.ui @@ -31,150 +31,7 @@ 9 - - - - 0 - 0 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 6 - - - 9 - - - 9 - - - 9 - - - 9 - - - - - Draw &Mode : - - - drawModeComboBox - - - - - - - - Smooth - - - - - Points - - - - - Wire - - - - - Flat Wire - - - - - Flat - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Load &Mesh - - - - - - - Load &Tetrahedron - - - - - - - Load &Dodecahedron - - - - - - - Qt::Horizontal - - - - 20 - 40 - - - - - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 6 - - - 9 - - - 9 - - - 9 - - - 9 - - - + @@ -187,15 +44,39 @@ 21 + + + File + + + + + + + + - + + + Load Mesh + + + + + Load Tetrahedron + + + + + Load Dodecahedron + + + + + Close + + - - drawModeComboBox - loadMeshPushButton - loadTetrahedronPushButton - loadDodecahedronPushButton - diff --git a/apps/sample/trimesh_QT_shared/mesh.h b/apps/sample/trimesh_QT_shared/mesh.h index d6e56d8f..bef74773 100644 --- a/apps/sample/trimesh_QT_shared/mesh.h +++ b/apps/sample/trimesh_QT_shared/mesh.h @@ -12,17 +12,17 @@ using namespace vcg; class CFaceO; class CVertexO; +class CEdgeO; -struct MyUsedTypes : public UsedTypes< Use ::AsVertexType, +struct MyUsedTypes : public UsedTypes ::AsVertexType, vcg::Use::AsEdgeType, Use ::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 CMeshO : public vcg::tri::TriMesh< std::vector, std::vector > +class CEdgeO : public vcg::Edge{}; +class CMeshO : public vcg::tri::TriMesh< std::vector, std::vector,std::vector > { -public: - vcg::Box3f bbox; }; #endif \ No newline at end of file diff --git a/apps/sample/trimesh_QT_shared/ml_scene_renderer.cpp b/apps/sample/trimesh_QT_shared/ml_scene_renderer.cpp deleted file mode 100644 index 7fab80a1..00000000 --- a/apps/sample/trimesh_QT_shared/ml_scene_renderer.cpp +++ /dev/null @@ -1,201 +0,0 @@ -#include "ml_scene_renderer.h" -#include "ml_thread_safe_memory_info.h" -#include "glarea.h" - -#include - -MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeGLMeshAttributesFeeder(CMeshO& mesh,MLThreadSafeMemoryInfo& gpumeminfo,size_t perbatchtriangles) - :GLMeshAttributesFeeder(mesh,gpumeminfo,perbatchtriangles),_lock(QReadWriteLock::Recursive) -{ -} - -void MLThreadSafeGLMeshAttributesFeeder::setPerBatchTriangles( size_t perbatchtriangles ) -{ - QWriteLocker locker(&_lock); - GLMeshAttributesFeeder::setPerBatchPrimitives(perbatchtriangles); -} - -size_t MLThreadSafeGLMeshAttributesFeeder::perBatchTriangles() const -{ - QReadLocker locker(&_lock); - return GLMeshAttributesFeeder::perBatchPrimitives(); - -} - -bool MLThreadSafeGLMeshAttributesFeeder::renderedWithBO() const -{ - QReadLocker locker(&_lock); - return GLMeshAttributesFeeder::isPossibleToUseBORendering(); -} - -void MLThreadSafeGLMeshAttributesFeeder::meshAttributesUpdated( int mask ) -{ - QWriteLocker locker(&_lock); - GLMeshAttributesFeeder::meshAttributesUpdated(mask); -} - -vcg::GLFeederInfo::ReqAtts MLThreadSafeGLMeshAttributesFeeder::setupRequestedAttributes(const vcg::GLFeederInfo::ReqAtts& rq,bool& allocated ) -{ - QWriteLocker locker(&_lock); - return GLMeshAttributesFeeder::setupRequestedAttributes(rq,allocated); -} - - -void MLThreadSafeGLMeshAttributesFeeder::drawWire(vcg::GLFeederInfo::ReqAtts& rq) -{ - glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_LIGHTING_BIT ); - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - drawTriangles(rq); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - glPopAttrib(); -} - -void MLThreadSafeGLMeshAttributesFeeder::drawFlatWire(vcg::GLFeederInfo::ReqAtts& rq) -{ - glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_LIGHTING_BIT ); - glEnable(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(1.0, 1); - drawTriangles(rq); - glDisable(GL_POLYGON_OFFSET_FILL); - - glEnable(GL_COLOR_MATERIAL); - glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE); - - ReqAtts tmp = rq; - tmp[ATT_VERTCOLOR] = false; - tmp[ATT_FACECOLOR] = false; - tmp[ATT_MESHCOLOR] = false; - - glColor3f(.3f,.3f,.3f); - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - QReadLocker locker(&_lock); - GLMeshAttributesFeeder::drawTriangles(tmp,_textids.textId()); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - - glPopAttrib(); -} - -void MLThreadSafeGLMeshAttributesFeeder::drawPoints(vcg::GLFeederInfo::ReqAtts& rq) -{ - QReadLocker locker(&_lock); - GLMeshAttributesFeeder::drawPoints(rq); -} - -void MLThreadSafeGLMeshAttributesFeeder::drawTriangles(vcg::GLFeederInfo::ReqAtts& rq) -{ - QReadLocker locker(&_lock); - GLMeshAttributesFeeder::drawTriangles(rq,_textids.textId()); -} - -void MLThreadSafeGLMeshAttributesFeeder::drawBBox(vcg::GLFeederInfo::ReqAtts& rq) -{ - QReadLocker locker(&_lock); - - vcg::Box3f& b = _mesh.bbox; - glPushAttrib(GL_ALL_ATTRIB_BITS); - glDisable(GL_LIGHTING); - GLuint bbhandle; - glGenBuffers(1,&bbhandle); - std::vector bbox(12 * 2); - - //0 - bbox[0] = vcg::Point3f((float)b.min[0],(float)b.min[1],(float)b.min[2]); - bbox[1] = vcg::Point3f((float)b.max[0],(float)b.min[1],(float)b.min[2]); - - //1 - bbox[2] = vcg::Point3f((float)b.max[0],(float)b.min[1],(float)b.min[2]); - bbox[3] = vcg::Point3f((float)b.max[0],(float)b.max[1],(float)b.min[2]); - - //2 - bbox[4] = vcg::Point3f((float)b.max[0],(float)b.max[1],(float)b.min[2]); - bbox[5] = vcg::Point3f((float)b.min[0],(float)b.max[1],(float)b.min[2]); - - //3 - bbox[6] = vcg::Point3f((float)b.min[0],(float)b.max[1],(float)b.min[2]); - bbox[7] = vcg::Point3f((float)b.min[0],(float)b.min[1],(float)b.min[2]); - - //4 - bbox[8] = vcg::Point3f((float)b.min[0],(float)b.min[1],(float)b.min[2]); - bbox[9] = vcg::Point3f((float)b.min[0],(float)b.min[1],(float)b.max[2]); - - //5 - bbox[10] = vcg::Point3f((float)b.min[0],(float)b.min[1],(float)b.max[2]); - bbox[11] = vcg::Point3f((float)b.max[0],(float)b.min[1],(float)b.max[2]); - - //6 - bbox[12] = vcg::Point3f((float)b.max[0],(float)b.min[1],(float)b.max[2]); - bbox[13] = vcg::Point3f((float)b.max[0],(float)b.min[1],(float)b.min[2]); - - //7 - bbox[14] = vcg::Point3f((float)b.max[0],(float)b.min[1],(float)b.max[2]); - bbox[15] = vcg::Point3f((float)b.max[0],(float)b.max[1],(float)b.max[2]); - - //8 - bbox[16] = vcg::Point3f((float)b.max[0],(float)b.max[1],(float)b.max[2]); - bbox[17] = vcg::Point3f((float)b.max[0],(float)b.max[1],(float)b.min[2]); - - //9 - bbox[18] = vcg::Point3f((float)b.max[0],(float)b.max[1],(float)b.max[2]); - bbox[19] = vcg::Point3f((float)b.min[0],(float)b.max[1],(float)b.max[2]); - - //10 - bbox[20] = vcg::Point3f((float)b.min[0],(float)b.max[1],(float)b.max[2]); - bbox[21] = vcg::Point3f((float)b.min[0],(float)b.min[1],(float)b.max[2]); - - //11 - bbox[22] = vcg::Point3f((float)b.min[0],(float)b.max[1],(float)b.max[2]); - bbox[23] = vcg::Point3f((float)b.min[0],(float)b.max[1],(float)b.min[2]); - - glColor3f(1.0f,1.0f,1.0f); - glBindBuffer(GL_ARRAY_BUFFER,bbhandle); - glBufferData(GL_ARRAY_BUFFER, 12 * 2 * sizeof(vcg::Point3f), &(bbox[0]), GL_STATIC_DRAW); - glVertexPointer(3,GL_FLOAT,0,0); - glBindBuffer(GL_ARRAY_BUFFER,0); - glEnableClientState(GL_VERTEX_ARRAY); - glDrawArrays(GL_LINES,0,24); - glDisableClientState(GL_VERTEX_ARRAY); - glDeleteBuffers(1,&bbhandle); - glPopAttrib(); -} - - -void MLThreadSafeGLMeshAttributesFeeder::deAllocateBO() -{ - QWriteLocker locker(&_lock); - GLMeshAttributesFeeder::buffersDeAllocationRequested(); -} - -MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeTextureNamesContainer::MLThreadSafeTextureNamesContainer() - :_tmid(),_lock(QReadWriteLock::Recursive) -{ - -} - -MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeTextureNamesContainer::~MLThreadSafeTextureNamesContainer() -{ - clear(); -} - -void MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeTextureNamesContainer::push_back( GLuint textid ) -{ - QWriteLocker locker(&_lock); - _tmid.push_back(textid); -} - -size_t MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeTextureNamesContainer::size() const -{ - QReadLocker locker(&_lock); - return _tmid.size(); -} - -bool MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeTextureNamesContainer::empty() const -{ - QReadLocker locker(&_lock); - return _tmid.empty(); -} - -void MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeTextureNamesContainer::clear() -{ - QWriteLocker locker(&_lock); - _tmid.clear(); -} \ No newline at end of file diff --git a/apps/sample/trimesh_QT_shared/ml_scene_renderer.h b/apps/sample/trimesh_QT_shared/ml_scene_renderer.h deleted file mode 100644 index 293d6205..00000000 --- a/apps/sample/trimesh_QT_shared/ml_scene_renderer.h +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** -* MeshLab o o * -* A versatile mesh processing toolbox o o * -* _ O _ * -* Copyright(C) 2005 \/)\/ * -* 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. * -* * -****************************************************************************/ - -#ifndef __ML_SCENE_RENDERER_H -#define __ML_SCENE_RENDERER_H - -#include -#include "mesh.h" -#include - -#include -#include -#include - - - -class MLThreadSafeMemoryInfo; - - -class MLThreadSafeGLMeshAttributesFeeder : public vcg::GLMeshAttributesFeeder -{ -public: - struct MLThreadSafeTextureNamesContainer - { - MLThreadSafeTextureNamesContainer(); - ~MLThreadSafeTextureNamesContainer(); - - void push_back(GLuint textid); - size_t size() const; - bool empty() const; - void clear(); - GLuint& operator[](size_t ii) {return _tmid[ii];}; - inline std::vector& textId() {return _tmid;}; - private: - std::vector _tmid; - mutable QReadWriteLock _lock; - }; - - - MLThreadSafeGLMeshAttributesFeeder(CMeshO& mesh,MLThreadSafeMemoryInfo& gpumeminfo,size_t perbatchtriangles); - ~MLThreadSafeGLMeshAttributesFeeder() {}; - - void setPerBatchTriangles(size_t perbatchtriangles); - - size_t perBatchTriangles() const; - - bool renderedWithBO() const; - - GLuint bufferObjectHandle() const; - - void meshAttributesUpdated(int mask); - - vcg::GLFeederInfo::ReqAtts setupRequestedAttributes(const vcg::GLFeederInfo::ReqAtts& rq,bool& allocated); - - void deAllocateBO(); - - void drawWire(vcg::GLFeederInfo::ReqAtts& rq); - - void drawFlatWire(vcg::GLFeederInfo::ReqAtts& rq); - - void drawPoints(vcg::GLFeederInfo::ReqAtts& rq); - - void drawTriangles(vcg::GLFeederInfo::ReqAtts& rq); - - void drawBBox(vcg::GLFeederInfo::ReqAtts& rq); - - inline CMeshO& mesh() {return _mesh;} - - inline MLThreadSafeTextureNamesContainer& textureIDContainer() {return _textids;} - - void buffersDeAllocationRequested(); -private: - mutable QReadWriteLock _lock; - MLThreadSafeTextureNamesContainer _textids; -}; - -#endif diff --git a/apps/sample/trimesh_QT_shared/ml_thread_safe_memory_info.cpp b/apps/sample/trimesh_QT_shared/ml_thread_safe_memory_info.cpp deleted file mode 100644 index 9838f86f..00000000 --- a/apps/sample/trimesh_QT_shared/ml_thread_safe_memory_info.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -* MeshLab o o * -* A versatile mesh processing toolbox o o * -* _ O _ * -* Copyright(C) 2005 \/)\/ * -* 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. * -* * -****************************************************************************/ - -#include "ml_thread_safe_memory_info.h" - -MLThreadSafeMemoryInfo::MLThreadSafeMemoryInfo( std::ptrdiff_t originalmem ) - :vcg::NotThreadSafeMemoryInfo(originalmem),lock(QReadWriteLock::Recursive) -{ - -} - -MLThreadSafeMemoryInfo::~MLThreadSafeMemoryInfo() -{ -} - -void MLThreadSafeMemoryInfo::acquiredMemory(std::ptrdiff_t mem) -{ - QWriteLocker locker(&lock); - vcg::NotThreadSafeMemoryInfo::acquiredMemory(mem); -} - -std::ptrdiff_t MLThreadSafeMemoryInfo::usedMemory() const -{ - QReadLocker locker(&lock); - return vcg::NotThreadSafeMemoryInfo::usedMemory(); - -} - -std::ptrdiff_t MLThreadSafeMemoryInfo::currentFreeMemory() const -{ - QReadLocker locker(&lock); - return vcg::NotThreadSafeMemoryInfo::currentFreeMemory(); -} - -void MLThreadSafeMemoryInfo::releasedMemory(std::ptrdiff_t mem) -{ - QWriteLocker locker(&lock); - vcg::NotThreadSafeMemoryInfo::releasedMemory(mem); -} - -bool MLThreadSafeMemoryInfo::isAdditionalMemoryAvailable( std::ptrdiff_t mem ) -{ - QReadLocker locker(&lock); - return vcg::NotThreadSafeMemoryInfo::isAdditionalMemoryAvailable(mem); -} diff --git a/apps/sample/trimesh_QT_shared/ml_thread_safe_memory_info.h b/apps/sample/trimesh_QT_shared/ml_thread_safe_memory_info.h deleted file mode 100644 index a4d65030..00000000 --- a/apps/sample/trimesh_QT_shared/ml_thread_safe_memory_info.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -* MeshLab o o * -* A versatile mesh processing toolbox o o * -* _ O _ * -* Copyright(C) 2005 \/)\/ * -* 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. * -* * -****************************************************************************/ - -#ifndef __ML_THREAD_SAFE_MEMORY_INFO_H -#define __ML_THREAD_SAFE_MEMORY_INFO_H - -#include - -#include - - -class MLThreadSafeMemoryInfo : public vcg::NotThreadSafeMemoryInfo -{ -public: - MLThreadSafeMemoryInfo(std::ptrdiff_t originalmem); - - ~MLThreadSafeMemoryInfo(); - - void acquiredMemory(std::ptrdiff_t mem); - - std::ptrdiff_t usedMemory() const; - - std::ptrdiff_t currentFreeMemory() const; - - void releasedMemory(std::ptrdiff_t mem = 0); - - bool isAdditionalMemoryAvailable(std::ptrdiff_t mem); -private: - //mutable objects can be modified from the declared const functions - //in this way we have not to modified the basic vcg::MemoryInfo interface for the logically const functions - //whose need to lock the mutex for a simple reading operation - mutable QReadWriteLock lock; -}; - -#endif diff --git a/apps/sample/trimesh_QT_shared/trimesh_qt.pro b/apps/sample/trimesh_QT_shared/trimesh_qt.pro index 1f7eebd0..88660bb4 100644 --- a/apps/sample/trimesh_QT_shared/trimesh_qt.pro +++ b/apps/sample/trimesh_QT_shared/trimesh_qt.pro @@ -37,17 +37,12 @@ win32{ # Input HEADERS += mainwindow.h HEADERS += glarea.h -HEADERS += ml_thread_safe_memory_info.h -HEADERS += ml_scene_renderer.h -HEADERS += ml_atomic_guard.h SOURCES += main.cpp SOURCES += mainwindow.cpp SOURCES += glarea.cpp -SOURCES += ml_thread_safe_memory_info.cpp -SOURCES += ml_scene_renderer.cpp FORMS += mainwindow.ui