Added ternary saturation overlay item

This commit is contained in:
Magne Sjaastad 2014-04-07 13:18:39 +02:00
parent 7dda4d8437
commit 0e92bc5d3f
7 changed files with 307 additions and 1 deletions

View File

@ -11,6 +11,7 @@ ${CEE_CURRENT_LIST_DIR}RivFaultPartMgr.h
${CEE_CURRENT_LIST_DIR}RivFaultGeometryGenerator.h
${CEE_CURRENT_LIST_DIR}RivNNCGeometryGenerator.h
${CEE_CURRENT_LIST_DIR}RivGridPartMgr.h
${CEE_CURRENT_LIST_DIR}RivTernarySaturationOverlayItem.h
${CEE_CURRENT_LIST_DIR}RivReservoirPartMgr.h
${CEE_CURRENT_LIST_DIR}RivReservoirViewPartMgr.h
${CEE_CURRENT_LIST_DIR}RivPipeGeometryGenerator.h
@ -27,9 +28,10 @@ set (SOURCE_GROUP_SOURCE_FILES
${CEE_CURRENT_LIST_DIR}RivCellEdgeEffectGenerator.cpp
${CEE_CURRENT_LIST_DIR}RivColorTableArray.cpp
${CEE_CURRENT_LIST_DIR}RivFaultPartMgr.cpp
${CEE_CURRENT_LIST_DIR}RivFaultGeometryGenerator.cpp
${CEE_CURRENT_LIST_DIR}RivNNCGeometryGenerator.cpp
${CEE_CURRENT_LIST_DIR}RivFaultGeometryGenerator.cpp
${CEE_CURRENT_LIST_DIR}RivGridPartMgr.cpp
${CEE_CURRENT_LIST_DIR}RivTernarySaturationOverlayItem.cpp
${CEE_CURRENT_LIST_DIR}RivReservoirFaultsPartMgr.cpp
${CEE_CURRENT_LIST_DIR}RivReservoirPartMgr.cpp
${CEE_CURRENT_LIST_DIR}RivReservoirViewPartMgr.cpp

View File

@ -0,0 +1,200 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) Statoil ASA, Ceetron Solutions AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "cvfBase.h"
#include "RivTernarySaturationOverlayItem.h"
#include "cvfOpenGL.h"
#include "cvfViewport.h"
#include "cvfCamera.h"
#include "cvfTextDrawer.h"
#include "cvfFont.h"
#include "cvfMatrixState.h"
#include "cvfRenderState_FF.h"
#include "cvfRenderStateDepth.h"
#include "cvfRenderStatePolygonOffset.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RivTernarySaturationOverlayItem::RivTernarySaturationOverlayItem(cvf::Font* font)
: m_textColor(cvf::Color3::BLACK),
m_font(font),
m_size(100, 120)
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RivTernarySaturationOverlayItem::~RivTernarySaturationOverlayItem()
{
// Empty destructor to avoid errors with undefined types when cvf::ref's destructor gets called
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivTernarySaturationOverlayItem::setAxisLabelsColor(const cvf::Color3f& color)
{
m_textColor = color;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Vec2ui RivTernarySaturationOverlayItem::sizeHint()
{
return m_size;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivTernarySaturationOverlayItem::setSize(const cvf::Vec2ui& size)
{
m_size = size;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivTernarySaturationOverlayItem::render(cvf::OpenGLContext* oglContext, const cvf::Vec2i& position, const cvf::Vec2ui& size)
{
render(oglContext, position, size, false);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivTernarySaturationOverlayItem::renderSoftware(cvf::OpenGLContext* oglContext, const cvf::Vec2i& position, const cvf::Vec2ui& size)
{
render(oglContext, position, size, true);
}
//--------------------------------------------------------------------------------------------------
/// Set up camera/viewport and render
//--------------------------------------------------------------------------------------------------
void RivTernarySaturationOverlayItem::render(cvf::OpenGLContext* oglContext, const cvf::Vec2i& position, const cvf::Vec2ui& size, bool software)
{
if (size.x() <= 0 || size.y() <= 0)
{
return;
}
cvf::Camera camera;
camera.setViewport(position.x(), position.y(), size.x(), size.y());
camera.setProjectionAsPixelExact2D();
camera.setViewMatrix(cvf::Mat4d::IDENTITY);
camera.applyOpenGL();
camera.viewport()->applyOpenGL(oglContext, cvf::Viewport::CLEAR_DEPTH);
cvf::TextDrawer textDrawer(m_font.p());
textDrawer.setTextColor(m_textColor);
textDrawer.addText("SWAT", cvf::Vec2f(0.0, 0.0));
textDrawer.addText("SOIL", cvf::Vec2f(static_cast<float>(size.x() - 28), 0.0));
textDrawer.addText("SGAS", cvf::Vec2f(static_cast<float>( (size.x() / 2) - 17 ), static_cast<float>(size.y() - 10)));
textDrawer.renderSoftware(oglContext, camera);
renderAxisImmediateMode(oglContext);
CVF_CHECK_OGL(oglContext);
}
//--------------------------------------------------------------------------------------------------
/// Draw the axis using immediate mode OpenGL
//--------------------------------------------------------------------------------------------------
void RivTernarySaturationOverlayItem::renderAxisImmediateMode(cvf::OpenGLContext* oglContext)
{
#ifdef CVF_OPENGL_ES
CVF_UNUSED(layout);
CVF_FAIL_MSG("Not supported on OpenGL ES");
#else
cvf::RenderStateDepth depth(false);
depth.applyOpenGL(oglContext);
cvf::RenderStateLighting_FF lighting(false);
lighting.applyOpenGL(oglContext);
cvf::Color3ub colA(cvf::Color3::BLUE);
cvf::Color3ub colB(cvf::Color3::GREEN);
cvf::Color3ub colC(cvf::Color3::RED);
float lowerBoundY = 20;
float upperBoundY = static_cast<float>(m_size.y() - 20);
cvf::Vec3f a(0, lowerBoundY, 0);
cvf::Vec3f b(static_cast<float>(m_size.x()), lowerBoundY, 0);
cvf::Vec3f c(static_cast<float>(m_size.x() / 2), upperBoundY, 0);
// Draw filled rectangle elements
glBegin(GL_TRIANGLE_FAN);
glColor3ubv(colA.ptr());
glVertex3fv(a.ptr());
glColor3ubv(colB.ptr());
glVertex3fv(b.ptr());
glColor3ubv(colC.ptr());
glVertex3fv(c.ptr());
glVertex3fv(c.ptr());
glEnd();
// Lines
cvf::Color3ub linesColor(cvf::Color3::WHITE);
glColor3ubv(linesColor.ptr());
glBegin(GL_LINE_LOOP);
glVertex3fv(a.ptr());
glVertex3fv(b.ptr());
glVertex3fv(c.ptr());
glEnd();
cvf::RenderStateDepth resetDepth;
resetDepth.applyOpenGL(oglContext);
// Reset render states
cvf::RenderStateLighting_FF resetLighting;
resetLighting.applyOpenGL(oglContext);
CVF_CHECK_OGL(oglContext);
#endif // CVF_OPENGL_ES
}

View File

@ -0,0 +1,62 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) Statoil ASA, Ceetron Solutions AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cvfOverlayItem.h"
#include "cvfMatrix4.h"
#include "cvfColor3.h"
#include "cvfString.h"
namespace cvf {
class Font;
}
//==================================================================================================
//
//
//
//==================================================================================================
class RivTernarySaturationOverlayItem : public cvf::OverlayItem
{
public:
RivTernarySaturationOverlayItem(cvf::Font* font);
~RivTernarySaturationOverlayItem();
virtual cvf::Vec2ui sizeHint();
virtual void render(cvf::OpenGLContext* oglContext, const cvf::Vec2i& position, const cvf::Vec2ui& size);
virtual void renderSoftware(cvf::OpenGLContext* oglContext, const cvf::Vec2i& position, const cvf::Vec2ui& size);
void setSize(const cvf::Vec2ui& size);
void setAxisLabelsColor(const cvf::Color3f& color);
private:
void render(cvf::OpenGLContext* oglContext, const cvf::Vec2i& position, const cvf::Vec2ui& size, bool software);
void renderAxisImmediateMode(cvf::OpenGLContext* oglContext);
private:
cvf::Color3f m_textColor; // Text color
cvf::ref<cvf::Font> m_font;
cvf::Vec2ui m_size; // Pixel size of draw area
};

View File

@ -74,6 +74,7 @@
#include <limits.h>
#include "cafCeetronPlusNavigation.h"
#include "RimFaultCollection.h"
#include "RivTernarySaturationOverlayItem.h"
namespace caf {
@ -1445,6 +1446,23 @@ void RimReservoirView::updateLegends()
this->cellEdgeResult()->legendConfig->setClosestToZeroValues(0, 0, 0, 0);
this->cellEdgeResult()->legendConfig->setAutomaticRanges(cvf::UNDEFINED_DOUBLE, cvf::UNDEFINED_DOUBLE, cvf::UNDEFINED_DOUBLE, cvf::UNDEFINED_DOUBLE);
}
if (m_ternarySaturationOverlayItem.notNull())
{
viewer()->removeOverlayItem(m_ternarySaturationOverlayItem.p());
}
if (this->cellResult()->isTernarySaturationSelected())
{
if (m_ternarySaturationOverlayItem.isNull())
{
cvf::Font* standardFont = RiaApplication::instance()->standardFont();
m_ternarySaturationOverlayItem = new RivTernarySaturationOverlayItem(standardFont);
m_ternarySaturationOverlayItem->setLayout(cvf::OverlayItem::VERTICAL, cvf::OverlayItem::BOTTOM_LEFT);
}
viewer()->addOverlayItem(m_ternarySaturationOverlayItem.p());
}
}
//--------------------------------------------------------------------------------------------------

View File

@ -57,6 +57,7 @@ namespace cvf
class Transform;
class ScalarMapperUniformLevels;
class ModelBasicList;
class OverlayItem;
}
enum PartRenderMaskEnum
@ -200,6 +201,8 @@ private:
cvf::ref<RivReservoirViewPartMgr> m_reservoirGridPartManager;
cvf::ref<RivReservoirPipesPartMgr> m_pipesPartManager;
cvf::ref<cvf::OverlayItem> m_ternarySaturationOverlayItem;
// Overridden PDM methods:
public:
virtual caf::PdmFieldHandle* userDescriptionField() { return &name; }

View File

@ -742,3 +742,19 @@ void RiuViewer::mousePressEvent(QMouseEvent* event)
m_lastMousePressPosition = event->pos();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewer::addOverlayItem(cvf::OverlayItem* overlayItem)
{
m_renderingSequence->firstRendering()->addOverlayItem(overlayItem);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewer::removeOverlayItem(cvf::OverlayItem* overlayItem)
{
m_renderingSequence->firstRendering()->removeOverlayItem(overlayItem);
}

View File

@ -34,6 +34,7 @@ class QCDEStyle;
namespace cvf
{
class Part;
class OverlayItem;
}
//==================================================================================================
@ -64,6 +65,10 @@ public:
void setHistogramPercentiles(double pmin, double pmax, double mean);
void showAnimationProgress(bool enable);
void addOverlayItem(cvf::OverlayItem* overlayItem);
void removeOverlayItem(cvf::OverlayItem* overlayItem);
public slots:
virtual void slotSetCurrentFrame(int frameIndex);