Merge pull request #5042 from maxGimeno/Viewer-Zoom_to_rectangle

Viewer zoom to rectangle
This commit is contained in:
Laurent Rineau 2020-10-09 16:50:24 +02:00
commit 7a48e35ffe
5 changed files with 69 additions and 12 deletions

View File

@ -895,13 +895,17 @@ Vec Camera::pointUnderPixel(const QPoint &pixel, bool &found) const {
/*! Moves the Camera so that the entire scene is visible. /*! Moves the Camera so that the entire scene is visible.
Simply calls fitSphere() on a sphere defined by sceneCenter() and Calls fitSphere() on a sphere defined by sceneCenter() and
sceneRadius(). sceneRadius(), and resets the default FOV.
You will typically use this method in CGAL::QGLViewer::init() after you defined a new You will typically use this method in CGAL::QGLViewer::init() after you defined a new
sceneRadius(). */ sceneRadius(). */
CGAL_INLINE_FUNCTION CGAL_INLINE_FUNCTION
void Camera::showEntireScene() { fitSphere(sceneCenter(), sceneRadius()); } void Camera::showEntireScene()
{
setFieldOfView(CGAL_PI/4.0);
fitSphere(sceneCenter(), sceneRadius());
}
/*! Moves the Camera so that its sceneCenter() is projected on the center of the /*! Moves the Camera so that its sceneCenter() is projected on the center of the
window. The orientation() and fieldOfView() are unchanged. window. The orientation() and fieldOfView() are unchanged.
@ -2115,7 +2119,7 @@ void Camera::initFromDOMElement(const QDomElement &element) {
while (!child.isNull()) { while (!child.isNull()) {
if (child.tagName() == "Parameters") { if (child.tagName() == "Parameters") {
// #CONNECTION# Default values set in constructor // #CONNECTION# Default values set in constructor
setFieldOfView(DomUtils::qrealFromDom(child, "fieldOfView", CGAL_PI / 4.0)); //setFieldOfView(DomUtils::qrealFromDom(child, "fieldOfView", CGAL_PI / 4.0));
setZNearCoefficient( setZNearCoefficient(
DomUtils::qrealFromDom(child, "zNearCoefficient", 0.005)); DomUtils::qrealFromDom(child, "zNearCoefficient", 0.005));
setZClippingCoefficient( setZClippingCoefficient(

View File

@ -371,8 +371,7 @@ void ManipulatedCameraFrame::mouseMoveEvent(QMouseEvent *const event,
break; break;
} }
case ZOOM_ON_REGION: default:
case NO_MOUSE_ACTION:
break; break;
} }
@ -424,6 +423,23 @@ void ManipulatedCameraFrame::wheelEvent(QWheelEvent *const event,
inverseTransformOf(Vec(0.0, 0.0, 0.2 * flySpeed() * event->angleDelta().y()))); inverseTransformOf(Vec(0.0, 0.0, 0.2 * flySpeed() * event->angleDelta().y())));
Q_EMIT manipulated(); Q_EMIT manipulated();
break; break;
case ZOOM_FOV:
{
qreal delta = - wheelDelta(event);//- sign to keep the same behavior as for the ZOOM action.
qreal new_fov = delta/100 + camera->fieldOfView();
if(new_fov > CGAL_PI/180.0)
{
new_fov = delta + camera->fieldOfView();
}
if(new_fov > CGAL_PI/4.0)
new_fov = CGAL_PI/4.0;
if( new_fov >= 0.0)
{
camera->setFieldOfView(new_fov);
}
Q_EMIT manipulated();
break;
}
default: default:
break; break;
} }
@ -447,7 +463,10 @@ void ManipulatedCameraFrame::wheelEvent(QWheelEvent *const event,
// isManipulated() returns false. But then fastDraw would not be used with // isManipulated() returns false. But then fastDraw would not be used with
// wheel. Detecting the last wheel event and forcing a final draw() is done // wheel. Detecting the last wheel event and forcing a final draw() is done
// using the timer_. // using the timer_.
if(action_ != ZOOM_FOV)
action_ = NO_MOUSE_ACTION; action_ = NO_MOUSE_ACTION;
//else done after postDraw().
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -458,7 +458,7 @@ void ManipulatedFrame::mouseMoveEvent(QMouseEvent *const event,
// These MouseAction values make no sense for a manipulatedFrame // These MouseAction values make no sense for a manipulatedFrame
break; break;
case NO_MOUSE_ACTION: default:
// Possible when the ManipulatedFrame is a MouseGrabber. This method is then // Possible when the ManipulatedFrame is a MouseGrabber. This method is then
// called without startAction because of mouseTracking. // called without startAction because of mouseTracking.
break; break;

View File

@ -598,6 +598,33 @@ void CGAL::QGLViewer::postDraw() {
if (displayMessage_) if (displayMessage_)
drawText(10, height() - 10, message_); drawText(10, height() - 10, message_);
//zoom region
if(camera()->frame()->action_ == qglviewer::ZOOM_ON_REGION)
{
QPainter painter(this);
painter.setPen(QColor(120,120,120));
painter.drawRect(QRect(camera()->frame()->pressPos_, mapFromGlobal(QCursor::pos())));
painter.end();
}
//zoom_fov indicator
if(camera()->frame()->action_ == qglviewer::ZOOM_FOV)
{
QPainter painter(this);
QPoint bot(width()-30,height()/2-0.33*height()),
top(width()-30, height()/2+0.33*height());
int fov_height = (top.y()-bot.y())*camera()->fieldOfView()*4.0/CGAL_PI + bot.y();
painter.setPen(QColor(120,120,120));
painter.drawLine(bot, top);
painter.fillRect(QRect(QPoint(width()-40, fov_height+10),
QPoint(width()-20, fov_height-10)),
QColor(120,120,120));
painter.end();
camera()->frame()->action_= qglviewer::NO_MOUSE_ACTION;
}
} }
@ -732,6 +759,7 @@ void CGAL::QGLViewer::setDefaultMouseBindings() {
setWheelBinding(modifiers, mh, qglviewer::ZOOM); setWheelBinding(modifiers, mh, qglviewer::ZOOM);
} }
setWheelBinding(::Qt::Key_Z, ::Qt::NoModifier, qglviewer::CAMERA, qglviewer::ZOOM_FOV);
// Z o o m o n r e g i o n // Z o o m o n r e g i o n
setMouseBinding(::Qt::ShiftModifier, ::Qt::MidButton, qglviewer::CAMERA, qglviewer::ZOOM_ON_REGION); setMouseBinding(::Qt::ShiftModifier, ::Qt::MidButton, qglviewer::CAMERA, qglviewer::ZOOM_ON_REGION);
@ -753,6 +781,7 @@ void CGAL::QGLViewer::setDefaultMouseBindings() {
setMouseBinding(::Qt::Key_Z, ::Qt::NoModifier, ::Qt::LeftButton, qglviewer::ZOOM_ON_PIXEL); setMouseBinding(::Qt::Key_Z, ::Qt::NoModifier, ::Qt::LeftButton, qglviewer::ZOOM_ON_PIXEL);
setMouseBinding(::Qt::Key_Z, ::Qt::NoModifier, ::Qt::RightButton, qglviewer::ZOOM_TO_FIT); setMouseBinding(::Qt::Key_Z, ::Qt::NoModifier, ::Qt::RightButton, qglviewer::ZOOM_TO_FIT);
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
// Specific Mac bindings for touchpads. Two fingers emulate a wheelEvent which // Specific Mac bindings for touchpads. Two fingers emulate a wheelEvent which
// zooms. There is no right button available : make Option key + left emulate // zooms. There is no right button available : make Option key + left emulate
@ -1636,6 +1665,8 @@ QString CGAL::QGLViewer::mouseActionString(qglviewer::MouseAction ma) {
"SCREEN_TRANSLATE mouse action"); "SCREEN_TRANSLATE mouse action");
case CGAL::qglviewer::ZOOM_ON_REGION: case CGAL::qglviewer::ZOOM_ON_REGION:
return CGAL::QGLViewer::tr("Zooms on region for", "ZOOM_ON_REGION mouse action"); return CGAL::QGLViewer::tr("Zooms on region for", "ZOOM_ON_REGION mouse action");
case CGAL::qglviewer::ZOOM_FOV:
return CGAL::QGLViewer::tr("Changes the FOV to emulate an optical zoom for ", "ZOOM_FOV mouse action");
} }
return QString(); return QString();
} }
@ -2722,14 +2753,16 @@ void CGAL::QGLViewer::setWheelBinding(::Qt::Key key, ::Qt::KeyboardModifiers mod
bool withConstraint) { bool withConstraint) {
//#CONNECTION# ManipulatedFrame::wheelEvent and //#CONNECTION# ManipulatedFrame::wheelEvent and
// ManipulatedCameraFrame::wheelEvent switches // ManipulatedCameraFrame::wheelEvent switches
if ((action != qglviewer::ZOOM) && (action != qglviewer::MOVE_FORWARD) && if ((action != qglviewer::ZOOM) && (action != qglviewer::ZOOM_FOV) &&
(action != qglviewer::MOVE_BACKWARD) && (action != qglviewer::NO_MOUSE_ACTION)) { (action != qglviewer::MOVE_FORWARD) && (action != qglviewer::MOVE_BACKWARD)
&& (action != qglviewer::NO_MOUSE_ACTION)) {
qWarning("Cannot bind %s to wheel", qWarning("Cannot bind %s to wheel",
mouseActionString(action).toLatin1().constData()); mouseActionString(action).toLatin1().constData());
return; return;
} }
if ((handler == qglviewer::FRAME) && (action != qglviewer::ZOOM) && (action != qglviewer::NO_MOUSE_ACTION)) { if ((handler == qglviewer::FRAME) && (action != qglviewer::ZOOM)
&& (action != qglviewer::NO_MOUSE_ACTION)) {
qWarning("Cannot bind %s to FRAME wheel", qWarning("Cannot bind %s to FRAME wheel",
mouseActionString(action).toLatin1().constData()); mouseActionString(action).toLatin1().constData());
return; return;

View File

@ -79,7 +79,8 @@ enum MouseAction {
ROLL, ROLL,
DRIVE, DRIVE,
SCREEN_TRANSLATE, SCREEN_TRANSLATE,
ZOOM_ON_REGION ZOOM_ON_REGION,
ZOOM_FOV
}; };
enum SnapShotBackground { enum SnapShotBackground {