From e96e859277b381c7b297ccb63bfde76b29c9834d Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 17 Sep 2015 12:31:56 +0200 Subject: [PATCH] (WIP) addition of camera positions --- .../Polyhedron/CGAL_demo/Viewer_interface.h | 1 + .../demo/Polyhedron/Camera_positions_list.cpp | 106 ++++++++++++++++++ .../demo/Polyhedron/Camera_positions_list.h | 4 +- ...olyhedron_demo_camera_positions_plugin.cpp | 5 +- Polyhedron/demo/Polyhedron/Scene.cpp | 2 +- Polyhedron/demo/Polyhedron/Scene.h | 1 + Polyhedron/demo/Polyhedron/Viewer.cpp | 12 ++ Polyhedron/demo/Polyhedron/Viewer.h | 3 +- 8 files changed, 130 insertions(+), 4 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/CGAL_demo/Viewer_interface.h b/Polyhedron/demo/Polyhedron/CGAL_demo/Viewer_interface.h index cb133b1054a..d11b7a00c5c 100644 --- a/Polyhedron/demo/Polyhedron/CGAL_demo/Viewer_interface.h +++ b/Polyhedron/demo/Polyhedron/CGAL_demo/Viewer_interface.h @@ -42,6 +42,7 @@ public: Q_SIGNALS: void selected(int); void requestContextMenu(QPoint global_pos); + void requestBasicPositions(Viewer_interface* viewer); void selectedPoint(double, double, double); void selectionRay(double, double, double, double, double, double); diff --git a/Polyhedron/demo/Polyhedron/Camera_positions_list.cpp b/Polyhedron/demo/Polyhedron/Camera_positions_list.cpp index 2175ad0a903..d7101e523b7 100644 --- a/Polyhedron/demo/Polyhedron/Camera_positions_list.cpp +++ b/Polyhedron/demo/Polyhedron/Camera_positions_list.cpp @@ -27,6 +27,8 @@ Camera_positions_list::Camera_positions_list(QWidget* parent) void Camera_positions_list::setViewer(Viewer_interface* viewer) { m_viewer = viewer; + connect(viewer, SIGNAL(requestBasicPositions(Viewer_interface*)), + this, SLOT(setBasicPositions(Viewer_interface*))); } void Camera_positions_list::on_plusButton_pressed() @@ -135,3 +137,107 @@ void Camera_positions_list::load(QString filename) { } } +void Camera_positions_list::setBasicPositions(Viewer_interface* viewer) +{ + qglviewer::Vec posFront = qglviewer::Vec(0,0,viewer->sceneRadius()/(sin (viewer->camera()->fieldOfView()/2))); + qglviewer::Quaternion dirFront; + dirFront.setAxisAngle(qglviewer::Vec(0,1,0),0); + QString frontCoord = QString("%1 %2 %3 %4 %5 %6 %7") + .arg(posFront[0]) + .arg(posFront[1]) + .arg(posFront[2]) + .arg(dirFront[0]) + .arg(dirFront[1]) + .arg(dirFront[2]) + .arg(dirFront[3]); + addItem(tr("Front"), + frontCoord); + qglviewer::Vec posBack = posFront; + posBack.z *= -1; + qglviewer::Quaternion dirBack = dirFront; + dirBack.setAxisAngle(qglviewer::Vec(0,1,0),M_PI); + + QString backCoord = QString("%1 %2 %3 %4 %5 %6 %7") + .arg(posBack[0]) + .arg(posBack[1]) + .arg(posBack[2]) + .arg(dirBack[0]) + .arg(dirBack[1]) + .arg(dirBack[2]) + .arg(dirBack[3]); + addItem(tr("Back"),backCoord); + + qglviewer::Vec posTop = posFront; + posTop.y = posTop.z; + posTop.z *= 0; + qglviewer::Quaternion dirTop = dirFront; + dirTop.setAxisAngle(qglviewer::Vec(1,0,0),-M_PI_2); + QString topCoord = QString("%1 %2 %3 %4 %5 %6 %7") + .arg(posTop[0]) + .arg(posTop[1]) + .arg(posTop[2]) + .arg(dirTop[0]) + .arg(dirTop[1]) + .arg(dirTop[2]) + .arg(dirTop[3]); + addItem(tr("Top"),topCoord); + qglviewer::Vec posBot = posTop; + posBot.y *= -1; + qglviewer::Quaternion dirBot = dirFront; + dirBot.setAxisAngle(qglviewer::Vec(1,0,0),M_PI_2); + QString botCoord= QString("%1 %2 %3 %4 %5 %6 %7") + .arg(posBot[0]) + .arg(posBot[1]) + .arg(posBot[2]) + .arg(dirBot[0]) + .arg(dirBot[1]) + .arg(dirBot[2]) + .arg(dirBot[3]); + addItem(tr("Bottom"),botCoord); + + qglviewer::Vec posRight = posFront; + posRight.x = posFront.z; + posRight.z *= 0; + qglviewer::Quaternion dirRight = dirFront; + dirRight.setAxisAngle(qglviewer::Vec(0,1,0),M_PI_2); + QString rightCoord = QString("%1 %2 %3 %4 %5 %6 %7") + .arg(posRight[0]) + .arg(posRight[1]) + .arg(posRight[2]) + .arg(dirRight[0]) + .arg(dirRight[1]) + .arg(dirRight[2]) + .arg(dirRight[3]); + addItem(tr("Right"),rightCoord); + + qglviewer::Vec posLeft = posRight; + posLeft.x *= -1; + qglviewer::Quaternion dirLeft = dirFront; + dirLeft.setAxisAngle(qglviewer::Vec(0,1,0),-M_PI_2); + QString leftCoord = QString("%1 %2 %3 %4 %5 %6 %7") + .arg(posLeft[0]) + .arg(posLeft[1]) + .arg(posLeft[2]) + .arg(dirLeft[0]) + .arg(dirLeft[1]) + .arg(dirLeft[2]) + .arg(dirLeft[3]); + addItem(tr("Left"),leftCoord); + insertItem(tr("Left"),leftCoord); + insertItem(tr("Right"),rightCoord); + insertItem(tr("Bottom"),botCoord); + insertItem(tr("Top"),topCoord); + insertItem(tr("Back"),backCoord); + insertItem(tr("Front"), frontCoord); + +} + +void Camera_positions_list::insertItem(QString text, QString data) +{ + QStandardItem* item = new QStandardItem(text); + + item->setData(data, Qt::UserRole); + m_model->insertRow(0, item); +} + + diff --git a/Polyhedron/demo/Polyhedron/Camera_positions_list.h b/Polyhedron/demo/Polyhedron/Camera_positions_list.h index 9739714187c..0485839dc4b 100644 --- a/Polyhedron/demo/Polyhedron/Camera_positions_list.h +++ b/Polyhedron/demo/Polyhedron/Camera_positions_list.h @@ -17,7 +17,9 @@ public: public Q_SLOTS: void load(QString filename); + void setBasicPositions(Viewer_interface*); protected Q_SLOTS: + void on_plusButton_pressed(); void on_minusButton_pressed(); void on_upButton_pressed(); @@ -25,7 +27,7 @@ protected Q_SLOTS: void on_openButton_pressed(); void on_saveButton_pressed(); void on_clearButton_pressed(); - + void insertItem(QString text, QString data); void activatedRow(QModelIndex index); protected: diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_camera_positions_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_camera_positions_plugin.cpp index b31f94c1373..2e296499c23 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_camera_positions_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_camera_positions_plugin.cpp @@ -36,8 +36,11 @@ private: void Polyhedron_demo_camera_positions_plugin::init(QMainWindow* mainWindow, Scene_interface*) { + cpl = new Camera_positions_list(mainWindow); - cpl->setViewer(mainWindow->findChild("viewer")); + Viewer_interface* viewer = mainWindow->findChild("viewer"); + cpl->setViewer(viewer); + cpl->setBasicPositions(viewer); mainWindow->addDockWidget(Qt::LeftDockWidgetArea, cpl); } diff --git a/Polyhedron/demo/Polyhedron/Scene.cpp b/Polyhedron/demo/Polyhedron/Scene.cpp index b4fdbdc3bc5..76cdabc7684 100644 --- a/Polyhedron/demo/Polyhedron/Scene.cpp +++ b/Polyhedron/demo/Polyhedron/Scene.cpp @@ -51,13 +51,13 @@ Scene::Scene(QObject* parent) Scene::Item_id Scene::addItem(Scene_item* item) { - Bbox bbox_before = bbox(); m_entries.push_back(item); connect(item, SIGNAL(itemChanged()), this, SLOT(itemChanged())); if(bbox_before + item->bbox() != bbox_before) { Q_EMIT updated_bbox(); } + Q_EMIT requestBasicPositions(); QAbstractListModel::beginResetModel(); Q_EMIT updated(); QAbstractListModel::endResetModel(); diff --git a/Polyhedron/demo/Polyhedron/Scene.h b/Polyhedron/demo/Polyhedron/Scene.h index 4f0f6817728..dd287f76e93 100644 --- a/Polyhedron/demo/Polyhedron/Scene.h +++ b/Polyhedron/demo/Polyhedron/Scene.h @@ -158,6 +158,7 @@ Q_SIGNALS: void itemAboutToBeDestroyed(Scene_item*); void selectionRay(double, double, double, double, double, double); void selectionChanged(int i); + void requestBasicPositions(); private Q_SLOTS: void setSelectionRay(double, double, double, double, double, double); diff --git a/Polyhedron/demo/Polyhedron/Viewer.cpp b/Polyhedron/demo/Polyhedron/Viewer.cpp index fee167b5b4c..65cf925a487 100644 --- a/Polyhedron/demo/Polyhedron/Viewer.cpp +++ b/Polyhedron/demo/Polyhedron/Viewer.cpp @@ -53,6 +53,7 @@ Viewer::Viewer(QWidget* parent, bool antialiasing) pickMatrix_[5]=1; pickMatrix_[10]=1; pickMatrix_[15]=1; + prev_radius = sceneRadius(); } Viewer::~Viewer() @@ -90,6 +91,7 @@ void Viewer::draw() { glEnable(GL_DEPTH_TEST); d->inFastDrawing = false; + testRadius(); QGLViewer::draw(); d->draw_aux(false, this); } @@ -97,6 +99,7 @@ void Viewer::draw() void Viewer::fastDraw() { d->inFastDrawing = true; + testRadius(); QGLViewer::fastDraw(); d->draw_aux(false, this); } @@ -374,3 +377,12 @@ void Viewer::endSelection(const QPoint& point) pickMatrix_[10]=1; pickMatrix_[15]=1; } + +void Viewer::testRadius() +{ + if(prev_radius != sceneRadius()) + { + Q_EMIT Viewer_interface::requestBasicPositions(this); + prev_radius = sceneRadius(); + } +} diff --git a/Polyhedron/demo/Polyhedron/Viewer.h b/Polyhedron/demo/Polyhedron/Viewer.h index e39f5b2dd43..f1bd4ca50d6 100644 --- a/Polyhedron/demo/Polyhedron/Viewer.h +++ b/Polyhedron/demo/Polyhedron/Viewer.h @@ -41,7 +41,6 @@ public Q_SLOTS: void setTwoSides(bool b); void turnCameraBy180Degres(); - QString dumpCameraCoordinates(); bool moveCameraToCoordinates(QString, float animation_duration = 0.5f); @@ -54,6 +53,8 @@ protected: protected: Viewer_impl* d; + double prev_radius; + void testRadius(); }; // end class Viewer #endif // VIEWER_H