From e8fc9bcdcb9ee3f70430f09cb93fcf1af5480007 Mon Sep 17 00:00:00 2001 From: Paolo Cignoni cignoni Date: Tue, 29 Nov 2005 11:22:23 +0000 Subject: [PATCH] Added experimental snapshot saving function --- src/meshlab/glarea.cpp | 39 ++++++++++++++++++++++++++++++++++++++ src/meshlab/glarea.h | 7 ++++++- src/meshlab/mainwindow.cpp | 25 ++++++++++++++++++++++++ src/meshlab/mainwindow.h | 2 ++ 4 files changed, 72 insertions(+), 1 deletion(-) diff --git a/src/meshlab/glarea.cpp b/src/meshlab/glarea.cpp index b85ac63bf..23fd37d57 100644 --- a/src/meshlab/glarea.cpp +++ b/src/meshlab/glarea.cpp @@ -24,6 +24,9 @@ History $Log$ +Revision 1.23 2005/11/29 11:22:23 vannini +Added experimental snapshot saving function + Revision 1.22 2005/11/28 21:05:37 alemochi Added menu preferences and configurable background @@ -146,6 +149,7 @@ void GLArea::initializeGL() rm.drawMode = GLW::DMSmooth; rm.drawColor = GLW::CMNone; + } void GLArea::paintGL() @@ -205,6 +209,41 @@ void GLArea::resizeGL(int _width, int _height) glViewport(0,0, _width, _height); } +bool GLArea::saveSnapshot(QString path) +{ + std::vector snap; + int vp[4]; + int p; + + glGetIntegerv( GL_VIEWPORT,vp ); // Lettura viewport + glPixelStorei( GL_PACK_ROW_LENGTH, 0); + glPixelStorei( GL_PACK_ALIGNMENT, 1); + + snap.resize(vp[2] * vp[3]); + + glReadPixels(vp[0],vp[1],vp[2],vp[3],GL_RGBA,GL_UNSIGNED_BYTE,(GLvoid *)&snap[0]); + + FILE * fp = fopen(path.toLocal8Bit(),"wb"); + if (fp==0) return false; + + fprintf(fp,"P6\n%d %d\n255\n",vp[2],vp[3]); + int j=0; + + for(int py=vp[3]-1; py >= 0; --py) + { + for(int px=0; px < vp[2]; ++px) + { + p=py * vp[2] + px; + fwrite(&(snap[p]),3,1,fp); + //printf("%d %d\n",px, py); + } + } + + fclose(fp); + + return true; +} + Trackball::Button QT2VCG(Qt::MouseButton qtbt, Qt::KeyboardModifiers modifiers) { int vcgbt=Trackball::BUTTON_NONE; diff --git a/src/meshlab/glarea.h b/src/meshlab/glarea.h index 8a32d121e..21a32a75a 100644 --- a/src/meshlab/glarea.h +++ b/src/meshlab/glarea.h @@ -24,6 +24,9 @@ History $Log$ +Revision 1.14 2005/11/29 11:22:23 vannini +Added experimental snapshot saving function + Revision 1.13 2005/11/28 21:05:37 alemochi Added menu preferences and configurable background @@ -133,6 +136,7 @@ public: void setColorMode(vcg::GLW::ColorMode mode); void setLight(bool state); void setLightMode(bool state,LightingModel lmode); + bool saveSnapshot(QString path); inline void RenderLight(); list > *iRendersList; protected: @@ -145,7 +149,8 @@ protected: void mouseReleaseEvent(QMouseEvent *event); void wheelEvent(QWheelEvent*e); - + + private: RenderMode rm; Point3f bColor; diff --git a/src/meshlab/mainwindow.cpp b/src/meshlab/mainwindow.cpp index c868efd23..2ef3dc9b0 100644 --- a/src/meshlab/mainwindow.cpp +++ b/src/meshlab/mainwindow.cpp @@ -24,6 +24,9 @@ History $Log$ +Revision 1.44 2005/11/29 11:22:23 vannini +Added experimental snapshot saving function + Revision 1.43 2005/11/28 21:05:37 alemochi Added menu preferences and configurable background @@ -256,6 +259,19 @@ bool MainWindow::saveAs() } } +bool MainWindow::saveSnapshot() +{ + QString snapshotPath = "snapshot.ppm"; + + bool ret=GLA()->saveSnapshot(snapshotPath); + + if (ret) + GLA()->log.Log(GLLogStream::Info,"Snapshot saved to %s",snapshotPath.toLocal8Bit().constData()); + else + GLA()->log.Log(GLLogStream::Error,"Error saving snapshot %s",snapshotPath.toLocal8Bit().constData()); + + return ret; +} void MainWindow::about() { QMessageBox::about(this, tr("About Plug & Paint"), @@ -280,6 +296,11 @@ void MainWindow::createActions() saveAsAct->setShortcut(tr("Ctrl+S")); connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); + saveSnapshotAct = new QAction(QIcon(":/images/save.png"),tr("&Save snapshot"), this); + connect(saveSnapshotAct, SIGNAL(triggered()), this, SLOT(saveSnapshot())); + + + for (int i = 0; i < MAXRECENTFILES; ++i) { recentFileActs[i] = new QAction(this); recentFileActs[i]->setVisible(false); @@ -393,6 +414,7 @@ void MainWindow::createToolBars() mainToolBar->setIconSize(QSize(32,32)); mainToolBar->addAction(openAct); mainToolBar->addAction(saveAsAct); + mainToolBar->addAction(saveSnapshotAct); renderToolBar = addToolBar(tr("Render")); renderToolBar->setIconSize(QSize(32,32)); @@ -406,6 +428,8 @@ void MainWindow::createMenus() fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(openAct); fileMenu->addAction(saveAsAct); + fileMenu->addAction(saveSnapshotAct); + separatorAct = fileMenu->addSeparator(); for (int i = 0; i < MAXRECENTFILES; ++i) fileMenu->addAction(recentFileActs[i]); updateRecentFileActions(); @@ -767,6 +791,7 @@ void MainWindow::updateMenus() { bool active = (bool)workspace->activeWindow(); saveAsAct->setEnabled(active); + saveSnapshotAct->setEnabled(active); filterMenu->setEnabled(active && !filterMenu->actions().isEmpty()); renderMenu->setEnabled(active); windowsMenu->setEnabled(active); diff --git a/src/meshlab/mainwindow.h b/src/meshlab/mainwindow.h index e0a7d9e2a..c5e7b0de8 100644 --- a/src/meshlab/mainwindow.h +++ b/src/meshlab/mainwindow.h @@ -50,6 +50,7 @@ private slots: void open(QString fileName=QString()); void openRecentFile(); bool saveAs(); + bool saveSnapshot(); void about(); // Plugin Slots /////////// @@ -121,6 +122,7 @@ private: QAction *openAct; QAction *saveAsAct; + QAction *saveSnapshotAct; QActionGroup *renderModeGroup;