From 4428f7545f32809573042e9c7ad730d7f435ff9c Mon Sep 17 00:00:00 2001 From: Paolo Cignoni cignoni Date: Tue, 6 Mar 2012 11:53:39 +0000 Subject: [PATCH] Still cleaning up the new raster viewing mode. Now the switch between the two modes preserve the trackball. --- src/meshlab/glarea.cpp | 41 ++++++++++++------ src/meshlab/glarea.h | 6 ++- src/meshlab/layerDialog.cpp | 68 ++++++++++++------------------ src/meshlab/layerDialog.h | 5 +-- src/meshlab/mainwindow_RunTime.cpp | 4 +- 5 files changed, 61 insertions(+), 63 deletions(-) diff --git a/src/meshlab/glarea.cpp b/src/meshlab/glarea.cpp index c2bdebd2f..d69109b3c 100644 --- a/src/meshlab/glarea.cpp +++ b/src/meshlab/glarea.cpp @@ -828,13 +828,13 @@ void GLArea::wheelEvent(QWheelEvent*e) float notch = e->delta()/ float(WHEEL_STEP); switch(e->modifiers()) { - case Qt::ShiftModifier + Qt::ControlModifier : clipRatioFar = math::Clamp( clipRatioFar*powf(1.2f, notch),0.01f,5000.0f); break; - case Qt::ControlModifier : clipRatioNear = math::Clamp(clipRatioNear*powf(1.2f, notch),0.01f,50.0f); break; - case Qt::AltModifier : glas.pointSize = math::Clamp(glas.pointSize*powf(1.2f, notch),0.01f,150.0f); + case Qt::ControlModifier+Qt::ShiftModifier : clipRatioFar = math::Clamp( clipRatioFar*powf(1.2f, notch),0.01f,5000.0f); break; + case Qt::ControlModifier : clipRatioNear = math::Clamp(clipRatioNear*powf(1.2f, notch),0.01f,50.0f); break; + case Qt::ShiftModifier : fov = math::Clamp(fov+1.2f*notch,5.0f,90.0f); break; + case Qt::AltModifier : glas.pointSize = math::Clamp(glas.pointSize*powf(1.2f, notch),0.01f,150.0f); foreach(MeshModel * mp, this->md()->meshList) mp->glw.SetHintParamf(GLW::HNPPointSize,glas.pointSize); break; - case Qt::ShiftModifier : fov = math::Clamp(fov+1.2f*notch,5.0f,90.0f); break; default: if(isRaster()) this->opacity = math::Clamp( opacity*powf(1.2f, notch),0.1f,1.0f); @@ -1050,10 +1050,11 @@ void GLArea::setView() // This parameter is the one that controls: // HOW LARGE IS THE TRACKBALL ICON ON THE SCREEN. float viewRatio = 1.75f; - float cameraDist = viewRatio / tanf(math::ToRad(fov*.5f)); - if(fov==5) - cameraDist = 1000; // small hack for orthographic projection where camera distance is rather meaningless... + float cameraDist = viewRatio / tanf(math::ToRad(fov*.5f)); // the distance between the center of the trackball and the viewer. + + if(fov==5) cameraDist = 1000; // small hack for orthographic projection where camera distance is rather meaningless... + nearPlane = cameraDist - 2.f*clipRatioNear; farPlane = cameraDist + 10.f*clipRatioFar; if(nearPlane<=cameraDist*.1f) nearPlane=cameraDist*.1f; @@ -1061,7 +1062,7 @@ void GLArea::setView() if (!takeSnapTile) { if(fov==5) glOrtho( -viewRatio*fAspect, viewRatio*fAspect, -viewRatio, viewRatio, cameraDist - 2.f*clipRatioNear, cameraDist+2.f*clipRatioFar); - else gluPerspective(fov, fAspect, nearPlane, farPlane); + else gluPerspective(fov, fAspect, nearPlane, farPlane); } else setTiledView(fov, viewRatio, fAspect, nearPlane, farPlane, cameraDist); @@ -1264,9 +1265,16 @@ void GLArea::showRaster() { if(!this->isRaster()) { + lastViewBeforeRasterMode = this->viewToText(); setIsRaster(true); loadRaster(md()->rm()->id() ); - } else this->setIsRaster(false); + } else + { + this->setIsRaster(false); + QDomDocument doc("StringDoc"); + doc.setContent(lastViewBeforeRasterMode); + this->loadViewFromViewStateFile(doc); + } } void GLArea::loadRaster(int id) @@ -1528,10 +1536,10 @@ void GLArea::loadViewFromViewStateFile(const QDomDocument &doc) loadShot(QPair (shot,trackball.track.sca)); } - -void GLArea::viewToClipboard() +QString GLArea::viewToText() { - QClipboard *clipboard = QApplication::clipboard(); + QString docString; + Shotf shot = shotFromTrackball().first; QDomDocument doc("ViewState"); @@ -1539,7 +1547,7 @@ void GLArea::viewToClipboard() doc.appendChild( root ); QDomElement shotElem = WriteShotToQDomNode(shot,doc); - root.appendChild(shotElem); + root.appendChild(shotElem); QDomElement settingsElem = doc.createElement( "ViewSettings" ); settingsElem.setAttribute( "TrackScale", trackball.track.sca); @@ -1559,7 +1567,12 @@ void GLArea::viewToClipboard() renderElem.setAttribute("SelectedVert",rm.selectedVert); root.appendChild(renderElem); - clipboard->setText(doc.toString()); //.remove(QChar('\n'))); + return doc.toString(); +} + +void GLArea::viewToClipboard() +{ + QApplication::clipboard()->setText(this->viewToText()); } void GLArea::viewFromClipboard() diff --git a/src/meshlab/glarea.h b/src/meshlab/glarea.h index 5c7508ad8..f5134946d 100644 --- a/src/meshlab/glarea.h +++ b/src/meshlab/glarea.h @@ -339,15 +339,16 @@ private: int zoomx, zoomy; bool zoom; - float opacity; + float opacity; GLuint targetTex; // here we store the reference image. The raster image is rendered as a texture + QString lastViewBeforeRasterMode; // keep the view immediately before switching to raster mode public: bool isRaster() {return _isRaster;} void setIsRaster(bool viewMode); void loadRaster(int id); - void setTarget(QImage &image); + void setTarget(QImage &image); private: void drawTarget(); @@ -359,6 +360,7 @@ public: bool viewFromFile(); void createOrthoView(QString); void viewToClipboard(); + QString viewToText(); void viewFromClipboard(); void loadShot(const QPair &) ; diff --git a/src/meshlab/layerDialog.cpp b/src/meshlab/layerDialog.cpp index 351e3a9ff..a2c263cbd 100644 --- a/src/meshlab/layerDialog.cpp +++ b/src/meshlab/layerDialog.cpp @@ -247,32 +247,32 @@ void LayerDialog::updateTable() { //TODO:Check if the current viewer is a GLArea if(!isVisible()) return; - if(isVisible() && !mw->GLA()) + if(isVisible() && !mw->GLA()) { setVisible(false); //The layer dialog cannot be opened unless a new document is opened return; } - MeshDocument *md=mw->meshDoc(); + MeshDocument *md=mw->meshDoc(); this->setWindowTitle(md->docLabel()); ui->meshTreeWidget->clear(); ui->meshTreeWidget->setColumnCount(4); - ui->meshTreeWidget->setColumnWidth(0,40); - ui->meshTreeWidget->setColumnWidth(1,40); - //ui->meshTreeWidget->setColumnWidth(2,40); + ui->meshTreeWidget->setColumnWidth(0,40); + ui->meshTreeWidget->setColumnWidth(1,40); + //ui->meshTreeWidget->setColumnWidth(2,40); ui->meshTreeWidget->header()->hide(); foreach(MeshModel* mmd, md->meshList) { - //Restore mesh visibility according to the current visibility map - //very good to keep viewer state consistent - if( mw->GLA()->meshVisibilityMap.contains(mmd->id())) - mmd->visible = mw->GLA()->meshVisibilityMap.value(mmd->id()); - else - { - mw->GLA()->meshVisibilityMap[mmd->id()]=true; - mmd->visible=true; - } + //Restore mesh visibility according to the current visibility map + //very good to keep viewer state consistent + if( mw->GLA()->meshVisibilityMap.contains(mmd->id())) + mmd->visible = mw->GLA()->meshVisibilityMap.value(mmd->id()); + else + { + mw->GLA()->meshVisibilityMap[mmd->id()]=true; + mmd->visible=true; + } MeshTreeWidgetItem *item = new MeshTreeWidgetItem(mmd); if(mmd== mw->GLA()->mm()) { @@ -315,12 +315,12 @@ void LayerDialog::updateTable() rmd->visible =mw->GLA()->rasterVisibilityMap.value(rmd->id()); RasterTreeWidgetItem *item = new RasterTreeWidgetItem(rmd); - if(rmd== mw->meshDoc()->rm()) { + if(rmd== mw->meshDoc()->rm()) { item->setBackground(1,QBrush(Qt::yellow)); item->setForeground(1,QBrush(Qt::blue)); - item->setBackground(2,QBrush(Qt::yellow)); + item->setBackground(2,QBrush(Qt::yellow)); item->setForeground(2,QBrush(Qt::blue)); - item->setBackground(3,QBrush(Qt::yellow)); + item->setBackground(3,QBrush(Qt::yellow)); item->setForeground(3,QBrush(Qt::blue)); } ui->rasterTreeWidget->addTopLevelItem(item); @@ -331,8 +331,6 @@ void LayerDialog::updateTable() for(int i=2; i< ui->rasterTreeWidget->columnCount(); i++) ui->rasterTreeWidget->resizeColumnToContents(i); - - } //Reconstruct the correct layout of the treewidget after updating the main table. It is necessary to keep the changing @@ -530,36 +528,29 @@ void LayerDialog::updateDecoratorParsView() MeshTreeWidgetItem::MeshTreeWidgetItem(MeshModel *meshModel) { - if(meshModel->visible) - setIcon(0,QIcon(":/images/layer_eye_open.png")); - else - setIcon(0,QIcon(":/images/layer_eye_close.png")); - -// setIcon(1,QIcon(":/images/layer_edit_unlocked.png")); - + if(meshModel->visible) setIcon(0,QIcon(":/images/layer_eye_open.png")); + else setIcon(0,QIcon(":/images/layer_eye_close.png")); setText(1, QString::number(meshModel->id())); QString meshName = meshModel->label(); if (meshModel->meshModified()) - meshName += " *"; + meshName += " *"; setText(2, meshName); - m=meshModel; + this->m=meshModel; } RasterTreeWidgetItem::RasterTreeWidgetItem(RasterModel *rasterModel) { - if(rasterModel->visible) - setIcon(0,QIcon(":/images/layer_eye_open.png")); - else - setIcon(0,QIcon(":/images/layer_eye_close.png")); + if(rasterModel->visible) setIcon(0,QIcon(":/images/layer_eye_open.png")); + else setIcon(0,QIcon(":/images/layer_eye_close.png")); - setText(1, QString::number(rasterModel->id())); + setText(1, QString::number(rasterModel->id())); QString rasterName = rasterModel->label(); - setText(2, rasterName); + setText(2, rasterName); - r=rasterModel; + this->r=rasterModel; } DecoratorParamsTreeWidget::DecoratorParamsTreeWidget(QAction* act,MainWindow *mw,QWidget* parent) @@ -583,22 +574,17 @@ DecoratorParamsTreeWidget::DecoratorParamsTreeWidget(QAction* act,MainWindow *mw dialoglayout = new QGridLayout(parent); frame = new StdParFrame(parent,mw->GLA()); - frame->loadFrameContent(tmpSet,mw->meshDoc()); + frame->loadFrameContent(tmpSet,mw->meshDoc()); savebut = new QPushButton("Save",parent); resetbut = new QPushButton("Reset",parent); - //applybut = new QPushButton("Apply",parent); loadbut = new QPushButton("Load",parent); dialoglayout->addWidget(savebut,1,0); dialoglayout->addWidget(resetbut,1,1); dialoglayout->addWidget(loadbut,1,2); - //dialoglayout->addWidget(applybut,1,3); dialoglayout->addWidget(frame,0,0,1,3); this->setLayout(dialoglayout); - //connect(applybut,SIGNAL(clicked()),this,SLOT(apply())); - //for(int ii = 0;ii < frame->stdfieldwidgets.size();++ii) connect(frame,SIGNAL(parameterChanged()),this,SLOT(apply())); - connect(resetbut,SIGNAL(clicked()),this,SLOT(reset())); connect(savebut,SIGNAL(clicked()),this,SLOT(save())); connect(loadbut,SIGNAL(clicked()),this,SLOT(load())); diff --git a/src/meshlab/layerDialog.h b/src/meshlab/layerDialog.h index 8cce686dd..1fed4104d 100644 --- a/src/meshlab/layerDialog.h +++ b/src/meshlab/layerDialog.h @@ -79,11 +79,10 @@ public slots: private: MainWindow* mainWin; - StdParFrame* frame; - RichParameterSet tmpSet; + StdParFrame* frame; + RichParameterSet tmpSet; QPushButton* savebut; QPushButton* resetbut; - //QPushButton* applybut; QPushButton* loadbut; QGridLayout* dialoglayout; }; diff --git a/src/meshlab/mainwindow_RunTime.cpp b/src/meshlab/mainwindow_RunTime.cpp index 432deb856..1b00d70ea 100644 --- a/src/meshlab/mainwindow_RunTime.cpp +++ b/src/meshlab/mainwindow_RunTime.cpp @@ -417,14 +417,13 @@ void MainWindow::setSplit(QAction *qa) if(mvc) { GLArea *glwClone=new GLArea(mvc, ¤tGlobalParams); - bool isRaster = GLA()->isRaster(); if(qa->text() == tr("&Horizontally")) mvc->addView(glwClone, Qt::Vertical); else if(qa->text() == tr("&Vertically")) mvc->addView(glwClone, Qt::Horizontal); //The loading of the raster must be here - if(isRaster){ + if(GLA()->isRaster()){ glwClone->setIsRaster(true); if(this->meshDoc()->rm()->id()>=0) glwClone->loadRaster(this->meshDoc()->rm()->id()); @@ -1079,7 +1078,6 @@ void MainWindow::executeFilter(MeshLabXMLFilterContainer* mfc, EnvWrap& env, boo } try { - GLArea * ar = GLA(); bool isinter = (mfc->xmlInfo->filterAttribute(fname,MLXMLElNames::filterIsInterruptible) == "true"); if (isinter) {