From 8407cd23f88ae54baeacb48eb71baeccbbd46bad Mon Sep 17 00:00:00 2001 From: Paolo Cignoni cignoni Date: Sat, 8 Jan 2011 02:43:59 +0000 Subject: [PATCH] Added option for individual tile saving in snapshot for combining into very very large images... --- src/meshlab/glarea.cpp | 96 ++++++++++++++-------------- src/meshlab/glarea.h | 6 +- src/meshlab/layerDialog.cpp | 15 ++--- src/meshlab/saveSnapshotDialog.cpp | 1 + src/meshlab/ui/savesnapshotDialog.ui | 14 +++- 5 files changed, 72 insertions(+), 60 deletions(-) diff --git a/src/meshlab/glarea.cpp b/src/meshlab/glarea.cpp index 1ec3a958d..eb4fea299 100644 --- a/src/meshlab/glarea.cpp +++ b/src/meshlab/glarea.cpp @@ -155,23 +155,35 @@ void GLArea::initializeGL() void GLArea::pasteTile() { + QString outfile; + glPushAttrib(GL_ENABLE_BIT); QImage tileBuffer=grabFrameBuffer(true).mirrored(false,true); + if(ss.tiledSave) + { + outfile=QString("%1/%2_%3-%4.png") + .arg(ss.outdir) + .arg(ss.basename) + .arg(tileCol,2,10,QChar('0')) + .arg(tileRow,2,10,QChar('0')); + tileBuffer.mirrored(false,true).save(outfile,"PNG"); + } + else + { + if (snapBuffer.isNull()) + snapBuffer = QImage(tileBuffer.width() * ss.resolution, tileBuffer.height() * ss.resolution, tileBuffer.format()); - if (snapBuffer.isNull()) - snapBuffer = QImage(tileBuffer.width() * ss.resolution, tileBuffer.height() * ss.resolution, tileBuffer.format()); + uchar *snapPtr = snapBuffer.bits() + (tileBuffer.bytesPerLine() * tileCol) + ((totalCols * tileRow) * tileBuffer.numBytes()); + uchar *tilePtr = tileBuffer.bits(); - uchar *snapPtr = snapBuffer.bits() + (tileBuffer.bytesPerLine() * tileCol) + ((totalCols * tileRow) * tileBuffer.numBytes()); - uchar *tilePtr = tileBuffer.bits(); - - for (int y=0; y < tileBuffer.height(); y++) - { - memcpy((void*) snapPtr, (void*) tilePtr, tileBuffer.bytesPerLine()); - snapPtr+=tileBuffer.bytesPerLine() * totalCols; - tilePtr+=tileBuffer.bytesPerLine(); - } - - tileCol++; + for (int y=0; y < tileBuffer.height(); y++) + { + memcpy((void*) snapPtr, (void*) tilePtr, tileBuffer.bytesPerLine()); + snapPtr+=tileBuffer.bytesPerLine() * totalCols; + tilePtr+=tileBuffer.bytesPerLine(); + } + } + tileCol++; if (tileCol >= totalCols) { @@ -180,31 +192,28 @@ void GLArea::pasteTile() if (tileRow >= totalRows) { - QString outfile; - if(ss.snapAllLayers) { - outfile=QString("%1/%2%3_L%4.png") - .arg(ss.outdir) - .arg(ss.basename) - .arg(ss.counter,2,10,QChar('0')) - .arg(currSnapLayer,2,10,QChar('0')); - } - else - { + outfile=QString("%1/%2%3_L%4.png") + .arg(ss.outdir).arg(ss.basename) + .arg(ss.counter,2,10,QChar('0')) + .arg(currSnapLayer,2,10,QChar('0')); + } else { outfile=QString("%1/%2%3.png") - .arg(ss.outdir) - .arg(ss.basename) - .arg(ss.counter++,2,10,QChar('0')); + .arg(ss.outdir).arg(ss.basename) + .arg(ss.counter++,2,10,QChar('0')); } - bool ret = (snapBuffer.mirrored(false,true)).save(outfile,"PNG"); - if (ret) log->Logf(GLLogStream::SYSTEM, "Snapshot saved to %s",outfile.toLocal8Bit().constData()); - else log->Logf(GLLogStream::WARNING,"Error saving %s",outfile.toLocal8Bit().constData()); + if(!ss.tiledSave) + { + bool ret = (snapBuffer.mirrored(false,true)).save(outfile,"PNG"); + if (ret) log->Logf(GLLogStream::SYSTEM, "Snapshot saved to %s",outfile.toLocal8Bit().constData()); + else log->Logf(GLLogStream::WARNING,"Error saving %s",outfile.toLocal8Bit().constData()); + } takeSnapTile=false; snapBuffer=QImage(); } - } + } update(); glPopAttrib(); } @@ -588,7 +597,6 @@ void GLArea::displayHelp(QPainter *painter) void GLArea::saveSnapshot() { // snap all layers - totalSnapLayer= meshDoc->meshList.size(); currSnapLayer=0; // number of subparts @@ -597,32 +605,25 @@ void GLArea::saveSnapshot() if(ss.snapAllLayers) { - - while(currSnapLayermeshList.size()) { tileRow=tileCol=0; - + qDebug("Snapping layer %i",currSnapLayer); meshDoc->setCurrentMesh(currSnapLayer); - for(int i=0; imeshList) { + meshSetVisibility(mp,false); } + meshSetVisibility(mm(),true); takeSnapTile=true; - update(); repaint(); currSnapLayer++; } //cleanup - for(int i=0; imeshList) { + meshSetVisibility(mp,true); } - ss.counter++; } else @@ -1214,9 +1215,10 @@ void GLArea::updateRasterSetVisibilities() } } -void GLArea::addMeshSetVisibility(int meshId, bool visibility) +void GLArea::meshSetVisibility(MeshModel *mp, bool visibility) { - meshVisibilityMap.insert(meshId,visibility); + mp->visible=visibility; + meshVisibilityMap[mp->id()]=visibility; } void GLArea::addRasterSetVisibility(int rasterId, bool visibility) diff --git a/src/meshlab/glarea.h b/src/meshlab/glarea.h index 2f142a475..3a7e01bcf 100644 --- a/src/meshlab/glarea.h +++ b/src/meshlab/glarea.h @@ -55,6 +55,7 @@ public: int resolution; bool transparentBackground; bool snapAllLayers; + bool tiledSave; // if true all the tiles are saved as separated files and not joined. SnapshotSetting() { @@ -64,6 +65,7 @@ public: resolution=1; transparentBackground=true; snapAllLayers=false; + tiledSave=false; }; }; @@ -296,7 +298,7 @@ public: QMap rasterVisibilityMap; // Add an entry in the mesh visibility map - void addMeshSetVisibility(int meshId, bool visibility); + void meshSetVisibility(MeshModel *mp, bool visibility); // Add an entry in the raster visibility map void addRasterSetVisibility(int rasterId, bool visibility); @@ -315,7 +317,7 @@ private: enum AnimMode { AnimNone, AnimSpin, AnimInterp}; AnimMode animMode; int tileCol, tileRow, totalCols, totalRows; // snapshot: total number of subparts and current subpart rendered - int totalSnapLayer, currSnapLayer; // snapshot: total number of layers and current layer rendered + int currSnapLayer; // snapshot: total number of layers and current layer rendered void setCursorTrack(vcg::TrackMode *tm); //-----------Raster support---------------------------- diff --git a/src/meshlab/layerDialog.cpp b/src/meshlab/layerDialog.cpp index b06f05554..ddefa6a7b 100644 --- a/src/meshlab/layerDialog.cpp +++ b/src/meshlab/layerDialog.cpp @@ -98,17 +98,14 @@ void LayerDialog::meshItemClicked (QTreeWidgetItem * item , int col) // Very useful for comparing meshes if(QApplication::keyboardModifiers() == Qt::ControlModifier) - foreach(MeshModel *mp, md->meshList) { - mp->visible=false; - mw->GLA()->addMeshSetVisibility(mp->id(), mp->visible); + foreach(MeshModel *mp, md->meshList) + { + mw->GLA()->meshSetVisibility(mp, false); + } } - - if(md->getMesh(clickedId)->visible) md->getMesh(clickedId)->visible = false; - else md->getMesh(clickedId)->visible = true; - - //Update current GLArea visibility - mw->GLA()->addMeshSetVisibility(md->getMesh(clickedId)->id(), md->getMesh(clickedId)->visible); + //Toggle visibility of current mesh + mw->GLA()->meshSetVisibility(md->getMesh(clickedId), !md->getMesh(clickedId)->visible); } break; case 1 : diff --git a/src/meshlab/saveSnapshotDialog.cpp b/src/meshlab/saveSnapshotDialog.cpp index 7bacce930..4bd6ed719 100644 --- a/src/meshlab/saveSnapshotDialog.cpp +++ b/src/meshlab/saveSnapshotDialog.cpp @@ -51,6 +51,7 @@ SnapshotSetting SaveSnapshotDialog::getValues() settings.resolution=ui->resolutionSpinBox->value(); settings.transparentBackground=ui->backgroundCheckBox->isChecked(); settings.snapAllLayers=ui->alllayersCheckBox->isChecked(); + settings.tiledSave=ui->tiledSaveCheckBox->isChecked(); return settings; } diff --git a/src/meshlab/ui/savesnapshotDialog.ui b/src/meshlab/ui/savesnapshotDialog.ui index cee462a79..100e09db2 100644 --- a/src/meshlab/ui/savesnapshotDialog.ui +++ b/src/meshlab/ui/savesnapshotDialog.ui @@ -6,8 +6,8 @@ 0 0 - 552 - 192 + 616 + 225 @@ -115,6 +115,16 @@ + + + + If checked, save each image independently, allowing to later combine the saved images into a very very large image + + + Tiled Save + + +