mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Change 18603 on 2012/09/11 by fredrik@fredrik_MBP-BootCamp
Added glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT); to get proper orientation of textures on point sprites
This commit is contained in:
@@ -34,6 +34,8 @@
|
||||
#include "cafFrameAnimationControl.h"
|
||||
#include "cafNavigationPolicy.h"
|
||||
#include "cafEffectGenerator.h"
|
||||
#include "RiuSimpleHistogramWidget.h"
|
||||
|
||||
|
||||
using cvf::ManipulatorTrackball;
|
||||
|
||||
@@ -61,6 +63,47 @@ RIViewer::RIViewer(const QGLFormat& format, QWidget* parent)
|
||||
m_mainRendering->addOverlayItem(axisCross, cvf::OverlayItem::BOTTOM_LEFT, cvf::OverlayItem::VERTICAL);
|
||||
|
||||
setReleaseOGLResourcesEachFrame(true);
|
||||
|
||||
QColor c;
|
||||
QPalette p = QApplication::palette();
|
||||
QColor frameAndTextColor(255, 255, 255, 200);
|
||||
p.setColor(QPalette::Window, QColor(144, 173, 208, 180));
|
||||
p.setColor(QPalette::WindowText, frameAndTextColor);
|
||||
|
||||
c = p.color(QPalette::Base );
|
||||
c.setAlpha(100);
|
||||
p.setColor(QPalette::Base, c);
|
||||
|
||||
//c = p.color(QPalette::AlternateBase );
|
||||
//c.setAlpha(0);
|
||||
//p.setColor(QPalette::AlternateBase, c);
|
||||
|
||||
|
||||
p.setColor(QPalette::Highlight, QColor(20, 20, 130, 100));
|
||||
|
||||
p.setColor(QPalette::HighlightedText, frameAndTextColor);
|
||||
|
||||
p.setColor(QPalette::Dark, QColor(230, 250, 255, 100));
|
||||
|
||||
// Info Text
|
||||
m_InfoLabel = new QLabel();
|
||||
m_InfoLabel->setPalette(p);
|
||||
m_InfoLabel->setFrameShape(QFrame::Box);
|
||||
m_showInfoText = true;
|
||||
|
||||
// Animation progress bar
|
||||
m_animationProgress = new QProgressBar();
|
||||
m_animationProgress->setPalette(p);
|
||||
m_animationProgress->setFormat("Time Step: %v/%m");
|
||||
m_animationProgress->setTextVisible(true);
|
||||
m_animationProgress->setStyle(new QCDEStyle());
|
||||
m_showAnimProgress = false;
|
||||
|
||||
// Histogram
|
||||
m_histogramWidget = new RiuSimpleHistogramWidget();
|
||||
m_histogramWidget->setPalette(p);
|
||||
m_showHistogram = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -356,3 +399,95 @@ cvf::Part* RIViewer::pickPointAndFace(int winPosX, int winPosY, uint* faceHit, c
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RIViewer::paintOverlayItems(QPainter* painter)
|
||||
{
|
||||
int columnWidth = 200;
|
||||
int margin = 5;
|
||||
int yPos = margin;
|
||||
|
||||
bool showAnimBar = false;
|
||||
if (isAnimationActive() && frameCount() > 1) showAnimBar = true;
|
||||
|
||||
//if (showAnimBar) columnWidth = CVF_MAX(columnWidth, m_animationProgress->width());
|
||||
if (m_showInfoText) columnWidth = CVF_MAX(columnWidth, m_InfoLabel->sizeHint().width());
|
||||
|
||||
int columnPos = this->width() - columnWidth - margin;
|
||||
|
||||
if (showAnimBar && m_showAnimProgress)
|
||||
{
|
||||
m_animationProgress->setMinimum(0);
|
||||
m_animationProgress->setMaximum(frameCount() - 1);
|
||||
m_animationProgress->setValue(currentFrameIndex());
|
||||
m_animationProgress->resize(columnWidth, m_animationProgress->sizeHint().height());
|
||||
|
||||
m_animationProgress->render(painter,QPoint(columnPos, yPos));
|
||||
yPos += m_animationProgress->height() + margin;
|
||||
|
||||
}
|
||||
|
||||
if (m_showInfoText)
|
||||
{
|
||||
m_InfoLabel->resize(columnWidth, m_InfoLabel->sizeHint().height());
|
||||
m_InfoLabel->render(painter, QPoint(columnPos, yPos));
|
||||
yPos += m_InfoLabel->height() + margin;
|
||||
}
|
||||
|
||||
if (m_showHistogram)
|
||||
{
|
||||
m_histogramWidget->resize(columnWidth, 40);
|
||||
m_histogramWidget->render(painter,QPoint(columnPos, yPos));
|
||||
yPos += m_InfoLabel->height() + margin;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RIViewer::setInfoText(QString text)
|
||||
{
|
||||
m_InfoLabel->setText(text);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RIViewer::showInfoText(bool enable)
|
||||
{
|
||||
m_showInfoText = enable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RIViewer::setHistogram(double min, double max, const std::vector<size_t>& histogram)
|
||||
{
|
||||
m_histogramWidget->setHistogramData(min, max, histogram);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RIViewer::setHistogramPercentiles(double pmin, double pmax)
|
||||
{
|
||||
m_histogramWidget->setPercentiles(pmin, pmax);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RIViewer::showAnimationProgress(bool enable)
|
||||
{
|
||||
m_showAnimProgress = enable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RIViewer::showHistogram(bool enable)
|
||||
{
|
||||
m_showHistogram = enable;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@
|
||||
#include "cafMouseState.h"
|
||||
|
||||
class RimReservoirView;
|
||||
class QLabel;
|
||||
class QProgressBar;
|
||||
class RiuSimpleHistogramWidget;
|
||||
|
||||
namespace cvf
|
||||
{
|
||||
@@ -52,12 +55,21 @@ public:
|
||||
void setPointOfInterest(cvf::Vec3d poi);
|
||||
void setOwnerReservoirView(RimReservoirView * owner);
|
||||
void setEnableMask(unsigned int mask);
|
||||
|
||||
void showInfoText(bool enable);
|
||||
void setInfoText(QString text);
|
||||
void showHistogram(bool enable);
|
||||
void setHistogram(double min, double max, const std::vector<size_t>& histogram);
|
||||
void setHistogramPercentiles(double pmin, double pmax);
|
||||
|
||||
void showAnimationProgress(bool enable);
|
||||
|
||||
public slots:
|
||||
virtual void slotSetCurrentFrame(int frameIndex);
|
||||
virtual void slotEndAnimation();
|
||||
|
||||
protected:
|
||||
void paintOverlayItems(QPainter* painter);
|
||||
void keyPressEvent(QKeyEvent* event);
|
||||
void mouseReleaseEvent(QMouseEvent* event);
|
||||
|
||||
@@ -68,6 +80,16 @@ private:
|
||||
void updateLegends();
|
||||
caf::QtMouseState m_mouseState;
|
||||
|
||||
QLabel* m_InfoLabel;
|
||||
bool m_showInfoText;;
|
||||
|
||||
QProgressBar* m_animationProgress;
|
||||
bool m_showAnimProgress;
|
||||
RiuSimpleHistogramWidget* m_histogramWidget;
|
||||
bool m_showHistogram;
|
||||
|
||||
|
||||
|
||||
cvf::ref<cvf::OverlayColorLegend> m_legend1;
|
||||
cvf::ref<cvf::OverlayColorLegend> m_legend2;
|
||||
|
||||
|
||||
97
ApplicationCode/UserInterface/RiuSimpleHistogramWidget.cpp
Normal file
97
ApplicationCode/UserInterface/RiuSimpleHistogramWidget.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
#include "RiuSimpleHistogramWidget.h"
|
||||
#include <QPainter>
|
||||
#include <cmath>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuSimpleHistogramWidget::RiuSimpleHistogramWidget(QWidget * parent /*= 0*/, Qt::WindowFlags f /*= 0*/):
|
||||
QWidget(parent, f)
|
||||
{
|
||||
m_minPercentile = HUGE_VAL;
|
||||
m_maxPercentile = HUGE_VAL;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuSimpleHistogramWidget::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
QPainter painter(this);
|
||||
this->draw(&painter, 0, 0, this->width()-1, this->height()-1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RiuSimpleHistogramWidget::draw(QPainter *painter,int x, int y, int width, int height )
|
||||
{
|
||||
|
||||
// Initialize variables
|
||||
m_x = x; m_y = y; m_width = width; m_height = height;
|
||||
|
||||
QRect r1(x,y,width, height);
|
||||
|
||||
// Frame around it all;
|
||||
QColor windowColor = palette().color(QPalette::Window);// QColor(144, 173, 208, 180);
|
||||
QColor frameColor = palette().color(QPalette::WindowText);//QColor(220, 240, 255, 100);
|
||||
QColor foregroundColor = palette().color(QPalette::Dark);// QColor(100, 141, 189);
|
||||
|
||||
//painter->fillRect(r1, windowColor);
|
||||
painter->setPen(frameColor);
|
||||
painter->drawRect(r1);
|
||||
|
||||
// Columns
|
||||
painter->setPen(foregroundColor);
|
||||
|
||||
int yColBottom = yPosFromCount(0);
|
||||
|
||||
for ( size_t colIdx = 0; colIdx < m_histogramData.size(); ++colIdx)
|
||||
{
|
||||
size_t colCount = m_histogramData[colIdx];
|
||||
int yColTop = yPosFromCount(colCount);
|
||||
int xColStart = xPosFromColIdx(colIdx);
|
||||
int xColEnd = xPosFromColIdx(colIdx+1);
|
||||
|
||||
// First line
|
||||
painter->drawLine(xColStart, yColBottom, xColStart, yColTop);
|
||||
// If we span more than one pixel with :
|
||||
++xColStart;
|
||||
for (;xColStart < xColEnd; ++xColStart )
|
||||
{
|
||||
painter->drawLine(xColStart, yColBottom, xColStart, yColTop);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Vertical lines for percentiles
|
||||
if (m_minPercentile != HUGE_VAL)
|
||||
{
|
||||
int xpos = xPosFromDomainValue(m_minPercentile);
|
||||
painter->setPen(QColor(255, 0, 0, 200));
|
||||
painter->drawLine(xpos, y+1, xpos, y + height -1);
|
||||
}
|
||||
|
||||
// Vertical lines for percentiles
|
||||
if (m_maxPercentile != HUGE_VAL)
|
||||
{
|
||||
int xpos = xPosFromDomainValue(m_maxPercentile);
|
||||
painter->setPen(QColor(255, 0, 0, 200));
|
||||
painter->drawLine(xpos, y+1, xpos, y + height -1);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuSimpleHistogramWidget::setHistogramData(double min, double max, const std::vector<size_t>& histogram)
|
||||
{
|
||||
m_min = min;
|
||||
m_max = max;
|
||||
m_histogramData = histogram;
|
||||
|
||||
m_maxHistogramCount = 0;
|
||||
for (size_t colIdx = 0; colIdx < m_histogramData.size(); ++colIdx)
|
||||
{
|
||||
if (m_maxHistogramCount < m_histogramData[colIdx]) m_maxHistogramCount = m_histogramData[colIdx] ;
|
||||
}
|
||||
}
|
||||
37
ApplicationCode/UserInterface/RiuSimpleHistogramWidget.h
Normal file
37
ApplicationCode/UserInterface/RiuSimpleHistogramWidget.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <QWidget>
|
||||
class QPaintEvent;
|
||||
class QString;
|
||||
class QStringList;
|
||||
|
||||
|
||||
class RiuSimpleHistogramWidget : public QWidget
|
||||
{
|
||||
public:
|
||||
RiuSimpleHistogramWidget( QWidget * parent = 0, Qt::WindowFlags f = 0);
|
||||
|
||||
void setHistogramData(double min, double max, const std::vector<size_t>& histogram);
|
||||
void setPercentiles(double pmin, double pmax) {m_minPercentile = pmin; m_maxPercentile = pmax;}
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent* event);
|
||||
|
||||
private:
|
||||
void draw(QPainter *painter,int x, int y, int width, int height );
|
||||
|
||||
int xPosFromColIdx(size_t colIdx) { return (int)(m_x + 1 + (m_width - 2 ) * colIdx/m_histogramData.size());}
|
||||
int yPosFromCount(size_t colHeight) { return (int)(m_y + m_height - 1 - (m_height - 3 ) * colHeight/m_maxHistogramCount);}
|
||||
|
||||
int xPosFromDomainValue(double value) { double range = m_max - m_min; return (range == 0.0) ? (m_x + 1) : (int)(m_x + 1 + (m_width - 2 ) * (value - m_min)/(m_max - m_min));}
|
||||
|
||||
std::vector<size_t> m_histogramData;
|
||||
double m_max;
|
||||
double m_min;
|
||||
double m_minPercentile;
|
||||
double m_maxPercentile;
|
||||
size_t m_maxHistogramCount;
|
||||
|
||||
double m_width;
|
||||
double m_height;
|
||||
double m_x;
|
||||
double m_y;
|
||||
};
|
||||
Reference in New Issue
Block a user