diff --git a/src/meshlab/glarea.cpp b/src/meshlab/glarea.cpp index fe44d01a5..0c50c7d6b 100644 --- a/src/meshlab/glarea.cpp +++ b/src/meshlab/glarea.cpp @@ -965,7 +965,7 @@ 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(vcg::math::ToRad(fov*.5f)); + float cameraDist = viewRatio / tanf(math::ToRad(fov*.5f)); if(fov==5) cameraDist = 1000; // small hack for orthographic projection where camera distance is rather meaningless... @@ -1074,9 +1074,14 @@ void GLArea::sendCameraPos(QString name) emit transmitViewDir(name, pos); } -void GLArea::sendShot(QString name) +void GLArea::sendViewerShot(QString name) { - Shotd curShot=shotFromTrackball().first; + Shotf curShot=shotFromTrackball().first; + emit transmitShot(name, curShot); +} +void GLArea::sendRasterShot(QString name) +{ + Shotf curShot= this->meshDoc->rm()->shot; emit transmitShot(name, curShot); } @@ -1180,9 +1185,8 @@ void GLArea::loadRaster(int id) //TODO temporaneo... poi bisogna creare un defaultShot createOrthoView("Front"); - Shotd* tmpShot = &(shotFromTrackball().first); - rm->setShot(*tmpShot); - } + rm->shot = shotFromTrackball().first; + } } void GLArea::drawTarget() { @@ -1190,14 +1194,17 @@ void GLArea::drawTarget() { double ratio = 1.0f; //ratio = align.imageRatio; quale ratio? - + if(meshDoc->rm()==0) return; + QImage &curImg = meshDoc->rm()->currentPlane->image; + float imageRatio = float(curImg.width())/float(curImg.height()); + float screenRatio = float(this->width())/float(this->height()); //set orthogonal view glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); - gluOrtho2D(-1.0f*ratio, 1.0f*ratio, -1, 1); + gluOrtho2D(-1.0f*screenRatio, 1.0f*screenRatio, -1, 1); glColor4f(1, 1, 1, opacity); glDisable(GL_LIGHTING); @@ -1208,13 +1215,13 @@ void GLArea::drawTarget() { glColor3f(1.0f, 1.0f, 1.0f); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); //first point - glVertex3f(-1.0f*ratio, -1.0f, 0.0f); + glVertex3f(-1.0f*imageRatio, -1.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); //second point - glVertex3f(1.0f*ratio, -1.0f, 0.0f); + glVertex3f(1.0f*imageRatio, -1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); //third point - glVertex3f(1.0f*ratio, 1.0f, 0.0f); + glVertex3f(1.0f*imageRatio, 1.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); //fourth point - glVertex3f(-1.0f*ratio, 1.0f, 0.0f); + glVertex3f(-1.0f*imageRatio, 1.0f, 0.0f); glEnd(); glEnable(GL_DEPTH_TEST); @@ -1262,7 +1269,7 @@ float GLArea::getCameraDistance() return cameraDist; } -void GLArea::initializeShot(Shotd &shot) +void GLArea::initializeShot(Shotf &shot) { //Da vedere shot.Intrinsics.PixelSizeMm[0]=0.036916077; @@ -1317,7 +1324,7 @@ void GLArea::loadShotFromTextAlignFile(const QDomDocument &doc) { QDomElement root = doc.documentElement(); QDomNode node; - Shotd shot; + Shotf shot; node = root.firstChild(); @@ -1367,7 +1374,7 @@ void GLArea::loadShotFromTextAlignFile(const QDomDocument &doc) trackball.track.sca =fabs(p2.Z()/p1.Z()); - loadShot(QPair (shot,trackball.track.sca)); + loadShot(QPair (shot,trackball.track.sca)); } @@ -1376,16 +1383,16 @@ ViewState file is an xml file format created by Meshlab with the action "copyToC */ void GLArea::loadViewFromViewStateFile(const QDomDocument &doc) { - Shotd shot; + Shotf shot; QDomElement root = doc.documentElement(); QDomNode node = root.firstChild(); while(!node.isNull()) { if (QString::compare(node.nodeName(),"VCGCamera")==0) - ReadShotFromQDomNode(shot,node); + ReadShotFromQDomNode(shot,node); else if (QString::compare(node.nodeName(),"CamParam")==0) - ReadShotFromOLDXML(shot,node); + ReadShotFromOLDXML(shot,node); else if (QString::compare(node.nodeName(),"ViewSettings")==0) { @@ -1413,13 +1420,13 @@ void GLArea::loadViewFromViewStateFile(const QDomDocument &doc) node = node.nextSibling(); } - loadShot(QPair (shot,trackball.track.sca)); + loadShot(QPair (shot,trackball.track.sca)); } void GLArea::viewToClipboard() { QClipboard *clipboard = QApplication::clipboard(); - Shotd shot = shotFromTrackball().first; + Shotf shot = shotFromTrackball().first; QDomDocument doc("ViewState"); QDomElement root = doc.createElement("project"); @@ -1458,9 +1465,9 @@ void GLArea::viewFromClipboard() loadViewFromViewStateFile(doc); } -QPair GLArea::shotFromTrackball() +QPair GLArea::shotFromTrackball() { - Shotd shot; + Shotf shot; initializeShot(shot); double viewportYMm=shot.Intrinsics.PixelSizeMm[1]*shot.Intrinsics.ViewportPx[1]; @@ -1473,9 +1480,9 @@ QPair GLArea::shotFromTrackball() //Add translation S^(-1) R^(-1)(gl) //Shotd doesn't introduce scaling //--------------------------------------------------------------------- - shot.Extrinsics.SetTra( shot.Extrinsics.Tra() + (Inverse(shot.Extrinsics.Rot())*Point3d(0, 0, cameraDist))); + shot.Extrinsics.SetTra( shot.Extrinsics.Tra() + (Inverse(shot.Extrinsics.Rot())*Point3f(0, 0, cameraDist))); - vcg::Shotd newShot = track2ShotCPU(shot, &trackball); + vcg::Shotf newShot = track2ShotCPU(shot, &trackball); ////Expressing scaling as a translation along z ////k is the ratio between default scale and new scale @@ -1493,12 +1500,12 @@ QPair GLArea::shotFromTrackball() //newShot.Extrinsics.SetTra(t0); - return QPair (newShot,trackball.track.sca); + return QPair (newShot,trackball.track.sca); } -void GLArea::loadShot(const QPair &shotAndScale){ +void GLArea::loadShot(const QPair &shotAndScale){ - Shotd shot = shotAndScale.first; + Shotf shot = shotAndScale.first; fov = shot.GetFovFromFocal(); @@ -1542,7 +1549,7 @@ void GLArea::loadShot(const QPair &shotAndScale){ void GLArea::createOrthoView(QString dir) { - Shotd view; + Shotf view; initializeShot(view); fov =5; @@ -1554,20 +1561,20 @@ void GLArea::createOrthoView(QString dir) trackball.track.sca = newScale; trackball.track.tra = -meshDoc->bbox().Center(); - vcg::Matrix44d rot; + vcg::Matrix44f rot; if(dir == tr("Top")) - rot.SetRotateDeg(90,Point3(1,0,0)); + rot.SetRotateDeg(90,Point3f(1,0,0)); else if(dir == tr("Bottom")) - rot.SetRotateDeg(90,Point3(-1,0,0)); + rot.SetRotateDeg(90,Point3f(-1,0,0)); else if(dir == tr("Left")) - rot.SetRotateDeg(90,Point3(0,1,0)); + rot.SetRotateDeg(90,Point3f(0,1,0)); else if(dir == tr("Right")) - rot.SetRotateDeg(90,Point3(0,-1,0)); + rot.SetRotateDeg(90,Point3f(0,-1,0)); else if(dir == tr("Front")) - rot.SetRotateDeg(0,Point3(0,1,0)); + rot.SetRotateDeg(0,Point3f(0,1,0)); else if(dir == tr("Back")) - rot.SetRotateDeg(180,Point3(0,1,0)); + rot.SetRotateDeg(180,Point3f(0,1,0)); view.Extrinsics.SetRot(rot); @@ -1578,11 +1585,11 @@ void GLArea::createOrthoView(QString dir) //Add translation S^(-1) R^(-1)(gl) //Shotd doesn't introduce scaling //--------------------------------------------------------------------- - view.Extrinsics.SetTra( view.Extrinsics.Tra() + (Inverse(view.Extrinsics.Rot())*Point3d(0, 0, cameraDist))); + view.Extrinsics.SetTra( view.Extrinsics.Tra() + (Inverse(view.Extrinsics.Rot())*Point3f(0, 0, cameraDist))); - Shotd shot = track2ShotCPU(view, &trackball); + Shotf shot = track2ShotCPU(view, &trackball); - QPair shotAndScale = QPair (shot, trackball.track.sca); + QPair shotAndScale = QPair (shot, trackball.track.sca); loadShot(shotAndScale); } diff --git a/src/meshlab/glarea.h b/src/meshlab/glarea.h index 48cc45c60..a7d449806 100644 --- a/src/meshlab/glarea.h +++ b/src/meshlab/glarea.h @@ -218,13 +218,14 @@ signals : void transmitViewPos(QString name, vcg::Point3f dir); void transmitSurfacePos(QString name,vcg::Point3f dir); void transmitCameraPos(QString name,vcg::Point3f dir); - void transmitShot(QString name, vcg::Shotd); + void transmitShot(QString name, vcg::Shotf); public slots: void sendViewPos(QString name); void sendSurfacePos(QString name); void sendViewDir(QString name); void sendCameraPos(QString name); - void sendShot(QString name); + void sendViewerShot(QString name); + void sendRasterShot(QString name); public: @@ -344,17 +345,17 @@ private: //-----------Shot support---------------------------- public: - QPair shotFromTrackball(); + QPair shotFromTrackball(); bool viewFromFile(); void createOrthoView(QString); void viewToClipboard(); void viewFromClipboard(); - void loadShot(const QPair &) ; + void loadShot(const QPair &) ; private: float getCameraDistance(); - void initializeShot(vcg::Shotd &shot); + void initializeShot(vcg::Shotf &shot); void loadShotFromTextAlignFile(const QDomDocument &doc); void loadViewFromViewStateFile(const QDomDocument &doc); @@ -419,16 +420,16 @@ private: _far = 100; //get shot extrinsics matrix - vcg::Matrix44f shotExtr; + vcg::Matrix44 shotExtr; refCamera.GetWorldToExtrinsicsMatrix().ToMatrix(shotExtr); - vcg::Matrix44f model2; + vcg::Matrix44 model2; model2 = (shotExtr)* track->Matrix(); - vcg::Matrix44d model; + vcg::Matrix44 model; model2.ToMatrix(model); //get translation out of modelview - vcg::Point3d tra; + vcg::Point3 tra; tra[0] = model[0][3]; tra[1] = model[1][3]; tra[2] = model[2][3]; model[0][3] = model[1][3] = model[2][3] = 0; @@ -440,7 +441,7 @@ private: view.Extrinsics.SetRot(model); //get pure translation out of modelview - vcg::Matrix44d imodel = model; + vcg::Matrix44 imodel = model; vcg::Transpose(imodel); tra = -(imodel*tra); tra *= idet; @@ -460,7 +461,7 @@ private: template void shot2Track(const vcg::Shot &from, const float cameraDist, vcg::Trackball &tb){ - vcg::Quaterniond qfrom; qfrom.FromMatrix(from.Extrinsics.Rot()); + vcg::Quaternion qfrom; qfrom.FromMatrix(from.Extrinsics.Rot()); tb.track.rot = vcg::Quaternionf::Construct(qfrom); tb.track.tra = (vcg::Point3f::Construct(-from.Extrinsics.Tra()));