Fixed clip plane related assert on linux. Hopefully the final fix of trouble related to : ca6e650a72 and 80985785 and 0128baddff

The fundamental problem was that the quad rendering was included in the boundingbox.
This commit is contained in:
Jacob Støren 2016-09-07 12:49:01 +02:00
parent cf8190cbf1
commit 1209c908e5
4 changed files with 26 additions and 39 deletions

View File

@ -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();

View File

@ -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));

View File

@ -113,8 +113,8 @@ cvf::ref<cvf::OpenGLContextGroup> 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;
}
//--------------------------------------------------------------------------------------------------

View File

@ -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<cvf::Camera> m_mainCamera;
cvf::ref<cvf::Rendering> 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: