ask the user whether to stop a rendering process when accidentally dragging the mouse in an ongoing rendering session

metadata
Wenzel Jakob 2014-01-14 00:46:14 +01:00
parent d432f51ae6
commit 31fc89690d
4 changed files with 46 additions and 5 deletions

View File

@ -98,6 +98,15 @@ public:
/// Get a pointer to the underlying scene (const version) /// Get a pointer to the underlying scene (const version)
inline const Scene *getScene() const { return m_scene.get(); } inline const Scene *getScene() const { return m_scene.get(); }
/// Get a pointer to the underlying render queue
inline RenderQueue *getRenderQueue() { return m_queue.get(); }
/// Get a pointer to the underlying render queue (const version)
inline const RenderQueue *getRenderQueue() const { return m_queue.get(); }
/// Return the amount of time spent rendering the given job (in seconds)
inline Float getRenderTime() const { return m_queue->getRenderTime(this); }
MTS_DECLARE_CLASS() MTS_DECLARE_CLASS()
protected: protected:
/// Virtual destructor /// Virtual destructor

View File

@ -362,12 +362,14 @@ void export_render() {
.staticmethod("loadScene"); .staticmethod("loadScene");
Scene *(RenderJob::*renderJob_getScene)(void) = &RenderJob::getScene; Scene *(RenderJob::*renderJob_getScene)(void) = &RenderJob::getScene;
RenderQueue *(RenderJob::*renderJob_getRenderQueue)(void) = &RenderJob::getRenderQueue;
BP_CLASS(RenderJob, Thread, (bp::init<const std::string &, Scene *, RenderQueue *>())) BP_CLASS(RenderJob, Thread, (bp::init<const std::string &, Scene *, RenderQueue *>()))
.def(bp::init<const std::string &, Scene *, RenderQueue *, int, bp::optional<int, int> >()) .def(bp::init<const std::string &, Scene *, RenderQueue *, int, bp::optional<int, int> >())
.def("flush", &RenderJob::flush) .def("flush", &RenderJob::flush)
.def("cancel", renderJob_cancel) .def("cancel", renderJob_cancel)
.def("wait", &RenderJob::wait) .def("wait", &RenderJob::wait)
.def("getScene", renderJob_getScene, BP_RETURN_VALUE); .def("getScene", renderJob_getScene, BP_RETURN_VALUE)
.def("getRenderQueue", renderJob_getRenderQueue, BP_RETURN_VALUE);
BP_CLASS(RenderQueue, Object, bp::init<>()) BP_CLASS(RenderQueue, Object, bp::init<>())
.def("getJobCount", &RenderQueue::getJobCount) .def("getJobCount", &RenderQueue::getJobCount)

View File

@ -386,13 +386,11 @@ void GLWidget::focusOutEvent(QFocusEvent *event) {
m_movementTimer->stop(); m_movementTimer->stop();
} }
void GLWidget::timerImpulse() { void GLWidget::timerImpulse() {
if (!m_context || !m_context->scene || !m_preview->isRunning()) { if (!m_context || !m_context->scene || !m_preview->isRunning()) {
m_movementTimer->stop(); m_movementTimer->stop();
return; return;
} }
if (m_animation) { if (m_animation) {
Float x = std::min(m_animationTimer->getMilliseconds() / 500.0f, 1.0f); Float x = std::min(m_animationTimer->getMilliseconds() / 500.0f, 1.0f);
Float t = x*x*x*(x*(x*6-15)+10); // smootherstep by Ken Perlin Float t = x*x*x*(x*(x*6-15)+10); // smootherstep by Ken Perlin
@ -453,6 +451,23 @@ void GLWidget::timerImpulse() {
resetPreview(); resetPreview();
} }
bool GLWidget::askReallyCancelRendering() {
try {
Float renderTime = m_context->renderJob->getRenderTime();
if (renderTime < 10) /* Only ask for jobs that have been rendering for a bit */
return true;
} catch (...) {
return true;
}
bool cancel = QMessageBox::question(this,
"Really cancel rendering?", "Camera motion detected. Do you really want to cancel the rendering?",
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes;
return cancel;
}
void GLWidget::resetPreview() { void GLWidget::resetPreview() {
if (!m_context || !m_context->scene || !m_preview->isRunning()) if (!m_context || !m_context->scene || !m_preview->isRunning())
return; return;
@ -543,6 +558,12 @@ void GLWidget::keyPressEvent(QKeyEvent *event) {
} }
if (!m_movementTimer->isActive() && (m_leftKeyDown || m_rightKeyDown if (!m_movementTimer->isActive() && (m_leftKeyDown || m_rightKeyDown
|| m_upKeyDown || m_downKeyDown)) { || m_upKeyDown || m_downKeyDown)) {
if (m_context->renderJob && !askReallyCancelRendering()) {
m_leftKeyDown = m_rightKeyDown = m_upKeyDown = m_downKeyDown = false;
return;
}
m_clock->reset(); m_clock->reset();
m_movementTimer->start(); m_movementTimer->start();
} }
@ -615,6 +636,12 @@ void GLWidget::mouseMoveEvent(QMouseEvent *event) {
nearClip = camera->getNearClip(), nearClip = camera->getNearClip(),
farClip = camera->getFarClip(); farClip = camera->getFarClip();
bool setCursor = true;
if (m_context->renderJob) {
if (!askReallyCancelRendering())
return;
setCursor = false;
}
if (focusDistance <= nearClip || focusDistance >= farClip) { if (focusDistance <= nearClip || focusDistance >= farClip) {
focusDistance = autoFocus(); focusDistance = autoFocus();
camera->setFocusDistance(focusDistance); camera->setFocusDistance(focusDistance);
@ -623,7 +650,7 @@ void GLWidget::mouseMoveEvent(QMouseEvent *event) {
Point target = p + d * focusDistance; Point target = p + d * focusDistance;
Vector up = m_context->up; Vector up = m_context->up;
if (!m_didSetCursor) { if (!m_didSetCursor && setCursor) {
QApplication::setOverrideCursor(Qt::BlankCursor); QApplication::setOverrideCursor(Qt::BlankCursor);
m_didSetCursor = true; m_didSetCursor = true;
} }
@ -828,11 +855,13 @@ void GLWidget::wheelEvent(QWheelEvent *event) {
} else { } else {
if (!m_preview->isRunning() || m_context == NULL || m_context->scene == NULL || m_animation) if (!m_preview->isRunning() || m_context == NULL || m_context->scene == NULL || m_animation)
return; return;
PerspectiveCamera *camera = getPerspectiveCamera(); PerspectiveCamera *camera = getPerspectiveCamera();
if (!camera) if (!camera)
return; return;
if (m_context->renderJob && !askReallyCancelRendering())
return;
Float focusDistance = camera->getFocusDistance(), Float focusDistance = camera->getFocusDistance(),
nearClip = camera->getNearClip(), nearClip = camera->getNearClip(),
farClip = camera->getFarClip(); farClip = camera->getFarClip();

View File

@ -127,6 +127,7 @@ protected:
Point2i upperLeft(bool flipY = false) const; Point2i upperLeft(bool flipY = false) const;
void reveal(const AABB &aabb); void reveal(const AABB &aabb);
Float autoFocus() const; Float autoFocus() const;
bool askReallyCancelRendering();
inline ProjectiveCamera *getProjectiveCamera() { inline ProjectiveCamera *getProjectiveCamera() {
Sensor *sensor = m_context->scene->getSensor(); Sensor *sensor = m_context->scene->getSensor();