Large changeset:

- Added methods for transmitting current raster camera to parameters 
- Added methods for setting the view with the camera of the current mesh or the current layer (still issues with the near/far)
- Added first sketch of document saving (does not work, committed just because was in the same files...)
This commit is contained in:
Paolo Cignoni cignoni 2010-11-16 18:16:42 +00:00
parent bfc5ba0d43
commit 2b8c602b73
7 changed files with 114 additions and 102 deletions

View File

@ -1068,10 +1068,10 @@ void GLArea::sendViewDir(QString name)
emit transmitViewDir(name,dir);
}
void GLArea::sendCameraPos(QString name)
void GLArea::sendMeshShot(QString name)
{
Point3f pos=meshDoc->mm()->cm.shot.GetViewPoint();
emit transmitViewDir(name, pos);
Shotf curShot=meshDoc->mm()->cm.shot;
emit transmitShot(name, curShot);
}
void GLArea::sendViewerShot(QString name)
@ -1176,27 +1176,17 @@ void GLArea::setIsRaster(bool viewMode){
}
void GLArea::loadRaster(int id)
{
foreach(RasterModel *rm, meshDoc->rasterList)
if(rm->id()==id){
meshDoc->setCurrentRaster(id);
setTarget(rm->currentPlane->image);
//load his shot or a default shot
//TODO temporaneo... poi bisogna creare un defaultShot
// createOrthoView("Front");
//rm->shot = shotFromTrackball().first;
if (rm->shot.IsValid())
{
//loadShot(QPair<Shotf, float> (rm->shot,trackball.track.sca));
{
foreach(RasterModel *rm, meshDoc->rasterList)
if(rm->id()==id){
meshDoc->setCurrentRaster(id);
setTarget(rm->currentPlane->image);
//load his shot or a default shot
if (rm->shot.IsValid())
loadShot(QPair<Shotf, float> (rm->shot,1));
}
else
createOrthoView("Front");
//rm->shot = shotFromTrackball().first;
}
else
createOrthoView("Front");
}
}
void GLArea::drawTarget() {
@ -1281,22 +1271,21 @@ float GLArea::getCameraDistance()
void GLArea::initializeShot(Shotf &shot)
{
//Da vedere
shot.Intrinsics.PixelSizeMm[0]=0.036916077;
shot.Intrinsics.PixelSizeMm[1]=0.036916077;
shot.Intrinsics.PixelSizeMm[0]=0.036916077;
shot.Intrinsics.PixelSizeMm[1]=0.036916077;
shot.Intrinsics.DistorCenterPx[0]=width()/2;
shot.Intrinsics.DistorCenterPx[1]=height()/2;
shot.Intrinsics.CenterPx[0]=width()/2;
shot.Intrinsics.CenterPx[1]=height()/2;
shot.Intrinsics.ViewportPx[0]=width();
shot.Intrinsics.ViewportPx[1]=height();
shot.Intrinsics.DistorCenterPx[0]=width()/2;
shot.Intrinsics.DistorCenterPx[1]=height()/2;
shot.Intrinsics.CenterPx[0]=width()/2;
shot.Intrinsics.CenterPx[1]=height()/2;
shot.Intrinsics.ViewportPx[0]=width();
shot.Intrinsics.ViewportPx[1]=height();
double viewportYMm = shot.Intrinsics.PixelSizeMm[1]*shot.Intrinsics.ViewportPx[1];
float defaultFov=60.0;
shot.Intrinsics.FocalMm = viewportYMm/(2*tanf(vcg::math::ToRad(defaultFov/2))); //27.846098mm
double viewportYMm = shot.Intrinsics.PixelSizeMm[1]*shot.Intrinsics.ViewportPx[1];
float defaultFov=60.0;
shot.Intrinsics.FocalMm = viewportYMm/(2*tanf(vcg::math::ToRad(defaultFov/2))); //27.846098mm
shot.Extrinsics.SetIdentity();
shot.Extrinsics.SetIdentity();
}
bool GLArea::viewFromFile()
@ -1318,11 +1307,9 @@ bool GLArea::viewFromFile()
QString type = doc.doctype().name();
//TextAlign file project
if(type == "RegProjectML")
loadShotFromTextAlignFile(doc);
if(type == "RegProjectML") loadShotFromTextAlignFile(doc);
//View State file
else if(type == "ViewState")
loadViewFromViewStateFile(doc);
else if(type == "ViewState") loadViewFromViewStateFile(doc);
qDebug("End file reading");
qf.close();
@ -1495,24 +1482,22 @@ QPair<vcg::Shotf,float> GLArea::shotFromTrackball()
vcg::Shotf newShot = track2ShotCPU<float>(shot, &trackball);
////Expressing scaling as a translation along z
////k is the ratio between default scale and new scale
//double oldScale= 3.0f/meshDoc->bbox().Diag();
//double k= oldScale/trackball.track.sca;
////Apply this formula
//// R(t+p) = kR'(t'+p) forall p, R=R', k is a costant
//// R(t)= kR(t')
//// t = k*t'
//Point3d t1 = newShot.Extrinsics.Tra();
//
//Matrix44d rapM = Matrix44d().SetScale(k, k, k);
//Point3d t0 = rapM*t1;
//newShot.Extrinsics.SetTra(t0);
return QPair<Shotf, float> (newShot,trackball.track.sca);
}
void GLArea::viewFromCurrentShot(QString kind)
{
Shotf localShot;
if(kind=="Mesh" && meshDoc->mm()) localShot = meshDoc->mm()->cm.shot;
if(kind=="Raster" && meshDoc->rm()) localShot = meshDoc->rm()->shot;
if(!localShot.IsValid())
{
this->log->Logf(GLLogStream::SYSTEM, "Unable to set Shot from current %s",qPrintable(kind));
return;
}
loadShot(QPair<Shotf, float>(localShot,trackball.track.sca));
}
void GLArea::loadShot(const QPair<vcg::Shotf,float> &shotAndScale){

View File

@ -223,7 +223,7 @@ public slots:
void sendViewPos(QString name);
void sendSurfacePos(QString name);
void sendViewDir(QString name);
void sendCameraPos(QString name);
void sendMeshShot(QString name);
void sendViewerShot(QString name);
void sendRasterShot(QString name);
@ -346,7 +346,8 @@ private:
//-----------Shot support----------------------------
public:
QPair<vcg::Shotf, float > shotFromTrackball();
bool viewFromFile();
void viewFromCurrentShot(QString kind);
bool viewFromFile();
void createOrthoView(QString);
void viewToClipboard();
void viewFromClipboard();

View File

@ -133,7 +133,9 @@ private slots:
void linkViewers();
void viewFrom(QAction *qa);
void readViewFromFile();
void copyViewToClipBoard();
void viewFromCurrentMeshShot();
void viewFromCurrentRasterShot();
void copyViewToClipBoard();
void pasteViewFromClipboard();
///////////Slot PopUp Menu Handles /////////////////////
@ -363,6 +365,8 @@ private:
QAction *viewRightAct;
QAction *viewFrontAct;
QAction *viewBackAct;
QAction *viewFromMeshAct;
QAction *viewFromRasterAct;
QAction *viewFromFileAct;
///////////Actions Menu Windows -> Link/Copy/Paste View ////////////////////////

View File

@ -290,17 +290,21 @@ void MainWindow::createActions()
viewFromGroupAct = new QActionGroup(this); viewFromGroupAct->setExclusive(true);
viewTopAct = new QAction(tr("Top"),viewFromGroupAct);
viewTopAct = new QAction(tr("Top"),viewFromGroupAct);
viewBottomAct = new QAction(tr("Bottom"),viewFromGroupAct);
viewLeftAct = new QAction(tr("Left"),viewFromGroupAct);
viewLeftAct = new QAction(tr("Left"),viewFromGroupAct);
viewRightAct = new QAction(tr("Right"),viewFromGroupAct);
viewFrontAct = new QAction(tr("Front"),viewFromGroupAct);
viewBackAct = new QAction(tr("Back"),viewFromGroupAct);
viewBackAct = new QAction(tr("Back"),viewFromGroupAct);
connect(viewFromGroupAct, SIGNAL(triggered(QAction *)), this, SLOT(viewFrom(QAction *)));
viewFromFileAct = new QAction (tr("View from file"), this);
connect(viewFromFileAct, SIGNAL(triggered()), this, SLOT(readViewFromFile()));
viewFromMeshAct = new QAction (tr("View from Mesh Camera"), this);
viewFromRasterAct = new QAction (tr("View from Raster Camera"), this);
viewFromFileAct = new QAction (tr("View from file"), this);
connect(viewFromFileAct, SIGNAL(triggered()), this, SLOT(readViewFromFile()));
connect(viewFromMeshAct, SIGNAL(triggered()), this, SLOT(viewFromCurrentMeshShot()));
connect(viewFromRasterAct, SIGNAL(triggered()), this, SLOT(viewFromCurrentRasterShot()));
copyShotToClipboardAct = new QAction (tr("Copy shot"), this);
copyShotToClipboardAct->setShortcut(QKeySequence::Copy);

View File

@ -37,11 +37,13 @@
#include "savemaskexporter.h"
#include "alnParser.h"
#include <wrap/io_trimesh/io_mask.h>
#include <vcg/complex/trimesh/update/normal.h>
#include <vcg/complex/trimesh/update/bounding.h>
#include <vcg/complex/trimesh/clean.h>
#include "../common/scriptinterface.h"
#include "../common/meshlabdocumentxml.h"
using namespace std;
using namespace vcg;
@ -125,16 +127,13 @@ void MainWindow::updateWindowMenu()
// View From SUBmenu
viewFromMenu = windowsMenu->addMenu(tr("&View from"));
viewFromMenu->addAction(viewTopAct);
viewFromMenu->addAction(viewBottomAct);
viewFromMenu->addAction(viewLeftAct);
viewFromMenu->addAction(viewRightAct);
viewFromMenu->addAction(viewFrontAct);
viewFromMenu->addAction(viewBackAct);
foreach(QAction *ac, viewFromGroupAct->actions())
viewFromMenu->addAction(ac);
// View From File act
windowsMenu->addAction(viewFromFileAct);
windowsMenu->addAction(viewFromMeshAct);
windowsMenu->addAction(viewFromRasterAct);
// Copy and paste shot acts
windowsMenu->addAction(copyShotToClipboardAct);
@ -181,10 +180,10 @@ void MainWindow::updateWindowMenu()
void MainWindow::setColorMode(QAction *qa)
{
if(qa->text() == tr("&None")) GLA()->setColorMode(GLW::CMNone);
if(qa->text() == tr("Per &Mesh")) GLA()->setColorMode(GLW::CMPerMesh);
if(qa->text() == tr("Per &Vertex")) GLA()->setColorMode(GLW::CMPerVert);
if(qa->text() == tr("Per &Face")) GLA()->setColorMode(GLW::CMPerFace);
if(qa->text() == tr("&None")) GLA()->setColorMode(GLW::CMNone);
if(qa->text() == tr("Per &Mesh")) GLA()->setColorMode(GLW::CMPerMesh);
if(qa->text() == tr("Per &Vertex")) GLA()->setColorMode(GLW::CMPerVert);
if(qa->text() == tr("Per &Face")) GLA()->setColorMode(GLW::CMPerFace);
}
void MainWindow::updateMenus()
@ -507,35 +506,36 @@ void MainWindow::linkViewers()
void MainWindow::viewFrom(QAction *qa)
{
MultiViewer_Container *mvc = currentViewContainer();
GLArea* glArea = qobject_cast<GLArea*>(mvc->currentView());
if(glArea)
glArea->createOrthoView(qa->text());
if(GLA()) GLA()->createOrthoView(qa->text());
}
void MainWindow::readViewFromFile()
{
MultiViewer_Container *mvc = currentViewContainer();
GLArea* glArea = qobject_cast<GLArea*>(mvc->currentView());
if(glArea)
glArea->viewFromFile();
if(GLA()) GLA()->viewFromFile();
updateMenus();
}
void MainWindow::viewFromCurrentMeshShot()
{
if(GLA()) GLA()->viewFromCurrentShot("Mesh");
updateMenus();
}
void MainWindow::viewFromCurrentRasterShot()
{
if(GLA()) GLA()->viewFromCurrentShot("Raster");
updateMenus();
}
void MainWindow::copyViewToClipBoard()
{
MultiViewer_Container *mvc = currentViewContainer();
GLArea* glArea = qobject_cast<GLArea*>(mvc->currentView());
if(glArea)
glArea->viewToClipboard();
if(GLA()) GLA()->viewToClipboard();
}
void MainWindow::pasteViewFromClipboard()
{
MultiViewer_Container *mvc = currentViewContainer();
GLArea* glArea = qobject_cast<GLArea*>(mvc->currentView());
if(glArea)
glArea->viewFromClipboard();
if(GLA()) GLA()->viewFromClipboard();
updateMenus();
}
@ -1123,8 +1123,8 @@ bool MainWindow::openIn(QString /* fileName */)
void MainWindow::saveProject()
{
QString fileName = QFileDialog::getSaveFileName(this,tr("Save Project File"),lastUsedDirectory.path().append("/untitled.aln"), tr("*.aln"));
QString fileName = QFileDialog::getSaveFileName(this,tr("Save Project File"),lastUsedDirectory.path().append("/test.mlp"), tr("*.aln,*.mlp"));
bool ret;
qDebug("Saving aln file %s\n",qPrintable(fileName));
if (fileName.isEmpty()) return;
else
@ -1134,7 +1134,9 @@ void MainWindow::saveProject()
path.truncate(path.lastIndexOf("/"));
lastUsedDirectory.setPath(path);
}
QFileInfo fi(fileName);
if (QString(fi.suffix()).toLower() == "aln")
{
vector<string> meshNameVector;
vector<Matrix44f> transfVector;
@ -1143,8 +1145,12 @@ void MainWindow::saveProject()
meshNameVector.push_back(qPrintable(mp->shortName()));
transfVector.push_back(mp->cm.Tr);
}
bool ret= ALNParser::SaveALN(qPrintable(fileName),meshNameVector,transfVector);
ret= ALNParser::SaveALN(qPrintable(fileName),meshNameVector,transfVector);
}
else
{
ret = MeshDocumentToXMLFile(*meshDoc(),fileName);
}
if(!ret)
QMessageBox::critical(this, tr("Meshlab Saving Error"), QString("Unable to save project file %1\n").arg(fileName));

View File

@ -527,10 +527,10 @@ Point3fWidget::Point3fWidget(QWidget *p, RichPoint3f* rpf, QWidget *gla_curr): M
connect(getPoint3Button,SIGNAL(clicked()),this,SLOT(getPoint()));
connect(getPoint3Combo,SIGNAL(currentIndexChanged(int)),this,SLOT(getPoint()));
connect(gla_curr,SIGNAL(transmitViewDir(QString,vcg::Point3f)),this,SLOT(setValue(QString,vcg::Point3f)));
connect(gla_curr,SIGNAL(transmitViewPos(QString,vcg::Point3f)),this,SLOT(setValue(QString,vcg::Point3f)));
connect(gla_curr,SIGNAL(transmitShot(QString,vcg::Shotf)),this,SLOT(setValue(QString,vcg::Point3f)));
connect(gla_curr,SIGNAL(transmitSurfacePos(QString,vcg::Point3f)),this,SLOT(setValue(QString,vcg::Point3f)));
connect(this,SIGNAL(askViewDir(QString)),gla_curr,SLOT(sendViewDir(QString)));
connect(this,SIGNAL(askViewPos(QString)),gla_curr,SLOT(sendViewPos(QString)));
connect(this,SIGNAL(askViewPos(QString)),gla_curr,SLOT(sendMeshShot(QString)));
connect(this,SIGNAL(askSurfacePos(QString)),gla_curr,SLOT(sendSurfacePos(QString)));
connect(this,SIGNAL(askCameraPos(QString)),gla_curr,SLOT(sendCameraPos(QString)));
}
@ -562,6 +562,12 @@ void Point3fWidget::setValue(QString name,Point3f newVal)
}
}
void Point3fWidget::setValue(QString name,Shotf newValShot)
{
Point3f p = newValShot.GetViewPoint();
setValue(name,p);
}
vcg::Point3f Point3fWidget::getValue()
{
return Point3f(coordSB[0]->text().toFloat(),coordSB[1]->text().toFloat(),coordSB[2]->text().toFloat());
@ -607,6 +613,7 @@ ShotfWidget::ShotfWidget(QWidget *p, RichShotf* rpf, QWidget *gla_curr): MeshLab
QStringList names;
names << "Current Trackball";
names << "Current Mesh";
names << "Current Raster";
getShotCombo = new QComboBox(p);
@ -616,6 +623,7 @@ ShotfWidget::ShotfWidget(QWidget *p, RichShotf* rpf, QWidget *gla_curr): MeshLab
connect(getShotButton,SIGNAL(clicked()),this,SLOT(getShot()));
connect(gla_curr,SIGNAL(transmitShot(QString,vcg::Shotf)),this,SLOT(setValue(QString,vcg::Shotf)));
connect(this,SIGNAL(askViewerShot(QString)),gla_curr,SLOT(sendViewerShot(QString)));
connect(this,SIGNAL(askMeshShot(QString)), gla_curr,SLOT(sendMeshShot(QString)));
connect(this,SIGNAL(askRasterShot(QString)),gla_curr,SLOT(sendRasterShot(QString)));
}
gridLay->addLayout(lay,row,1,Qt::AlignTop);
@ -624,10 +632,12 @@ ShotfWidget::ShotfWidget(QWidget *p, RichShotf* rpf, QWidget *gla_curr): MeshLab
void ShotfWidget::getShot()
{
int index = getShotCombo->currentIndex();
if(index==0)
emit askViewerShot(paramName);
else
emit askRasterShot(paramName);
switch(index) {
case 0 : emit askViewerShot(paramName); break;
case 1 : emit askMeshShot(paramName); break;
case 2 : emit askRasterShot(paramName); break;
default : assert(0);
}
}
ShotfWidget::~ShotfWidget() {}

View File

@ -248,6 +248,7 @@ public:
public slots:
void getPoint();
void setValue(QString name, vcg::Point3f val);
void setValue(QString name, vcg::Shotf val);
signals:
void askViewDir(QString);
void askViewPos(QString);
@ -285,6 +286,7 @@ public:
void setValue(QString name, vcg::Shotf val);
signals:
void askRasterShot(QString);
void askMeshShot(QString);
void askViewerShot(QString);
protected: