From 1209c908e58ebe82147e358ca83c3f3f96b30290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Wed, 7 Sep 2016 12:49:01 +0200 Subject: [PATCH] Fixed clip plane related assert on linux. Hopefully the final fix of trouble related to : ca6e650a72 and 80985785 and 0128baddff5 The fundamental problem was that the quad rendering was included in the boundingbox. --- ApplicationCode/ProjectDataModel/RimView.cpp | 2 +- ApplicationCode/UserInterface/RiuViewer.cpp | 2 +- Fwk/AppFwk/cafViewer/cafViewer.cpp | 53 ++++++++------------ Fwk/AppFwk/cafViewer/cafViewer.h | 8 +-- 4 files changed, 26 insertions(+), 39 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/RimView.cpp b/ApplicationCode/ProjectDataModel/RimView.cpp index 51045223d3..79c3b7a553 100644 --- a/ApplicationCode/ProjectDataModel/RimView.cpp +++ b/ApplicationCode/ProjectDataModel/RimView.cpp @@ -207,7 +207,7 @@ void RimView::updateViewerWidget() m_viewer->setOwnerReservoirView(this); RiuMainWindow::instance()->addViewer(m_viewer->layoutWidget(), mdiWindowGeometry()); - m_viewer->setMinNearPlaneDistance(10); + m_viewer->setDefaultPerspectiveNearPlaneDistance(10); this->resetLegendsInViewer(); diff --git a/ApplicationCode/UserInterface/RiuViewer.cpp b/ApplicationCode/UserInterface/RiuViewer.cpp index 67c9ecd8ef..68c5f9a209 100644 --- a/ApplicationCode/UserInterface/RiuViewer.cpp +++ b/ApplicationCode/UserInterface/RiuViewer.cpp @@ -198,7 +198,7 @@ RiuViewer::~RiuViewer() //-------------------------------------------------------------------------------------------------- void RiuViewer::setDefaultView() { - cvf::BoundingBox bb = m_renderingSequence->boundingBox(); + cvf::BoundingBox bb = m_mainRendering->boundingBox(); if (!bb.isValid()) { bb.add(cvf::Vec3d(-1, -1, -1)); diff --git a/Fwk/AppFwk/cafViewer/cafViewer.cpp b/Fwk/AppFwk/cafViewer/cafViewer.cpp index 6971ef9f09..5f470f19b4 100644 --- a/Fwk/AppFwk/cafViewer/cafViewer.cpp +++ b/Fwk/AppFwk/cafViewer/cafViewer.cpp @@ -113,8 +113,8 @@ cvf::ref caf::Viewer::sm_openGLContextGroup; caf::Viewer::Viewer(const QGLFormat& format, QWidget* parent) : caf::OpenGLWidget(contextGroup(), format, new QWidget(parent), sharedWidget()), m_navigationPolicy(NULL), - m_minNearPlaneDistance(0.05), - m_maxFarPlaneDistance(cvf::UNDEFINED_DOUBLE), + m_defaultPerspectiveNearPlaneDistance(0.05), + m_maxClipPlaneDistance(cvf::UNDEFINED_DOUBLE), m_cameraFieldOfViewYDeg(40.0), m_releaseOGLResourcesEachFrame(false), m_paintCounter(0), @@ -334,10 +334,10 @@ bool caf::Viewer::canRender() const //-------------------------------------------------------------------------------------------------- void caf::Viewer::optimizeClippingPlanes() { - cvf::BoundingBox bb = m_renderingSequence->boundingBox(); + cvf::BoundingBox bb = m_mainRendering->boundingBox(); if (!bb.isValid()) return; - cvf::Vec3d eye = m_mainCamera->position(); + cvf::Vec3d eye = m_mainCamera->position(); cvf::Vec3d viewdir = m_mainCamera->direction(); cvf::Vec3d bboxCorners[8]; @@ -362,7 +362,7 @@ void caf::Viewer::optimizeClippingPlanes() } } - double farPlaneDist = CVF_MIN(maxDistEyeToCornerAlongViewDir * 1.2, m_maxFarPlaneDistance); + double farPlaneDist = CVF_MIN(maxDistEyeToCornerAlongViewDir * 1.2, m_maxClipPlaneDistance); // Near-plane: @@ -373,49 +373,36 @@ void caf::Viewer::optimizeClippingPlanes() if (m_mainCamera->projection() == cvf::Camera::PERSPECTIVE || isOrthoNearPlaneFollowingCamera) { - nearPlaneDist = CVF_MAX( m_minNearPlaneDistance, minDistEyeToCornerAlongViewDir); - if (m_navigationPolicy.notNull() && m_navigationPolicyEnabled) + // Choose the one furthest from the camera of: 0.8*bbox distance, m_minPerspectiveNearPlaneDistance. + nearPlaneDist = CVF_MAX( m_defaultPerspectiveNearPlaneDistance, 0.8*minDistEyeToCornerAlongViewDir); + + // If we are zooming into a detail, allow the near-plane to move towards camera beyond the m_minPerspectiveNearPlaneDistance + if ( nearPlaneDist == m_defaultPerspectiveNearPlaneDistance // We are inside the bounding box + && m_navigationPolicy.notNull() && m_navigationPolicyEnabled) { double pointOfInterestDist = (eye - m_navigationPolicy->pointOfInterest()).length(); nearPlaneDist = CVF_MIN(nearPlaneDist, pointOfInterestDist*0.2); } + + // Guard against the zero nearplane possibility + if (nearPlaneDist <= 0) nearPlaneDist = m_defaultPerspectiveNearPlaneDistance; } else // Orthographic projection. Set to encapsulate the complete boundingbox, possibly setting a negative nearplane { if(minDistEyeToCornerAlongViewDir >= 0) { - nearPlaneDist = CVF_MIN(0.8 * minDistEyeToCornerAlongViewDir, m_maxFarPlaneDistance); + nearPlaneDist = CVF_MIN(0.8 * minDistEyeToCornerAlongViewDir, m_maxClipPlaneDistance); } else { - nearPlaneDist = CVF_MAX(1.2 * minDistEyeToCornerAlongViewDir, -m_maxFarPlaneDistance); + nearPlaneDist = CVF_MAX(1.2 * minDistEyeToCornerAlongViewDir, -m_maxClipPlaneDistance); } } -#if 0 - double distEyeBoxCenterAlongViewDir = (bb.center() - eye)*viewdir; - - double farPlaneDist = distEyeBoxCenterAlongViewDir + bb.radius() * 1.2; - farPlaneDist = CVF_MIN(farPlaneDist, m_maxFarPlaneDistance); - - double nearPlaneDist = distEyeBoxCenterAlongViewDir - bb.radius(); - if (nearPlaneDist < m_minNearPlaneDistance) nearPlaneDist = m_minNearPlaneDistance; - if (m_navigationPolicy.notNull() && m_navigationPolicyEnabled) - { - double pointOfInterestDist = (eye - m_navigationPolicy->pointOfInterest()).length(); - nearPlaneDist = CVF_MIN(nearPlaneDist, pointOfInterestDist*0.2); - } -#endif - - if (farPlaneDist <= nearPlaneDist) farPlaneDist = nearPlaneDist + 1.0; if (m_mainCamera->projection() == cvf::Camera::PERSPECTIVE) { - // TODO: Investigate why this is needed on Linux - // When loading grid files on Linux, the nearPlaneDist results in 0 at this point - nearPlaneDist = CVF_MAX(m_minNearPlaneDistance, nearPlaneDist); - m_mainCamera->setProjectionAsPerspective(m_cameraFieldOfViewYDeg, nearPlaneDist, farPlaneDist); } else @@ -629,17 +616,17 @@ void caf::Viewer::paintEvent(QPaintEvent* event) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void caf::Viewer::setMinNearPlaneDistance(double dist) +void caf::Viewer::setDefaultPerspectiveNearPlaneDistance(double dist) { - m_minNearPlaneDistance = dist; + m_defaultPerspectiveNearPlaneDistance = dist; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void caf::Viewer::setMaxFarPlaneDistance(double dist) +void caf::Viewer::setMaxClipPlaneDistance(double dist) { - m_maxFarPlaneDistance = dist; + m_maxClipPlaneDistance = dist; } //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/AppFwk/cafViewer/cafViewer.h b/Fwk/AppFwk/cafViewer/cafViewer.h index fdbc200b78..38dad95e5b 100644 --- a/Fwk/AppFwk/cafViewer/cafViewer.h +++ b/Fwk/AppFwk/cafViewer/cafViewer.h @@ -129,8 +129,8 @@ public: virtual void navigationPolicyUpdate(); // Min max near far plane. - void setMinNearPlaneDistance(double dist); - void setMaxFarPlaneDistance(double dist); + void setDefaultPerspectiveNearPlaneDistance(double dist); + void setMaxClipPlaneDistance(double dist); // Test whether it is any point in doing navigation etc. bool canRender() const; @@ -183,8 +183,8 @@ protected: cvf::ref m_mainCamera; cvf::ref m_mainRendering; - double m_minNearPlaneDistance; - double m_maxFarPlaneDistance; + double m_defaultPerspectiveNearPlaneDistance; + double m_maxClipPlaneDistance; //< Max far plane distance and max negative near plane distance in orthographic projection double m_cameraFieldOfViewYDeg; private: