mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-09 23:16:00 -06:00
#2337 Window Edge axis overlay item working.
This commit is contained in:
parent
c3ea8f3415
commit
911571e267
@ -111,6 +111,7 @@ list( APPEND REFERENCED_CMAKE_FILES
|
||||
ModelVisualization/CMakeLists_files.cmake
|
||||
ModelVisualization/GridBox/CMakeLists_files.cmake
|
||||
ModelVisualization/Intersections/CMakeLists_files.cmake
|
||||
ModelVisualization/WindowEdgeAxesOverlayItem/CMakeLists_files.cmake
|
||||
|
||||
UserInterface/CMakeLists_files.cmake
|
||||
|
||||
|
@ -0,0 +1,24 @@
|
||||
|
||||
# Use this workaround until we're on 2.8.3 on all platforms and can use CMAKE_CURRENT_LIST_DIR directly
|
||||
if (${CMAKE_VERSION} VERSION_GREATER "2.8.2")
|
||||
set(CEE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}/)
|
||||
endif()
|
||||
|
||||
set (SOURCE_GROUP_HEADER_FILES
|
||||
${CEE_CURRENT_LIST_DIR}RivWindowEdgeAxesOverlayItem.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
${CEE_CURRENT_LIST_DIR}RivWindowEdgeAxesOverlayItem.cpp
|
||||
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
${SOURCE_GROUP_HEADER_FILES}
|
||||
)
|
||||
|
||||
list(APPEND CODE_SOURCE_FILES
|
||||
${SOURCE_GROUP_SOURCE_FILES}
|
||||
)
|
||||
|
||||
source_group( "ModelVisualization\\WindowEdgeAxesOverlayItem" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${CEE_CURRENT_LIST_DIR}CMakeLists_files.cmake )
|
@ -0,0 +1,480 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- Statoil ASA
|
||||
//
|
||||
// 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 "RivWindowEdgeAxesOverlayItem.h"
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfOpenGL.h"
|
||||
#include "cvfOpenGLResourceManager.h"
|
||||
#include "cvfGeometryBuilderDrawableGeo.h"
|
||||
#include "cvfGeometryUtils.h"
|
||||
#include "cvfViewport.h"
|
||||
#include "cvfCamera.h"
|
||||
#include "cvfTextDrawer.h"
|
||||
#include "cvfFont.h"
|
||||
#include "cvfShaderProgram.h"
|
||||
#include "cvfShaderProgramGenerator.h"
|
||||
#include "cvfShaderSourceProvider.h"
|
||||
#include "cvfShaderSourceRepository.h"
|
||||
#include "cvfUniform.h"
|
||||
#include "cvfMatrixState.h"
|
||||
#include "cvfBufferObjectManaged.h"
|
||||
#include "cvfGlyph.h"
|
||||
#include "cvfRenderStateDepth.h"
|
||||
#include "cvfRenderStateLine.h"
|
||||
|
||||
#ifndef CVF_OPENGL_ES
|
||||
#include "cvfRenderState_FF.h"
|
||||
#endif
|
||||
|
||||
#include "cvfScalarMapper.h"
|
||||
#include "cvfRenderStateBlending.h"
|
||||
#include "cvfScalarMapperDiscreteLinear.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
/// \class cvf::OverlayColorLegend
|
||||
/// \ingroup Render
|
||||
///
|
||||
///
|
||||
///
|
||||
//==================================================================================================
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Constructor
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RivWindowEdgeAxesOverlayItem::RivWindowEdgeAxesOverlayItem(Font* font)
|
||||
: m_windowSize(600, 600),
|
||||
m_textColor(Color3::BLACK),
|
||||
m_lineColor(Color3::BLACK),
|
||||
m_lineWidth(1),
|
||||
m_font(font),
|
||||
m_isSwitchingYAxisValueSign(true)
|
||||
{
|
||||
CVF_ASSERT(font);
|
||||
CVF_ASSERT(!font->isEmpty());
|
||||
|
||||
m_tickValues.reserve(3);
|
||||
m_tickValues.add(0.0);
|
||||
m_tickValues.add(0.5);
|
||||
m_tickValues.add(1.0);
|
||||
|
||||
setLayoutFixedPosition({0,0});
|
||||
updateGeomerySizes();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RivWindowEdgeAxesOverlayItem::~RivWindowEdgeAxesOverlayItem()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivWindowEdgeAxesOverlayItem::setDisplayCoordTransform(const caf::DisplayCoordTransform* displayCoordTransform)
|
||||
{
|
||||
m_dispalyCoordsTransform = displayCoordTransform;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivWindowEdgeAxesOverlayItem::updateGeomerySizes()
|
||||
{
|
||||
String str = String::number(99999.0);
|
||||
m_textSize = m_font->textExtent(str);
|
||||
m_pixelSpacing = 2.0f;
|
||||
m_tickLineLength = m_textSize.y() *0.3f;
|
||||
m_frameHeight = m_pixelSpacing + m_textSize.y() + m_pixelSpacing + m_tickLineLength + m_lineWidth;
|
||||
m_frameWidth = m_pixelSpacing + m_textSize.x() + m_pixelSpacing + m_tickLineLength + m_lineWidth;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivWindowEdgeAxesOverlayItem::updateFromCamera(const Camera* camera)
|
||||
{
|
||||
m_windowSize = Vec2ui( camera->viewport()->width(), camera->viewport()->height());
|
||||
Vec3d windowOrigoInDomain;
|
||||
Vec3d windowMaxInDomain;
|
||||
camera->unproject(Vec3d(0,0,0), &windowOrigoInDomain );
|
||||
camera->unproject(Vec3d(m_windowSize.x(),m_windowSize.y(),0), &windowMaxInDomain );
|
||||
|
||||
if (m_dispalyCoordsTransform.notNull())
|
||||
{
|
||||
windowOrigoInDomain = m_dispalyCoordsTransform->transformToDomainCoord(windowOrigoInDomain);
|
||||
windowMaxInDomain = m_dispalyCoordsTransform->transformToDomainCoord(windowMaxInDomain);
|
||||
}
|
||||
|
||||
double domainMinX = windowOrigoInDomain.x();
|
||||
double domainMaxX = windowMaxInDomain.x();
|
||||
|
||||
double domainMinY = windowOrigoInDomain.z();
|
||||
double domainMaxY = windowMaxInDomain.z();
|
||||
|
||||
int xTickMaxCount = m_windowSize.x()/(2*m_textSize.x());
|
||||
int yTickMaxCount = m_windowSize.y()/(2*m_textSize.x());
|
||||
|
||||
m_domainCoordsXValues.clear();
|
||||
cvf::ScalarMapperDiscreteLinear linDiscreteScalarMapper;
|
||||
linDiscreteScalarMapper.setRange(domainMinX, domainMaxX);
|
||||
linDiscreteScalarMapper.setLevelCount(xTickMaxCount, true);
|
||||
linDiscreteScalarMapper.majorTickValues(&m_domainCoordsXValues);
|
||||
|
||||
m_domainCoordsYValues.clear();
|
||||
linDiscreteScalarMapper.setRange(domainMinY, domainMaxY);
|
||||
linDiscreteScalarMapper.setLevelCount(yTickMaxCount, true);
|
||||
linDiscreteScalarMapper.majorTickValues(&m_domainCoordsYValues);
|
||||
|
||||
m_windowTickXValues.clear();
|
||||
Vec3d windowPoint;
|
||||
double domainYValue0 = m_domainCoordsYValues[0];
|
||||
for (double domainX : m_domainCoordsXValues)
|
||||
{
|
||||
Vec3d displayDomainTick(domainX, 0, domainYValue0);
|
||||
if ( m_dispalyCoordsTransform.notNull() )
|
||||
{
|
||||
displayDomainTick = m_dispalyCoordsTransform->transformToDisplayCoord(displayDomainTick);
|
||||
}
|
||||
camera->project(displayDomainTick, &windowPoint);
|
||||
m_windowTickXValues.push_back(windowPoint.x());
|
||||
}
|
||||
|
||||
m_windowTickYValues.clear();
|
||||
double domainXValue0 = m_domainCoordsXValues[0];
|
||||
for (double domainY : m_domainCoordsYValues)
|
||||
{
|
||||
Vec3d displayDomainTick(domainXValue0, 0, domainY);
|
||||
if ( m_dispalyCoordsTransform.notNull() )
|
||||
{
|
||||
displayDomainTick = m_dispalyCoordsTransform->transformToDisplayCoord(displayDomainTick);
|
||||
}
|
||||
camera->project(displayDomainTick, &windowPoint);
|
||||
m_windowTickYValues.push_back(windowPoint.y());
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Vec2ui RivWindowEdgeAxesOverlayItem::sizeHint()
|
||||
{
|
||||
return m_windowSize;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Set color of the text and lines to be rendered
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivWindowEdgeAxesOverlayItem::setTextColor(const Color3f& color)
|
||||
{
|
||||
m_textColor = color;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Returns the color of the text and lines
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const Color3f& RivWindowEdgeAxesOverlayItem::textColor() const
|
||||
{
|
||||
return m_textColor;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Hardware rendering using shader programs
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivWindowEdgeAxesOverlayItem::render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size)
|
||||
{
|
||||
render(oglContext, position, size, false);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Software rendering using software
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivWindowEdgeAxesOverlayItem::renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size)
|
||||
{
|
||||
render(oglContext, position, size, true);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RivWindowEdgeAxesOverlayItem::pick(int oglXCoord, int oglYCoord, const Vec2i& position, const Vec2ui& size)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Set up camera/viewport and render
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivWindowEdgeAxesOverlayItem::render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size, bool software)
|
||||
{
|
||||
if (size.x() <= 0 || size.y() <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Camera camera;
|
||||
camera.setViewport(position.x(), position.y(), size.x(), size.y());
|
||||
camera.setProjectionAsPixelExact2D();
|
||||
camera.setViewMatrix(Mat4d::IDENTITY);
|
||||
camera.applyOpenGL();
|
||||
camera.viewport()->applyOpenGL(oglContext, Viewport::CLEAR_DEPTH);
|
||||
|
||||
TextDrawer textDrawer(m_font.p());
|
||||
addTextToTextDrawer(&textDrawer);
|
||||
|
||||
renderLegendImmediateMode(oglContext);
|
||||
|
||||
if (software)
|
||||
{
|
||||
textDrawer.renderSoftware(oglContext, camera);
|
||||
}
|
||||
else
|
||||
{
|
||||
textDrawer.render(oglContext, camera);
|
||||
}
|
||||
|
||||
CVF_CHECK_OGL(oglContext);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivWindowEdgeAxesOverlayItem::addTextToTextDrawer(TextDrawer* textDrawer)
|
||||
{
|
||||
textDrawer->setVerticalAlignment(TextDrawer::CENTER);
|
||||
textDrawer->setTextColor(m_textColor);
|
||||
|
||||
// Bottom X - axis text
|
||||
{
|
||||
const float textY = m_pixelSpacing + m_textSize.y()*0.5f;
|
||||
size_t numTicks = m_domainCoordsXValues.size();
|
||||
size_t i;
|
||||
for ( i = 0; i < numTicks; i++ )
|
||||
{
|
||||
float textX = static_cast<float>(m_windowTickXValues[i]);
|
||||
|
||||
double tickValue = m_domainCoordsXValues[i];
|
||||
String valueString;
|
||||
|
||||
valueString = String::number(tickValue);
|
||||
auto labelSize = m_font->textExtent(valueString);
|
||||
|
||||
Vec2f pos(textX - labelSize.x()*0.5f, textY);
|
||||
textDrawer->addText(valueString, pos);
|
||||
}
|
||||
}
|
||||
|
||||
// Right Y - axis texts
|
||||
{
|
||||
const float textX = m_windowSize.x() - m_pixelSpacing - m_textSize.x();
|
||||
|
||||
size_t numTicks = m_domainCoordsYValues.size();
|
||||
size_t i;
|
||||
for ( i = 0; i < numTicks; i++ )
|
||||
{
|
||||
float textY = static_cast<float>(m_windowTickYValues[i]);
|
||||
|
||||
double tickValue = m_isSwitchingYAxisValueSign ? -m_domainCoordsYValues[i]: m_domainCoordsYValues[i];
|
||||
String valueString;
|
||||
|
||||
valueString = String::number(tickValue);
|
||||
auto labelSize = m_font->textExtent(valueString);
|
||||
|
||||
Vec2f pos(textX, textY);
|
||||
textDrawer->addText(valueString, pos);
|
||||
}
|
||||
}
|
||||
|
||||
// Left Y - axis texts
|
||||
{
|
||||
const float textX = m_frameWidth - m_tickLineLength - m_pixelSpacing;
|
||||
|
||||
size_t numTicks = m_domainCoordsYValues.size();
|
||||
size_t i;
|
||||
for ( i = 0; i < numTicks; i++ )
|
||||
{
|
||||
float textY = static_cast<float>(m_windowTickYValues[i]);
|
||||
|
||||
double tickValue = m_isSwitchingYAxisValueSign ? -m_domainCoordsYValues[i]: m_domainCoordsYValues[i];
|
||||
String valueString;
|
||||
|
||||
valueString = String::number(tickValue);
|
||||
auto labelSize = m_font->textExtent(valueString);
|
||||
|
||||
Vec2f pos(textX - labelSize.x(), textY);
|
||||
textDrawer->addText(valueString, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Draw the legend using immediate mode OpenGL
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivWindowEdgeAxesOverlayItem::renderLegendImmediateMode(OpenGLContext* oglContext)
|
||||
{
|
||||
RenderStateDepth depth(false);
|
||||
depth.applyOpenGL(oglContext);
|
||||
|
||||
RenderStateLighting_FF lighting(false);
|
||||
lighting.applyOpenGL(oglContext);
|
||||
|
||||
RenderStateBlending blend;
|
||||
blend.configureTransparencyBlending();
|
||||
blend.applyOpenGL(oglContext);
|
||||
|
||||
// Frame vertices
|
||||
|
||||
Vec3f v0(Vec3f::ZERO);
|
||||
Vec3f v1(Vec3f::ZERO);
|
||||
Vec3f v2(Vec3f::ZERO);
|
||||
Vec3f v3(Vec3f::ZERO);
|
||||
Vec3f v4(Vec3f::ZERO);
|
||||
Vec3f v5(Vec3f::ZERO);
|
||||
Vec3f v6(Vec3f::ZERO);
|
||||
Vec3f v7(Vec3f::ZERO);
|
||||
|
||||
v1[0] = static_cast<float>(m_windowSize.x());
|
||||
v2[0] = static_cast<float>(m_windowSize.x());
|
||||
v2[1] = static_cast<float>(m_windowSize.y());
|
||||
v3[1] = static_cast<float>(m_windowSize.y());
|
||||
|
||||
v4[0] = m_frameWidth;
|
||||
v4[1] = m_frameHeight;
|
||||
|
||||
v5[0] = v1[0] - m_frameWidth;
|
||||
v5[1] = m_frameHeight;
|
||||
|
||||
v6[0] = v2[0] - m_frameWidth;
|
||||
v6[1] = v2[1];
|
||||
|
||||
v7[0] = m_frameWidth;
|
||||
v7[1] = v3[1];
|
||||
|
||||
glColor4fv(Vec4f(1.0f,1.0f,1.0f,0.5f).ptr());
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
glVertex3fv(v0.ptr());
|
||||
glVertex3fv(v1.ptr());
|
||||
glVertex3fv(v5.ptr());
|
||||
glVertex3fv(v4.ptr());
|
||||
glEnd();
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
glVertex3fv(v1.ptr());
|
||||
glVertex3fv(v2.ptr());
|
||||
glVertex3fv(v6.ptr());
|
||||
glVertex3fv(v5.ptr());
|
||||
glEnd();
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
glVertex3fv(v3.ptr());
|
||||
glVertex3fv(v0.ptr());
|
||||
glVertex3fv(v4.ptr());
|
||||
glVertex3fv(v7.ptr());
|
||||
glEnd();
|
||||
|
||||
|
||||
// Render Line around
|
||||
|
||||
{
|
||||
glColor3fv(m_lineColor.ptr());
|
||||
glBegin(GL_LINES);
|
||||
// Frame lines
|
||||
glVertex3fv(v7.ptr());
|
||||
glVertex3fv(v4.ptr());
|
||||
glVertex3fv(v4.ptr());
|
||||
glVertex3fv(v5.ptr());
|
||||
glVertex3fv(v5.ptr());
|
||||
glVertex3fv(v6.ptr());
|
||||
|
||||
// X - axis Tick lines
|
||||
for (double txpos : m_windowTickXValues)
|
||||
{
|
||||
Vec3f p1(Vec3f::ZERO);
|
||||
Vec3f p2(Vec3f::ZERO);
|
||||
|
||||
p1[0] = (float)txpos;
|
||||
p1[1] = m_frameHeight;
|
||||
p2[0] = (float)txpos;
|
||||
p2[1] = m_frameHeight - m_tickLineLength;
|
||||
|
||||
glVertex3fv(p1.ptr());
|
||||
glVertex3fv(p2.ptr());
|
||||
}
|
||||
|
||||
// Left Y - axis Tick lines
|
||||
for (double typos : m_windowTickYValues)
|
||||
{
|
||||
Vec3f p1(Vec3f::ZERO);
|
||||
Vec3f p2(Vec3f::ZERO);
|
||||
|
||||
p1[0] = m_frameWidth;
|
||||
p1[1] = (float)typos;
|
||||
p2[0] = m_frameWidth - m_tickLineLength;
|
||||
p2[1] = (float)typos;
|
||||
|
||||
glVertex3fv(p1.ptr());
|
||||
glVertex3fv(p2.ptr());
|
||||
|
||||
p1[0] = m_windowSize.x() - m_frameWidth;
|
||||
p1[1] = (float)typos;
|
||||
p2[0] = m_windowSize.x() - m_frameWidth + m_tickLineLength;
|
||||
p2[1] = (float)typos;
|
||||
|
||||
glVertex3fv(p1.ptr());
|
||||
glVertex3fv(p2.ptr());
|
||||
}
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
// Reset render states
|
||||
|
||||
RenderStateLighting_FF resetLighting;
|
||||
resetLighting.applyOpenGL(oglContext);
|
||||
RenderStateDepth resetDepth;
|
||||
resetDepth.applyOpenGL(oglContext);
|
||||
RenderStateBlending resetblend;
|
||||
resetblend.applyOpenGL(oglContext);
|
||||
CVF_CHECK_OGL(oglContext);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivWindowEdgeAxesOverlayItem::setLineColor(const Color3f& lineColor)
|
||||
{
|
||||
m_lineColor = lineColor;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const Color3f& RivWindowEdgeAxesOverlayItem::lineColor() const
|
||||
{
|
||||
return m_lineColor;
|
||||
}
|
||||
|
@ -0,0 +1,130 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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.
|
||||
//
|
||||
// This library 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.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cvfOverlayItem.h"
|
||||
#include "cvfArray.h"
|
||||
#include "cvfCamera.h"
|
||||
#include "cvfString.h"
|
||||
#include "cvfRect.h"
|
||||
#include "cafDisplayCoordTransform.h"
|
||||
|
||||
namespace caf
|
||||
{
|
||||
class DisplayCoordTransform;
|
||||
}
|
||||
|
||||
namespace cvf
|
||||
{
|
||||
class Font;
|
||||
class ShaderProgram;
|
||||
class MatrixState;
|
||||
class TextDrawer;
|
||||
class ScalarMapper;
|
||||
}
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
// Overlay color legend
|
||||
//
|
||||
//==================================================================================================
|
||||
class RivWindowEdgeAxesOverlayItem : public cvf::OverlayItem
|
||||
{
|
||||
using Font = cvf::Font;
|
||||
using Vec2ui = cvf::Vec2ui;
|
||||
using ScalarMapper = cvf::ScalarMapper;
|
||||
using OpenGLContext = cvf::OpenGLContext;
|
||||
using Vec2i = cvf::Vec2i;
|
||||
using Color3f = cvf::Color3f;
|
||||
using String = cvf::String;
|
||||
using Vec2f = cvf::Vec2f;
|
||||
using Rectf = cvf::Rectf;
|
||||
using DoubleArray = cvf::DoubleArray;
|
||||
using MatrixState = cvf::MatrixState;
|
||||
using TextDrawer = cvf::TextDrawer;
|
||||
using Camera = cvf::Camera;
|
||||
public:
|
||||
RivWindowEdgeAxesOverlayItem(Font* font);
|
||||
virtual ~RivWindowEdgeAxesOverlayItem();
|
||||
|
||||
void setDisplayCoordTransform(const caf::DisplayCoordTransform* displayCoordTransform);
|
||||
void updateFromCamera(const Camera* camera);
|
||||
|
||||
void setTextColor(const Color3f& color);
|
||||
const Color3f& textColor() const;
|
||||
void setLineColor(const Color3f& lineColor);
|
||||
const Color3f& lineColor() const;
|
||||
|
||||
protected:
|
||||
virtual Vec2ui sizeHint();
|
||||
virtual void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size);
|
||||
virtual void renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size);
|
||||
virtual bool pick(int oglXCoord, int oglYCoord, const Vec2i& position, const Vec2ui& size);
|
||||
|
||||
protected:
|
||||
void updateGeomerySizes();
|
||||
void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size, bool software);
|
||||
void renderLegendImmediateMode(OpenGLContext* oglContext);
|
||||
void addTextToTextDrawer(TextDrawer* textDrawer);
|
||||
|
||||
protected:
|
||||
cvf::cref<caf::DisplayCoordTransform> m_dispalyCoordsTransform;
|
||||
|
||||
DoubleArray m_tickValues; // Ticks between each level + top and bottom of legend (n+1 entries)
|
||||
std::vector<bool> m_visibleTickLabels; // Skip tick labels ending up on top of previous visible label
|
||||
|
||||
Vec2ui m_windowSize; // Pixel size of the window
|
||||
Vec2ui m_textSize;
|
||||
Color3f m_textColor;
|
||||
Color3f m_lineColor;
|
||||
int m_lineWidth;
|
||||
cvf::ref<Font> m_font;
|
||||
|
||||
float m_frameHeight;
|
||||
float m_frameWidth;
|
||||
float m_tickLineLength;
|
||||
float m_pixelSpacing;
|
||||
bool m_isSwitchingYAxisValueSign;
|
||||
|
||||
std::vector<double> m_domainCoordsXValues;
|
||||
std::vector<double> m_domainCoordsYValues;
|
||||
std::vector<double> m_windowTickXValues;
|
||||
std::vector<double> m_windowTickYValues;
|
||||
};
|
||||
|
||||
|
@ -383,6 +383,7 @@ void Rim2dIntersectionView::resetLegendsInViewer()
|
||||
m_viewer->showAnimationProgress(true);
|
||||
m_viewer->showHistogram(false);
|
||||
m_viewer->showInfoText(false);
|
||||
m_viewer->showEdgeTickMarks(false);
|
||||
|
||||
m_viewer->setMainScene(new cvf::Scene());
|
||||
m_viewer->enableNavigationRotation(false);
|
||||
|
@ -59,6 +59,7 @@
|
||||
#include <QLabel>
|
||||
#include <QMouseEvent>
|
||||
#include <QProgressBar>
|
||||
#include "WindowEdgeAxesOverlayItem/RivWindowEdgeAxesOverlayItem.h"
|
||||
|
||||
using cvf::ManipulatorTrackball;
|
||||
|
||||
@ -175,6 +176,8 @@ RiuViewer::RiuViewer(const QGLFormat& format, QWidget* parent)
|
||||
m_gridBoxGenerator = new RivGridBoxGenerator;
|
||||
|
||||
m_cursorPositionDomainCoords = cvf::Vec3d::UNDEFINED;
|
||||
m_windowEdgeAxisOverlay = new RivWindowEdgeAxesOverlayItem(standardFont);
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -697,8 +700,9 @@ RimViewWindow* RiuViewer::ownerViewWindow() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuViewer::optimizeClippingPlanes()
|
||||
{
|
||||
m_windowEdgeAxisOverlay->setDisplayCoordTransform(m_rimView->displayCoordTransform().p());
|
||||
m_gridBoxGenerator->updateFromCamera(mainCamera());
|
||||
|
||||
m_windowEdgeAxisOverlay->updateFromCamera(this->mainCamera());
|
||||
caf::Viewer::optimizeClippingPlanes();
|
||||
}
|
||||
|
||||
@ -789,6 +793,19 @@ void RiuViewer::updateGridBoxData(double scaleZ,
|
||||
m_gridBoxGenerator->createGridBoxParts();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuViewer::showEdgeTickMarks(bool enable)
|
||||
{
|
||||
m_mainRendering->removeOverlayItem(m_windowEdgeAxisOverlay.p());
|
||||
|
||||
if (enable)
|
||||
{
|
||||
m_mainRendering->addOverlayItem(m_windowEdgeAxisOverlay.p());
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -36,6 +36,7 @@ class Rim3dView;
|
||||
class RiuSimpleHistogramWidget;
|
||||
class RiuViewerCommands;
|
||||
class RivGridBoxGenerator;
|
||||
class RivWindowEdgeAxesOverlayItem;
|
||||
|
||||
class QCDEStyle;
|
||||
class QLabel;
|
||||
@ -83,6 +84,7 @@ public:
|
||||
const cvf::Vec3d& displayModelOffset,
|
||||
const cvf::Color3f& backgroundColor,
|
||||
const cvf::BoundingBox& domainCoordBoundingBox);
|
||||
void showEdgeTickMarks(bool enable);
|
||||
|
||||
void updateAnnotationItems();
|
||||
|
||||
@ -155,6 +157,7 @@ private:
|
||||
RiuViewerCommands* m_viewerCommands;
|
||||
|
||||
RivGridBoxGenerator* m_gridBoxGenerator;
|
||||
cvf::ref<RivWindowEdgeAxesOverlayItem> m_windowEdgeAxisOverlay;
|
||||
|
||||
cvf::Vec3d m_cursorPositionDomainCoords;
|
||||
bool m_isNavigationRotationEnabled;
|
||||
|
Loading…
Reference in New Issue
Block a user